mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-16 00:38:53 +01:00
s3: accept the governance bypass header case-insensitively (#12667)
* s3: accept the governance bypass header case-insensitively botocore and the AWS CLI send x-amz-bypass-governance-retention: True, so the exact "true" match ignored the bypass and governance-locked deletes and retention changes failed with AccessDenied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3: test governance bypass with SDK-style header values Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c0509cf499
commit
c09009a74f
6 files changed
+65
-10
No files matched your search
@@ -82,6 +82,7 @@ const (
|
||||
AmzObjectLockMode = "X-Amz-Object-Lock-Mode"
|
||||
AmzObjectLockRetainUntilDate = "X-Amz-Object-Lock-Retain-Until-Date"
|
||||
AmzObjectLockLegalHold = "X-Amz-Object-Lock-Legal-Hold"
|
||||
AmzBypassGovernanceRetention = "X-Amz-Bypass-Governance-Retention"
|
||||
|
||||
// S3 checksum headers
|
||||
AmzChecksumAlgorithm = "X-Amz-Checksum-Algorithm"
|
||||
|
||||
@@ -239,6 +239,18 @@ func TestGovernanceBypassHeader(t *testing.T) {
|
||||
expectedResult: true,
|
||||
description: "Header with 'true' value should enable bypass",
|
||||
},
|
||||
{
|
||||
name: "bypass_header_title_case",
|
||||
headerValue: "True",
|
||||
expectedResult: true,
|
||||
description: "botocore and the AWS CLI send 'True'",
|
||||
},
|
||||
{
|
||||
name: "bypass_header_upper_case",
|
||||
headerValue: "TRUE",
|
||||
expectedResult: true,
|
||||
description: "Header value is case-insensitive",
|
||||
},
|
||||
{
|
||||
name: "bypass_header_false",
|
||||
headerValue: "false",
|
||||
@@ -266,7 +278,7 @@ func TestGovernanceBypassHeader(t *testing.T) {
|
||||
req.Header.Set("x-amz-bypass-governance-retention", tt.headerValue)
|
||||
}
|
||||
|
||||
result := req.Header.Get("x-amz-bypass-governance-retention") == "true"
|
||||
result := governanceBypassRequested(req)
|
||||
|
||||
if result != tt.expectedResult {
|
||||
t.Errorf("bypass header check = %v, want %v. %s", result, tt.expectedResult, tt.description)
|
||||
@@ -450,7 +462,7 @@ func TestGovernancePermissionHTTPFlow(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test the header processing logic used in handlers
|
||||
bypassGovernance := req.Header.Get("x-amz-bypass-governance-retention") == "true"
|
||||
bypassGovernance := governanceBypassRequested(req)
|
||||
|
||||
if bypassGovernance != tt.expectedBypassGovernance {
|
||||
t.Errorf("Expected bypassGovernance to be %v, got %v", tt.expectedBypassGovernance, bypassGovernance)
|
||||
@@ -471,7 +483,7 @@ func TestGovernancePermissionMethodCalls(t *testing.T) {
|
||||
// Extract parameters as done in the handler
|
||||
bucket, object := s3_constants.GetBucketAndObject(req)
|
||||
versionId := req.URL.Query().Get("versionId")
|
||||
bypassGovernance := req.Header.Get("x-amz-bypass-governance-retention") == "true"
|
||||
bypassGovernance := governanceBypassRequested(req)
|
||||
|
||||
// Verify the parameters are extracted correctly
|
||||
// Note: The actual bucket and object extraction depends on the URL structure
|
||||
@@ -491,7 +503,7 @@ func TestGovernancePermissionMethodCalls(t *testing.T) {
|
||||
|
||||
// Extract parameters as done in the handler
|
||||
bucket, object := s3_constants.GetBucketAndObject(req)
|
||||
bypassGovernance := req.Header.Get("x-amz-bypass-governance-retention") == "true"
|
||||
bypassGovernance := governanceBypassRequested(req)
|
||||
versioningEnabled := true // Would be determined by isVersioningEnabled(bucket)
|
||||
|
||||
// Verify the parameters are extracted correctly
|
||||
|
||||
@@ -2594,11 +2594,8 @@ func (s3a *S3ApiServer) validateObjectLockHeaders(r *http.Request, bucket, objec
|
||||
}
|
||||
}
|
||||
|
||||
// Check for governance bypass header - only valid for buckets with Object Lock enabled
|
||||
bypassGovernance := r.Header.Get("x-amz-bypass-governance-retention") == "true"
|
||||
|
||||
// Governance bypass headers are only valid for buckets with Object Lock enabled
|
||||
if bypassGovernance && !objectLockEnabled {
|
||||
if governanceBypassRequested(r) && !objectLockEnabled {
|
||||
return ErrGovernanceBypassVersioningRequired
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,38 @@ func TestGovernanceBypassDoesNotInheritDeleteObjectVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvaluateGovernanceBypassRequestHeaderCase(t *testing.T) {
|
||||
iam := &IdentityAccessManagement{}
|
||||
require.NoError(t, iam.PutPolicy("BypassGovernance",
|
||||
`{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:DeleteObjectVersion","s3:BypassGovernanceRetention"],"Resource":"arn:aws:s3:::worm/*"}]}`))
|
||||
s3a := &S3ApiServer{iam: iam}
|
||||
|
||||
for _, tc := range []struct {
|
||||
header string
|
||||
want bool
|
||||
}{
|
||||
{"true", true},
|
||||
{"True", true},
|
||||
{"TRUE", true},
|
||||
{"false", false},
|
||||
{"", false},
|
||||
} {
|
||||
req := httptest.NewRequest(http.MethodDelete, "http://localhost:8333/worm/doc.txt?versionId=abc123", nil)
|
||||
req = mux.SetURLVars(req, map[string]string{"bucket": "worm", "object": "doc.txt"})
|
||||
if tc.header != "" {
|
||||
req.Header.Set(s3_constants.AmzBypassGovernanceRetention, tc.header)
|
||||
}
|
||||
req = req.WithContext(s3_constants.SetIdentityInContext(req.Context(), &Identity{
|
||||
Name: "breaker",
|
||||
PolicyNames: []string{"BypassGovernance"},
|
||||
Account: &Account{Id: "test-account"},
|
||||
}))
|
||||
if got := s3a.evaluateGovernanceBypassRequest(req, "worm", "/doc.txt"); got != tc.want {
|
||||
t.Errorf("header %q: evaluateGovernanceBypassRequest() = %v, want %v", tc.header, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The object-lock request headers on PutObject/CreateMultipartUpload must be
|
||||
// authorized as s3:PutObjectRetention / s3:PutObjectLegalHold; s3:PutObject
|
||||
// alone used to set retention and legal hold on new versions.
|
||||
|
||||
@@ -520,6 +520,14 @@ func TestValidateObjectLockHeaders(t *testing.T) {
|
||||
assert.True(t, errors.Is(err, ErrGovernanceBypassVersioningRequired))
|
||||
})
|
||||
|
||||
t.Run("Title-case governance bypass header on non-versioned bucket", func(t *testing.T) {
|
||||
req := httptest.NewRequest("PUT", "/bucket/object", nil)
|
||||
req.Header.Set("x-amz-bypass-governance-retention", "True")
|
||||
|
||||
err := s3a.validateObjectLockHeaders(req, "bucket", "object", false)
|
||||
assert.True(t, errors.Is(err, ErrGovernanceBypassVersioningRequired))
|
||||
})
|
||||
|
||||
t.Run("Governance bypass header on versioned bucket should pass", func(t *testing.T) {
|
||||
req := httptest.NewRequest("PUT", "/bucket/object", nil)
|
||||
req.Header.Set("x-amz-bypass-governance-retention", "true")
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
@@ -543,11 +544,15 @@ func (s3a *S3ApiServer) checkGovernanceBypassPermission(request *http.Request, b
|
||||
return true
|
||||
}
|
||||
|
||||
// AWS SDKs send the boolean as "true" or "True".
|
||||
func governanceBypassRequested(r *http.Request) bool {
|
||||
return strings.EqualFold(r.Header.Get(s3_constants.AmzBypassGovernanceRetention), "true")
|
||||
}
|
||||
|
||||
// evaluateGovernanceBypassRequest evaluates if governance bypass is requested and permitted
|
||||
func (s3a *S3ApiServer) evaluateGovernanceBypassRequest(r *http.Request, bucket, object string) bool {
|
||||
// Step 1: Check if governance bypass was requested via header
|
||||
bypassRequested := r.Header.Get("x-amz-bypass-governance-retention") == "true"
|
||||
if !bypassRequested {
|
||||
if !governanceBypassRequested(r) {
|
||||
// No bypass requested - normal retention enforcement applies
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user