diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2025-07-15 23:21:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 23:21:58 -0700 |
| commit | dde1cf63c2ab826844f06555c20df008e37e8312 (patch) | |
| tree | 7d3d35fd5c1306e6e3df7a4dcbe27932ba02bd11 /weed/s3api/s3api_bucket_handlers.go | |
| parent | 64c5dde2f321dbdc24b3cdc00a17c7b6b2c8f0bd (diff) | |
| download | seaweedfs-dde1cf63c2ab826844f06555c20df008e37e8312.tar.xz seaweedfs-dde1cf63c2ab826844f06555c20df008e37e8312.zip | |
S3 Object Lock: ensure x-amz-bucket-object-lock-enabled header (#6990)
* ensure x-amz-bucket-object-lock-enabled header
* fix tests
* combine 2 metadata changes into one
* address comments
* Update s3api_bucket_handlers.go
* Update weed/s3api/s3api_bucket_handlers.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/retention/object_lock_reproduce_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/retention/object_lock_validation_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/retention/s3_bucket_object_lock_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_handlers.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_handlers.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update test/s3/retention/s3_bucket_object_lock_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update weed/s3api/s3api_bucket_handlers.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* package name
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Diffstat (limited to 'weed/s3api/s3api_bucket_handlers.go')
| -rw-r--r-- | weed/s3api/s3api_bucket_handlers.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go index ecc6af2ac..e9dc10cff 100644 --- a/weed/s3api/s3api_bucket_handlers.go +++ b/weed/s3api/s3api_bucket_handlers.go @@ -136,6 +136,48 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request) s3err.WriteErrorResponse(w, r, s3err.ErrInternalError) return } + + // Check for x-amz-bucket-object-lock-enabled header (S3 standard compliance) + if objectLockHeaderValue := r.Header.Get(s3_constants.AmzBucketObjectLockEnabled); strings.EqualFold(objectLockHeaderValue, "true") { + glog.V(3).Infof("PutBucketHandler: enabling Object Lock and Versioning for bucket %s due to x-amz-bucket-object-lock-enabled header", bucket) + + // Atomically update the configuration of the specified bucket. See the updateBucketConfig + // function definition for detailed documentation on parameters and behavior. + errCode := s3a.updateBucketConfig(bucket, func(bucketConfig *BucketConfig) error { + // Enable versioning (required for Object Lock) + bucketConfig.Versioning = s3_constants.VersioningEnabled + + // Enable Object Lock configuration + if bucketConfig.Entry.Extended == nil { + bucketConfig.Entry.Extended = make(map[string][]byte) + } + + // Create basic Object Lock configuration (enabled without default retention) + // The ObjectLockConfiguration struct is defined below in this file. + objectLockConfig := &ObjectLockConfiguration{ + ObjectLockEnabled: s3_constants.ObjectLockEnabled, + } + + // Store the configuration as XML in extended attributes + configXML, err := xml.Marshal(objectLockConfig) + if err != nil { + return fmt.Errorf("failed to marshal Object Lock configuration to XML: %v", err) + } + + bucketConfig.Entry.Extended[s3_constants.ExtObjectLockConfigKey] = configXML + bucketConfig.Entry.Extended[s3_constants.ExtObjectLockEnabledKey] = []byte(s3_constants.ObjectLockEnabled) + + return nil + }) + + if errCode != s3err.ErrNone { + glog.Errorf("PutBucketHandler: failed to enable Object Lock for bucket %s: %v", bucket, errCode) + s3err.WriteErrorResponse(w, r, errCode) + return + } + glog.V(3).Infof("PutBucketHandler: enabled Object Lock and Versioning for bucket %s", bucket) + } + w.Header().Set("Location", "/"+bucket) writeSuccessResponseEmpty(w, r) } |
