Files
seaweedfs/seaweed-block/core/host/master/authz.go
T
pingqiuandClaude Opus 5.5 647ba06119 master: cluster format level (FORMAT-GATE): reads_level, finalize, level-0 v1.0 semantics, retire
Hosts report the format they read (heartbeat reads_level). The cluster's
format level is the master's attestation file's form: v1.0's bare map is
level 0, the envelope (format 2, format_level 1) level 1.

At level 0 the master keeps v1.0's semantics, so a v1.0.x master started
on the store stays safe: renewals clamp to the persisted horizon and an
extender keeps it current; forced moves and re-grants wait for the later
of horizon and deadline plus skew; records are envelope version 1.

sw-block cluster finalize-format raises the level in one durable step
(the envelope write), refused while a registered host has not reported
that it reads level 1; then the publisher switches under both its locks.
At any level no new work goes to a host that reads below it; its
heartbeat is refused binary_too_old; every assignment carries the level.
sw-block cluster retire-host removes a host that holds no volume.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 18:27:53 -08:00

89 lines
4.8 KiB
Go

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
// (phase 0): the minimum person role, and whether a node may call it. A node
// call's own-server-id check is the handler's (auth.RequireNode); a forced
// move's admin check is MoveWorkspace's (auth.RequireRole). A method missing
// here is refused (TestMasterAuthorizationTableCoversEveryMethod).
var masterRules = map[string]auth.Rule{
control.LifecycleService_GetVolume_FullMethodName: {Min: auth.RoleViewer},
control.LifecycleService_ReserveVolumeDeletion_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.LifecycleService_CheckVolumeNoLiveLease_FullMethodName: {Min: auth.RoleViewer},
control.LifecycleService_FinalizeFormat_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.LifecycleService_RetireHost_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.ObservationService_ReportHeartbeat_FullMethodName: {Node: true},
control.ObservationService_ReportClusterEvent_FullMethodName: {Min: auth.RoleOperator},
control.AssignmentService_SubscribeAssignments_FullMethodName: {Node: true},
control.AssignmentService_SubscribeProbeRounds_FullMethodName: {Node: true},
control.ObservationService_AnswerProbe_FullMethodName: {Node: true},
control.EvidenceService_QueryVolumeStatus_FullMethodName: {Min: auth.RoleViewer, Node: true},
control.ClusterEvidenceService_GetClusterStatus_FullMethodName: {Min: auth.RoleViewer},
control.ClusterEvidenceService_ListVolumes_FullMethodName: {Min: auth.RoleViewer},
control.ClusterEvidenceService_GetVolumeStatus_FullMethodName: {Min: auth.RoleViewer},
control.ClusterEvidenceService_GetVolumeTimeline_FullMethodName: {Min: auth.RoleViewer},
control.ClusterEvidenceService_WatchClusterEvents_FullMethodName: {Min: auth.RoleViewer},
control.LifecycleService_CreateVolume_FullMethodName: {Min: auth.RoleOperator, Strict: true},
control.LifecycleService_DeleteVolume_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.LifecycleService_MarkVolumeDeleting_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.LifecycleService_AbortVolumeDeleting_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.LifecycleService_CommitVolumeDeleting_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.FailbackService_ExecuteFailback_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.WorkspaceService_RegisterWorkspaceBinding_FullMethodName: {Min: auth.RoleAdmin, Strict: true},
control.WorkspaceService_PlaceWorkspace_FullMethodName: {Min: auth.RoleOperator, Strict: true},
control.WorkspaceService_RenewWorkspaceLease_FullMethodName: {Node: true},
control.WorkspaceService_AckWorkspaceRevoked_FullMethodName: {Node: true},
control.WorkspaceService_RevokeWorkspace_FullMethodName: {Min: auth.RoleOperator, Strict: true},
control.WorkspaceService_MoveWorkspace_FullMethodName: {Min: auth.RoleOperator, Strict: true}, // forced: admin, in the handler
control.WorkspaceService_QueryWorkspace_FullMethodName: {Min: auth.RoleViewer},
control.WorkspaceService_QueryWorkspaceLostRange_FullMethodName: {Min: auth.RoleViewer},
control.WorkspaceService_PreviewWorkspaceMove_FullMethodName: {Min: auth.RoleViewer},
}
// serverAuth returns the interceptor chain of the master's gRPC server: the
// authenticator's when authentication is configured, else development mode
// (plaintext, loopback only; every call marked as such).
func serverAuth(a *auth.Authenticator) link.ServerConfig {
if a == nil {
return link.ServerConfig{
Unary: []grpc.UnaryServerInterceptor{auth.DevUnaryInterceptor()},
Stream: []grpc.StreamServerInterceptor{auth.DevStreamInterceptor()},
}
}
return link.ServerConfig{
Unary: []grpc.UnaryServerInterceptor{a.UnaryInterceptor(masterRules)},
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)
}