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 ¶
- Variables
- type Authenticator
- type Config
- type Hub
- func (h *Hub) Connected(cell string) bool
- func (h *Hub) ConnectedCells() []string
- func (h *Hub) Do(ctx context.Context, cell string, op *cellv1.Op) (*cellv1.OpResult, error)
- func (h *Hub) Refresh(ctx context.Context, cell string) error
- func (h *Hub) RefreshAndWait(ctx context.Context, cell string) error
- func (h *Hub) Sync(ctx context.Context, stream cellv1connect.CellServiceSyncServerStream) error
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrCellOffline = errors.New("cell agent is not connected")
ErrCellOffline is returned when an operation targets a cell with no connected agent.
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 ¶
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 (*Hub) ConnectedCells ¶
ConnectedCells lists the cells with a connected agent.
func (*Hub) Do ¶
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 ¶
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 ¶
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 ¶
func (h *Hub) Sync(ctx context.Context, stream cellv1connect.CellServiceSyncServerStream) error
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.