-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Feature Request: print current temporary session credentials #3711
Comments
@hubertgrzeskowiak - Thanks for reaching out. This would be a good feature for the CLI so I'm labeling it as such pending further review and 👍. |
@hubertgrzeskowiak - After a second look, I'm curious if you have already tried working with AWS Security Token Service (AWS STS) commands like When using
The session token can also be added to an HTTP header or to a query string using a parameter named The temporary security credentials created by
Please advise if this meets your requirement and use case. |
What you describe is using an IAM user profile to assume the role manually. This works, but you need to know the IAM role and which profile to use to assume it. The beauty of the AWS config is that it hides these implementation details in the credentials and config files. I only need to know the profile that holds the IAM role. This comes especially handy if you want to use a script that has expectations on the AWS profiles, but not the particular users and their roles. |
I guess we could use |
@hubertgrzeskowiak - Thanks for the feedback. Relabeling as a Feature Request pending more investigating. |
Similar situation as @hubertgrzeskowiak. One way of solving this would be to support As an example the command will become,
given a config,
|
Adding my vote for this feature request. It'd be great to get the temporary credentials easily to be able to use in other contexts. |
UP VOTE!! over a year has passed and this is still an issue. I think it is necessary in vastly common instances to view the cached credential and to use it in another context outside of the cli (eg: a client). Its not like this is a security concern because if you look in the As mentioned above, parsing all the cache files to find the right one is a bit tedious and expensive which is a common work around now :P At least as a minimum expose a command to view the cached temp credentials via Peace 👍 |
I think this is actually a bug more than a feature request. Example below:
$ aws configure --profile saml list
Name Value Type Location
---- ----- ---- --------
profile saml manual --profile
access_key ****************ABCD shared-credentials-file
secret_key ****************WXYZ shared-credentials-file
region <not set> None None
$ aws configure get profile.saml.aws_access_key_id
ABCDEFGHIJKLMNOP
$ aws configure --profile admin list
Name Value Type Location
---- ----- ---- --------
profile admin manual --profile
access_key ****************EFGH assume-role
secret_key ****************RSUV assume-role
region <not set> None None
$ aws configure get profile.admin.aws_access_key_id
$ Note that AWS CLI will display a preview of both credentials' values, but it can only output one of them. I think getting feature parity here would be easy code-wise, and provide more uniform functionality. Thank you |
@justnance based on above comment, could this be reclassified as a bug and its priority bumped up? if it required considerable new development i would understand the feature request aspect, but it seems all it's missing is a couple lines of code to display the values already being loaded by the configure function. thanks |
Ideally, it should also work for SSO credentials: after aws configure --profile myProfile list
Name Value Type Location
---- ----- ---- --------
profile myProfile manual --profile
access_key ****************XXXX sso
secret_key ****************YYYY sso
region <not set> None None |
For people looking for a quick answer here, this snippet works for me:
|
Awesome @xiaket! Thanks for that inspiration. And if someone would prefer to have it in json:
Would be great to retrive those credentials with a native aws cli command though. |
Linking related issue: #5261. Not sure if there is enough overlap between these issues for them to be considered duplicates but I think that may be the case. |
Bit of modification to use credentials in another shell easily:
Then prints:
|
Seems like workarounds are not necessary anymore to get credentials, #5261 got resolved. How you can get credentials in json form now: aws configure export-credentials It essentially uses the same frozen credentials mechanism described in the above comments. For providing env variables, it's natively supported too: aws configure export-credentials --format env I think this issue can be resolved. |
@reegnz |
Thanks all for following up here, I agree it looks like this can be closed now. Here is the documentation for the |
I think this may be related, so I'll leave it here. I know this issue is for the CLI but I ended up here looking for a solution for the Ruby client. On a running EC2 instance, e.g. in Elastic Beanstalk platform, where EC2 servers assume role, if you need to print current credentials for the role assumed by the ec2 server user, you can use the credentials = Aws::InstanceProfileCredentials.new.credentials
aws_credentials = {
access_key_id: credentials.access_key_id,
secret_access_key: credentials.secret_access_key,
region: ENV["AWS_REGION"],
} |
@januszm TBQH with ruby (or any other AWS SDK really) it is even better to use the default credential provider chain: credentials = Aws::CredentialProviderChain.new.resolve.credentials Then it works on your local machine with shared credentials, aws sso, credential_process, and also in k8s, in fargate, etc., without having to modify the code each time. |
Whenever I assume a role using a role profile, the AWS CLI fetches temporary session tokens and saves them in
~/.aws/cli/cache/${random}.json
. Is there any way to print the currently used credentials? I would like to pass them as env variables to another program.Parsing all json files and filtering the right one myself is a rather tedious and error-prone process.
The text was updated successfully, but these errors were encountered: