This repository was archived by the owner on Jul 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
aws/session: Add support for AssumeRoles with MFA #1088
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Feb 18, 2017
Closed
xibz
suggested changes
Feb 18, 2017
@@ -73,7 +73,7 @@ func New(cfgs ...*aws.Config) *Session { | |||
return s | |||
} | |||
|
|||
return oldNewSession(cfgs...) | |||
return deprecatedNewSession(cfgs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, way better name
aws/session/session.go
Outdated
// | ||
// This field is only used if the shared config enables assume role with | ||
// MFA support. | ||
AssumeRoleTokenProvider func() (string, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this isn't an interface but a function pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch here was focused on simplicity. Since an isolated piece of logic was being provided an function pointer was simpler and provided the same functionality.
2000a7d
to
e136293
Compare
Added more detailed docs and verified with the stdin token provider is able to assume roles that require MFA. |
a3d89fd
to
5409a97
Compare
xibz
approved these changes
Feb 20, 2017
Adds support for assuming IAM roles with MFA enabled. A TokenProvider func was added to stscreds.AssumeRoleProvider that will be called each time the role's credentials need to be refreshed. A basic token provider that sources the MFA token from stdin as stscreds.StdinTokenProvider. In addition when creating a session a new session option was added, AssumeRoleTokenProvider. The value of this field will be passed to the stscreds.AssumeRoleProvider if the shared config enables assume role with MFA, and the SDK will be assuming the role. This allows you to configure the SDK via the shared config to assume a role with MFA tokens. Note to use the SDK with the shared config and assume role the SharedConfigState session option must be SharedConfigEnable, or the AWS_SDK_LOAD_CONFIG environment variable set. Assume role with MFA is enabled via the shared config when the serial_number field is set. Creating an AssumeRoleProvider with MFA // Initial credentials loaded from SDK's default credential chain. Such as // the environment, shared credentials (~/.aws/credentials), or EC2 Instance // Role. These credentials will be used to to make the STS Assume Role API. sess := session.Must(session.NewSession()) // Create the credentials from AssumeRoleProvider to assume the role // referenced by the "myRoleARN" ARN. Prompting for MFA token from stdin. creds := stscreds.NewCredentials(sess, "myRoleArn", func(p *stscreds.AssumeRoleProvider) { p.SerialNumber = aws.String("myTokenSerialNumber") p.TokenProvider = stscreds.StdinTokenProvider }) // Create service client value configured for credentials // from assumed role. svc := s3.New(sess, &aws.Config{Credentials: creds}) Creating a Session with shared config enabled to assume a role with MFA sess := session.Must(session.NewSessionWithOptions(session.Options{ AssumeRoleTokenProvider: stscreds.StdinTokenProvider, SharedConfigState: session.SharedConfigEnable, })) // Create service client value configured for credentials // from assumed role. svc := s3.New(sess) Fix # 842
58cb169
to
8f52800
Compare
Merged
skotambkar
pushed a commit
to skotambkar/aws-sdk-go
that referenced
this pull request
May 20, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds support for assuming IAM roles with MFA enabled. A TokenProvider
func was added to
stscreds.AssumeRoleProvider
that will be called eachtime the role's credentials need to be refreshed. A basic token provider
that sources the MFA token from stdin as
stscreds.StdinTokenProvider
.This change also adds a new session option,
AssumeRoleTokenProvider
.The value of this field will be passed to the
stscreds.AssumeRoleProvider
if the shared configuration is enabled and the config (
~/.aws/config
) orcredentials files (
~/.aws/credentials
) specify a role to assumewith MFA.
In order for the SDK to assume a role with MFA the
SharedConfigState
session option must be set to
SharedConfigEnable
, orAWS_SDK_LOAD_CONFIG
environment variable set.
Creating an AssumeRoleProvider with MFA:
Creating a Session with shared config enabled to assume a role with MFA:
Fix #842
Related To hashicorp/terraform#9349