Help us shape the future of Go! Take the 2026 Go Developer Survey

cellserver

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0, AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cellserver is the server side of the cell protocol: it accepts outbound Sync streams from cell agents, pushes each cell's compiled policy timeline, and delivers signed operations whose results callers wait for.

Index

Constants

This section is empty.

Variables

View Source
var ErrCellOffline = errors.New("cell agent is not connected")

ErrCellOffline is returned when an operation targets a cell with no connected agent.

View Source
var ErrPolicyNotApplied = errors.New("cell did not apply the policy")

ErrPolicyNotApplied is returned when a cell refuses or fails to apply a revision RefreshAndWait waits for.

Functions

This section is empty.

Types

type Authenticator

type Authenticator func(ctx context.Context) (cell string, err error)

Authenticator maps an incoming stream to the cell it is allowed to speak for (normally by the fingerprint of its mTLS client certificate). A Hello naming any other cell is rejected.

type Config

type Config struct {
	Signer       ed25519.PrivateKey
	Store        Store
	Authenticate Authenticator
	// Horizon and MaxRevisions bound the precomputed policy timeline (defaults 24h and 32).
	Horizon      time.Duration
	MaxRevisions int
	Policy       policy.Options
	// HeartbeatInterval is how often the server pings each agent (default 15s).
	HeartbeatInterval time.Duration
	Now               func() time.Time
	Logger            *slog.Logger
}

Config configures a Hub.

type Hub

type Hub struct {
	cellv1connect.UnimplementedCellServiceHandler
	// contains filtered or unexported fields
}

Hub tracks connected cells. It implements cellv1connect.CellServiceHandler.

func NewHub

func NewHub(cfg Config) (*Hub, error)

NewHub returns a Hub.

func (*Hub) Connected

func (h *Hub) Connected(cell string) bool

Connected reports whether a cell agent is currently connected.

func (*Hub) ConnectedCells

func (h *Hub) ConnectedCells() []string

ConnectedCells lists the cells with a connected agent.

func (*Hub) Do

func (h *Hub) Do(ctx context.Context, cell string, op *cellv1.Op) (*cellv1.OpResult, error)

Do signs op, sends it to the cell and waits for its result (bounded by ctx). The op must not have an id or signature; Do assigns both and sets a not-after deadline from ctx (or one minute).

func (*Hub) Refresh

func (h *Hub) Refresh(ctx context.Context, cell string) error

Refresh recompiles the cell's policy timeline and pushes it if it changed. Callers invoke it after any write that affects policy (grant created or revoked, device enrolled or removed, rule changed). Offline cells are skipped; they receive the current timeline when they reconnect.

func (*Hub) RefreshAndWait

func (h *Hub) RefreshAndWait(ctx context.Context, cell string) error

RefreshAndWait pushes the cell's current timeline and waits until the agent has applied it (or a later revision). Callers use it when the next step depends on the new policy being live — for example before handing out a pre-auth key whose tags the cell must already know.

func (*Hub) Sync

Sync handles one agent stream.

type Store

type Store interface {
	// Snapshot loads the cell's tenancy state for policy compilation.
	Snapshot(ctx context.Context, cell string, now time.Time, horizon time.Duration) (policy.Snapshot, error)
	// RecordHello, RecordObserved and RecordApplied persist what agents report (audit, drift alerts, metrics).
	RecordHello(ctx context.Context, cell string, hello *cellv1.Hello) error
	RecordObserved(ctx context.Context, cell string, obs *cellv1.Observed) error
	RecordApplied(ctx context.Context, cell string, applied *cellv1.PolicyApplied) error
	// NextRevision returns a revision number greater than any previously issued for the cell.
	NextRevision(ctx context.Context, cell string) (uint64, error)
	// RecordTimeline persists a timeline before it is sent, so every revision a cell may apply is on record.
	RecordTimeline(ctx context.Context, cell string, timeline []*cellv1.PolicyRevision) error
}

Store is what the hub needs from persistence.

Jump to

Keyboard shortcuts

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