Skip to content

Commit 781a03d

Browse files
committed
RBAC for action-alias help changelog entry.
1 parent 1a3fab0 commit 781a03d

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Fixed
1313
* Bumped `paramiko` to `2.10.5` to fix an issue with SSH Certs - https://github.com/paramiko/paramiko/issues/2017
1414
Contributed by @jk464
1515

16+
* Added RBAC support to action-alias help end point. #6022
17+
Contributed by @nzlosh
18+
1619
Added
1720
~~~~~
1821
* Move `git clone` to `user_home/.st2packs` #5845

st2api/st2api/controllers/v1/actionalias.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
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
2423
from st2common.models.api.action import ActionAliasAPI
2524
from st2common.persistence.actionalias import ActionAlias
2625
from st2common.rbac.types import PermissionType
@@ -75,13 +74,22 @@ def get_one(self, ref_or_id, requester_user):
7574
ref_or_id, requester_user=requester_user, permission_type=permission_type
7675
)
7776

78-
def match(self, action_alias_match_api):
77+
def match(self, action_alias_match_api, requester_user=None):
7978
"""
8079
Find a matching action alias.
8180
8281
Handles requests:
8382
POST /actionalias/match
8483
"""
84+
85+
permission_type = PermissionType.ACTION_ALIAS_MATCH
86+
rbac_utils = get_rbac_backend().get_utils_class()
87+
88+
rbac_utils.assert_user_has_permission(
89+
user_db=requester_user,
90+
permission_type=permission_type,
91+
)
92+
8593
command = action_alias_match_api.command
8694

8795
try:
@@ -111,32 +119,23 @@ def help(self, filter, pack, limit, offset, **kwargs):
111119

112120
permission_type = PermissionType.ACTION_ALIAS_HELP
113121
rbac_utils = get_rbac_backend().get_utils_class()
114-
122+
rbac_utils.assert_user_has_permission(
123+
user_db=requester_user,
124+
permission_type=permission_type,
125+
)
115126
try:
116127
aliases_resp = super(ActionAliasController, self)._get_all(**kwargs)
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.")
128+
aliases = [ActionAliasAPI(**alias) for alias in aliases_resp.json]
130129

131130
return generate_helpstring_result(
132131
aliases, filter, pack, int(limit), int(offset)
133132
)
134-
except (TypeError) as e:
133+
except TypeError as exception_type:
135134
LOG.exception(
136135
"Helpstring request contains an invalid data type: %s.",
137-
six.text_type(e),
136+
six.text_type(exception_type),
138137
)
139-
return abort(http_client.BAD_REQUEST, six.text_type(e))
138+
return abort(http_client.BAD_REQUEST, six.text_type(exception_type))
140139

141140
def post(self, action_alias, requester_user):
142141
"""

0 commit comments

Comments
 (0)