mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 10:54:08 +01:00
s3api: report no ownership controls after DeleteBucketOwnershipControls (#12748)
* test/s3: run tigrisdata-community s3-api-compat-tests in CI Runs the suite, pinned to a commit, against weed mini through a small provider patch, and fails on any test that is not in expected_failures.txt or on a listed test that starts passing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * s3api: report no ownership controls after DeleteBucketOwnershipControls GetBucketOwnershipControls reports BucketOwnerEnforced for a bucket that never stored a setting, so it kept reporting it after the setting was deleted. The delete now records that it happened, and GET answers OwnershipControlsNotFoundError until ownership is put again. How objects are written after the delete is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * s3api: answer DeleteBucketOwnershipControls with 204 No Content AWS answers a successful DeleteBucketOwnershipControls with 204 and no body; this answered 200 with an empty OwnershipControls document. 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
aceb089bc8
commit
b1c315b837
12 files changed
+383
-11
No files matched your search
@@ -5,6 +5,7 @@ const (
|
||||
ExtAmzOwnerKey = "Seaweed-X-Amz-Owner"
|
||||
ExtAmzAclKey = "Seaweed-X-Amz-Acl"
|
||||
ExtOwnershipKey = "Seaweed-X-Amz-Ownership"
|
||||
ExtOwnershipDeletedKey = "Seaweed-X-Amz-Ownership-Deleted"
|
||||
ExtPublicAccessBlockKey = "Seaweed-X-Amz-Public-Access-Block"
|
||||
ExtVersioningKey = "Seaweed-X-Amz-Versioning"
|
||||
ExtVersionIdKey = "Seaweed-X-Amz-Version-Id"
|
||||
|
||||
@@ -36,6 +36,7 @@ type BucketConfig struct {
|
||||
Name string
|
||||
Versioning string // "Enabled", "Suspended", or ""
|
||||
Ownership string
|
||||
OwnershipDeleted bool // DeleteBucketOwnershipControls removed it; GET reports none
|
||||
ACL []byte
|
||||
Owner string
|
||||
IdentityId string // identity that created the bucket
|
||||
@@ -432,6 +433,7 @@ func (s3a *S3ApiServer) newBucketConfigFromEntry(bucket string, entry *filer_pb.
|
||||
if ownership, exists := entry.Extended[s3_constants.ExtOwnershipKey]; exists {
|
||||
config.Ownership = string(ownership)
|
||||
}
|
||||
config.OwnershipDeleted = len(entry.Extended[s3_constants.ExtOwnershipDeletedKey]) > 0
|
||||
if data, exists := entry.Extended[s3_constants.ExtPublicAccessBlockKey]; exists && len(data) > 0 {
|
||||
if pab, err := parsePublicAccessBlock(data); err == nil {
|
||||
config.PublicAccessBlock = pab
|
||||
@@ -587,6 +589,11 @@ func applyBucketConfigToExtended(config *BucketConfig, ext map[string][]byte) er
|
||||
}
|
||||
setOrDelete(s3_constants.ExtVersioningKey, []byte(config.Versioning))
|
||||
setOrDelete(s3_constants.ExtOwnershipKey, []byte(config.Ownership))
|
||||
if config.OwnershipDeleted && config.Ownership == "" {
|
||||
ext[s3_constants.ExtOwnershipDeletedKey] = []byte("true")
|
||||
} else {
|
||||
delete(ext, s3_constants.ExtOwnershipDeletedKey)
|
||||
}
|
||||
if config.PublicAccessBlock != nil {
|
||||
data, err := xml.Marshal(config.PublicAccessBlock)
|
||||
if err != nil {
|
||||
@@ -767,6 +774,9 @@ func (s3a *S3ApiServer) getBucketOwnership(bucket string) (string, s3err.ErrorCo
|
||||
if errCode != s3err.ErrNone {
|
||||
return "", errCode
|
||||
}
|
||||
if config.OwnershipDeleted && config.Ownership == "" {
|
||||
return "", s3err.OwnershipControlsNotFoundError
|
||||
}
|
||||
|
||||
return s3_constants.EffectiveOwnership(config.Ownership), s3err.ErrNone
|
||||
}
|
||||
|
||||
@@ -1505,7 +1505,7 @@ func (s3a *S3ApiServer) GetBucketOwnershipControls(w http.ResponseWriter, r *htt
|
||||
// DeleteBucketOwnershipControls https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketOwnershipControls.html
|
||||
func (s3a *S3ApiServer) DeleteBucketOwnershipControls(w http.ResponseWriter, r *http.Request) {
|
||||
bucket, _ := s3_constants.GetBucketAndObject(r)
|
||||
glog.V(3).Infof("PutBucketOwnershipControls %s", bucket)
|
||||
glog.V(3).Infof("DeleteBucketOwnershipControls %s", bucket)
|
||||
|
||||
errCode := s3a.checkAccessByOwnership(r, bucket)
|
||||
if errCode != s3err.ErrNone {
|
||||
@@ -1529,17 +1529,16 @@ func (s3a *S3ApiServer) DeleteBucketOwnershipControls(w http.ResponseWriter, r *
|
||||
return
|
||||
}
|
||||
|
||||
delete(bucketEntry.Extended, s3_constants.ExtOwnershipKey)
|
||||
err = s3a.updateEntry(s3a.option.BucketsPath, bucketEntry)
|
||||
if err != nil {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||
if errCode := s3a.updateBucketConfig(bucket, func(config *BucketConfig) error {
|
||||
config.Ownership = ""
|
||||
config.OwnershipDeleted = true
|
||||
return nil
|
||||
}); errCode != s3err.ErrNone {
|
||||
s3err.WriteErrorResponse(w, r, errCode)
|
||||
return
|
||||
}
|
||||
|
||||
emptyOwnershipControls := &s3.OwnershipControls{
|
||||
Rules: []*s3.OwnershipControlsRule{},
|
||||
}
|
||||
s3err.WriteAwsXMLResponse(w, r, http.StatusOK, emptyOwnershipControls)
|
||||
s3err.WriteEmptyResponse(w, r, http.StatusNoContent)
|
||||
}
|
||||
|
||||
// GetBucketVersioningHandler Get Bucket Versioning status
|
||||
|
||||
@@ -207,6 +207,55 @@ func TestGetBucketOwnershipControlsDefaultsToBucketOwnerEnforced(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBucketOwnershipControlsAfterDelete(t *testing.T) {
|
||||
ownerID := AccountAdmin.Id
|
||||
s3a := newMiscTestServer(t, "b")
|
||||
s3a.bucketConfigCache.Set("b", &BucketConfig{Name: "b", OwnershipDeleted: true})
|
||||
s3a.bucketRegistry = NewBucketRegistry(nil)
|
||||
s3a.bucketRegistry.setMetadataCache(&BucketMetaData{
|
||||
Name: "b",
|
||||
Owner: &s3.Owner{ID: &ownerID},
|
||||
})
|
||||
req := newBucketRequest(http.MethodGet, "b", "ownershipControls=", "")
|
||||
req.Header.Set(s3_constants.AmzAccountId, AccountAdmin.Id)
|
||||
req = req.WithContext(s3_constants.SetIdentityInContext(req.Context(), &Identity{
|
||||
Name: "admin",
|
||||
Account: &AccountAdmin,
|
||||
Actions: []Action{s3_constants.ACTION_ADMIN},
|
||||
}))
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
s3a.GetBucketOwnershipControls(rec, req)
|
||||
|
||||
if rec.Code != http.StatusNotFound || !strings.Contains(rec.Body.String(), "OwnershipControlsNotFoundError") {
|
||||
t.Fatalf("status = %d, body=%s, want 404 OwnershipControlsNotFoundError", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBucketConfigOwnershipDeletedRoundTrip(t *testing.T) {
|
||||
s3a := &S3ApiServer{}
|
||||
ext := map[string][]byte{s3_constants.ExtOwnershipKey: []byte(s3_constants.OwnershipObjectWriter)}
|
||||
|
||||
deleted := &BucketConfig{OwnershipDeleted: true}
|
||||
if err := applyBucketConfigToExtended(deleted, ext); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := ext[s3_constants.ExtOwnershipKey]; ok {
|
||||
t.Fatalf("ownership still stored after delete: %v", ext)
|
||||
}
|
||||
if got := s3a.newBucketConfigFromEntry("b", &filer_pb.Entry{Extended: ext}); !got.OwnershipDeleted || got.Ownership != "" {
|
||||
t.Fatalf("reloaded config = %+v, want deleted ownership", got)
|
||||
}
|
||||
|
||||
put := &BucketConfig{Ownership: s3_constants.OwnershipBucketOwnerEnforced, OwnershipDeleted: true}
|
||||
if err := applyBucketConfigToExtended(put, ext); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := s3a.newBucketConfigFromEntry("b", &filer_pb.Entry{Extended: ext}); got.OwnershipDeleted || got.Ownership != s3_constants.OwnershipBucketOwnerEnforced {
|
||||
t.Fatalf("reloaded config = %+v, want stored BucketOwnerEnforced", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBucketAccelerateConfiguration(t *testing.T) {
|
||||
s3a := newMiscTestServer(t, "b")
|
||||
req := newBucketRequest(http.MethodGet, "b", "accelerate=", "")
|
||||
|
||||
Reference in new issue
Block a user