fix: validate and apply the ListBuckets bucket-region query
ListBuckets ignored bucket-region: a value that is not a region was accepted, and a region other than the gateway one still listed every bucket. S3 rejects an invalid value with 400 InvalidArgument, "Argument value abc is not a valid AWS Region", and lists only the buckets of the requested region. Check bucket-region against the AWS region code format, always accepting the gateway region whatever its name, and return an empty list for any other region, since every bucket lives in the gateway region. Enable the REST tests that cover both cases. Fixes #1923 Fixes #1930
This commit is contained in:
1 parent
2bb327ec69
commit
b7ff97181d
8 files changed
+175
-6
No files matched your search
@@ -40,6 +40,8 @@ import (
|
||||
var (
|
||||
bucketNameRegexp = regexp.MustCompile(`^[a-z0-9][a-z0-9.-]+[a-z0-9]$`)
|
||||
bucketNameIpRegexp = regexp.MustCompile(`^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`)
|
||||
// AWS region codes, such as us-east-1, us-gov-west-1 or eusc-de-east-1
|
||||
awsRegionRegexp = regexp.MustCompile(`^[a-z]{2,4}(-[a-z]+)+-[0-9]+$`)
|
||||
)
|
||||
|
||||
var strictBucketNameValidation atomic.Bool
|
||||
@@ -1153,6 +1155,13 @@ func ValidateLocationConstraint(constraint *string, region string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsValidBucketRegion checks a ListBuckets bucket-region value. The gateway
|
||||
// region is valid whatever its name, any other value has to be an AWS region
|
||||
// code.
|
||||
func IsValidBucketRegion(bucketRegion, region string) bool {
|
||||
return bucketRegion == region || awsRegionRegexp.MatchString(bucketRegion)
|
||||
}
|
||||
|
||||
// AwsChunkedEncoding is the coding a client announces when it frames a body in
|
||||
// aws-chunked, as the SDKs do to carry a trailing checksum.
|
||||
const AwsChunkedEncoding = "aws-chunked"
|
||||
|
||||
Reference in new issue
Block a user