question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CLI supports assuming a different role locally via --assume-role-arn

See original GitHub issue

To add a new command line flag --assume-role-arn [role-arn] which will assume the given role locally before executing any commands.

This should be semantically equivalent to setting the following configuration when using the aws-sdk:

AWS.config.credentials = new AWS.ChainableTemporaryCredentials({
  params: {RoleArn: '...'}
});

It would be expected to work with all variations of --ec2creds.

Use Case

Sometimes the current credentials are not enough to execute CDK. This is different from --role-arn which happens on ChangeSet execution. However CDK needs to do things before that (e.g. uploading assets).

This is also supported by the aws-cli via profiles, which proves the use case. However working with cli profiles from the JavaScript world is painful (even though support got better) and is more complicated to automate in CI/CD environments.

Terraform has a similar option: https://www.terraform.io/docs/providers/aws/index.html#assume_role

Proposed Solution

See above. We need a new cli flag. Somewhere in aws-auth the value would need to be passed in to ChainableTemporaryCredentials which would be used to configure the SDK.

  • [x ] 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
danwashusencommented, Sep 21, 2021

For anyone else trying to plug CDK into an automated build environment, here’s my solution:

    - ASSUMED_FOLE=$(aws sts assume-role --role-arn "$AWS_ROLE_ARN" --role-session-name $GITLAB_USER_LOGIN --output json)
    - export AWS_ACCESS_KEY_ID=$(echo $ASSUMED_FOLE | jq -r .Credentials.AccessKeyId)
    - export AWS_SECRET_ACCESS_KEY=$(echo $ASSUMED_FOLE | jq -r .Credentials.SecretAccessKey)
    - export AWS_SESSION_TOKEN=$(echo $ASSUMED_FOLE | jq -r .Credentials.SessionToken)
    - cdk bootstrap
    - cdk deploy foobar

It requires the standard AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be defined for the initial sts call.

3reactions
mrgraincommented, Jun 2, 2020

I cannot speak for CodeBuild, as we are using Jenkins running on an EC2. I can only assume there would be a similar use case to the one we have. In any case, apparently it was warranted that @rix0rrr included the quoted section into the linked master issue.

For Jenkins/EC2 the issue is that agent instances run on a single shared EC2 with a single shared instance role. In order to maintain least privilege permissions, we have each stage of every Job assume permissions appropriate to what the stage is doing. This could be assuming a role on AWS to deploy (multiple) CDK stacks or upload a file to S3, but also credentials to install private npm packages. Again, I’m not actively using CodeBuild, but this might be equivalent to different CodeBuild phases requiring different roles.

Read more comments on GitHub >

github_iconTop Results From Across the Web

assume-role — AWS CLI 1.27.37 Command Reference
To assume a role from a different account, your Amazon Web Services account must be trusted by the role. The trust relationship is...
Read more >
How to assume a role using the AWS CLI and STS
In this article, we will look at how to use AWS CLI to assume an IAM role using STS.
Read more >
mozilla-aws-cli - PyPI
Command line tool to enable accessing AWS using federated single sign on. ... are members of group "foo" to assume role arn:aws:iam::123456789012:role/baz.
Read more >
How do I assume an IAM role using the AWS CLI? - YouTube
We appreciate your feedback: https://amazonintna.qualtrics.com/jfe/form/SV_exLaAkzYfQHSjj0Find more details in the AWS Knowledge Center: ...
Read more >
AWS Command Line Interface (CLI) with separate credentials ...
aws/config ). The AWS CLI also supports named profiles which can help you deal with multiple access keys but also to assume IAM...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found