-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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): adding addPrincipalsToAssumedBy() to allow adding moreprincipals to TrustRelationship of Role to overcome limitation of grantAssumeRole() (#22550) #31135
Conversation
…principals to TrustRelationship of Role to overcome limitation of grantAssumeRole() (aws#22550)
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.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
* More Details on how grantAssumeRole() doesn't adds principals to trust relationship on below issue: | ||
* https://github.com/aws/aws-cdk/issues/22550#issuecomment-1283095003 | ||
*/ | ||
public addPrincipalsToAssumedBy(principals: IPrincipal[]): void { |
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.
i think we can do it currently with the help of role.assumeRolePolicy?
.
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.
Correct, but I personally fell rather than relying role.assumeRolePolicy, it is better to have similar function like grant()
, grantAssume()
. Having function of similar kind addPrincipalsToAssumedBy() to give better helper value to users (though it is documented well).
Consider this following scenario, grant()
is sufficient enough to add a PolicyDocument, but we do have helper functions like grantSendMessage() for sqs
, grantEncryptDepcrypt() for kms
to service for specific purposes right?, so this will also serve similar value is my thought.
Would like you hear from you..
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.
grant methods are encapsulation for policy statements, i don't think we're encapsulating any policies here(just the assume role), we are using the same object and just modifying it in the function, i'll put this into perspective with the help of dx to make it more clear and to be sure i'm not missing something here:
Current method:
role.assumeRolePolicy?.addStatements(new iam.PolicyStatement({
actions: ['sts:AssumeRole'],
principals: [
new iam.AccountPrincipal('123456789'),
new iam.ServicePrincipal('beep-boop.amazonaws.com')
],
}));
Proposed:
role.addPrincipalsToAssumedBy([
new iam.AccountPrincipal('123456789012'),
new iam.ServicePrincipal('beep-boop.amazonaws.com')
]);
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.
Exactly, you got my point. that sts:AssumeRole is the one i am talking about in terms of easing usage of utilities.
For Example see here how it is used in other utility functions in current scenario,
aws-cdk/packages/aws-cdk-lib/aws-kms/lib/key.ts
Lines 201 to 203 in 975df1f
public grantDecrypt(grantee: iam.IGrantable): iam.Grant { | |
return this.grant(grantee, ...perms.DECRYPT_ACTIONS); | |
} |
aws-cdk/packages/aws-cdk-lib/aws-kms/lib/private/perms.ts
Lines 26 to 28 in 975df1f
export const DECRYPT_ACTIONS = [ | |
'kms:Decrypt', | |
]; |
This just adds kms:Decrypt
to the provided Grantee
.
Thanks @stm29 for submitting this PR, we're aware of the current limitations of |
Hi @shikha372 , is there any comments, pending from my end to be addressed? |
Hi @stm29, |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #22550
Reason for this change
assumeRolePolicy
property of aRole
to add more trust relationships to a role, asgrantAssumeRole()
has a limitation mentioned in aws-iam: Make setting trust on roles more clear in overview and function descriptions #22550 (comment)assumeRolePolicy
inREADME.md
ArnPrincipal()
using grantAssumeRole(), (Doing this does nothing) as mentioned on below issues,Description of changes
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