mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
* filer: path- and method-scoped tokens on the filesystem gRPC service * filer: close scoped admission and compatibility gaps * filer: test subscription key ambiguity and retained write success * filer: assert verified peer chains survive subscription fallback * filer: keep a hard link's count and chunks together under a scoped token A scoped write may keep a hard link the target already has, but the link count it sends was stored as is, and its chunks could stay on the name with the link dropped. Either let a scoped token delete its own name and take the chunks of a name outside its grants with it: the forged count reaches zero, or the detached name owns the shared chunks. The handler recheck now refuses a scoped write that changes a stored link's count or keeps its chunks without the link. Dropping the link together with the data, and appending to a linked file, are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: leave subscriptions with a non-scope bearer to the existing verifier The stream interceptor refused a SubscribeMetadata or SubscribeLocalMetadata call whose bearer does not verify under the filer key unless the bearer was a subscription token, and it checked that token with the peer stripped. With no subscription key, or on an mTLS peer, the existing verifier admits such a call, so filer.sync sending another cluster's admin token stopped. When the bearer is no filer scope, the subscription verifier now decides on the original context, as before scoped tokens. A scoped token still reaches the refusal for scoped subscriptions, and malformed metadata is still refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: refuse scoped writes that would make ancestors outside the grant A scoped create, append or rename checked only its target. The filer then creates the target's missing ancestors up to the first one it finds, and turns that one into a directory if it is a file, dropping its ttl. A token granted /data/proj/ws could so promote the file /data/proj, or create /q and /q/r for a grant /q/r/ws. The scope now walks the same ancestors before admitting the write and refuses one outside the write grants that is missing or not a directory. A create with skip_check_parent_directory makes no ancestors and is not walked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: require write grants for scoped lock mutations * filer: document scoped signatures and read-only token upgrades * filer: enforce WORM retention for scoped mutations * filer: refuse scoped writes through shared hard links * filer: drop series notes from scope comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: refuse scoped subtree mutations across WORM rules --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
3.3 KiB
Go
102 lines
3.3 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
func TestScopePosixLockOperationsUseReadWriteGrants(t *testing.T) {
|
|
const key = scopePosixLockKeyPrefix + aliceWS + "/file"
|
|
operations := []struct {
|
|
name string
|
|
op filer_pb.PosixLockOp
|
|
write bool
|
|
}{
|
|
{name: "get lock", op: filer_pb.PosixLockOp_GET_LK},
|
|
{name: "try lock", op: filer_pb.PosixLockOp_TRY_LOCK, write: true},
|
|
{name: "unlock", op: filer_pb.PosixLockOp_UNLOCK, write: true},
|
|
{name: "release posix owner", op: filer_pb.PosixLockOp_RELEASE_POSIX_OWNER, write: true},
|
|
{name: "release flock owner", op: filer_pb.PosixLockOp_RELEASE_FLOCK_OWNER, write: true},
|
|
{name: "keep alive", op: filer_pb.PosixLockOp_KEEP_ALIVE, write: true},
|
|
}
|
|
|
|
for _, tc := range operations {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
h := newScopeHarness(t)
|
|
c := h.client(scopedToken("alice", time.Hour, nil, []string{aliceWS}))
|
|
call := func() error {
|
|
_, err := c.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{
|
|
Key: key,
|
|
Op: tc.op,
|
|
Lock: &filer_pb.PosixLockRange{
|
|
Start: 1,
|
|
End: 2,
|
|
},
|
|
})
|
|
return err
|
|
}
|
|
if tc.write {
|
|
expectScopeDenied(t, h, "PosixLock", "write operation under read-only prefix", call)
|
|
return
|
|
}
|
|
expectScopeForwarded(t, h, "PosixLock", "GET_LK under read-only prefix", call)
|
|
})
|
|
|
|
t.Run(tc.name+" with write grant", func(t *testing.T) {
|
|
h := newScopeHarness(t)
|
|
c := h.client(scopedToken("alice", time.Hour, []string{aliceWS}, nil))
|
|
expectScopeForwarded(t, h, "PosixLock", "operation under read-write prefix", func() error {
|
|
_, err := c.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{
|
|
Key: key,
|
|
Op: tc.op,
|
|
Lock: &filer_pb.PosixLockRange{
|
|
Start: 1,
|
|
End: 2,
|
|
},
|
|
})
|
|
return err
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestScopePosixLockHardLinkOperationsRequireWriteGrant(t *testing.T) {
|
|
id := []byte("known-hard-link")
|
|
key := scopePosixLockKeyPrefix + "hl:" + hex.EncodeToString(id)
|
|
|
|
readOnly := newScopeHarness(t)
|
|
readOnly.fake.putKV(id, []byte("/buckets/t1/users/alice/workspace/file"))
|
|
readOnlyClient := readOnly.client(scopedToken("alice", time.Hour, nil, []string{aliceWS}))
|
|
expectScopeForwarded(t, readOnly, "PosixLock", "GET_LK on a known hard link with a read-only grant", func() error {
|
|
_, err := readOnlyClient.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{
|
|
Key: key,
|
|
Op: filer_pb.PosixLockOp_GET_LK,
|
|
Lock: &filer_pb.PosixLockRange{},
|
|
})
|
|
return err
|
|
})
|
|
expectScopeDenied(t, readOnly, "PosixLock", "mutating a hard-link lock with only a read-only grant", func() error {
|
|
_, err := readOnlyClient.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{
|
|
Key: key,
|
|
Op: filer_pb.PosixLockOp_TRY_LOCK,
|
|
Lock: &filer_pb.PosixLockRange{},
|
|
})
|
|
return err
|
|
})
|
|
|
|
write := newScopeHarness(t)
|
|
write.fake.putKV(id, []byte("/buckets/t1/users/alice/workspace/file"))
|
|
writeClient := write.client(scopedToken("alice", time.Hour, []string{aliceWS}, nil))
|
|
expectScopeForwarded(t, write, "PosixLock", "mutating a hard-link lock with a write grant", func() error {
|
|
_, err := writeClient.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{
|
|
Key: key,
|
|
Op: filer_pb.PosixLockOp_TRY_LOCK,
|
|
Lock: &filer_pb.PosixLockRange{},
|
|
})
|
|
return err
|
|
})
|
|
}
|