Skip to content

Commit 5d4d605

Browse files
authored
Merge pull request #353 from KReg27/fix-exclude-actions
Fix Excluded Actions
2 parents 3e8a209 + 164184b commit 5d4d605

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mode: crud
2+
write:
3+
- arn:aws:s3:::test
4+
exclude-actions:
5+
- "iam:Pass*"

policy_sentry/writing/sid_group.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ def get_rendered_policy(self, minimize=None):
174174
else:
175175
actions = temp_actions
176176
# temp_actions.clear()
177+
# Check if SID is empty of actions. Continue if yes.
178+
if not actions:
179+
continue
177180
match_found = False
178181
if minimize is not None and isinstance(minimize, int):
179182
logger.debug("Minimizing statements...")

test/writing/test_sid_group_crud.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,69 @@ def test_exclude_actions_from_crud_output(self):
593593
]
594594
}
595595
self.assertDictEqual(results, expected_result)
596+
597+
598+
def test_exclude_actions_empty_sid_from_crud_output(self):
599+
sid_group = SidGroup()
600+
crud_with_exclude_actions_empty_sid = os.path.abspath(
601+
os.path.join(
602+
os.path.dirname(__file__),
603+
os.path.pardir,
604+
os.path.pardir,
605+
"examples",
606+
"yml",
607+
"crud-with-exclude-actions-empty-sid.yml",
608+
)
609+
)
610+
611+
with open(crud_with_exclude_actions_empty_sid, "r") as this_yaml_file:
612+
crud_with_exclude_actions_empty_sid_cfg = yaml.safe_load(this_yaml_file)
613+
# crud_with_exclude_actions_empty_sid_cfg = {
614+
# "mode": "crud",
615+
# "write": [
616+
# "arn:aws:s3:::test"
617+
# ],
618+
# "exclude-actions": [
619+
# "iam:Pass*"
620+
# ]
621+
# }
622+
623+
# print(json.dumps(crud_with_exclude_actions_empty_sid_cfg, indent=4))
624+
sid_group.process_template(crud_with_exclude_actions_empty_sid_cfg)
625+
result = sid_group.get_rendered_policy(crud_with_exclude_actions_empty_sid_cfg)
626+
# print(json.dumps(result, indent=4))
627+
expected_result = {
628+
"Version": "2012-10-17",
629+
"Statement": [
630+
{
631+
"Sid": "S3WriteBucket",
632+
"Effect": "Allow",
633+
"Action": [
634+
"s3:CreateBucket",
635+
"s3:DeleteBucket",
636+
"s3:DeleteBucketOwnershipControls",
637+
"s3:DeleteBucketWebsite",
638+
"s3:PutAccelerateConfiguration",
639+
"s3:PutAnalyticsConfiguration",
640+
"s3:PutBucketCORS",
641+
"s3:PutBucketLogging",
642+
"s3:PutBucketNotification",
643+
"s3:PutBucketObjectLockConfiguration",
644+
"s3:PutBucketOwnershipControls",
645+
"s3:PutBucketRequestPayment",
646+
"s3:PutBucketVersioning",
647+
"s3:PutBucketWebsite",
648+
"s3:PutEncryptionConfiguration",
649+
"s3:PutIntelligentTieringConfiguration",
650+
"s3:PutInventoryConfiguration",
651+
"s3:PutLifecycleConfiguration",
652+
"s3:PutMetricsConfiguration",
653+
"s3:PutReplicationConfiguration"
654+
],
655+
"Resource": [
656+
"arn:aws:s3:::test"
657+
]
658+
}
659+
]
660+
}
661+
self.assertDictEqual(result, expected_result)

0 commit comments

Comments
 (0)