aws-cdk/aws-iam: should check for invalid array in PolicyStatement conditions #25826
Labels
@aws-cdk/aws-iam
Related to AWS Identity and Access Management
effort/small
Small work item – less than a day of effort
feature-request
A feature should be added or improved.
p2
Describe the bug
For some reason, typescript allows an array to be set on
PolicyStatement.conditions
, which is supposed to be an object of type{[key: string]: any}
. This raises no compile errors either in Typescript or CDK and generates an invalid PolicyDocument in the CFN template.Expected Behavior
The broken code should not synth.
Current Behavior
When accidentally passing an array to
PolicyStatement.conditions
, there are no type errors raised (so IDE shows no problem in syntax highlighting) and some invalid CFN is synthed.Reproduction Steps
I had this code:
Which synthed fine and resulted in a CFN template that looks like this:
When applying this template, CFN reports this error:
Possible Solution
I'm really not sure why Typescript doesn't report this as a proper type error, but it might be worth adding something defensive to check that the PolicyStatement condition is actually an object and not an array, and failing the build if the developer puts the wrong thing in (like I did).
Additional Information/Context
No response
CDK CLI Version
2.79.1
Framework Version
No response
Node.js Version
19.1.0
OS
Linux
Language
Typescript
Language Version
4.9.5
Other information
No response
The text was updated successfully, but these errors were encountered: