feat(iam): add feature flag to validate PolicyStatement SID is alphanumeric#36150
feat(iam): add feature flag to validate PolicyStatement SID is alphanumeric#36150camerondurham wants to merge 4 commits intoaws:mainfrom
Conversation
|
Will fix later today after work. |
5860098 to
78f1ade
Compare
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
|
|
||||||||||||||
|
|
||||||||||||||
Pull request has been modified.
0f282ac to
f65aa85
Compare
Pull request has been modified.
…umeric - Add IAM_POLICY_STATEMENT_VALIDATE_SID feature flag - Validate SIDs are alphanumeric (A-Z, a-z, 0-9) when flag enabled - Fix invalid SIDs in aws-ecs cluster.ts - Add comprehensive test coverage for SID validation - Add README documentation and integ test Closes aws#34819
f65aa85 to
eae33a5
Compare
Pull request has been modified.
|
Thanks for working on this @camerondurham — catching invalid SIDs at synth time instead of deploy time is a real improvement. I have a suggestion that would simplify this PR significantly by removing the need for a feature flag entirely. The issue I see with the current approachThe validation currently lives in
I suspect the feature flag was introduced because applying the validation universally would break resource policies that legitimately use broader SID characters (your prior PR #34828 had to modify existing integ tests for this reason, if I'm reading the history correctly). If that's the case, there's a simpler path that avoids the flag altogether. Proposed alternative: move validation to
|
|
Great point @alvazjor , that's my bad I missed the SID restriction didn't apply to every type of policy document just the IAM ones. I've moved SID validation to a dedicated function and removed the feature flag. I ran builds / new integ and framework tests but was not able to completely run deploy-mode on changes. This PR should now just be scoped to IAM Identity policies only and the feature flag behavior removed. Let me know if there's any additional feedback, thank you! |
| }); | ||
|
|
||
| expect(statement.validateForIdentityPolicy()).toEqual([ | ||
| "Statement ID (sid) 'Invalid-SID' must be alphanumeric (A-Z, a-z, 0-9) when used in an identity-based policy. See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_sid.html", |
There was a problem hiding this comment.
This URL may change in the future and this would immediately become stale. Should this be removed? Are agents / llms good enough to look up and use latest AWS docs automatically so this is irreleant?
Resolves #34819 by throwing error when PolicyStatement Statement id contains characters not allowed by the API.
Note this does duplicate #34828. I realized that PR makes too many changes to existing integ tests. This change is intended to be less intrusive.
Reference: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_sid.html
Issue # (if applicable)
Closes #34819
Reason for this change
CDK build allows users to write invalid statement ids containing dashes when building policy statements, then failed on deployment. To reduce time to a successful deployment, I believe the CDK should throw an exception at build time to help user make a fix locally before a failed deployment.
Description of changes
Validate that statement id matches requirements specified in https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_sid.html in the constructor.
Add tests that verify only valid statement ids are set in constructor.
Describe any new or updated permissions being added
n/a
Description of how you validated changes
yes, added unit tests
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license