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

Initial commit of assume role cred provider #990

Merged
merged 2 commits into from
Nov 8, 2014

Conversation

jamesls
Copy link
Member

@jamesls jamesls commented Nov 7, 2014

This builds on the work of several existing
pull requests combining what I believe is
the combination of all the suggested changes
including:

I think a strong case can be made to move this to botocore.
However, the file caching makes me somewhat hesitant to move
this into botocore (but I think the AssumeRoleProvider without
the caching could be added to botocore). I'd like to evaluate this in
the future but for now, I don't think it's unreasonable to leave
this in the AWS CLI for the time being. At any rate, this is
a straightforward and compatible move if we decide to do so.

Also, the ability to open a browser with the currently scoped
session has not been ported over. I'd like to address that
in a separate pull request.

cc @kyleknap @danielgtaylor

@garnaat
Copy link
Contributor

garnaat commented Nov 7, 2014

I would vote for this going into botocore. It's really important functionality that would be useful in a lot of places, boto3 for starters. Even if that doesn't happen right away I really think it is the right place for it to live.

Also, is there any way that we could also add support for sessions that use MFA? For example, allowing the MFA serial number to be added to a profile and then, perhaps by prompting, request the MFA token to send with the AssumeRole request?

cc @ehammond

@jamesls
Copy link
Member Author

jamesls commented Nov 7, 2014

I think the MFA part would be really useful, and would work well for the CLI given it's typically a short lived process. However, there are some scenarios, mostly with aws s3 cp/sync where it's possible to have a really long running process during which the temporary credentials expire. The current PR handles this case and refreshes the creds, but this gets a little more complicated when MFA is involved.

I believe the two options we MFA is involved are that we can either try to pause the S3 transfer and re-prompt for the new MFA, or we can just error out in that scenario. I'll look into adding this.

@ehammond
Copy link

ehammond commented Nov 7, 2014

+1 for MFA.

Defaulting to an error sounds best, with perhaps a future option to prompt for interactive use. Unexpected pauses for prompts can be problematic in automation.

This builds on the work of several existing
pull requests combining what I believe is
the combination of all the suggested changes
including:

* Use role_arn to trigger assume role behavior.
  Do not require an explicit session to be created
  and ended (aws#667).
* Cache the temporary credentials.  If the credentials
  are not expired then we should reuse them instead of
  making the assume role call every time
  (aws#656 and boto/botocore#226).

I think a strong case can be made to move this to botocore.
However, the file caching makes me somewhat hesitant to move
this into botocore (but I think the AssumeRoleProvider without
the caching could be added to botocore).  I'd like to evaluate this in
the future but for now, I don't think it's unreasonable to leave
this in the AWS CLI for the time being.  At any rate, this is
a straightforward and compatible move if we decide to do so.

Also, the ability to open a browser with the currently scoped
session has not been ported over.  I'd like to address that
in a separate pull request.
@danielgtaylor
Copy link
Contributor

LGTM aside from the test failure.



def _create_creds_from_response(self, response):
#return credentials.Credentials(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the commented out code.

@jamesls
Copy link
Member Author

jamesls commented Nov 8, 2014

I think that makes sense. So the plan is:

  • Update this PR to support MFA. When the temp creds expire and MFA is required, then an error will occur. In the future we can possibly add an option for interactive use.

As for botocore, I do want to get something in botocore, the interactive prompting makes me a little more hesitant, but I do think we should eventually move this into botocore.

@kyleknap
Copy link
Contributor

kyleknap commented Nov 8, 2014

Yeah looks good to me as well. Test should pass now with the botocore pull request fixing that issue. 🚢

@jamesls jamesls force-pushed the assume-role-provider branch from c62b135 to df8fcb7 Compare November 8, 2014 02:07
@jamesls
Copy link
Member Author

jamesls commented Nov 8, 2014

Ok, so update on the plan. The MFA changes are an additive change so I'd like to get this initial version merged and tested to ensure there's no issues with the baseline code. I'll then send another PR for the MFA changes shortly.

@jamesls jamesls merged commit df8fcb7 into aws:develop Nov 8, 2014
jamesls added a commit to jamesls/aws-cli that referenced this pull request Nov 10, 2014
Feedback from aws#990, this adds support for MFA when assuming a role.
To enable this, in addition to role_arn and source_profile, you can
specify an mfa_serial option in your config file::

    [profile foo]
    role_arn = ...
    source_profile = development
    mfa_serial = .....

This is the the mfa arn/device id.  If an mfa_serial is
provided then a user will be prompted for the token code when
the AssumeRole call happens.

As mentioned in the original PR, for now when the temporary
credentials expire, an exception will be raised if MFA is
required.  We can look into updating this in the future to support
reprompting the user.  This only affects the case where the
credentials expire within the duration of the AWS CLI process.
Aside from some of the ``aws s3 cp/sync`` commands, the AWS CLI
is generally a short lived process so this won't affect the
common usage scenarios.
jamesls added a commit to jamesls/aws-cli that referenced this pull request Nov 10, 2014
Feedback from aws#990, this adds support for MFA when assuming a role.
To enable this, in addition to role_arn and source_profile, you can
specify an mfa_serial option in your config file::

    [profile foo]
    role_arn = ...
    source_profile = development
    mfa_serial = .....

This is the the mfa arn/device id.  If an mfa_serial is
provided then a user will be prompted for the token code when
the AssumeRole call happens.

As mentioned in the original PR, for now when the temporary
credentials expire, an exception will be raised if MFA is
required.  We can look into updating this in the future to support
reprompting the user.  This only affects the case where the
credentials expire within the duration of the AWS CLI process.
Aside from some of the ``aws s3 cp/sync`` commands, the AWS CLI
is generally a short lived process so this won't affect the
common usage scenarios.
jamesls added a commit to jamesls/aws-cli that referenced this pull request Nov 10, 2014
Feedback from aws#990, this adds support for MFA when assuming a role.
To enable this, in addition to role_arn and source_profile, you can
specify an mfa_serial option in your config file::

    [profile foo]
    role_arn = ...
    source_profile = development
    mfa_serial = .....

This is the the mfa arn/device id.  If an mfa_serial is
provided then a user will be prompted for the token code when
the AssumeRole call happens.

As mentioned in the original PR, for now when the temporary
credentials expire, an exception will be raised if MFA is
required.  We can look into updating this in the future to support
reprompting the user.  This only affects the case where the
credentials expire within the duration of the AWS CLI process.
Aside from some of the ``aws s3 cp/sync`` commands, the AWS CLI
is generally a short lived process so this won't affect the
common usage scenarios.
thoward-godaddy pushed a commit to thoward-godaddy/aws-cli that referenced this pull request Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants