Files
seaweedfs/seaweed-block/core/host/master/authz.go
T
pingqiuandClaude Opus 5.5 36d797cf01 master: read-only format level, a new cluster starts at level 1
LifecycleService.FormatLevel answers the cluster's format level (a
viewer's read; sw-block cluster format-level). A master that finds no
prior authority state writes the level-1 envelope before it serves;
existing state keeps its level, so only a cluster holding v1.0 data
needs the finalize. Above level 0 a node that has not reported its read
level is refused new work typed and retryable (AWAITING_FIRST_REPORT),
and the cluster status shows it awaiting report. The master tests' fake
hosts report reads_level 1 as a v1.1 host does; the FormatGate upgrade
tests start from a store in v1.0.x's form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 02:07:57 -08:00

90 lines
4.9 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_FormatLevel_FullMethodName: {Min: auth.RoleViewer},
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)
}