authz

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package authz provides authorization and signature-verification helpers for the registry server (R3.1 of the registry decomposition plan).

Checker holds the admin/dashboard token configuration and exposes gate-checking methods that were previously inline on Server. Functions that need network or node data accept narrow reader interfaces rather than coupling to Server internals, keeping authz free of circular imports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyHeartbeatSignature

func VerifyHeartbeatSignature(pubKey []byte, adminToken string, msg map[string]interface{}, challenge string) error

VerifyHeartbeatSignature is an alias for VerifyNodeSignature with a caller-supplied adminToken (copied before releasing a read lock). This is the variant hot-path heartbeat handlers use when they have already snapshot-copied node fields.

func VerifyNodeSignature

func VerifyNodeSignature(pubKey []byte, adminToken string, msg map[string]interface{}, challenge string) error

VerifyNodeSignature verifies a registry write operation signature. pubKey is the node's stored Ed25519 public key; adminToken is a pre-copied value of the global admin token (copy it before releasing the server mutex). msg must contain a "signature" field (base64). challenge is the pre-image string that was signed.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker holds token configuration and exposes authorization gate methods.

func NewChecker

func NewChecker(adminToken, dashboardToken string) *Checker

NewChecker returns a Checker configured with the given tokens. Either token may be empty to disable the corresponding gate.

func (*Checker) AdminToken

func (c *Checker) AdminToken() string

AdminToken returns the admin token stored in this Checker. Used by callers that need to copy it before releasing a lock (e.g. Server.requireAdminToken).

func (*Checker) CheckAdminToken

func (c *Checker) CheckAdminToken(msg map[string]interface{}) bool

CheckAdminToken returns nil when msg carries a valid admin token, or a descriptive error otherwise. It is the core helper used by both RequireAdminToken and RequireAdminTokenWith.

func (*Checker) DashboardToken

func (c *Checker) DashboardToken() string

DashboardToken returns the dashboard token stored in this Checker.

func (*Checker) IsEnterpriseNode

func (c *Checker) IsEnterpriseNode(nodeID uint32, nodes NodeReader, nr NetworkReader) bool

IsEnterpriseNode returns true when nodeID belongs to at least one enterprise network. Both nr (NetworkReader) and nodes (NodeReader) must not be nil.

func (*Checker) RequireAdminToken

func (c *Checker) RequireAdminToken(msg map[string]interface{}) error

RequireAdminToken validates the "admin_token" field in msg against the stored admin token. Returns a non-nil error when the token is absent, incorrect, or the checker has no admin token configured.

The caller should copy c.AdminToken() under the server mutex before calling if concurrent updates to the token are possible.

func (*Checker) RequireAdminTokenWith

func (c *Checker) RequireAdminTokenWith(msg map[string]interface{}, adminToken string) error

RequireAdminTokenWith is like RequireAdminToken but uses the supplied pre-copied token value. Use this variant when the caller already holds a read lock and has copied the token, avoiding a second lock acquisition.

func (*Checker) RequireEnterprise

func (c *Checker) RequireEnterprise(netID uint16, nr NetworkReader) error

RequireEnterprise returns nil when netID is an enterprise network, or a clear error otherwise. nr must not be nil.

func (*Checker) RequireNetworkRole

func (c *Checker) RequireNetworkRole(msg map[string]interface{}, netID uint16, nr NetworkReader, allowedRoles ...Role) error

RequireNetworkRole checks whether the request is authorized to act in netID with one of allowedRoles. Authorization succeeds when any of the following holds:

  1. The global admin token in msg is valid.
  2. The per-network admin token in msg matches the network's AdminToken.
  3. The requesting node (identified by msg["node_id"]) has one of allowedRoles in netID according to nr.

nr must not be nil.

func (*Checker) SetAdminToken

func (c *Checker) SetAdminToken(t string)

SetAdminToken replaces the admin token. Not safe for concurrent use; call only at configuration time before the server is serving requests.

func (*Checker) SetDashboardToken

func (c *Checker) SetDashboardToken(t string)

SetDashboardToken replaces the dashboard token.

type NetworkReader

type NetworkReader interface {
	// GetNetworkAdminToken returns the per-network admin token and whether
	// the network exists.
	GetNetworkAdminToken(netID uint16) (adminToken string, ok bool)

	// GetMemberRole returns the role for nodeID in netID and whether it exists.
	GetMemberRole(netID uint16, nodeID uint32) (role Role, ok bool)

	// IsEnterpriseNetwork returns true when netID is an enterprise network.
	IsEnterpriseNetwork(netID uint16) (enterprise bool, ok bool)
}

NetworkReader is the minimal read-only view over network state that the authorization helpers need. Server implements this directly; tests can supply a lightweight stub.

type NodeReader

type NodeReader interface {
	// GetNodeNetworks returns the network IDs the node belongs to and
	// whether the node exists.
	GetNodeNetworks(nodeID uint32) (netIDs []uint16, ok bool)
}

NodeReader is the minimal read-only view over node state that IsEnterpriseNode needs.

type Role

type Role = string

Role is a member's permission level within a network. Values match the string constants used throughout the registry.

const (
	RoleOwner  Role = "owner"  // created the network, full control
	RoleAdmin  Role = "admin"  // can invite, remove members, change settings
	RoleMember Role = "member" // can communicate, cannot manage
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL