SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
s3api: fix S3 Tables auth to allow auto-hashing of body (#8170)
Chris Lu6a9e7360df71
diff --git a/weed/s3api/auth_signature_v4.go b/weed/s3api/auth_signature_v4.goindex bf07df8c1b..9c68a8359b 100644--- a/weed/s3api/auth_signature_v4.go+++ b/weed/s3api/auth_signature_v4.go@@ -477,7 +477,7 @@ func extractV4AuthInfoFromHeader(r *http.Request) (*v4AuthInfo, s3err.ErrorCode)}hashedPayload := getContentSha256Cksum(r)- if signV4Values.Credential.scope.service != "s3" && signV4Values.Credential.scope.service != "s3tables" && hashedPayload == emptySHA256 && r.Body != nil {+ if signV4Values.Credential.scope.service != "s3" && hashedPayload == emptySHA256 && r.Body != nil {var hashErr errorhashedPayload, hashErr = streamHashRequestBody(r, iamRequestBodyLimit)if hashErr != nil {diff --git a/weed/s3api/auth_signature_v4_test.go b/weed/s3api/auth_signature_v4_test.goindex 9ec4f232e3..849d895b5b 100644--- a/weed/s3api/auth_signature_v4_test.go+++ b/weed/s3api/auth_signature_v4_test.go@@ -1,10 +1,71 @@package s3apiimport (+ "bytes"+ "crypto/sha256"+ "encoding/hex"+ "fmt""net/http""testing"+ "time"++ "github.com/seaweedfs/seaweedfs/weed/s3api/s3err")+func TestExtractV4AuthInfoFromHeader_S3Tables(t *testing.T) {+ now := time.Now().UTC()+ dateStr := now.Format(iso8601Format)++ tests := []struct {+ name string+ service string+ body string+ expectAutoHash bool+ }{+ {+ name: "s3 service should not auto-hash",+ service: "s3",+ body: "hello",+ expectAutoHash: false,+ },+ {+ name: "s3tables service should auto-hash",+ service: "s3tables",+ body: "hello",+ expectAutoHash: true,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ body := bytes.NewReader([]byte(tt.body))+ req, _ := http.NewRequest(http.MethodPost, "http://localhost/", body)++ authHeader := fmt.Sprintf("AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/%s/us-east-1/%s/aws4_request, SignedHeaders=host, Signature=dummy",+ now.Format(yyyymmdd), tt.service)+ req.Header.Set("Authorization", authHeader)+ req.Header.Set("x-amz-date", dateStr)++ authInfo, errCode := extractV4AuthInfoFromHeader(req)+ if errCode != s3err.ErrNone {+ t.Fatalf("extractV4AuthInfoFromHeader failed: %v", errCode)+ }++ if tt.expectAutoHash {+ expectedHash := sha256.Sum256([]byte(tt.body))+ expectedHashStr := hex.EncodeToString(expectedHash[:])+ if authInfo.HashedPayload != expectedHashStr {+ t.Errorf("Expected auto-hashed payload %s, got %s", expectedHashStr, authInfo.HashedPayload)+ }+ } else {+ if authInfo.HashedPayload != emptySHA256 {+ t.Errorf("Expected non-auto-hashed payload %s (emptySHA256), got %s", emptySHA256, authInfo.HashedPayload)+ }+ }+ })+ }+}+func TestBuildPathWithForwardedPrefix(t *testing.T) {tests := []struct {name string