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

AssumeRoleOptions does not have TokenCode member #1384

Closed
3 tasks done
NukaCody opened this issue Aug 18, 2021 · 4 comments · Fixed by #1406
Closed
3 tasks done

AssumeRoleOptions does not have TokenCode member #1384

NukaCody opened this issue Aug 18, 2021 · 4 comments · Fixed by #1406
Labels
documentation This is a problem with documentation. guidance Question that needs advice or information.

Comments

@NukaCody
Copy link

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug

AssumeRoleOptions does not have a TokenCode member despite documentation using it as an example for static MFA token

Version of AWS SDK for Go?

1.8.0

Version of Go (go version)?

go version go1.16.6 darwin/amd64

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code or minimal repo)

	tokenCode, _ = stscreds.StdinTokenProvider()

    // Below would be in goroutine
	creds := stscreds.NewAssumeRoleProvider(stsc, role, func(aro *stscreds.AssumeRoleOptions) {
		aro.SerialNumber = aws.String("arn:aws:iam::*:mfa/user")
		aro.TokenCode = aws.String(tokenCode)
	})

Expected behavior
A clear and concise description of what you expected to happen.

Get MFA token at the entry point of the app, then spin up hundreds of goroutines that assume roles into different accounts that have MFA required using the static token code. Moving StdinTokenProvider inside of the goroutine won't be goroutine safe nor scalable

@NukaCody NukaCody added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 18, 2021
@skmcgrail skmcgrail added documentation This is a problem with documentation. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 19, 2021
@skmcgrail
Copy link
Member

Thanks for raising this documentation issue, the correct structure field to use is TokenProvider which takes a func() (string, error) that returns a token to be used.

https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/credentials/stscreds#hdr-Assume_Role_with_MFA_Token_Provider has a correct example usage for this.

We will work on getting this addressed and updated.

@jasdel jasdel added the guidance Question that needs advice or information. label Aug 21, 2021
@NukaCody
Copy link
Author

NukaCody commented Aug 31, 2021

I'm not sure if it's purely documentation. There's still a strong use case for static TokenCode.

It looks like TokenProvider opens up STDIN to read a token, but if you were to run this is thousands of go routines (at least till that MFA code expire). It wouldn't be a scalable method. Because you would have to enter the MFA code thousands of times

@jasdel
Copy link
Contributor

jasdel commented Sep 8, 2021

Thanks for the update @NukaCody. We'll work to get the documentation for this updated.

The StdinTokenProvider is a basic implementation of the TokenProvider provided by the SDK for reading token from stdin, but it is very limited and is not configurable.

Instead of using the SDK provided StdinTokenProvider you could provide a custom function that returns the static code.

cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
	panic(err)
}

// Use a custom function to provide the token for assume role credential provider.
staticTokenProvider := func() (string, error) {
     return "someCode", nil
}

// Create the credentials from AssumeRoleProvider to assume the role
// referenced by the "myRoleARN" ARN using the MFA token code provided.
creds := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), "myRoleArn", func(o *stscreds.AssumeRoleOptions) {
	o.SerialNumber = aws.String("myTokenSerialNumber")
	o.TokenProvider = staticTokenProvider
})

cfg.Credentials = aws.NewCredentialsCache(creds)

// Create service client value configured for credentials
// from assumed role.
svc := s3.NewFromConfig(cfg)

jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Sep 8, 2021
Fixes the AssumeRoleProvider's documentation for using custom
TokenProviders.

Fixes aws#1384
jasdel added a commit that referenced this issue Sep 8, 2021
…1406)

Fixes the AssumeRoleProvider's documentation and error message for using custom TokenProviders.

Fixes #1384
@github-actions
Copy link

github-actions bot commented Sep 8, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

jrichard8 pushed a commit to jrichard8/aws-sdk-go-v2 that referenced this issue Feb 14, 2022
…ws#1406)

Fixes the AssumeRoleProvider's documentation and error message for using custom TokenProviders.

Fixes aws#1384
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. guidance Question that needs advice or information.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants