-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
AWS auth login with multi region STS support #21960
Merged
raymonstah
merged 7 commits into
main
from
VAULT-18128/aws-auth-login-multi-region-sts-support
Jul 28, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3a525df
AWS auth login with multi region STS support
raymonstah e61f780
add changelog
raymonstah 561b1f6
fix variable name in test
raymonstah 2b8a415
gofmt
raymonstah ba3d873
update docs to mention `sts_region_from_client` is only for IAM-based…
raymonstah f8547ce
remove extra period in changelog
raymonstah 8f125f1
rename to 'use_sts_region_from_client'
raymonstah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import ( | |
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sts" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/hashicorp/vault/sdk/logical" | ||
) | ||
|
||
|
@@ -625,6 +627,58 @@ func TestBackend_defaultAliasMetadata(t *testing.T) { | |
} | ||
} | ||
|
||
func TestRegionFromHeader(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍 |
||
tcs := map[string]struct { | ||
header string | ||
expectedRegion string | ||
expectedSTSEndpoint string | ||
}{ | ||
"us-east-1": { | ||
header: "AWS4-HMAC-SHA256 Credential=AAAAAAAAAAAAAAAAAAAA/20230719/us-east-1/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
expectedRegion: "us-east-1", | ||
expectedSTSEndpoint: "https://sts.us-east-1.amazonaws.com", | ||
}, | ||
"us-west-2": { | ||
header: "AWS4-HMAC-SHA256 Credential=AAAAAAAAAAAAAAAAAAAA/20230719/us-west-2/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
expectedRegion: "us-west-2", | ||
expectedSTSEndpoint: "https://sts.us-west-2.amazonaws.com", | ||
}, | ||
"ap-northeast-3": { | ||
header: "AWS4-HMAC-SHA256 Credential=AAAAAAAAAAAAAAAAAAAA/20230719/ap-northeast-3/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
expectedRegion: "ap-northeast-3", | ||
expectedSTSEndpoint: "https://sts.ap-northeast-3.amazonaws.com", | ||
}, | ||
"us-gov-east-1": { | ||
header: "AWS4-HMAC-SHA256 Credential=AAAAAAAAAAAAAAAAAAAA/20230719/us-gov-east-1/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
expectedRegion: "us-gov-east-1", | ||
expectedSTSEndpoint: "https://sts.us-gov-east-1.amazonaws.com", | ||
}, | ||
} | ||
for name, tc := range tcs { | ||
t.Run(name, func(t *testing.T) { | ||
region, err := awsRegionFromHeader(tc.header) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.expectedRegion, region) | ||
|
||
stsEndpoint, err := stsRegionalEndpoint(region) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.expectedSTSEndpoint, stsEndpoint) | ||
}) | ||
} | ||
|
||
t.Run("invalid-header", func(t *testing.T) { | ||
region, err := awsRegionFromHeader("this-is-an-invalid-header/foobar") | ||
assert.EqualError(t, err, "invalid header format") | ||
assert.Empty(t, region) | ||
}) | ||
|
||
t.Run("invalid-region", func(t *testing.T) { | ||
endpoint, err := stsRegionalEndpoint("fake-region-1") | ||
assert.EqualError(t, err, "unable to get regional STS endpoint for region: fake-region-1") | ||
assert.Empty(t, endpoint) | ||
}) | ||
} | ||
|
||
func defaultLoginData() (map[string]interface{}, error) { | ||
awsSession, err := session.NewSession() | ||
if err != nil { | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
aws/auth: Adds a new config field `use_sts_region_from_client` which allows for using dynamic regional sts endpoints based on Authorization header when using IAM-based authentication. | ||
``` |
This file contains 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
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.
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.
Thanks, this comment is helpful!