-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add command to export credentials #7388
Comments
This PR builds on the interface proposed in aws#6808 and implements the additional features proposed in aws#7388. From the original PRs, the additional features are: * Added support for an explicit `--format` args to control the output format. * Add support for env vars, powershell/windows vars, and a JSON format that's enables this command to be used as a `credential_process`. * Detect, and prevent infinite recursion when the credential process resolution results in the CLI calling itself with the same command. Closes aws#7388 Closes aws#5261
This PR builds on the interface proposed in aws#6808 and implements the additional features proposed in aws#7388. From the original PRs, the additional features are: * Added support for an explicit `--format` args to control the output format. * Add support for env vars, powershell/windows vars, and a JSON format that's enables this command to be used as a `credential_process`. * Detect, and prevent infinite recursion when the credential process resolution results in the CLI calling itself with the same command. Closes aws#7388 Closes aws#5261
This looks good. Just jotting down some thoughts:
|
@benkehoe I meant this issue as originally we were trying to treat this issue as a medium for outlining the design/interface. I don't have a strong preference though as I will eventually be leaving comments in the PR. |
If you want to go with that approach, it'll probably just be making the expiry time attribute public. I sketched out my ideal way to fix the issue in the linked botocore issue, tl;dr move the fake expiry logic up a layer into the IMDS credential provider, but it's a more invasive change that will need a good amount of testing (assuming it's even possible) so I'd suggest holding off on that larger change for now.
Nice! I completely forgot that we supported that (I even mentioned in this issue we should support refreshing from env vars). I'll update.
Hadn't considered it, it's never come up in my usage. I wouldn't mind adding it, assuming we had a use case for it, but I like keeping the |
aws-export-credentials has
Over on the issue I suggest making expiry time public but not setting it for IMDS credentials for now, allowing the change to be made quicker, not waiting for the larger movement of the logic to happen. |
Hi guys, I see #7398 is merged and released, so the issue probably should be closed, but I noticed one strange behaviour: ❯ AWS_PROFILE=some-profile aws configure export-credentials --format env
export AWS_ACCESS_KEY_ID=[redacted]
export AWS_SECRET_ACCESS_KEY=[redacted]
export AWS_SESSION_TOKEN=[redacted]
export AWS_CREDENTIAL_EXPIRATION=2023-01-01T18:18:38+00:00 that works as expected, but - when I use ❯ aws-assume some-profile
[✔] [some-profile](eu-central-1) session credentials will expire in 8 hours
❯ aws configure export-credentials --format env
export AWS_ACCESS_KEY_ID=[redacted]
export AWS_SECRET_ACCESS_KEY=[redacted]
export AWS_SESSION_TOKEN=[redacted] the What's interesting - it works correctly with @benkehoe's ❯ aws-assume some-profile
[✔] [some-profile](eu-central-1) session credentials will expire in 8 hours
❯ aws-export-credentials --env-export
export AWS_ACCESS_KEY_ID=[redacted]
export AWS_SECRET_ACCESS_KEY=[redacted]
export AWS_SESSION_TOKEN=[redacted]
export AWS_CREDENTIALS_EXPIRATION=2023-01-01T18:28:15Z |
Ah okay, I guess I got the point - when envars are set,
That was fine with
|
Since #7398 was merged as mentioned above, I also think this issue can be closed. A new issue can be created to track any issues related to this one going forward. |
|
Describe the feature
This is attempting to drive closure to existing feature requests/PRs by proposing the exact feature set we should support for exporting credentials. This proposes an
aws configure export-creds
command that resolves the existing AWS CLI credential chain and formats the credentials in various formats, including as environment variables and in the credential process format, allowing the AWS CLI to be used as a credential process.Use Case
For context, original issue:
To save you a few clicks, the rationale for this feature:
sso_session
section it supports), but it still provides a succinct way to reduce duplication in your AWS config file.Proposed Solution
I propose we move forward with #6808 with a few additional changes.
aws configure export-creds
command that will use the AWS CLI's credential resolution process and output the results in various formats.--format
parameter that supports common formats the customers use for exporting credentials.Synopsis
The default value will be
process
which outputs the credentials in the output required by a credential process.We'll support the following output formats, which are the formats we see with SSO, or other console related tooling that allows you to export creds in various formats:
process
- The default output format, enables usage as acredential_process
source.env
- Exports env vars as in a posix compatible shell (export AWS_ACCESS_KEY_ID=...
)powershell
- Export env vars in powershell specific format ($Env:AWS_ACCESS_KEY_ID="..."
)windows-cmd
- Export env vars in a windows cmd console format (set AWS_ACCESS_KEY_ID=...
)Examples
To use this command as a credential process in your config file:
Then use just like any other profile:
To use this with env vars in a posix shell (bash/zsh etc):
I noticed we have a few tools that also export fish shell creds, not sure if it's worth supporting at the moment so I've omitted it for now, but additional formatters would be straightforward to add. Also not supporting the "CLI config" format because if you're going to write out a new profile/section to the CLI config file, we should be recommending them to use a
credential_process
instead, which can properly handle (non-trivial) refreshes.Other Information
One of the implementation details we'll need to figure out is being able to provide the expiry time of credentials, which is required by the credential process (if you want to refresh credentials), and arguably should be supported by other formats as well (e.g. env vars). For the AWS CLI, and specifically botocore, we do not provide the expiry time as a public attribute.
FWIW, I don't think I had any specific reason for not exposing the expiry time other than it was an implementation detail that wasn't relevant to consumers of credentials (I don't remember the exact timeline but I know we added assume role / refreshable credentials years before I introduced the credential process functionality). We really only cared about expiry time to handle the bookkeeping for advisory/mandatory refreshes.
I've seen the discussion on boto/botocore#2694, and while I think it is curious about the "not expired but maybe actually it is" expiry time specific to IMDS, I will follow up and see if there's any path forward there. Maybe we just add it to
ReadOnlyCredentials
with an extra attribute denoting expiry time fuzziness is sufficient.Other implementation note we'll need to be careful of is detecting recursive invocations when running CLI commands against profiles that also have the AWS CLI configured as a credential process. We'll probably need to require you specify a different profile than the parent CLI process otherwise we'll error out, but we can explore what options we have available to us.
Last thing, I'm happy to drive this to completion and implement the remaining delta we need to get this feature complete.
Acknowledgements
CLI version used
v2
Environment details (OS name and version, etc.)
All of them
The text was updated successfully, but these errors were encountered: