Skip to content

Commit 8e463fb

Browse files
authored
Add additionalProps false to IAM conditions (#3767)
1 parent 7e514f4 commit 8e463fb

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
]
6969
},
7070
"Condition": {
71+
"additionalProperties": false,
7172
"patternProperties": {
7273
"ForAllValues:^(Not)?IpAddress$": {
7374
"$ref": "#/definitions/ConditionSetValue"

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

+32
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,35 @@ def test_string_statements(self):
162162
errs[1].message, "'2012-10-18' is not one of ['2008-10-17', '2012-10-17']"
163163
)
164164
self.assertListEqual(list(errs[1].path), ["Version"])
165+
166+
def test_string_statements_with_condition(self):
167+
validator = CfnTemplateValidator()
168+
169+
policy = """
170+
{
171+
"Version": "2012-10-17",
172+
"Statement": [
173+
{
174+
"Effect": "Allow",
175+
"Action": "*",
176+
"Resource": "*",
177+
"Condition": {
178+
"iam:PassedToService": "cloudformation.amazonaws.com"
179+
}
180+
}
181+
]
182+
}
183+
"""
184+
185+
errs = list(
186+
self.rule.validate(
187+
validator=validator, policy=policy, schema={}, policy_type=None
188+
)
189+
)
190+
self.assertEqual(len(errs), 1, errs)
191+
self.assertTrue(
192+
errs[0].message.startswith("'iam:PassedToService' does not match")
193+
)
194+
self.assertListEqual(
195+
list(errs[0].path), ["Statement", 0, "Condition", "iam:PassedToService"]
196+
)

0 commit comments

Comments
 (0)