Skip to content

Commit 8ed4857

Browse files
committed
skip placeholder for service names and match catalog with servicecatalog
1 parent 21be907 commit 8ed4857

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

policy_sentry/shared/iam_data.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ def get_service_prefix_data(service_prefix: str) -> dict[str, Any]:
4545
List: A list of metadata about that service
4646
"""
4747
try:
48-
return cast("dict[str, Any]", iam_definition.get(service_prefix, {}))
48+
return cast("dict[str, Any]", iam_definition[service_prefix])
4949
# pylint: disable=bare-except, inconsistent-return-statements
5050
except:
51+
if service_prefix == "catalog":
52+
# the resource types "Portfolio" and "Product" have the service name "catalog" in their ARN
53+
# https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsservicecatalog.html#awsservicecatalog-resources-for-iam-policies
54+
return cast("dict[str, Any]", iam_definition["servicecatalog"])
55+
5156
logger.info(f"Service prefix not {service_prefix} found.")
5257
return {}

policy_sentry/writing/sid_group.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ def add_by_arn_and_access_level(
320320
"""
321321
for arn in arn_list:
322322
service_prefix = get_service_from_arn(arn)
323+
if "$" in service_prefix:
324+
logger.debug(
325+
f"Not supported service {service_prefix} found in ARN {arn}"
326+
)
327+
continue
328+
323329
service_action_data = get_action_data(service_prefix, "*")
324330
for service_prefix, action_data in service_action_data.items():
325331
for row in action_data:

test/writing/test_sid_group_crud.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ def test_resource_restriction_plus_dependent_action_simple_2(self):
297297
# print(json.dumps(output, indent=4))
298298
self.assertDictEqual(output, desired_output)
299299

300+
def test_add_by_arn_and_access_level_ignores_placeholder_services(self):
301+
# https://github.com/salesforce/policy_sentry/issues/448
302+
303+
sid_group = SidGroup()
304+
sid_group.add_by_arn_and_access_level(
305+
["arn:${Partition}:${Vendor}:${Region}:*:${ResourceType}:${RecoveryPointId}"], "Read"
306+
)
307+
308+
self.assertTrue(not sid_group.sids)
309+
300310
def test_add_by_list_of_actions(self):
301311
actions_test_data_1 = ["kms:CreateCustomKeyStore", "kms:CreateGrant"]
302312
sid_group = SidGroup()

0 commit comments

Comments
 (0)