Skip to content

Commit 1a3fab0

Browse files
committed
Add RBAC to action-alias help api.
1 parent b2dad1e commit 1a3fab0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

st2api/st2api/controllers/v1/actionalias.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from st2common import log as logging
2121
from st2common.exceptions.actionalias import ActionAliasAmbiguityException
2222
from st2common.exceptions.apivalidation import ValueValidationException
23+
from st2common.exceptions.rbac import ResourceTypeAccessDeniedError
2324
from st2common.models.api.action import ActionAliasAPI
2425
from st2common.persistence.actionalias import ActionAlias
2526
from st2common.rbac.types import PermissionType
@@ -106,9 +107,27 @@ def help(self, filter, pack, limit, offset, **kwargs):
106107
Handles requests:
107108
GET /actionalias/help
108109
"""
110+
requester_user = kwargs.get("requester_user")
111+
112+
permission_type = PermissionType.ACTION_ALIAS_HELP
113+
rbac_utils = get_rbac_backend().get_utils_class()
114+
109115
try:
110116
aliases_resp = super(ActionAliasController, self)._get_all(**kwargs)
111-
aliases = [ActionAliasAPI(**alias) for alias in aliases_resp.json]
117+
aliases = []
118+
for alias in aliases_resp.json:
119+
try:
120+
rbac_utils.assert_user_has_permission(
121+
user_db=requester_user,
122+
permission_type=permission_type,
123+
)
124+
aliases.append(ActionAliasAPI(**alias))
125+
except ResourceTypeAccessDeniedError as exception:
126+
# Permission denied, don't include in output.
127+
pass
128+
except Exception as exception:
129+
LOG.exception(f"Error processing action-alias.")
130+
112131
return generate_helpstring_result(
113132
aliases, filter, pack, int(limit), int(offset)
114133
)

st2common/st2common/openapi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,11 @@ paths:
806806
description: Object containing the format to be matched.
807807
schema:
808808
$ref: '#/definitions/ActionAliasMatchRequest'
809+
x-parameters:
810+
- name: user
811+
in: context
812+
x-as: requester_user
813+
description: User performing the operation.
809814
responses:
810815
'200':
811816
description: Action alias match pattern
@@ -840,6 +845,11 @@ paths:
840845
description: Number of actions alias to offset
841846
type: integer
842847
default: 0
848+
x-parameters:
849+
- name: user
850+
in: context
851+
x-as: requester_user
852+
description: User performing the operation.
843853
responses:
844854
'200':
845855
description: Action alias match pattern

st2common/st2common/openapi.yaml.j2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,11 @@ paths:
802802
description: Object containing the format to be matched.
803803
schema:
804804
$ref: '#/definitions/ActionAliasMatchRequest'
805+
x-parameters:
806+
- name: user
807+
in: context
808+
x-as: requester_user
809+
description: User performing the operation.
805810
responses:
806811
'200':
807812
description: Action alias match pattern
@@ -836,6 +841,11 @@ paths:
836841
description: Number of actions alias to offset
837842
type: integer
838843
default: 0
844+
x-parameters:
845+
- name: user
846+
in: context
847+
x-as: requester_user
848+
description: User performing the operation.
839849
responses:
840850
'200':
841851
description: Action alias match pattern

0 commit comments

Comments
 (0)