Skip to content

feat: expand capability of '*' querying action table #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion policy_sentry/querying/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ def get_action_data(service: str, action_name: str) -> dict[str, list[dict[str,
action_data_results = {}
try:
service_prefix_data = get_service_prefix_data(service)
if action_name == "*":
if action_name.endswith("*"):
stripped_action_name = action_name.removesuffix("*")
results = []
for this_action_name, this_action_data in service_prefix_data["privileges"].items():
if not this_action_name.startswith(stripped_action_name):
continue
if this_action_data:
entries = create_action_data_entries(
service_prefix_data=service_prefix_data,
Expand Down
27 changes: 27 additions & 0 deletions test/querying/test_query_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,33 @@ def test_get_action_data(self):
self.maxDiff = None
self.assertDictEqual(desired_output, output)

def test_get_action_data_with_glob(self):
"""Query action-table with glob."""
desired_output = {
"sns": [
{
"action": "sns:ListSubscriptions",
"description": "Grants permission to return a list of the requester's subscriptions",
"access_level": "List",
"api_documentation_link": "https://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptions.html",
"resource_arn_format": "*",
"condition_keys": [],
"dependent_actions": [],
},
{
"action": "sns:ListSubscriptionsByTopic",
"description": "Grants permission to return a list of the subscriptions to a specific topic",
"access_level": "List",
"api_documentation_link": "https://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptionsByTopic.html",
"resource_arn_format": "arn:${Partition}:sns:${Region}:${Account}:${TopicName}",
"condition_keys": ["aws:ResourceTag/${TagKey}"],
"dependent_actions": [],
},
]
}
results = get_action_data("sns", "ListSubscriptions*")
self.assertDictEqual(desired_output, results)

def test_get_actions_that_support_wildcard_arns_only(self):
"""querying.actions.get_actions_that_support_wildcard_arns_only"""
# Variant 1: Secrets manager
Expand Down