From 1f65d9e70819cd9a38f182e897b34a4e4d28f2bf Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 2 Dec 2026 04:10:17 -0800 Subject: [PATCH] s3api: answer GetBucketLocation with a LocationConstraint document (#13292) GetBucketLocation wrote the CreateBucket request body (CreateBucketConfiguration), so clients that check the root element, such as the AWS Rust SDK, failed with "expected LocationConstraint tag". Reply with an empty LocationConstraint in the S3 namespace, which is what AWS sends for us-east-1 buckets. Co-authored-by: Claude Opus 5.5 --- weed/s3api/s3api_bucket_handlers.go | 2 +- weed/s3api/s3api_bucket_handlers_misc_test.go | 17 +++++++++++++++++ weed/s3api/s3api_xsd_generated.go | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go index 6d998fbe6a..d69b4f857a 100644 --- a/weed/s3api/s3api_bucket_handlers.go +++ b/weed/s3api/s3api_bucket_handlers.go @@ -1400,7 +1400,7 @@ func (s3a *S3ApiServer) GetBucketLocationHandler(w http.ResponseWriter, r *http. return } - writeSuccessResponseXML(w, r, CreateBucketConfiguration{}) + writeSuccessResponseXML(w, r, LocationConstraint{}) } // GetBucketRequestPaymentHandler Get bucket request payment diff --git a/weed/s3api/s3api_bucket_handlers_misc_test.go b/weed/s3api/s3api_bucket_handlers_misc_test.go index 1bd9a2f75c..8649cd5afd 100644 --- a/weed/s3api/s3api_bucket_handlers_misc_test.go +++ b/weed/s3api/s3api_bucket_handlers_misc_test.go @@ -3,6 +3,7 @@ package s3api import ( "context" "encoding/json" + "encoding/xml" "fmt" "io" "net/http" @@ -322,6 +323,22 @@ func TestGetBucketLocationInvalidBucketName(t *testing.T) { } } +func TestGetBucketLocationReturnsLocationConstraint(t *testing.T) { + s3a := newMiscTestServer(t, "test-bucket") + rec := httptest.NewRecorder() + + s3a.GetBucketLocationHandler(rec, newBucketRequest(http.MethodGet, "test-bucket", "location=", "")) + + require.Equal(t, http.StatusOK, rec.Code, rec.Body.String()) + var got struct { + XMLName xml.Name + Value string `xml:",chardata"` + } + require.NoError(t, xml.Unmarshal(rec.Body.Bytes(), &got), rec.Body.String()) + require.Equal(t, xml.Name{Space: "http://s3.amazonaws.com/doc/2006-03-01/", Local: "LocationConstraint"}, got.XMLName, rec.Body.String()) + require.Empty(t, got.Value) +} + func TestHandleAutoCreateBucketDisabled(t *testing.T) { s3a := &S3ApiServer{option: &S3ApiServerOption{}} req := newBucketRequest(http.MethodPut, "test-bucket", "", "") diff --git a/weed/s3api/s3api_xsd_generated.go b/weed/s3api/s3api_xsd_generated.go index aecf95f10c..d8cbb88b03 100644 --- a/weed/s3api/s3api_xsd_generated.go +++ b/weed/s3api/s3api_xsd_generated.go @@ -680,6 +680,11 @@ type CreateBucketConfiguration struct { LocationConstraint string `xml:"LocationConstraint"` } +type LocationConstraint struct { + XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint"` + Value string `xml:",chardata"` +} + type CreateBucketResponse struct { CreateBucketReturn CreateBucketResult `xml:"CreateBucketReturn"` }