When schedueling execution through API, include user RBAC related
information in action_context.rbac dictionary.
@@ -45,6 +45,7 @@ from st2common.router import Response
from st2common.services import action as action_service
from st2common.services import executions as execution_service
from st2common.services import trace as trace_service
+from st2common.services import rbac as rbac_service
from st2common.util import isotime
from st2common.util import action_db as action_utils
from st2common.util import param as param_utils
@@ -143,6 +144,16 @@ class ActionExecutionsControllerMixin(BaseRestControllerMixin):
raise ValueError('Unable to convert st2-context from the headers into JSON.')
liveaction.context.update(context)
+ # Include RBAC context (if RBAC is available and enabled)
+ if cfg.CONF.rbac.enable:
+ user_db = UserDB(name=user)
+ role_dbs = rbac_service.get_roles_for_user(user_db=user_db, include_remote=True)
+ roles = [role_db.name for role_db in role_dbs]
+ liveaction.context['rbac'] = {
+ 'user': user,
+ 'roles': roles
+ }
+
# Schedule the action execution.
liveaction_db = LiveActionAPI.to_model(liveaction)
liveaction_db, actionexecution_db = action_service.create_request(liveaction_db)
