Skip to content

Commit a017a95

Browse files
authored
Update policy condition definitions (#3779)
* Update condition regex patterns
1 parent de28d1e commit a017a95

File tree

3 files changed

+28
-56
lines changed

3 files changed

+28
-56
lines changed

src/cfnlint/data/schemas/other/iam/policy.json

+14-53
Original file line numberDiff line numberDiff line change
@@ -70,76 +70,37 @@
7070
"Condition": {
7171
"additionalProperties": false,
7272
"patternProperties": {
73-
"ForAllValues:^(Not)?IpAddress$": {
74-
"$ref": "#/definitions/ConditionSetValue"
75-
},
76-
"ForAllValues:^Arn(Not)?Equals$": {
77-
"$ref": "#/definitions/ConditionSetValue"
78-
},
79-
"ForAllValues:^Arn(Not)?Like$": {
80-
"$ref": "#/definitions/ConditionSetValue"
81-
},
82-
"ForAllValues:^Date(Not)?Equals$": {
83-
"$ref": "#/definitions/ConditionSetValue"
84-
},
85-
"ForAllValues:^Number(Less|Greater)Than(Equals)?$": {
86-
"$ref": "#/definitions/ConditionSetValue"
87-
},
88-
"ForAllValues:^Number(Not)?Equals$": {
89-
"$ref": "#/definitions/ConditionSetValue"
90-
},
91-
"ForAllValues:^String(Not)?Equals(IgnoreCase)?$": {
92-
"$ref": "#/definitions/ConditionSetValue"
93-
},
94-
"ForAllValues:^String(Not)?Like$": {
95-
"$ref": "#/definitions/ConditionSetValue"
96-
},
97-
"ForAnyValues:^(Not)?IpAddress$": {
98-
"$ref": "#/definitions/ConditionSetValue"
99-
},
100-
"ForAnyValues:^Arn(Not)?Equals$": {
101-
"$ref": "#/definitions/ConditionSetValue"
102-
},
103-
"ForAnyValues:^Arn(Not)?Like$": {
104-
"$ref": "#/definitions/ConditionSetValue"
105-
},
106-
"ForAnyValues:^Date(Not)?Equals$": {
107-
"$ref": "#/definitions/ConditionSetValue"
108-
},
109-
"ForAnyValues:^Number(Less|Greater)Than(Equals)?$": {
110-
"$ref": "#/definitions/ConditionSetValue"
111-
},
112-
"ForAnyValues:^Number(Not)?Equals$": {
113-
"$ref": "#/definitions/ConditionSetValue"
73+
"^(ForAnyValue:|ForAllValues:)?(Not)?IpAddress(Exists)?(IfExists)?$": {
74+
"$ref": "#/definitions/ConditionValue"
11475
},
115-
"ForAnyValues:^String(Not)?Equals(IgnoreCase)?$": {
116-
"$ref": "#/definitions/ConditionSetValue"
76+
"^(ForAnyValue:|ForAllValues:)?Arn(Not)?Equals(Exists)?(IfExists)?$": {
77+
"$ref": "#/definitions/ConditionValue"
11778
},
118-
"ForAnyValues:^String(Not)?Like?$": {
119-
"$ref": "#/definitions/ConditionSetValue"
79+
"^(ForAnyValue:|ForAllValues:)?Arn(Not)?Like(Exists)?(IfExists)?$": {
80+
"$ref": "#/definitions/ConditionValue"
12081
},
121-
"^(Not)?IpAddress(Exists)?$": {
82+
"^(ForAnyValue:|ForAllValues:)?Bool(IfExists)?$": {
12283
"$ref": "#/definitions/ConditionValue"
12384
},
124-
"^Arn(Not)?Equals(Exists)?$": {
85+
"^(ForAnyValue:|ForAllValues:)?Date(Less|Greater)Than(Equals)?(IfExists)?$": {
12586
"$ref": "#/definitions/ConditionValue"
12687
},
127-
"^Arn(Not)?Like(Exists)?$": {
88+
"^(ForAnyValue:|ForAllValues:)?Date(Not)?Equals(IfExists)?$": {
12889
"$ref": "#/definitions/ConditionValue"
12990
},
130-
"^Date(Not)?Equals(Exists)?$": {
91+
"^(ForAnyValue:|ForAllValues:)?Null(IfExists)?$": {
13192
"$ref": "#/definitions/ConditionValue"
13293
},
133-
"^Number(Less|Greater)Than(Equals)?(Exists)?$": {
94+
"^(ForAnyValue:|ForAllValues:)?Numeric(Less|Greater)Than(Equals)?(Exists)?(IfExists)?$": {
13495
"$ref": "#/definitions/ConditionValue"
13596
},
136-
"^Number(Not)?Equals(Exists)?$": {
97+
"^(ForAnyValue:|ForAllValues:)?Numeric(Not)?Equals(Exists)?(IfExists)?$": {
13798
"$ref": "#/definitions/ConditionValue"
13899
},
139-
"^String(Not)?Equals(IgnoreCase)?(Exists)?$": {
100+
"^(ForAnyValue:|ForAllValues:)?String(Not)?Equals(IgnoreCase)?(Exists)?(IfExists)?$": {
140101
"$ref": "#/definitions/ConditionValue"
141102
},
142-
"^String(Not)?Like(Exists)?$": {
103+
"^(ForAnyValue:|ForAllValues:)?String(Not)?Like(Exists)?(IfExists)?$": {
143104
"$ref": "#/definitions/ConditionValue"
144105
}
145106
},

test/unit/rules/resources/iam/test_identity_policy.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,18 @@ def test_string_statements_with_condition(self):
175175
"Action": "*",
176176
"Resource": "*",
177177
"Condition": {
178-
"iam:PassedToService": "cloudformation.amazonaws.com"
178+
"iam:PassedToService": "cloudformation.amazonaws.com",
179+
"StringEquals": {"aws:PrincipalTag/job-category": "iamuser-admin"},
180+
"StringLike": {"s3:prefix": ["", "home/", "home/${aws:username}/"]},
181+
"ArnLike": {"aws:SourceArn": "arn:aws:cloudtrail:*:111122223333:trail/*"},
182+
"NumericLessThanEquals": {"s3:max-keys": "10"},
183+
"DateGreaterThan": {"aws:TokenIssueTime": "2020-01-01T00:00:01Z"},
184+
"Bool": { "aws:SecureTransport": "false"},
185+
"BinaryEquals": { "key" : "QmluYXJ5VmFsdWVJbkJhc2U2NA=="},
186+
"IpAddress": {"aws:SourceIp": "203.0.113.0/24"},
187+
"ArnEquals": {"aws:SourceArn": "arn:aws:sns:REGION:123456789012:TOPIC-ID"},
188+
"StringLikeIfExists": { "ec2:InstanceType": [ "t1.*", "t2.*" ]},
189+
"Null":{"aws:TokenIssueTime":"true"}
179190
}
180191
}
181192
]

test/unit/rules/resources/iam/test_resource_policy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def test_object_multiple_effect(self):
6060
},
6161
"Condition": {
6262
"Null": {
63-
"s3:x-amz-server-side-encryption": [False],
64-
"aws:TagKeys": False,
63+
"s3:x-amz-server-side-encryption": ["false"],
64+
"aws:TagKeys": "false",
6565
}
6666
},
6767
}

0 commit comments

Comments
 (0)