fleet

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: AGPL-3.0 Imports: 49 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fleet is the panel side of the node fleet: the panel CA and the agent endpoint (mTLS), node enrollment, the agent stream (liveness, reliable stats/events ingestion), desired-state computation and push, and the admin NodeService / FleetService handlers backed by that data.

Index

Constants

View Source
const APIVersion = 1

APIVersion is the agent wire API version this panel serves (Hello.api_version, EnrollRequest.api_version).

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AgentSNI is the secret server name of the agent endpoint (e.g. "q3m8x2kd7w.invalid"). Required.
	AgentSNI string
	// PanelAddr is the host:port agents dial; it goes into the install command. Required for CreateEnrollment.
	PanelAddr string
	// ExpectedAgentVersion is the newest agent version this panel ships (ListNodes marks older agents).
	ExpectedAgentVersion string
	// Debounce is the StateChanged coalescing window. Default 200 ms.
	Debounce time.Duration
	// Desired is the desired-state source, required: it returns the enabled inbounds of a node with their
	// complete credential sets (the access module's effective-access rule, so it exists once). Spec.ID must
	// be set. This module owns revisions, hashes, deltas and push.
	Desired func(ctx context.Context, nodeID string) ([]statehash.Inbound, error)
	// MaxNodeBytesPerSec is the most traffic one node may report in total per second of a stats interval; a batch
	// above it is dropped (see statsguard.go). Default 1.25e9 bytes/s (10 Gbit/s).
	MaxNodeBytesPerSec uint64
	// OnUsage is called after a stats batch added usage to these users (new used_bytes are committed), e.g.
	// access.Service.Recompute, so a quota overrun takes effect within one stats interval.
	OnUsage func(ctx context.Context, userIDs []string)
	// Actor returns the admin id for audit rows. Default: the signed-in admin from the auth interceptor.
	Actor func(context.Context) string
	Log   *slog.Logger
	// Now is the clock (tests). Default time.Now.
	Now func() time.Time
}

Config configures Fleet.

type Fleet

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

Fleet is the fleet module.

func New

func New(st *store.Store, v *vault.Vault, reg *protocols.Registry, cfg Config) (*Fleet, error)

New builds the module: it loads (or creates) the panel CA. Call Run to start the background work.

func (*Fleet) AgentHandler

func (f *Fleet) AgentHandler() http.Handler

AgentHandler serves EnrollmentService and AgentService. Mount it on the agent endpoint only (TLS with AgentTLSConfig); it refuses requests that did not arrive with the agent SNI.

func (*Fleet) AgentTLSConfig

func (f *Fleet) AgentTLSConfig(h *tls.ClientHelloInfo) (*tls.Config, error)

AgentTLSConfig is the per-SNI tls.Config of the agent endpoint, for tls.Config.GetConfigForClient of the panel's main listener. For any other server name it returns (nil, nil): the listener then keeps its normal behaviour, so a prober without the secret name sees only the decoy.

For the agent SNI the panel presents a server certificate from its own CA and asks for a client certificate without demanding one (VerifyClientCertIfGiven): the Enroll RPC has no certificate yet. AgentHandler enforces per RPC that everything except Enroll carries a verified, non-revoked node certificate; VerifyConnection already rejects revoked or retired certificates at the handshake.

func (*Fleet) ApplyFix

func (f *Fleet) ApplyFix(ctx context.Context, nodeID, fixID string, dryRun bool, params map[string]string) (*agentv1.CommandResult, error)

ApplyFix sends one fix (or its dry run) to a connected node with the doctor capability and waits up to the node's apply timeout for the CommandResult.

func (*Fleet) CACertPEM

func (f *Fleet) CACertPEM() string

CACertPEM is the panel CA certificate.

func (*Fleet) CAFingerprint

func (f *Fleet) CAFingerprint() string

CAFingerprint is the lowercase hex SHA-256 of the panel CA certificate (what install commands carry).

func (*Fleet) CreateProvisionEnrollment

func (f *Fleet) CreateProvisionEnrollment(ctx context.Context, spec provision.NodeSpec, actor string, now, expires time.Time) (string, string, error)

CreateProvisionEnrollment creates the pending node, or rotates its pending enrollment token when a job is resumed. The token is returned exactly once to the caller and is never written to an audit row.

func (*Fleet) FleetHandler

func (f *Fleet) FleetHandler(opts ...connect.HandlerOption) (string, http.Handler)

FleetHandler is the admin FleetService (Overview, ListEvents); see NodeHandler for opts.

func (*Fleet) Live

func (f *Fleet) Live(nodeID string) (connected bool, caps []string, drift bool)

Live reports whether the node has a stream now, the capabilities its Hello listed and whether the desired state stays different from the applied one after the automatic resend (state drift).

func (*Fleet) NetworkUsage added in v0.1.9

func (f *Fleet) NetworkUsage(nodeID string) (rxBps, txBps uint64, sampledAt time.Time, ok bool)

NetworkUsage returns the latest host-network sample received from a connected node. The timestamp is when the panel received that sample, so callers can hide percentages when the agent stops reporting.

func (*Fleet) NodeHandler

func (f *Fleet) NodeHandler(opts ...connect.HandlerOption) (string, http.Handler)

NodeHandler is the admin NodeService. Pass connect.WithInterceptors(auth.Interceptor()) so that it is behind the admin session; the path is the Connect prefix to mount it on.

func (*Fleet) NodeStatus

func (f *Fleet) NodeStatus(ctx context.Context, n store.NodeRow) adminv1.NodeStatus

NodeStatus is the status the admin UI shows for a node row.

func (*Fleet) Online

func (f *Fleet) Online() []OnlineSession

Online returns the open sessions of every connected node (in memory, refreshed by each stats batch).

func (*Fleet) OnlineByInbound

func (f *Fleet) OnlineByInbound() map[string]int

OnlineByInbound counts the open sessions of every inbound of the connected nodes (the health and WARP dialogs say how many connections a restart or a pause drops).

func (*Fleet) OnlineUsers

func (f *Fleet) OnlineUsers() map[string]string

OnlineUsers maps each user with an open session to the node of the newest one (access.OnlineSource).

func (*Fleet) OnlineUsersByNode

func (f *Fleet) OnlineUsersByNode() map[string]int

OnlineUsersByNode counts the distinct users with an open session on each connected node (the canary is the node with the fewest).

func (*Fleet) ProvisionNodeConnected

func (f *Fleet) ProvisionNodeConnected(nodeID string) bool

ProvisionNodeConnected reports whether the agent has established its authenticated stream.

func (*Fleet) ProvisionNodeState

func (f *Fleet) ProvisionNodeState(ctx context.Context, nodeID string) (string, error)

ProvisionNodeState reports the durable fleet state used to resume an installation safely.

func (*Fleet) RollbackAgent

func (f *Fleet) RollbackAgent(ctx context.Context, nodeID string, wait time.Duration) (*agentv1.CommandResult, error)

RollbackAgent asks a connected node with the update capability to put its previous binary back.

func (*Fleet) Run

func (f *Fleet) Run(ctx context.Context) error

Run drives the debounced recompute and the node-down sweeper until ctx ends, then closes all streams.

func (*Fleet) RunDoctor

func (f *Fleet) RunDoctor(ctx context.Context, nodeID string, checks []string, wait time.Duration) (*agentv1.DoctorReport, error)

RunDoctor asks a connected node with the doctor capability to run checks (nil = all) and waits for the report that echoes the request. The report has been handed to Health by then. A node without the capability is never sent anything (FAILED_PRECONDITION "agent too old").

func (*Fleet) SetHealth

func (f *Fleet) SetHealth(h Health)

SetHealth connects the health module. Call it before serving; nil disconnects.

func (*Fleet) SetUpdates

func (f *Fleet) SetUpdates(u Updates)

SetUpdates connects the updates module. Call it before serving; nil disconnects (FetchUpdate answers UNIMPLEMENTED).

func (*Fleet) SetWarp

func (f *Fleet) SetWarp(w Warp)

SetWarp connects the WARP module. Call it before serving; nil disconnects (no WarpSpec is sent, no health is stored).

func (*Fleet) StateChanged

func (f *Fleet) StateChanged()

StateChanged tells the module that something that feeds desired state changed (users, profiles, inbounds, nodes). It returns at once; a debounced recompute pushes the result to connected nodes.

func (*Fleet) UpdateAgent

func (f *Fleet) UpdateAgent(ctx context.Context, nodeID string, manifest, signature []byte, wait time.Duration) (*agentv1.CommandResult, error)

UpdateAgent sends a signed manifest to a connected node with the update capability and waits up to wait for the CommandResult (the download is part of it). The agent answers before it re-executes; a stream that drops right after the answer still delivers it.

func (*Fleet) WarpPauseApplied

func (f *Fleet) WarpPauseApplied(ctx context.Context, nodeID string) bool

WarpPauseApplied reports whether the node holds a paused WARP: the last state sent on its stream pauses it, and the node confirmed exactly that state. It is RestartWarp's proof that the tunnel went down; another change applied meanwhile (a state that still runs WARP) does not count.

type Health

type Health interface {
	// DoctorReport hands over every DoctorReport of a node (periodic, requested or the re-check after a fix).
	DoctorReport(ctx context.Context, nodeID string, r *agentv1.DoctorReport)
	// NodeReturned says that an active node came back after a silence of less than the blip window with an
	// unchanged boot time: health writes the history record.
	NodeReturned(ctx context.Context, nodeID string, silentSince, now time.Time)
	// NodeHealth is what the node status and card show: the synthetic checks of the node all failing
	// (noTraffic, with how many of how many) and the check of the worst FAIL of its last doctor report.
	NodeHealth(nodeID string) (noTraffic bool, failed, total int, doctorFail string)
	// AlertCounts feeds the badge of the Overview: active alerts not muted and not INFO, and the critical ones.
	AlertCounts(ctx context.Context) (active, critical uint32)
}

Health is implemented by the health module. All methods must be cheap and must not call back into the stream they run on.

type OnlineSession

type OnlineSession struct {
	NodeID, UserID, DeviceID, Protocol, InboundID, RemoteIP string
	ConnectedAt                                             time.Time
}

OnlineSession is one open client session as last reported by a node.

type Updates

type Updates interface {
	// Updating reports that a rollout step of the node is in flight (command sent, reconnect or gate pending): its
	// stream drops when the agent re-executes, and that is neither a blip nor an outage.
	Updating(nodeID string) bool
	// Serve streams the named file of the current trusted bundle from offset: send gets at most 256 KiB at a time
	// and the size of the whole file. Errors are Connect errors (NOT_FOUND, RESOURCE_EXHAUSTED, FAILED_PRECONDITION).
	Serve(ctx context.Context, nodeID, name string, offset uint64, send func(chunk []byte, total uint64) error) error
	// NodeBinary is the absolute path, on the panel's server, of the agent binary for the platform in the current
	// trusted bundle; "" when there is none. The add-node window offers it as a ready scp command.
	NodeBinary(goos, goarch string) string
}

Updates is implemented by the updates module. Both methods must be cheap; Serve blocks for the length of a download.

type Warp

type Warp interface {
	// Spec is the node's WarpSpec (nil = the node has no account; Enabled=false = paused). It is sent only to a stream
	// that listed "warp/1".
	Spec(ctx context.Context, nodeID string) (*plugin.WarpSpec, error)
	// StoreHealth keeps the last WarpHealth of a node (for GetWarp and the node badge).
	StoreHealth(ctx context.Context, nodeID string, h *agentv1.WarpHealth) error
	// NeedsAttention records why the owner has to decide ("" clears it).
	NeedsAttention(ctx context.Context, nodeID, reason string) error
	// RefreshByNode reads the account back from Cloudflare because the node's WARP could not heal itself (read only).
	RefreshByNode(ctx context.Context, nodeID string) error
	// AutoReregister replaces a revoked registered account when the owner switched that on; reports whether it did.
	AutoReregister(ctx context.Context, nodeID string) (bool, error)
	// Summary is the badge of a node card; a is nil when the node has no account.
	Summary(a *store.WarpAccountRow, online bool, now time.Time) *adminv1.WarpSummary
}

Warp is implemented by the WARP module (internal/panel/warp). The fleet asks it for the node's WarpSpec and hands it what the node reports; it never touches an account itself. Every method must be cheap or return quickly: Spec runs for every reconcile of a node, StoreHealth for every stats batch.

Jump to

Keyboard shortcuts

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