Documentation
¶
Overview ¶
Package update is the panel side of the node-agent updates: it reads the release bundle the owner signed and dropped into <data-dir>/dist, shows whether it is trusted, serves its files to the node agents (only through the agent mTLS endpoint, see fleet.Updates), runs the staged rollout (canary, batches, a health gate per node, automatic rollback) whose state lives in the database, and serves the admin UpdateService.
The panel is a courier, not an authority: the agents verify the signature with the release key compiled into their own binary. Everything here that looks like a trust decision (TRUSTED) is for display and for refusing to start a pointless rollout.
It imports neither the fleet nor the health module except for one data type: the fleet is reached through the Fleet interface below (implemented by *fleet.Fleet), health through Health, and cmd/mistgate wires all directions.
Index ¶
- Variables
- func PanelUpdateHostSupported() bool
- func RunPanelUpdateHelper(args []string) error
- type Config
- type Fleet
- type GitHubPanelUpdater
- type Health
- type PanelUpdateConfig
- type PanelUpdateStatus
- type PanelUpdater
- type Service
- func (s *Service) Conditions(ctx context.Context) []health.ExtCond
- func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)
- func (s *Service) NodeBinary(goos, goarch string) string
- func (s *Service) OpenNodeBinary(goos, goarch string) (*os.File, int64, string, error)
- func (s *Service) Run(ctx context.Context)
- func (s *Service) Serve(ctx context.Context, nodeID, name string, offset uint64, ...) error
- func (s *Service) Updating(nodeID string) bool
- type Timing
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoPanelRelease = errors.New("no stable panel release is published") ErrNoPanelUpdate = errors.New("the panel is already up to date") ErrPanelUnsupported = errors.New("panel self-update requires a root systemd installation") ErrPanelAssetMissing = errors.New("the latest release has no binary for this architecture") )
Functions ¶
func PanelUpdateHostSupported ¶
func PanelUpdateHostSupported() bool
PanelUpdateHostSupported reports whether this process can use the root system service manager to replace the panel.
func RunPanelUpdateHelper ¶
RunPanelUpdateHelper is the hidden command started by systemd-run. It executes outside the panel service's ProtectSystem sandbox, replaces only its own executable, restarts the configured unit and restores the backup if the new service does not start.
Types ¶
type Config ¶
type Config struct {
// DataDir holds dist/ (the bundle). Empty = no bundle directory at all (tests).
DataDir string
// Key is the release public key of this build (buildinfo.ReleasePublicKey); nil = an unsigned build: bundles are
// shown but never TRUSTED and no rollout can start.
Key ed25519.PublicKey
// PanelVersion and PanelBuilt describe this panel's own build (buildinfo.Version, buildinfo.BuiltUnix()).
PanelVersion string
PanelBuilt int64
// PanelUpdater checks official GitHub releases and schedules a checked panel binary replacement when available.
PanelUpdater PanelUpdater
// StepUp is auth.Service.RequireStepUp: every change calls it first. Required.
StepUp func(context.Context) error
// Actor returns the admin id for audit rows and for the rollout's created_by. Default: the signed-in admin.
Actor func(context.Context) string
Timing
Log *slog.Logger
Now func() time.Time // the clock (tests)
}
Config configures Service.
type Fleet ¶
type Fleet interface {
// Live: whether the node has an agent stream now, the capabilities of its Hello, whether its state drift persists.
Live(nodeID string) (connected bool, caps []string, drift bool)
// UpdateAgent sends a signed manifest and waits for the CommandResult (the download is part of it).
// FAILED_PRECONDITION when the node is not connected or did not list "update/1": nothing was sent.
UpdateAgent(ctx context.Context, nodeID string, manifest, signature []byte, wait time.Duration) (*agentv1.CommandResult, error)
// RollbackAgent asks the node to put its previous binary back; same preconditions.
RollbackAgent(ctx context.Context, nodeID string, wait time.Duration) (*agentv1.CommandResult, error)
// OnlineUsersByNode is the number of distinct users with an open session on each connected node.
OnlineUsersByNode() map[string]int
}
Fleet is what the module needs from the fleet module (*fleet.Fleet implements it).
type GitHubPanelUpdater ¶
type GitHubPanelUpdater struct {
// contains filtered or unexported fields
}
func NewGitHubPanelUpdater ¶
func NewGitHubPanelUpdater(cfg PanelUpdateConfig) *GitHubPanelUpdater
NewGitHubPanelUpdater creates a fail-closed checker. An unsupported installation can still read release metadata, but the RPC never schedules a binary replacement for it.
func (*GitHubPanelUpdater) Check ¶
func (u *GitHubPanelUpdater) Check(ctx context.Context) PanelUpdateStatus
Check fetches the latest stable release. The endpoint is fixed to the Mistgate repository in production; every version, URL, asset name and digest is validated before any of it can reach the installer.
func (*GitHubPanelUpdater) Install ¶
func (u *GitHubPanelUpdater) Install(ctx context.Context) error
Install re-checks GitHub immediately before download, verifies the API-provided SHA-256 and ELF architecture, then asks systemd to run the built-in helper outside the panel service's filesystem sandbox.
func (*GitHubPanelUpdater) Run ¶
func (u *GitHubPanelUpdater) Run(ctx context.Context)
func (*GitHubPanelUpdater) Status ¶
func (u *GitHubPanelUpdater) Status() PanelUpdateStatus
type Health ¶
type Health interface {
// RunChecksNow schedules an immediate synthetic round for the inbounds of a node (rate limited to one per 30 s).
RunChecksNow(ctx context.Context, nodeID string) (scheduled, skipped int, retry time.Duration, err error)
// NodeChecksSince counts the probeable inbounds of the node and how many have a round that ended at or after since
// with OK / with FAILED or DEGRADED.
NodeChecksSince(ctx context.Context, nodeID string, since time.Time) (probeable, ok, failed int)
}
Health is what the rollout gate needs from the health module (*health.Service implements it); nil = no probe gate.
type PanelUpdateConfig ¶
type PanelUpdateConfig struct {
CurrentVersion string
CurrentBuilt int64
DataDir string
ServiceUnit string
Executable string
// Enabled is set only for a root Linux process with systemd available. Tests may set it explicitly.
Enabled bool
// APIURL, HTTPClient, Runner, OS, Arch and Now are injectable test seams. Production uses the fixed Mistgate
// endpoint, the default GitHub client and the host values.
APIURL string
HTTPClient *http.Client
Runner func(context.Context, string, ...string) error
OS string
Arch string
Now func() time.Time
Log *slog.Logger
}
type PanelUpdateStatus ¶
type PanelUpdateStatus struct {
Version string
URL string
PublishedUnix int64
CheckedUnix int64
Available bool
Supported bool
Installable bool
Installing bool
ErrorKey string
}
PanelUpdateStatus is the release information exposed on the Updates screen. ErrorKey is a stable UI key, not an upstream error message.
type PanelUpdater ¶
type PanelUpdater interface {
Status() PanelUpdateStatus
Check(context.Context) PanelUpdateStatus
Install(context.Context) error
Run(context.Context)
}
PanelUpdater is the GitHub release checker and the privileged installer for the panel binary.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the updates module.
func New ¶
New builds the module and reads the bundle directory once. Call Run to start the worker, fleet.SetUpdates and health.AddConditionSource (Conditions) to connect it.
func (*Service) Conditions ¶
Conditions is the health condition source (health.Service.AddConditionSource): while the active rollout is paused because a step failed, the gate failed or the panel lost track of a step, UPDATE_FAILED is raised; resuming, cancelling or a new rollout makes it go away. A pause by the owner or by a changed bundle raises nothing.
func (*Service) Handler ¶
Handler is the admin UpdateService (see fleet.NodeHandler for how it is mounted behind the session).
func (*Service) NodeBinary ¶
NodeBinary is fleet.Updates.NodeBinary: the absolute path of the platform's file of the current trusted bundle, "" without one. The path is the one the last scan verified; Serve re-checks the file itself, scp of the owner does not need to.
func (*Service) OpenNodeBinary ¶
OpenNodeBinary opens a verified node binary from the current trusted bundle. The caller receives the signed manifest's digest as well and must verify the bytes it transfers: the descriptor is stable across path replacement, while an in-place write can still change bytes after this method returns.
func (*Service) Run ¶
Run drives the worker, the bundle poll and the retention sweep until ctx ends, then waits for the command goroutines it started.
func (*Service) Serve ¶
func (s *Service) Serve(ctx context.Context, nodeID, name string, offset uint64, send func(chunk []byte, total uint64) error) error
Serve is fleet.Updates.Serve: it streams one file of the current trusted bundle to an agent that already authenticated with its node certificate. Only names in the trusted manifest are served, at most maxServes at a time; the descriptor is opened once, so a file replaced during a download cannot corrupt it.
type Timing ¶
type Timing struct {
Tick time.Duration // worker period; default 5 s
Rescan time.Duration // bundle directory poll; default 60 s
AnswerWait time.Duration // UpdateAgent: the agent's CommandResult, download included; default 10 min
ReconnectWait time.Duration // after the answer: the node is back with the new build; default 3 min
GateWait time.Duration // after the reconnect: the gate passes or fails; default 5 min
RollbackWait time.Duration // RollbackAgent answer; default 60 s
InboundGrace time.Duration // an inbound FAILED that long (two evaluations) fails the gate at once; default 30 s
Prune time.Duration // retention sweep period; default 6 h
}
Timing of the module. The zero value is production; tests shorten what they need.