Merge pull request #1730 from versity/sis/create-bucket-location-constraint-us-east-1

fix: fixes CreateBucket LocationConstraint validation
This commit is contained in:
Ben McClelland
2026-01-03 20:52:57 -08:00
committed by GitHub
4 changed files with 25 additions and 14 deletions

View File

@@ -562,10 +562,10 @@ func (c S3ApiController) CreateBucket(ctx *fiber.Ctx) (*Response, error) {
}, s3err.GetAPIError(s3err.ErrMalformedXML)
}
if body.LocationConstraint != "" {
if body.LocationConstraint != nil {
region := utils.ContextKeyRegion.Get(ctx).(string)
if body.LocationConstraint != region {
debuglogger.Logf("invalid location constraint: %s", body.LocationConstraint)
if *body.LocationConstraint != region || *body.LocationConstraint == "us-east-1" {
debuglogger.Logf("invalid location constraint: %s", *body.LocationConstraint)
return &Response{
MetaOpts: &MetaOptions{
BucketOwner: acct.Access,

View File

@@ -700,7 +700,7 @@ func TestS3ApiController_CreateBucket(t *testing.T) {
}
invLocConstBody, err := xml.Marshal(s3response.CreateBucketConfiguration{
LocationConstraint: "us-west-1",
LocationConstraint: utils.GetStringPtr("us-west-1"),
})
assert.NoError(t, err)

View File

@@ -730,6 +730,6 @@ type LocationConstraint struct {
}
type CreateBucketConfiguration struct {
LocationConstraint string
LocationConstraint *string
TagSet []types.Tag `xml:"Tags>Tag"`
}

View File

@@ -342,16 +342,27 @@ func CreateBucket_invalid_location_constraint(s *S3Conf) error {
region = types.BucketLocationConstraintUsWest1
}
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
Bucket: &bucket,
CreateBucketConfiguration: &types.CreateBucketConfiguration{
LocationConstraint: region,
},
})
cancel()
createBucket := func(region types.BucketLocationConstraint) error {
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
Bucket: &bucket,
CreateBucketConfiguration: &types.CreateBucketConfiguration{
LocationConstraint: region,
},
})
cancel()
return checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidLocationConstraint))
return checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidLocationConstraint))
}
for _, lConstraint := range []types.BucketLocationConstraint{region, "us-east-1"} {
err := createBucket(lConstraint)
if err != nil {
return err
}
}
return nil
})
}