From ec049adacb704c4d5ac35b7d7f69b5b27f5d29c8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 24 Nov 2026 09:05:58 -0800 Subject: [PATCH] feat(master): node calls only for their own server id; forced move needs admin Phase 0, S5: heartbeat, assignment stream (every volume), renewal and ACK require the caller's certificate id to be the request's server id (auth.RequireNode); the registered-host address checks stay beside it. QueryVolumeStatus admits a node only for a volume whose line it holds. A forced MoveWorkspace needs an admin. Development mode admits as before. T2 starts its master. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/host/master/authz.go | 18 ++++++++++++++++++ seaweed-block/core/host/master/authz_test.go | 1 + seaweed-block/core/host/master/services.go | 12 ++++++++++++ .../core/host/master/workspace_service.go | 15 +++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/seaweed-block/core/host/master/authz.go b/seaweed-block/core/host/master/authz.go index c181ce8b03..e7ca02465d 100644 --- a/seaweed-block/core/host/master/authz.go +++ b/seaweed-block/core/host/master/authz.go @@ -1,10 +1,13 @@ package master import ( + "context" "github.com/seaweedfs/seaweed-block/core/auth" control "github.com/seaweedfs/seaweed-block/core/rpc/control" "github.com/seaweedfs/seaweed-block/core/rpc/link" "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) // masterRules is the authorization table of every blockmaster gRPC method @@ -60,3 +63,18 @@ func serverAuth(a *auth.Authenticator) link.ServerConfig { Stream: []grpc.StreamServerInterceptor{a.StreamInterceptor(masterRules)}, } } + +// requireLineHolderNode admits a person (the method's rule already did) or a +// node whose server id owns vol's published line (the GC epoch pull); any +// other node is refused. +func (s *services) requireLineHolderNode(ctx context.Context, vol string) error { + p, ok := auth.FromContext(ctx) + if !ok || p.Role != auth.RoleNode { + return nil + } + line, published := s.host.Publisher().PublishedAuthorityLine(vol) + if published && s.host.workspaceLineOwner(line, vol, line.ReplicaID, line.Epoch) == p.ID { + return nil + } + return status.Errorf(codes.PermissionDenied, "node %s does not hold volume %s's line", p.ID, vol) +} diff --git a/seaweed-block/core/host/master/authz_test.go b/seaweed-block/core/host/master/authz_test.go index 54208a4e2e..a4329ebed7 100644 --- a/seaweed-block/core/host/master/authz_test.go +++ b/seaweed-block/core/host/master/authz_test.go @@ -13,6 +13,7 @@ func TestMasterAuthorizationTableCoversEveryMethod(t *testing.T) { if err != nil { t.Fatal(err) } + h.Start() t.Cleanup(func() { closeTestMaster(t, h) }) registered := map[string]bool{} for svc, info := range h.grpc.GetServiceInfo() { diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index ae22453d36..a2ea390bb4 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/seaweedfs/seaweed-block/core/auth" "sync/atomic" "time" @@ -286,6 +287,10 @@ func (s *services) ReportHeartbeat(ctx context.Context, r *control.HeartbeatRepo if err := validateHeartbeat(r); err != nil { return nil, err } + // Phase 0: a node reports only for its own server id (TERM-CALLER-001). + if err := auth.RequireNode(ctx, r.ServerId); err != nil { + return nil, err + } // Journal isolation: alarm on a durable root sharing the authority // store's file system; under strict isolation refuse it unless the node // already serves volumes (refusing a serving node stops its renewals). @@ -380,6 +385,10 @@ func (s *services) SubscribeAssignments(req *control.SubscribeRequest, stream co if req.VolumeId == "" { return fmt.Errorf("subscribe: volume_id required") } + // Phase 0: a node subscribes only as its own server id, for every volume. + if err := auth.RequireNode(stream.Context(), req.GetServerId()); err != nil { + return err + } pub := s.host.boot.Publisher ctx := stream.Context() @@ -487,6 +496,9 @@ func (s *services) QueryVolumeStatus(ctx context.Context, req *control.StatusReq if req.VolumeId == "" { return nil, fmt.Errorf("status: volume_id required") } + if err := s.requireLineHolderNode(ctx, req.VolumeId); err != nil { + return nil, err + } pub := s.host.boot.Publisher ctrl := s.host.ctrl diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index 04981c09fa..fd0d31f601 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/seaweedfs/seaweed-block/core/auth" "strings" "time" @@ -99,6 +100,10 @@ func (s *services) holderMatches(ctx context.Context, volume, replica, server st } func (s *services) RenewWorkspaceLease(ctx context.Context, q *control.WorkspaceIdentity) (*control.WorkspaceLeaseFact, error) { + // Phase 0: the holder's server id is the caller's certificate's id. + if err := auth.RequireNode(ctx, q.GetServerId()); err != nil { + return nil, err + } if err := s.workspaceVolumeForRenewal(q.GetVolumeId()); err != nil { return nil, err } @@ -130,6 +135,9 @@ func (s *services) RevokeWorkspace(ctx context.Context, q *control.WorkspaceIden } func (s *services) AckWorkspaceRevoked(ctx context.Context, q *control.WorkspaceRevocationAck) (*control.WorkspaceEmpty, error) { + if err := auth.RequireNode(ctx, q.GetIdentity().GetServerId()); err != nil { + return nil, err + } s.host.workspaceMu.Lock() defer s.host.workspaceMu.Unlock() id := q.GetIdentity() @@ -203,6 +211,13 @@ func (s *services) logForcedGrant(g *control.WorkspaceGrant, replay bool, postIs } func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove) (_ *control.WorkspaceGrant, resultErr error) { + // Phase 0: a forced move (it may lose acknowledged writes) needs an + // admin; a clean move an operator (the method's rule). + if q.GetKind() == "forced" || q.GetForce() { + if err := auth.RequireRole(ctx, auth.RoleAdmin); err != nil { + return nil, err + } + } // Remote reads never hold the workspace mutation lock. Re-read every // local precondition below; Publisher checks the expected epoch atomically. // A refusal is logged after the lock is released (deferred first, so it