mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +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>
130 lines
4.2 KiB
Go
130 lines
4.2 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"google.golang.org/grpc/codes"
|
|
)
|
|
|
|
func TestScopeProtectsFilerConfAndItsAncestors(t *testing.T) {
|
|
h := newScopeHarness(t)
|
|
c := h.client(scopedToken("alice", time.Hour, []string{"/"}, nil))
|
|
|
|
expectScopeDenied(t, h, "CreateEntry", "create filer.conf", func() error {
|
|
_, err := c.CreateEntry(scopeCtx(t), &filer_pb.CreateEntryRequest{
|
|
Directory: scopeFilerConfDir,
|
|
Entry: &filer_pb.Entry{Name: scopeFilerConfName},
|
|
})
|
|
return err
|
|
})
|
|
expectScopeDenied(t, h, "UpdateEntry", "update filer.conf", func() error {
|
|
_, err := c.UpdateEntry(scopeCtx(t), &filer_pb.UpdateEntryRequest{
|
|
Directory: scopeFilerConfDir,
|
|
Entry: &filer_pb.Entry{Name: scopeFilerConfName},
|
|
})
|
|
return err
|
|
})
|
|
expectScopeDenied(t, h, "AppendToEntry", "append filer.conf", func() error {
|
|
_, err := c.AppendToEntry(scopeCtx(t), &filer_pb.AppendToEntryRequest{
|
|
Directory: scopeFilerConfDir,
|
|
EntryName: scopeFilerConfName,
|
|
})
|
|
return err
|
|
})
|
|
expectScopeDenied(t, h, "TouchAccessTime", "touch filer.conf", func() error {
|
|
_, err := c.TouchAccessTime(scopeCtx(t), &filer_pb.TouchAccessTimeRequest{
|
|
Directory: scopeFilerConfDir,
|
|
Name: scopeFilerConfName,
|
|
})
|
|
return err
|
|
})
|
|
expectScopeDenied(t, h, "DeleteEntry", "delete filer.conf ancestor", func() error {
|
|
_, err := c.DeleteEntry(scopeCtx(t), &filer_pb.DeleteEntryRequest{
|
|
Directory: "/etc",
|
|
Name: "seaweedfs",
|
|
})
|
|
return err
|
|
})
|
|
expectScopeDenied(t, h, "AtomicRenameEntry", "rename filer.conf ancestor", func() error {
|
|
_, err := c.AtomicRenameEntry(scopeCtx(t), &filer_pb.AtomicRenameEntryRequest{
|
|
OldDirectory: "/etc",
|
|
OldName: "seaweedfs",
|
|
NewDirectory: "/tmp",
|
|
NewName: "seaweedfs",
|
|
})
|
|
return err
|
|
})
|
|
expectScopeDenied(t, h, "AtomicRenameEntry", "rename into filer.conf descendant", func() error {
|
|
_, err := c.AtomicRenameEntry(scopeCtx(t), &filer_pb.AtomicRenameEntryRequest{
|
|
OldDirectory: "/tmp",
|
|
OldName: "ordinary",
|
|
NewDirectory: scopeFilerConfDir + "/" + scopeFilerConfName,
|
|
NewName: "child",
|
|
})
|
|
return err
|
|
})
|
|
|
|
// The configuration directory itself remains usable for ordinary metadata.
|
|
expectScopeForwarded(t, h, "CreateEntry", "create ordinary metadata beside filer.conf", func() error {
|
|
_, err := c.CreateEntry(scopeCtx(t), &filer_pb.CreateEntryRequest{
|
|
Directory: scopeFilerConfDir,
|
|
Entry: &filer_pb.Entry{Name: "ordinary.json"},
|
|
})
|
|
return err
|
|
})
|
|
}
|
|
|
|
func TestScopeStreamsProtectFilerConfDelegatedMutations(t *testing.T) {
|
|
h := newScopeHarness(t)
|
|
c := h.client(scopedToken("alice", time.Hour, []string{"/"}, nil))
|
|
|
|
beforeRename := len(h.fake.received("StreamRenameEntry"))
|
|
rename, err := c.StreamRenameEntry(scopeCtx(t), &filer_pb.StreamRenameEntryRequest{
|
|
OldDirectory: "/etc",
|
|
OldName: "seaweedfs",
|
|
NewDirectory: "/tmp",
|
|
NewName: "moved",
|
|
})
|
|
if err == nil {
|
|
_, err = rename.Recv()
|
|
}
|
|
expectScopeCode(t, "stream rename filer.conf ancestor", err, codes.PermissionDenied)
|
|
if got := len(h.fake.received("StreamRenameEntry")); got != beforeRename {
|
|
t.Fatalf("refused stream rename reached handler: %d calls before=%d", got, beforeRename)
|
|
}
|
|
|
|
stream, err := c.StreamMutateEntry(scopeCtx(t))
|
|
if err != nil {
|
|
t.Fatalf("open mutate stream: %v", err)
|
|
}
|
|
if err := stream.Send(&filer_pb.StreamMutateEntryRequest{
|
|
RequestId: 1,
|
|
Request: &filer_pb.StreamMutateEntryRequest_CreateRequest{CreateRequest: &filer_pb.CreateEntryRequest{
|
|
Directory: scopeFilerConfDir,
|
|
Entry: &filer_pb.Entry{Name: scopeFilerConfName},
|
|
}},
|
|
}); err != nil {
|
|
t.Fatalf("send filer.conf create: %v", err)
|
|
}
|
|
response, err := stream.Recv()
|
|
if err != nil {
|
|
t.Fatalf("receive filer.conf refusal: %v", err)
|
|
}
|
|
if response.GetErrno() != scopeErrnoEACCES || response.GetError() == "" || !response.GetIsLast() {
|
|
t.Fatalf("filer.conf stream refusal=%v, want EACCES", response)
|
|
}
|
|
if err := stream.CloseSend(); err != nil {
|
|
t.Fatalf("close mutate stream: %v", err)
|
|
}
|
|
if _, err := stream.Recv(); !errors.Is(err, io.EOF) {
|
|
t.Fatalf("mutate stream after close = %v, want EOF", err)
|
|
}
|
|
if got := len(h.fake.received("StreamMutateEntry")); got != 0 {
|
|
t.Fatalf("refused filer.conf mutation reached handler: %d calls", got)
|
|
}
|
|
}
|