Files
seaweedfs/weed/server/filer_grpc_scope_worm.go
T
Chris LuandClaude Opus 5.5 dbbf2907a6 webdav: refuse to delete, move or overwrite entries under Object Lock or WORM (#12959)
* webdav: refuse to delete entries under Object Lock or WORM

DELETE removed versions under legal hold or retention and WORM files that
the S3 API and the filer HTTP API refuse to delete. Check the entry, and
for a collection everything below it, then pin the delete to the Object
Lock state that was checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* webdav: refuse to move entries under Object Lock or WORM

MOVE could rename a locked version or WORM file away, move a directory
holding them, or replace a protected target. Check the source, a source
directory's contents and the target before the rename.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* webdav: refuse to overwrite entries under Object Lock or WORM

PUT and COPY replaced a locked or WORM file with a fresh entry, dropping
its content and its lock. Check an existing file before creating over it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* webdav: pin an upload's final update to the Object Lock state it read

An upload writes the whole entry back when it closes. A hold or retention
set on the new object while the upload was buffering would be dropped, so
the filer now refuses the update if that state changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* webdav: recheck an upload's target when it commits instead of pinning it

The precondition on the final update sent it to the path's write owner,
while the placeholder create stayed on the connected filer. With
separate filer stores the owner could miss the placeholder and refuse
the update, leaving an empty file. The upload now rechecks the target
right before the update, as the SFTP upload does, and the update stays
local.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: share the WORM retention and subtree checks

FilerConf.WormEnforced and IntersectsWorm replace the copies in the filer
server and mount; ReadFilerConfFromClient reads filer.conf over a filer client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* sftp, webdav: use the shared Object Lock and WORM helpers

Both servers now call FilerConf.WormEnforced, IntersectsWorm,
ReadFilerConfFromClient and s3_objectlock.ObjectLockState instead of
keeping their own copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 14:08:06 -08:00

44 lines
1.4 KiB
Go

package weed_server
import (
"context"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/util/constants"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// checkScopeWorm applies the same WORM retention decision used by the HTTP
// filer to scoped gRPC mutations. The caller holds the path lock before
// invoking this helper, so the lookup and the mutation cannot be interleaved
// on this filer.
func (fs *FilerServer) checkScopeWorm(ctx context.Context, fullPath string) error {
if !scopeKeepOnly(ctx) {
return nil
}
enforced, err := fs.wormEnforcedForEntry(ctx, fullPath)
if err != nil {
return fmt.Errorf("check WORM %s: %w", fullPath, err)
}
if enforced {
return status.Error(codes.PermissionDenied, constants.ErrMsgOperationNotPermitted)
}
return nil
}
// checkScopeWormDirectory refuses a subtree mutation wherever WORM could apply.
// The endpoint path locks do not lock descendants, so checking their timestamps
// before mutation would race with child writes. Check configuration instead,
// before moving or deleting any entries, even if no child is currently retained.
func (fs *FilerServer) checkScopeWormDirectory(ctx context.Context, fullPath string) error {
if !scopeKeepOnly(ctx) {
return nil
}
if fs.filer.FilerConf.IntersectsWorm(fullPath) {
return status.Error(codes.PermissionDenied, "scoped directory mutation intersects a WORM rule")
}
return nil
}