-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(agentcore): custom execution role policy for runtime lacks proper permissions #35849
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
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 for the PR @go-to-k . Looks all good to me.
|
@go-to-k
In case of an imported/referenced role(i.e the one not created by the cdk app where runtime is being created), these operation will not have any effect as the referenced copy of a role is merely a read-only version of it. My suggestion would be to use the result of the |
...aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/runtime/integ.runtime-with-custom-role.ts
Show resolved
Hide resolved
packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/runtime/runtime.test.ts
Show resolved
Hide resolved
No, that's not the case for IAM roles. Even for imported IAM roles, a new policy resource ( const imported = iam.Role.fromRoleArn(this, 'ImportedRole', 'arn:aws:iam::123456789012:role/ExistingExecutionRole');
imported.addToPrincipalPolicy(new iam.PolicyStatement({
actions: ['s3:GetObject'],
resources: ['arn:aws:s3:::my-bucket/my-object'],
})); "Resources": {
"ImportedRolePolicyawscdkbedrockagentcoreruntimewithimportedroleImportedRole261507D78EB91FCC": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": "s3:GetObject",
"Effect": "Allow",
"Resource": "arn:aws:s3:::my-bucket/my-object"
}
],
"Version": "2012-10-17"
},
"PolicyName": "PolicyawscdkbedrockagentcoreruntimewithimportedroleImportedRole261507D7",
"Roles": [
"ExistingExecutionRole"
]
}
}
}, |
|
I'll check the rest of the comments later :) |
|
@go-to-k Thanks for the explanation : #35849 (comment) I see that there are a couple of configurable params while importing a role, (options) In that case the suggestion here can help us inform the users earlier(during synth/compile) if the policy additions were not successful.
I am not sure of all the patterns to reference roles and adding this check would be our way to ensure the behaviour is visible to the user (atleast via logs) Edited the comment |
packages/@aws-cdk/aws-bedrock-agentcore-alpha/test/agentcore/runtime/runtime.test.ts
Show resolved
Hide resolved
|
to: #35849
The user has explicitly specified While it's useful to provide warnings when something doesn't happen as expected, I don't think there's a need to output Annotations when things are working exactly as intended. If such a notification is necessary, shouldn't it be provided by the Role construct itself rather than in the Agentcore Runtime? (It also doesn't seem like this kind of thing is commonly done in constructs of other modules)
Also, even if the role is immutable and the |
|
For comment : #35849 (comment)
I agree. My point was to output a log line(not an Annotation based warning) for user to inform them regardless of whether the permission are added to the user's custom role or not. When a user deploys the AgentCoreRuntime resources via CDK they will see the role changes during Example how
In a big enough code-base a user doing incremental changes might not have context around how a specific role is generated(created within the app or reference via the |
Isn't that code used in the provider-framework's custom resource Lambda, rather than in the CDK App (constructs) itself?
My understanding is that all constructs run within the CDK App, and the CDK App runs as a subprocess of the CDK CLI. Therefore, I think,
As seen here, Also, this just relates to IAM role permissions. If permissions are added to an IAM role, a list of the policies being granted will be output to the user's terminal based on ref: |
|
@go-to-k
For below, yes my idea was to give users visibility on why a certain role/permission addition they see during
|
|
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. |
|
Thanks for your approval and the all comments! |
|
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 requeue |
✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically |
|
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). |
|
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). |
|
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #35852 .
Reason for this change
ECR permissions are attached even when the role is a custom role or an imported role. (https://github.com/aws/aws-cdk/blob/v2.221.0/packages/%40aws-cdk/aws-bedrock-agentcore-alpha/agentcore/runtime/runtime-artifact.ts#L65)
However, the other required permissions are only granted to a policy for an auto-generated role. (https://github.com/aws/aws-cdk/blob/v2.221.0/packages/%40aws-cdk/aws-bedrock-agentcore-alpha/agentcore/runtime/runtime.ts#L252-L259)
In constructs of other common modules, permissions are attached even when a custom role is passed.
So this PR adds the permissions to the custom role.
FYI: If you avoid to add the permissions to the custom role, you can use
withoutPolicyUpdates()method for Role.Description of changes
Add the permissions to the custom role.
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