Skip to content

Commit dc5c773

Browse files
committed
fixing failing testcases
1 parent a9d959d commit dc5c773

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

policy_sentry/util/arns.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def same_resource_type(self, arn_in_database):
109109

110110
lower_resource_string = list(map(lambda x:x.lower(),split_resource_string_to_test))
111111
for i in non_empty_arn_format_list:
112-
# if i.lower() in [x.lower() for x in split_resource_string_to_test]:
113112
if i.lower() not in lower_resource_string:
114113
return False
115114

@@ -130,20 +129,20 @@ def same_resource_type(self, arn_in_database):
130129

131130
# 4. Special type for S3 bucket objects and CodeCommit repos
132131
# Note: Each service can only have one of these, so these are definitely exceptions
133-
exclusion_list = ["${ObjectName}", "${RepositoryName}", "${BucketName}", "table/${TableName}"]
132+
exclusion_list = ["${ObjectName}", "${RepositoryName}", "${BucketName}", "table/${TableName}", "${BucketName}/${ObjectName}"]
134133
resource_path_arn_in_database = elements[5]
135134
if resource_path_arn_in_database in exclusion_list:
136135
logger.debug("Special type: %s", resource_path_arn_in_database)
137136
# handling special case table/${TableName}
138-
if resource_string_arn_in_database == "table/${TableName}":
137+
if resource_string_arn_in_database in ["table/${TableName}", "${BucketName}"]:
139138
if len(self.resource_string.split('/')) == len(elements[5].split('/')):
140139
return True
141140
else:
142141
return False
143142
# If we've made it this far, then it is a special type
144143
# return True
145144
# Presence of / would mean it's an object in both so it matches
146-
if "/" in self.resource_string and "/" in elements[5]:
145+
elif "/" in self.resource_string and "/" in elements[5]:
147146
return True
148147
# / not being present in either means it's a bucket in both so it matches
149148
elif "/" not in self.resource_string and "/" not in elements[5]:

test/files/test_gh_204_multiple_resource_types_wildcards.json

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"Effect": "Allow",
118118
"Action": [
119119
"rds:AddRoleToDBCluster",
120+
"rds:ApplyPendingMaintenanceAction",
120121
"rds:BacktrackDBCluster",
121122
"rds:CreateDBCluster",
122123
"rds:CreateDBClusterEndpoint",
@@ -361,41 +362,42 @@
361362
"Effect": "Allow",
362363
"Action": [
363364
"rds:DescribeDBClusterBacktracks",
365+
"rds:DescribeDBClusterEndpoints",
364366
"rds:DescribeDBClusters",
365-
"rds:DescribeDBProxyTargets"
367+
"rds:DescribeDBProxyTargets",
368+
"rds:DescribePendingMaintenanceActions"
366369
],
367370
"Resource": [
368371
"arn:aws:rds:us-east-1:123456789012:*:*"
369372
]
370373
},
371374
{
372-
"Sid": "RdsListClusterpg",
375+
"Sid": "RdsListClusterendpoint",
373376
"Effect": "Allow",
374377
"Action": [
375-
"rds:DescribeDBClusterParameterGroups",
376-
"rds:DescribeDBClusterParameters"
378+
"rds:DescribeDBClusterEndpoints"
377379
],
378380
"Resource": [
379381
"arn:aws:rds:us-east-1:123456789012:*:*"
380382
]
381383
},
382384
{
383-
"Sid": "RdsListClustersnapshot",
385+
"Sid": "RdsListClusterpg",
384386
"Effect": "Allow",
385387
"Action": [
386-
"rds:DescribeDBClusterSnapshotAttributes"
388+
"rds:DescribeDBClusterParameterGroups",
389+
"rds:DescribeDBClusterParameters"
387390
],
388391
"Resource": [
389392
"arn:aws:rds:us-east-1:123456789012:*:*"
390393
]
391394
},
392395
{
393-
"Sid": "RdsListPg",
396+
"Sid": "RdsListClustersnapshot",
394397
"Effect": "Allow",
395398
"Action": [
396-
"rds:DescribeDBEngineVersions",
397-
"rds:DescribeDBParameterGroups",
398-
"rds:DescribeDBParameters"
399+
"rds:DescribeDBClusterSnapshotAttributes",
400+
"rds:DescribeDBClusterSnapshots"
399401
],
400402
"Resource": [
401403
"arn:aws:rds:us-east-1:123456789012:*:*"
@@ -405,6 +407,8 @@
405407
"Sid": "RdsListDb",
406408
"Effect": "Allow",
407409
"Action": [
410+
"rds:DescribeDBInstanceAutomatedBackups",
411+
"rds:DescribeDBInstances",
408412
"rds:DescribeDBLogFiles",
409413
"rds:DescribeDBProxyTargets",
410414
"rds:DescribeDBSnapshots",
@@ -415,6 +419,17 @@
415419
"arn:aws:rds:us-east-1:123456789012:*:*"
416420
]
417421
},
422+
{
423+
"Sid": "RdsListPg",
424+
"Effect": "Allow",
425+
"Action": [
426+
"rds:DescribeDBParameterGroups",
427+
"rds:DescribeDBParameters"
428+
],
429+
"Resource": [
430+
"arn:aws:rds:us-east-1:123456789012:*:*"
431+
]
432+
},
418433
{
419434
"Sid": "RdsListProxy",
420435
"Effect": "Allow",
@@ -478,6 +493,16 @@
478493
"arn:aws:rds:us-east-1:123456789012:*:*"
479494
]
480495
},
496+
{
497+
"Sid": "RdsListGlobalcluster",
498+
"Effect": "Allow",
499+
"Action": [
500+
"rds:DescribeGlobalClusters"
501+
],
502+
"Resource": [
503+
"arn:aws:rds:us-east-1:123456789012:*:*"
504+
]
505+
},
481506
{
482507
"Sid": "RdsListOg",
483508
"Effect": "Allow",

0 commit comments

Comments
 (0)