Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

stm29
Copy link
Contributor

@stm29 stm29 commented Aug 17, 2024

Issue # (if applicable)

Closes #22550

Reason for this change

Description of changes

  • Added addPrincipalsToAssumedBy() function
  • Removed Optional property on assumeRolePolicy (as I guess, it will never be undefined)
  • Changed README.md respectively
  • Added Integration Tests

Description of how you validated changes

  • Unit Tests
  • Integ Tests
  • $ yarn integ --directory test/aws-iam/test --update-on-failed
    

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…principals to TrustRelationship of Role to overcome limitation of grantAssumeRole() (aws#22550)
@aws-cdk-automation aws-cdk-automation requested a review from a team August 17, 2024 09:11
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Aug 17, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a 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.

@stm29 stm29 changed the title fix(aws-iam): Adding addPrincipalsToAssumedBy() to allow adding moreprincipals to TrustRelationship of Role to overcome limitation of grantAssumeRole() (#22550) fix(iam): Adding addPrincipalsToAssumedBy() to allow adding moreprincipals to TrustRelationship of Role to overcome limitation of grantAssumeRole() (#22550) Aug 17, 2024
@stm29 stm29 changed the title fix(iam): Adding addPrincipalsToAssumedBy() to allow adding moreprincipals to TrustRelationship of Role to overcome limitation of grantAssumeRole() (#22550) fix(iam): adding addPrincipalsToAssumedBy() to allow adding moreprincipals to TrustRelationship of Role to overcome limitation of grantAssumeRole() (#22550) Aug 17, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review August 17, 2024 09:42

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 14f0889
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Aug 17, 2024
@shikha372 shikha372 self-assigned this Aug 19, 2024
* 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 {
Copy link
Contributor

@shikha372 shikha372 Aug 19, 2024

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? .

Copy link
Contributor Author

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..

Copy link
Contributor

@shikha372 shikha372 Aug 20, 2024

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')
]);

Copy link
Contributor Author

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,

public grantDecrypt(grantee: iam.IGrantable): iam.Grant {
return this.grant(grantee, ...perms.DECRYPT_ACTIONS);
}

export const DECRYPT_ACTIONS = [
'kms:Decrypt',
];

This just adds kms:Decrypt to the provided Grantee.

@shikha372
Copy link
Contributor

shikha372 commented Aug 19, 2024

Thanks @stm29 for submitting this PR, we're aware of the current limitations of grantAssumeRole method and it is documented in README as well. While we value our community contributions, the functionality that we're trying to add here can easily be done already with role.assumeRole, i don't see how doing the same thing by two different methods could help.

@stm29
Copy link
Contributor Author

stm29 commented Aug 30, 2024

Hi @shikha372 , is there any comments, pending from my end to be addressed?

@shikha372
Copy link
Contributor

Hi @stm29,
Thank you for contributing to this, aligned with team as well that this function is not adding any value to the current usage. Hence, will be closing this PR. If we wish to modify this behaviour, right place to address it could be under assumeRole function where current behaviour is to throw an error.

@shikha372 shikha372 closed this Sep 11, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-iam: Make setting trust on roles more clear in overview and function descriptions
3 participants