fix: reject a ListBuckets bucket-region other than the gateway region

S3 never lists an empty result for another region: a valid region
other than the endpoint's own gets 400 InvalidArgument, "Requests with
bucket-region specified must be made to the corresponding regional
endpoint", with no ArgumentValue. The gateway is a single regional
endpoint, so it now does the same instead of clearing the listing.

Match the region case-insensitively like S3, and check an empty
bucket-region= too by looking for the query argument itself, since an
empty value is not a valid AWS region either.
This commit is contained in:
dualfroz committed 2026-10-05 20:42:30 +02:00
1 parent 5d293b1316
commit e1d2284906
7 files changed
+104 -56

No files matched your search

+18 -8
View File
@@ -19,6 +19,7 @@ import (
"fmt"
"slices"
"sort"
"strings"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
@@ -308,21 +309,30 @@ func ListBuckets_bucket_region(s *S3Conf) error {
bucket, s.awsRegion, buckets)
}
// every bucket of the gateway lives in its own region
// the region is matched case-insensitively
buckets, err = listBuckets(strings.ToUpper(s.awsRegion))
if err != nil {
return err
}
if !slices.ContainsFunc(buckets, func(b types.Bucket) bool { return getString(b.Name) == bucket }) {
return fmt.Errorf("expected bucket %v in the %v listing, instead got %v",
bucket, strings.ToUpper(s.awsRegion), buckets)
}
// every bucket of the gateway lives in its own region, so like an S3
// regional endpoint it rejects any other region
otherRegion := "us-west-2"
if s.awsRegion == otherRegion {
otherRegion = "us-east-1"
}
buckets, err = listBuckets(otherRegion)
if err != nil {
_, err = listBuckets(otherRegion)
if err := checkApiErr(err, s3err.GetInvalidArgumentErr(s3err.InvalidArgBucketRegionEndpoint, "")); err != nil {
return err
}
if len(buckets) != 0 {
return fmt.Errorf("expected an empty %v listing, instead got %v",
otherRegion, buckets)
}
return nil
// an empty bucket-region is not a valid region either
_, err = listBuckets("")
return checkApiErr(err, s3err.GetInvalidArgBucketRegion(""))
})
}
+7 -3
View File
@@ -285,12 +285,16 @@ export RUN_USERS=true
run setup_bucket "$bucket_name"
assert_success
local params=()
if [ "$DIRECT" == "true" ]; then
params+=("-url" "https://s3.$test_region.amazonaws.com" "-awsRegion" "$test_region")
# the regional endpoint of that region lists only its own buckets
run list_buckets_bucket_not_in_list "$bucket_name" "$test_region" "-url" "https://s3.$test_region.amazonaws.com" "-awsRegion" "$test_region"
assert_success
return
fi
run list_buckets_bucket_not_in_list "$bucket_name" "$test_region" "${params[@]}"
# the gateway is a single regional endpoint, so any other region is rejected
run send_rest_go_command_expect_error_with_specific_arg_name_value "400" "InvalidArgument" "Requests with bucket-region specified must be made to the corresponding regional endpoint" \
"ArgumentName" "bucket-region" "-query" "bucket-region=$test_region"
assert_success
}