-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(agentcore): addToRolePolicy for runtime with imported role destroys and recreates policies on every deployment
#35842
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
Conversation
addToRolePolicy for Runtime recreates policies on every deployment with imported rolesaddToRolePolicy for Runtime destroys and recreates policies on every deployment with imported roles
addToRolePolicy for Runtime destroys and recreates policies on every deployment with imported rolesaddToRolePolicy for Runtime with imported roles destroys and recreates policies on every deployment
addToRolePolicy for Runtime with imported roles destroys and recreates policies on every deploymentaddToRolePolicy for Runtime with imported role destroys and recreates policies on every deployment
addToRolePolicy for Runtime with imported role destroys and recreates policies on every deploymentaddToRolePolicy for runtime with imported role destroys and recreates policies on every deployment
addToRolePolicy for runtime with imported role destroys and recreates policies on every deploymentaddToRolePolicy for Runtime with imported role destroys and recreates policies on every deployment
addToRolePolicy for Runtime with imported role destroys and recreates policies on every deploymentaddToRolePolicy for runtime with imported role destroys and recreates policies on every deployment
dineshSajwan
left a comment
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 @go-to-k .
LGTM.
| const policy = new iam.Policy(this, `CustomPolicy${this._policyCounter++}`, { | ||
| statements: [statement], | ||
| }); | ||
| this.role.attachInlinePolicy(policy); |
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.
There is no need to create a new Policyobject, just use addtoPrincipalPolicy()
| this.role.attachInlinePolicy(policy); | |
| this.role.addToPrincipalPolicy(statement); |
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.
Summarized it like this. Many other Constructs are done this way. How about it?
public addToRolePolicy(statement: iam.PolicyStatement): IBedrockAgentRuntime {
- // Check if role is a concrete Role instance
- if (this.role instanceof iam.Role) {
- this.role.addToPolicy(statement);
- } else {
- // For imported roles (IRole), we need to attach via a new policy
- const policy = new iam.Policy(this, `CustomPolicy${Date.now()}`, {
- statements: [statement],
- });
- this.role.attachInlinePolicy(policy);
- }
+ this.role.addToPrincipalPolicy(statement);
return this;
}Pull request has been modified.
e72f80e to
ef4b0c0
Compare
Abogical
left a comment
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.
Thanks! I have asked for a security review for this.
|
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 update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. |
Pull request has been modified.
|
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). |
|
@Mergifyio rebase |
✅ Branch has been successfully rebased |
9e2cd39 to
63fe336
Compare
|
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). |
|
@Mergifyio update |
✅ Branch has been successfully updated |
|
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). |
|
@Mergifyio update |
☑️ Nothing to do, the required conditions are not met
|
|
@Mergifyio requeue |
✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically |
|
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #35844
Reason for this change
The current
addToRolePolicyfor Runtime with imported role destroys and recreates policies on every deployment.The reason is that
Date.now()is used for a construct ID of a new Policy in the situation:https://github.com/aws/aws-cdk/blob/v2.221.0/packages/%40aws-cdk/aws-bedrock-agentcore-alpha/agentcore/runtime/runtime-base.ts#L253
Reproduction
Deploy or diff the stack with the same CDK code again.
The change will occur:
Description of changes
Use
addToPrincipalPolicydirectly instead.Describe any new or updated permissions being added
Description of how you validated changes
Both unit tests and an integ test.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license