mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
s3api: fail closed when the directory marker lock check cannot read the marker (#13326)
* s3api: refuse a directory marker PUT when the existing marker cannot be read Only a missing marker skips the Object Lock check. Any other lookup error now fails the request instead of letting mkdir replace a marker that may be under retention or legal hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: create the Extended map before applying upload ACL metadata A directory extracted from a zip without an owner header reached applyPutObjectACL with a nil Extended map and panicked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: refuse extracting over a marker that cannot be read The zip extract mkdir path had the same fail-open lookup as the directory marker PUT; a failed read now reports InternalError for the member. 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
d6d5e99f9b
commit
a7c1cc32ec
5 files changed
+122
-2
No files matched your search
@@ -267,9 +267,13 @@ func (s3a *S3ApiServer) extractZipObject(w http.ResponseWriter, r *http.Request,
|
||||
// must read there too — a routed read can miss a marker the owner
|
||||
// has not received yet.
|
||||
existing, existErr := s3a.getEntry(dirName, entryName)
|
||||
if existErr != nil {
|
||||
if errors.Is(existErr, filer_pb.ErrNotFound) {
|
||||
return s3err.ErrNone
|
||||
}
|
||||
if existErr != nil {
|
||||
glog.Errorf("extractZipObject: cannot read existing marker %s/%s: %v", bucket, memberKey, existErr)
|
||||
return s3err.ErrInternalError
|
||||
}
|
||||
if lockErr := s3a.enforceObjectLockOnEntry(existing, bucket, memberKey, "", s3a.evaluateGovernanceBypassRequest(r, bucket, memberKey)); lockErr != nil {
|
||||
return s3err.ErrAccessDenied
|
||||
}
|
||||
|
||||
@@ -8,11 +8,14 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func makeZipArchive(t *testing.T, members map[string]string) []byte {
|
||||
@@ -191,3 +194,61 @@ func TestExtractZipPutObjectRejectsExplicitSSE(t *testing.T) {
|
||||
t.Fatalf("entries created despite explicit SSE headers: %v", filerImpl.entries)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractZipOverLockedMarkerFailsClosedOnLookupError(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
absent bool
|
||||
lookupErr error
|
||||
wantErr []string
|
||||
}{
|
||||
{name: "absent", absent: true},
|
||||
{name: "locked", wantErr: []string{"zipdir: AccessDenied"}},
|
||||
{name: "lookup error", lookupErr: status.Error(codes.Unavailable, "filer unavailable"), wantErr: []string{"zipdir: InternalError"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s3a, filerImpl := newExtractTestServer(t)
|
||||
s3a.bucketConfigCache.Set("b", &BucketConfig{
|
||||
Name: "b",
|
||||
Versioning: s3_constants.VersioningEnabled,
|
||||
ObjectLockConfig: &ObjectLockConfiguration{ObjectLockEnabled: s3_constants.ObjectLockEnabled},
|
||||
})
|
||||
locked := &filer_pb.Entry{
|
||||
Name: "zipdir",
|
||||
IsDirectory: true,
|
||||
Attributes: &filer_pb.FuseAttributes{Mime: "locked"},
|
||||
Extended: map[string][]byte{s3_constants.ExtLegalHoldKey: []byte(s3_constants.LegalHoldOn)},
|
||||
}
|
||||
if !tc.absent {
|
||||
filerImpl.entries["/buckets/b/zipdir"] = locked
|
||||
}
|
||||
filerImpl.lookupErr, filerImpl.lookupFailKey = tc.lookupErr, "/buckets/b/zipdir"
|
||||
|
||||
body := makeZipArchive(t, map[string]string{"zipdir/": ""})
|
||||
r := httptest.NewRequest(http.MethodPut, "/b/upload.zip", bytes.NewReader(body))
|
||||
r.Header.Set(s3_constants.SeaweedFSExtract, "zip")
|
||||
rec := httptest.NewRecorder()
|
||||
s3a.extractZipObject(rec, r, "b", "upload.zip", r.Body)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200; body: %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var result extractZipResult
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(result.Errors, tc.wantErr) {
|
||||
t.Fatalf("errors = %v, want %v", result.Errors, tc.wantErr)
|
||||
}
|
||||
filerImpl.mu.Lock()
|
||||
defer filerImpl.mu.Unlock()
|
||||
entry := filerImpl.entries["/buckets/b/zipdir"]
|
||||
if entry == nil || !entry.IsDirectory {
|
||||
t.Fatalf("marker missing: %+v", entry)
|
||||
}
|
||||
if !tc.absent && (entry.Attributes.Mime != "locked" || string(entry.Extended[s3_constants.ExtLegalHoldKey]) != s3_constants.LegalHoldOn) {
|
||||
t.Fatalf("locked marker replaced: %+v", entry)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -318,9 +318,13 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
|
||||
// must read there too — a routed read can miss a marker the owner
|
||||
// has not received yet.
|
||||
existing, existErr := s3a.getEntry(fullDirPath, entryName)
|
||||
if existErr != nil {
|
||||
if errors.Is(existErr, filer_pb.ErrNotFound) {
|
||||
return s3err.ErrNone
|
||||
}
|
||||
if existErr != nil {
|
||||
glog.Errorf("PutObjectHandler: cannot read existing marker %s/%s: %v", bucket, object, existErr)
|
||||
return s3err.ErrInternalError
|
||||
}
|
||||
if lockErr := s3a.enforceObjectLockOnEntry(existing, bucket, object, "", s3a.evaluateGovernanceBypassRequest(r, bucket, object)); lockErr != nil {
|
||||
glog.V(2).Infof("PutObjectHandler: object lock permissions check failed for %s/%s: %v", bucket, object, lockErr)
|
||||
return s3err.ErrAccessDenied
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
"github.com/seaweedfs/seaweedfs/weed/wdclient"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidateRetention(t *testing.T) {
|
||||
@@ -1293,3 +1294,50 @@ func TestRoutedDeleteOfLockedDeleteMarkerSkipsWormGuard(t *testing.T) {
|
||||
t.Fatalf("delete marker removal must not carry WORM guards, got %+v", cond)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPutDirectoryMarkerOverLockedMarkerFailsClosedOnLookupError(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
absent bool
|
||||
lookupErr error
|
||||
want int
|
||||
}{
|
||||
{name: "absent", absent: true, want: http.StatusOK},
|
||||
{name: "locked", want: http.StatusForbidden},
|
||||
{name: "lookup error", lookupErr: status.Error(codes.Unavailable, "filer unavailable"), want: http.StatusInternalServerError},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s3a, filer, _ := newHeaderTestServer(t, s3_constants.VersioningEnabled)
|
||||
s3a.bucketConfigCache.Set("b", &BucketConfig{
|
||||
Name: "b",
|
||||
Versioning: s3_constants.VersioningEnabled,
|
||||
ObjectLockConfig: &ObjectLockConfiguration{ObjectLockEnabled: s3_constants.ObjectLockEnabled},
|
||||
})
|
||||
if !tc.absent {
|
||||
filer.entries["/buckets/b/dir"] = &filer_pb.Entry{
|
||||
Name: "dir",
|
||||
IsDirectory: true,
|
||||
Content: []byte("locked"),
|
||||
Attributes: &filer_pb.FuseAttributes{},
|
||||
Extended: map[string][]byte{s3_constants.ExtLegalHoldKey: []byte(s3_constants.LegalHoldOn)},
|
||||
}
|
||||
}
|
||||
filer.lookupErr, filer.lookupFailKey = tc.lookupErr, "/buckets/b/dir"
|
||||
|
||||
req, probe := newHeaderTestRequest("/b/dir/", "dir/", "replaced", "Content-Type", "text/plain")
|
||||
s3a.PutObjectHandler(probe, req)
|
||||
|
||||
require.Equal(t, tc.want, probe.Code, probe.Body.String())
|
||||
filer.mu.Lock()
|
||||
defer filer.mu.Unlock()
|
||||
entry := filer.entries["/buckets/b/dir"]
|
||||
require.NotNil(t, entry)
|
||||
if tc.absent {
|
||||
require.Equal(t, "replaced", string(entry.Content))
|
||||
return
|
||||
}
|
||||
require.Equal(t, "locked", string(entry.Content))
|
||||
require.Equal(t, s3_constants.LegalHoldOn, string(entry.Extended[s3_constants.ExtLegalHoldKey]))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -289,6 +289,9 @@ func (s3a *S3ApiServer) attachPutObjectACL(r, aclRequest *http.Request, metadata
|
||||
// Multipart parts do not carry this PutObject context.
|
||||
func applyPutObjectACL(r *http.Request, entry *filer_pb.Entry) {
|
||||
metadata, _ := r.Context().Value(putObjectACLContextKey{}).(putObjectACLMetadata)
|
||||
if len(metadata.extended) > 0 && entry.Extended == nil {
|
||||
entry.Extended = make(map[string][]byte, len(metadata.extended))
|
||||
}
|
||||
for key, value := range metadata.extended {
|
||||
entry.Extended[key] = value
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user