Files
seaweedfs/weed/server/webdav_object_lock.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

111 lines
3.3 KiB
Go

package weed_server
import (
"context"
"errors"
"os"
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_objectlock"
"github.com/seaweedfs/seaweedfs/weed/util"
)
func (fs *WebDavFileSystem) getEntry(ctx context.Context, p string) (*filer_pb.Entry, error) {
entry, _, _, err := filer_pb.GetEntry(ctx, fs, util.FullPath(p))
if errors.Is(err, filer_pb.ErrNotFound) || err == nil && entry == nil {
return nil, os.ErrNotExist
}
return entry, err
}
// checkWritable refuses a write that would replace a protected file; a file
// over a directory is left for the filer to refuse.
func (fs *WebDavFileSystem) checkWritable(ctx context.Context, p string) error {
entry, err := fs.getEntry(ctx, p)
if errors.Is(err, os.ErrNotExist) {
return nil
}
if err != nil {
return err
}
if entry.IsDirectory {
return nil
}
return fs.checkEntryProtected(ctx, p, entry)
}
// checkEntryProtected refuses to change an entry that the S3 API or the filer
// HTTP API would refuse to change: one under an active Object Lock or WORM.
func (fs *WebDavFileSystem) checkEntryProtected(ctx context.Context, p string, entry *filer_pb.Entry) error {
if string(entry.Extended[s3_constants.ExtDeleteMarkerKey]) != "true" && s3_objectlock.EntryHasActiveLock(entry, time.Now()) {
glog.V(0).Infof("webdav: %s is under Object Lock", p)
return os.ErrPermission
}
if entry.WormEnforcedAtTsNs == 0 {
return nil
}
fc, err := filer.ReadFilerConfFromClient(ctx, fs, fs.filerClient)
if err != nil {
return err
}
if fc.WormEnforced(p, entry.WormEnforcedAtTsNs) {
glog.V(0).Infof("webdav: %s is write-once", p)
return os.ErrPermission
}
return nil
}
// checkSubtreeProtected refuses to delete or move a directory that a WORM
// rule covers or that holds an object under Object Lock.
func (fs *WebDavFileSystem) checkSubtreeProtected(ctx context.Context, dir string) error {
fc, err := filer.ReadFilerConfFromClient(ctx, fs, fs.filerClient)
if err != nil {
return err
}
if fc.IntersectsWorm(dir) {
glog.V(0).Infof("webdav: %s intersects a WORM rule", dir)
return os.ErrPermission
}
var locked bool
if err := fs.WithFilerClient(true, func(client filer_pb.SeaweedFilerClient) error {
locked, err = s3_objectlock.HasObjectsWithActiveLocks(ctx, client, dir)
return err
}); err != nil {
return err
}
if locked {
glog.V(0).Infof("webdav: %s holds objects under Object Lock", dir)
return os.ErrPermission
}
return nil
}
// checkRenameProtected refuses to move a protected entry, a directory holding
// one, or onto a protected target, which the rename would replace.
func (fs *WebDavFileSystem) checkRenameProtected(ctx context.Context, oldName, newName string) error {
srcEntry, err := fs.getEntry(ctx, oldName)
if err != nil {
return err
}
if err := fs.checkEntryProtected(ctx, oldName, srcEntry); err != nil {
return err
}
if srcEntry.IsDirectory {
if err := fs.checkSubtreeProtected(ctx, oldName); err != nil {
return err
}
}
dstEntry, err := fs.getEntry(ctx, newName)
if errors.Is(err, os.ErrNotExist) {
return nil
}
if err != nil {
return err
}
return fs.checkEntryProtected(ctx, newName, dstEntry)
}