-
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
Role.addManagedPolicy does not work for imported roles #8307
Comments
It looks like addManagedPolicy is not implemented... https://github.com/aws/aws-cdk/blob/v1.42.1/packages/@aws-cdk/aws-iam/lib/role.ts#L216 Is there a way that this can be clearly stated in documentation? |
We can certainly add that to the documentation. |
Could this be resolved by changing addManagedPolicy to take a I feel like this could fit in with the design guidelines - "It's okay to enable multiple ways to achieve the same thing, in order to make it more natural for users who come from different mental models", even though it technically violates [awslint:ref-via-interface]. Also the |
Just run into this bug, trying to configure some policies for roles managed outside of cdk app 😢 |
Same here, this is really unfortunate. It fails silently and doesn't attach anything. |
We just hit this issue. Especially surprising that even a warning is not getting printed. https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/aws-iam/lib/role.ts#L227 |
The workaround I found is below. It's not perfect, but it's pretty good:
Example
|
I know this issue has been open for some time now. Is there a fix team is working on ?. I have a use case where I want to create roles and policies separately and then associate them later using Role.addManagedPolicy. The only way right now is to attach the policy to the role to policy during the role creation itself (using managed_policies) which is not ideal. |
This is still wrong in the documentation when importing an existing role. One can set a
Which is untrue. You may only modify the role by adding inline policies. Not managed policies. |
the function addManagedPolicy for ImportedRole only adds a warning the warning isn't even really shown to the user, it just prints
Is there any other way to add an AWS Managed Policy to an Imported Role? |
@jayhilden's solution could work, even if it requires to copy&paste the statements from a Managed Policy to a new one (handled by us). |
It would be nice to have this solved, in the meantime a solution like this works:
|
This shouldn't be marked as documentation issue, it rather should just be implemented - I don't see anything wrong in idea of adding managed policies to the imported role (for example to the auto-generated service roles). |
As a workaround, you can use an AwsCustomResource to attach a managed policy to a role:
|
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
Inconsistent Behavior: aws_iam.Role.attachManagedPolicy vs aws_iam.ManagedPolicy.attachToRole
The Scenario
TLDR; aws_iam.Role.attachManagedPolicy does not attach the specified managed policy to the role, aws_iam.ManagedPolicy.attachToRole does.
I have two stacks: one stack deploys roles another deploys an application stack (both are in the same account). The roles stack is deployed first.
In the application stack, I would like to attach a managed policy to a role in the first.
Attempting to use aws_iam.Role.attachManagedPolicy does not create the association but aws_iam.ManagedPolicy.attachToRole does.
Environment
Other information
Steps to reproduce
Observed
Expected
The text was updated successfully, but these errors were encountered: