Open Sandmania opened 5 years ago
We will review how this works in the other AWS SDKs and work to add support for it.
any updates so far?
Unfortunately not. We're willing to accept contributions for this feature, but it's behind quite a few other things in our backlog (see https://github.com/aws/aws-sdk-java-v2/projects/1 for what we're working on).
wouldn't the more logical way to do this be to grab temporary credentials by using STS assume role and then adding those permissions to a profile in /.aws/credentials
?
some psuedo code like
aws sts assume-role --role-arn arn:aws:iam::123456789012:role/xaccounts3access --role-session-name s3-access-example | jq .Credentials | some transform script here >> ~/.aws/credentials
and then use a temporary aws profile env after that?
i think the issue with using something like System.out.println(StsClient.create().getCallerIdentity().account())
to get the credentials assumes that you have an interactive terminal available to supply the mfa or similar.
there appears to be a couple of tools that do this already e.g. https://github.com/rik2803/aws-sts-assumerole
We believe that the SSO feature fills a lot of the same gaps as this feature. It's documented here: https://docs.aws.amazon.com/sdkref/latest/guide/setting-global-sso_account_id.html
We won't close this feature, but feel free to see whether SSO works for your authentication scenario over the mfa_serial.
When using a role to access a different account with MFA Conditions, I would expect the SDKs ProfileCredentialsProvider to handle the token querying and using the session credentials to all subsequent calls. Something like this has already been proposed for the old SDK, see https://github.com/aws/aws-sdk-java/issues/1345.
Expected Behavior
Given
~/.aws/credentials
likeand a call like
System.out.println(StsClient.create().getCallerIdentity().account())
When Running an executable jar with the aforementioned call like
$ java -jar myExecutable.jar
and$ AWS_PROFILE=testAccountProfile java -jar myExecutable.jar
Then For the first call, should print the account id for the
default
profile (222222222222) For the second call, should prompt for MFA token. Once correct code given, should print account if fortestAccountProfile
(111111111111)Current Behavior
The first call works as expected. The second call does not prompt for MFA token and fails with the following exception:
Possible Solution
Something similar already suggested for the old SDK: https://github.com/aws/aws-sdk-java/issues/1345
Context
I'm using java sdk based command line tools to access multiple accounts. The access is role based and protected with MFA.
Your Environment