Files
seaweedfs/weed/server/filer_grpc_scope_mutation_flags_test.go
T
39675b2faf filer: hide remote rename source paths from scoped responses (#13010)
* filer: redact remote rename source from scoped responses

* Preserve scoped remote rename markers

* Consolidate scoped marker replacement coverage

* Refuse scoped whole-entry guards during remote rename

* Keep coded create refusals for guarded scoped writes

* Make scoped subscription batch coverage deterministic

* filer: refuse scoped conditions that compare the remote rename source

IF_EXTENDED_NOT_EQUAL clauses and ExpectedExtended on Create, Update
and DeleteEntry could still compare a guess against the hidden marker,
so a scoped client could confirm the source path it redacts.

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

* filer: refuse scoped condition gates on the remote rename source

An IF_EXTENDED_TIME_ELAPSED gate applies its time check only when the
gate value matches, so a gate on the marker also confirms a guess.

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

* filer: keep a pending rename source out of remote copy errors

A failed copy of a pending remote-only rename named the marker's source
location, which the backend error repeats, and rename RPCs return that error
to scoped callers. Log the full error and return one naming only the paths
the caller supplied.

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

* filer: let a scoped local overwrite end a pending remote rename

Scoped replacements kept the hidden rename source marker even though a
scoped entry can never stay remote-only, so the marker was stale on the
local copy and every later scoped IF_ENTRY_EQUAL write was refused. Drop the
preservation and let the overwrite clear the marker as other local writes do.

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

* codespell: ignore poligon only inside URLs

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 12:31:02 -08:00

103 lines
3.6 KiB
Go

package weed_server
import (
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
)
func TestScopeUnaryRenameAndLockBoundaries(t *testing.T) {
h := newScopeHarness(t)
c := h.client(scopedToken("alice", time.Hour, []string{aliceWS}, nil))
expectScopeDenied(t, h, "AtomicRenameEntry", "cross-prefix unary rename", func() error {
_, err := c.AtomicRenameEntry(scopeCtx(t), &filer_pb.AtomicRenameEntryRequest{
OldDirectory: aliceWS,
OldName: "old",
NewDirectory: bobWS,
NewName: "new",
})
return err
})
expectScopeDenied(t, h, "PosixLock", "cross-prefix unary lock", func() error {
_, err := c.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{Key: scopePosixLockKeyPrefix + bobWS + "/file"})
return err
})
}
func TestScopeRejectsMovedMutations(t *testing.T) {
h := newScopeHarness(t)
c := h.client(scopedToken("alice", time.Hour, []string{aliceWS}, nil))
expectScopeDenied(t, h, "DeleteEntry", "moved delete", func() error {
_, err := c.DeleteEntry(scopeCtx(t), &filer_pb.DeleteEntryRequest{
Directory: aliceWS,
Name: "file",
IsMoved: true,
})
return err
})
expectScopeDenied(t, h, "PosixLock", "moved lock", func() error {
_, err := c.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{
Key: scopePosixLockKeyPrefix + aliceWS + "/file",
IsMoved: true,
})
return err
})
expectScopeDenied(t, h, "PosixLock", "cooling-probe lock", func() error {
_, err := c.PosixLock(scopeCtx(t), &filer_pb.PosixLockRequest{
Key: scopePosixLockKeyPrefix + aliceWS + "/file",
CoolingProbe: true,
})
return err
})
}
func TestScopeRejectsConditionsOnRemoteRenameSource(t *testing.T) {
h := newScopeHarness(t)
c := h.client(scopedToken("alice", time.Hour, []string{aliceWS}, nil))
guess := []byte("/buckets/other/file")
notEqual := &filer_pb.WriteCondition{Clauses: []*filer_pb.WriteCondition_Clause{{
Kind: filer_pb.WriteCondition_IF_EXTENDED_NOT_EQUAL, ExtKey: filer.ExtRemoteRenameSourceKey, ExtValue: string(guess),
}}}
expectScopeDenied(t, h, "CreateEntry", "create conditioned on the marker", func() error {
_, err := c.CreateEntry(scopeCtx(t), &filer_pb.CreateEntryRequest{
Directory: aliceWS, Entry: &filer_pb.Entry{Name: "file"}, Condition: notEqual,
})
return err
})
expectScopeDenied(t, h, "UpdateEntry", "update conditioned on the marker", func() error {
_, err := c.UpdateEntry(scopeCtx(t), &filer_pb.UpdateEntryRequest{
Directory: aliceWS, Entry: &filer_pb.Entry{Name: "file"}, Condition: notEqual,
})
return err
})
expectScopeDenied(t, h, "UpdateEntry", "update gated on the marker", func() error {
_, err := c.UpdateEntry(scopeCtx(t), &filer_pb.UpdateEntryRequest{
Directory: aliceWS, Entry: &filer_pb.Entry{Name: "file"},
Condition: &filer_pb.WriteCondition{Clauses: []*filer_pb.WriteCondition_Clause{{
Kind: filer_pb.WriteCondition_IF_EXTENDED_TIME_ELAPSED, ExtKey: "client.expiry",
GateKey: filer.ExtRemoteRenameSourceKey, GateValue: string(guess),
}}},
})
return err
})
expectScopeDenied(t, h, "UpdateEntry", "update expecting the marker", func() error {
_, err := c.UpdateEntry(scopeCtx(t), &filer_pb.UpdateEntryRequest{
Directory: aliceWS, Entry: &filer_pb.Entry{Name: "file"},
ExpectedExtended: map[string][]byte{filer.ExtRemoteRenameSourceKey: guess},
})
return err
})
expectScopeDenied(t, h, "DeleteEntry", "delete expecting the marker", func() error {
_, err := c.DeleteEntry(scopeCtx(t), &filer_pb.DeleteEntryRequest{
Directory: aliceWS, Name: "file",
ExpectedExtended: map[string][]byte{filer.ExtRemoteRenameSourceKey: guess},
})
return err
})
}