Repository navigation
Fix AWS MFA for roles assumed through a source profile - #684
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
When a profile assumes a role through a
source_profile,resolveLocalAnd1PasswordConfigurationsgives every profile in the chain the item's MFA serial and one-time password. So the source profile already resolved to an MFAGetSessionTokenprovider, andNewAssumeRoleProviderthen wrapped it in a second one. That second call is signed with the first call's session credentials, which AWS rejects withCannot call GetSessionToken with session credentials. It only failed when nothing was cached: a cached MFA or role session skips both calls, which is why it worked intermittently, and why running a command against the default profile first appeared to fix it. Chains through more than one role were broken the same way.MFA is now applied once, to the long-lived access keys at the root of the
source_profilechain, andNewAssumeRoleProviderno longer adds it. MFA settings found on any profile in the chain are carried down to the root, so anmfa_serialset only on the role profile still applies. Roles without asource_profileand MFA-only profiles build the same chain as before, and cache keys are unchanged.Type of change
Related Issue(s)
How To Test
Unit tests, including a regression test for the reported bug:
go test ./plugins/aws/ -vTestSTSProviderChainbuilds the provider chain with the real factory and an empty cache, then asserts the STS calls it makes. It checks for a single MFAGetSessionTokenin four cases: the reportedsource_profilesetup, a role without asource_profile, a role chained through another role, and anmfa_serialset only on the role profile. The existingTestSTSProvisionercases use a mock factory that ignores the source provider, which is why they didn't catch this.End to end with the CLI, using an item with access keys, a one-time password and an MFA serial, and a role the IAM user can assume:
Note: Run it more than 15 minutes after your last
awscommand so nothing is cached. This failed withCannot call GetSessionToken with session credentialsbefore the change and should now return the assumed role.aws sts get-caller-identitywith the default profile should still return the IAM user.Changelog
The AWS plugin no longer fails with
Cannot call GetSessionToken with session credentialswhen a profile with MFA assumes a role through asource_profile.