-
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
fix(iam): Role.addManagedPolicy()
does not work for imported roles IRole
#8307
#31212
Conversation
…ill result in IRole used with IManagedPolicy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes seem reasonable to me.
Can I get one more community review? |
Communicated in #contributing channel. waiting for one more community review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix! I left some comments :)
packages/aws-cdk-lib/aws-s3/lib/notifications-resource/notifications-resource-handler.ts
Outdated
Show resolved
Hide resolved
policy.attachToRole(this); | ||
} catch (e) { | ||
if (e instanceof Error && e.message === 'policy.attachToRole is not a function') { | ||
throw new Error('Can\'t Combine IRole with IManagedPolicy. use ManagedPolicy directly.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an error from this function is also a breaking change. Can we just add a warning as the previous behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packages/aws-cdk-lib/aws-s3/lib/notifications-resource/notifications-resource-handler.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk-lib/aws-s3/lib/notifications-resource/notifications-resource-handler.ts
Outdated
Show resolved
Hide resolved
Role.addManagedPolicy()
does not work for imported roles #8307Role.addManagedPolicy()
does not work for imported roles IRole
#8307
} else { | ||
Annotations.of(this).addWarningV2( | ||
'@aws-cdk/aws-iam:IRoleCantBeUsedWithIManagedPolicy', | ||
'Can\'t combine IRole with IManagedPolicy. Use ManagedPolicy directly.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add more information like ${policy.managedPolicyArn} to imported role: ${this.roleName}
as in the original code to make it clearer why and where the warning is emitted. So that we do not have to add another warning from a caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected with One Common message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
packages/aws-cdk-lib/aws-s3/lib/notifications-resource/notifications-resource-handler.ts
Outdated
Show resolved
Hide resolved
Hi @stm29 thanks for your contribution! Reading through the changes, I'm trying to understand the nature of the changes being made. The PR description mentions you're adding functionality to I also did some digging through the rest of the codebase, and it seems like some of the other extensions of public addManagedPolicy(policy: IManagedPolicy): void {
this.managedPolicies.push(policy);
} Would a change like this work instead of the more complex logic? It also looks like the changes in the S3 notifications resource are minor, so I would agree that moving that change to another PR and opening a separate issue would be best, as long as the tests that currently exist for it still pass with this change. Though I'm not quite sure what the issue is in this case. It seems like a few other libraries already call on the |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #31212 +/- ##
=======================================
Coverage 78.67% 78.67%
=======================================
Files 107 107
Lines 7237 7237
Branches 1329 1329
=======================================
Hits 5694 5694
Misses 1357 1357
Partials 186 186
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@Leo10Gama , Thanks for the review.
Updated this with correct
Indeed Logic is simple, following is the working Logic which adds Policy to the Role. and this is same as how other Implementations are already in place.
Other
Sorry for the confusion, There is no change in Quick Question: Should we need to add Unit Tests in all the possible occurrence of IManagedPolicy with IRole, or Just UnitTests in |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This pull request has been removed from the queue for the following reason: The pull request can't be updated. You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. If you want to requeue this pull request, you need to post a comment with the text: |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue #8307
Closes #8307
Reason for this change
Description of changes
IRole
is used withIManagedPolicy
, due to constrainsApproaches decided
aws-cdk/packages/aws-cdk-lib/aws-iam/lib/identity-base.ts
Lines 17 to 21 in 823ff6e
This PR Implements follows,
IRole
is used withIManagedPolicy
.Description of how you validated changes
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license