-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(iam):
Role.addManagedPolicy()
does not work for imported roles …
…`IRole` #8307 (#31212) ### Issue #8307 Closes #8307 ### Reason for this change - This addManagedPolicy() just does nothing, neither throws warning nor fails. ### Description of changes - This implements **addManagedPolicy()** for **ImportedRole** - This throws Error, when `IRole` is used with `IManagedPolicy`, due to constrains ### Approaches decided - we can't change **addManagedPolicy(policy: IManagedPolicy)** to **addManagedPolicy(policy: ManagedPolicy)** (i.e., to ManagedPolicy) , like how **attachInlinePolicy(policy: Policy)**, it will break for almost many customers. - https://github.com/aws/aws-cdk/blob/823ff6e03899f790a4cb1c43f92a02cc906ac356/packages/aws-cdk-lib/aws-iam/lib/identity-base.ts#L17-L21 - So, we need to handle this gracefully when accepting only **ManagedPolicy**. - We can't use IRole & IManagedPolicy to do the work at the same time, so we need to allow ManagedPolicy in params, and throw Error when IManagedPolicy is being sent, because of how **attachToRole()** will be used by **addManagedPolicy()** - #### This PR Implements follows, - enables **addManagedPolicy()** - Accepts **ManagedPolicy** - Throws understandable Error, when `IRole` is used with `IManagedPolicy`. ### Description of how you validated changes - unit & integration tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --------- Co-authored-by: paulhcsun <[email protected]> Co-authored-by: GZ <[email protected]>
- Loading branch information
1 parent
f4c19c7
commit c78ef1b
Showing
17 changed files
with
24,662 additions
and
54,758 deletions.
There are no files selected for viewing
12 changes: 6 additions & 6 deletions
12
.../test/aws-iam/test/integ.imported-role.js.snapshot/ImportedRoleTestAssertions.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.