Files
seaweedfs/seaweed-block/core/host/master/authz.go
T
pingqiuandClaude Opus 5.5 ab747bfa47 change: cut over to the content-named store and delete the legacy store
The runtime stores each volume in one content-named layout on the filer:
immutable chunks, segments and roots are ordinary filer files, and one
HEAD entry per volume carries every conditional commit. A holder claims
HEAD under its granted epoch and claim id, cuts in its own session,
commits by HEAD generation and position, and is fenced when its identity
moves. Catalog, restore, snapshot, retention, cleaning, verify and volume
delete run through the layout kernel; the master mints the layout
identity, reads HEAD proofs and holds the delete reservation and lease
barrier. The legacy store, its intents and its compatibility paths are
removed; existing stores are recreated, not converted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:59:23 -08:00

87 lines
4.6 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.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)
}