-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(aws-iam): policy document optimization #14713
Comments
I implemented this in #14714 |
Leaving this open for future upvotes which may increase the weight, but we consciously decided not to do anything about this. IAM policy optimization is attractive but also dangerous, and we're super scared of messing up. If you want to implement this for now, I would suggest you implement an Aspect to twiddle the construct tree out-of-band. |
@rix0rrr wondering if you saw my comment just above you? The PR received no comments. |
The absence of this results in AWS CodePipelines being unusable for cross-region deployments in many cases. See #16244 for more details. |
I think this has been resolved by #19114 |
|
I wonder if this is an acceptable feature request. If so, I could try submitting a PR myself.
aws-iam
currently creates sub-optimal policies that could be pretty easily optimized. For example consider a helper method that runs this on an ECR repository:If
policy
is a "shared" policy, and the stack adds new ECR repositories over time, this construct will very quickly run into #11562.The optimization would be that instead of creating duplicate statements with the same actions for every separate resource, it could just create one policy statement and merge all the resources together.
For example, it would be the equivalent of adding just one policy of:
Note that I'm aware that new resources could be added to the
PolicyStatement
instead of adding new statements to the policy, but this results in a lot of extra complexity in the stack's implementation, and I feel that cdk could do an optimization here instead.Additionally, there are places like:
aws-cdk/packages/@aws-cdk/aws-iam/lib/role.ts
Lines 241 to 246 in 7966f8d
Use Case
The main issue is that the resulting CloudFormation template ends up huge, and runs over some internal limits as mentioned in #11562 (comment) and #11562 (comment)
Proposed Solution
My initial idea is to add a post-processor similar to the one in:
aws-cdk/packages/@aws-cdk/aws-iam/lib/policy-document.ts
Line 55 in 7966f8d
It would detect if the generated policy can be optimized by merging similar resources or actions together.
Other
I think this shouldn't be a breaking change if implemented correctly. Also I'm not sure if it requires any changes, or if it affects the
IAM Statement Changes
interactive prompt.This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: