fix: retrieve IAM user explicitly in credentials rotation#925
Open
jbbarth wants to merge 1 commit intofwdcloudsec:mainfrom
Open
fix: retrieve IAM user explicitly in credentials rotation#925jbbarth wants to merge 1 commit intofwdcloudsec:mainfrom
jbbarth wants to merge 1 commit intofwdcloudsec:mainfrom
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.
The bug is explained here: #911
Summary
When a restrictive IAM policy is in place and includes a condition on
${aws:username}, thengranted credentials rotatebreaks and the policy evaluation somehow inserts a "null" string before the username (so I'm getting an access denied onnulljean-baptiste.barthon my side).If we retrieve the username explicitly before issuing the API calls, then everything works perfectly fine.
Longer explanation
When
granted credentials rotatecalls IAM APIs (CreateAccessKey,UpdateAccessKey,DeleteAccessKey), it doesn't explicitly set theUserNamefield. AWS is documented to default to the calling user whenUserNameis omitted, and the API call itself succeeds.However, a problem can appear during IAM policy evaluation. If you have an identity-based policy restricting key operations to the current user, e.g.:
AWS then constructs the request's resource ARN with the literal string "null" instead of the actual username when UserName is omitted. So the evaluated ARN becomes something like
arn:aws:iam::123456789:user/nulljean-baptiste.barth, which doesn't match the policy, and the request is denied.This is why it works fine for users with broad IAM permissions but fails for users with least-privilege policies. And we actually added such restrictions recently to limit what our non admin users can do.
Fix
In pkg/granted/credentials.go, we can call
iam.GetUser(with no UserName, which returns the calling user) before the key operations, then pass the retrieved username explicitly to all three API calls.