MIGRATION ISSUE: GetBucketRegion
in v2 requires valid credentials
#3077
Labels
needs-triage
This issue or PR still needs to be triaged.
v1-v2-inconsistency
v1-v2-inconsistency Behavior has changed from v1 to v2, or feature is missing altogether
Pre-Migration Checklist
Go Version Used
Go 1.24
Describe the Migration Issue
Originally posted in trufflesecurity/trufflehog#4069 (comment).
I discovered an undocumented behavioral difference between V1’s
GetBucketRegionWithClient
and V2'sGetBucketRegion
.Specifically, V1’s
GetBucketRegionWithClient
does not return an error when credentials are invalid, whereas V2’sGetBucketRegion
fails under the same conditions.In the following code examples, I used a fake access key, fake secret key, and a fake role ARN.
Code Comparison
GetBucketRegionWithClient
in V1GetBucketRegion
in V2Observed Differences/Errors
V1 Code Snippet Output
Running the V1 code snippet above produces the following output:
Upon inspecting the source code of V1's
GetBucketRegionWithClient
, we can see that it bypasses the configured credentials and issues theHeadBucket
request usingcredentials.AnonymousCredentials
:V2 Code Snippet Output
Running the V2 code snippet above code results in the following output:
The error originates from the following call chain:
Additional Context
It turns out that valid credentials are not required to retrieve a bucket's region using the HeadBucket API.
A simple
HEAD
request returns thex-amz-bucket-region
header, even when the response status is403 Forbidden
:This matches the test case for
TestGetBucketRegion_Exists
, where we expect the bucket region is included in the header when the response is403 Forbidden
.aws-sdk-go-v2/feature/s3/manager/bucket_region_test.go
Lines 50 to 53 in cfef7b8
The text was updated successfully, but these errors were encountered: