Skip to content

Fix Excluded Actions #353

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
Apr 7, 2021
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: 5 additions & 0 deletions examples/yml/crud-with-exclude-actions-empty-sid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mode: crud
write:
- arn:aws:s3:::test
exclude-actions:
- "iam:Pass*"
3 changes: 3 additions & 0 deletions policy_sentry/writing/sid_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def get_rendered_policy(self, minimize=None):
else:
actions = temp_actions
# temp_actions.clear()
# Check if SID is empty of actions. Continue if yes.
if not actions:
continue
match_found = False
if minimize is not None and isinstance(minimize, int):
logger.debug("Minimizing statements...")
Expand Down
66 changes: 66 additions & 0 deletions test/writing/test_sid_group_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,69 @@ def test_exclude_actions_from_crud_output(self):
]
}
self.assertDictEqual(results, expected_result)


def test_exclude_actions_empty_sid_from_crud_output(self):
sid_group = SidGroup()
crud_with_exclude_actions_empty_sid = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.path.pardir,
os.path.pardir,
"examples",
"yml",
"crud-with-exclude-actions-empty-sid.yml",
)
)

with open(crud_with_exclude_actions_empty_sid, "r") as this_yaml_file:
crud_with_exclude_actions_empty_sid_cfg = yaml.safe_load(this_yaml_file)
# crud_with_exclude_actions_empty_sid_cfg = {
# "mode": "crud",
# "write": [
# "arn:aws:s3:::test"
# ],
# "exclude-actions": [
# "iam:Pass*"
# ]
# }

# print(json.dumps(crud_with_exclude_actions_empty_sid_cfg, indent=4))
sid_group.process_template(crud_with_exclude_actions_empty_sid_cfg)
result = sid_group.get_rendered_policy(crud_with_exclude_actions_empty_sid_cfg)
# print(json.dumps(result, indent=4))
expected_result = {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3WriteBucket",
"Effect": "Allow",
"Action": [
"s3:CreateBucket",
"s3:DeleteBucket",
"s3:DeleteBucketOwnershipControls",
"s3:DeleteBucketWebsite",
"s3:PutAccelerateConfiguration",
"s3:PutAnalyticsConfiguration",
"s3:PutBucketCORS",
"s3:PutBucketLogging",
"s3:PutBucketNotification",
"s3:PutBucketObjectLockConfiguration",
"s3:PutBucketOwnershipControls",
"s3:PutBucketRequestPayment",
"s3:PutBucketVersioning",
"s3:PutBucketWebsite",
"s3:PutEncryptionConfiguration",
"s3:PutIntelligentTieringConfiguration",
"s3:PutInventoryConfiguration",
"s3:PutLifecycleConfiguration",
"s3:PutMetricsConfiguration",
"s3:PutReplicationConfiguration"
],
"Resource": [
"arn:aws:s3:::test"
]
}
]
}
self.assertDictEqual(result, expected_result)