Skip to content

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.

S3: add s3: prefix to x-amz-* condition keys for AWS compatibility (#8765)

Chris Lu152884eff26a
diff --git a/weed/s3api/policy_engine/engine.go b/weed/s3api/policy_engine/engine.go
index d7b4d4758f..2432b695c1 100644
--- a/weed/s3api/policy_engine/engine.go
+++ b/weed/s3api/policy_engine/engine.go
@@ -427,10 +427,11 @@ func ExtractConditionValuesFromRequest(r *http.Request) map[string][]string {
// HTTP method
values["s3:RequestMethod"] = []string{r.Method}
- // Extract custom headers
+ // Extract custom headers with s3: prefix for AWS-compatible condition keys
for key, headerValues := range r.Header {
- if strings.HasPrefix(strings.ToLower(key), "x-amz-") {
- values[strings.ToLower(key)] = headerValues
+ lowerKey := strings.ToLower(key)
+ if strings.HasPrefix(lowerKey, "x-amz-") {
+ values["s3:"+lowerKey] = headerValues
}
}
diff --git a/weed/s3api/policy_engine/engine_test.go b/weed/s3api/policy_engine/engine_test.go
index 7f2da18871..1ad8c434ac 100644
--- a/weed/s3api/policy_engine/engine_test.go
+++ b/weed/s3api/policy_engine/engine_test.go
@@ -444,8 +444,8 @@ func TestExtractConditionValuesFromRequest(t *testing.T) {
t.Errorf("Expected RequestMethod to be GET, got %v", values["s3:RequestMethod"])
}
- if len(values["x-amz-copy-source"]) != 1 || values["x-amz-copy-source"][0] != "source-bucket/source-object" {
- t.Errorf("Expected X-Amz-Copy-Source header to be extracted, got %v", values["x-amz-copy-source"])
+ if len(values["s3:x-amz-copy-source"]) != 1 || values["s3:x-amz-copy-source"][0] != "source-bucket/source-object" {
+ t.Errorf("Expected X-Amz-Copy-Source header to be extracted with s3: prefix, got %v", values["s3:x-amz-copy-source"])
}
// Check that aws:CurrentTime is properly set