selfupdate

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 25 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 selfupdate is the Windows MSI self-updater (`agent self-update --system`, run by the SYSTEM update task through the bootstrap). It asks agent-api latest-binary for the tenant's target, verifies every artefact (SSHSIG over the checksum before download, sha256 after, Authenticode publisher), stages it as an immutable versions\<v> directory and switches the state.json pointer the bootstrap reads. See internal/updatestate for the on-disk contract.

Index

Constants

View Source
const (
	EventOK             = "update_ok"
	EventConfirmed      = "update_confirmed"
	EventRolledBack     = "update_rolled_back"
	EventDownloadFailed = "update_download_failed"
	EventVerifyFailed   = "update_verify_failed"
	EventStageFailed    = "update_stage_failed"
	EventHealthFailed   = "update_health_failed"
	EventSwitchFailed   = "update_switch_failed"
	EventSwitchDeferred = "update_switch_deferred"
	EventCheckFailed    = "update_check_failed"
	EventRefusedFloor   = "update_refused_floor"
	EventDisabled       = "update_disabled"
	EventPointerInvalid = "update_pointer_invalid"
	EventACLDrift       = "update_acl_drift"
	EventStateCorrupt   = "update_state_corrupt"
	EventUpdaterFailed  = "update_updater_failed"
)

Event names (spec §7).

View Source
const (
	ReasonBadRuns        = "bad_runs"
	ReasonSmokeFailed    = "smoke_failed"
	ReasonPointerInvalid = "pointer_invalid"
	ReasonInconclusive   = "inconclusive"
)

Rollback and quarantine reasons (error_message of update_rolled_back).

View Source
const (
	ExitOK     = 0
	ExitFailed = 1
)

Exit codes. Non-zero tells the bootstrap this updater failed (three in a row make it fall back to the seed's updater).

View Source
const (
	SelfCheckProbeTimeout = 10 * time.Second
)

SelfCheckProbeTimeout bounds the self-check's device-id probe; smokeMargin is the headroom the smoke limit keeps above it (startup, config load).

Variables

View Source
var ErrCheck = errors.New("latest-binary check failed")

ErrCheck wraps every latest-binary failure (update_check_failed).

View Source
var ErrDownload = errors.New("download failed")

ErrDownload wraps a download that failed from every source (update_download_failed).

View Source
var ErrEventRejected = errors.New("update event rejected by the backend")

ErrEventRejected marks an event the backend refused (4xx); it is dropped rather than retried.

View Source
var ErrSmokeTimeout = errors.New("self-check timed out")

ErrSmokeTimeout means the self-check didn't answer within the smoke limit: retried, not held against the version, until it repeats.

View Source
var ErrVerify = errors.New("verification failed")

ErrVerify wraps every signature, checksum or publisher failure (update_verify_failed).

Functions

func EnsureConfigACL

func EnsureConfigACL(string) (bool, error)

EnsureConfigACL is Windows-only; elsewhere config.json keeps its mode.

func Floor

func Floor() updatestate.Version

Floor returns F.

func FreeBytes

func FreeBytes(path string) (uint64, error)

FreeBytes reports the bytes available to this process on path's volume.

func InstallerBusy

func InstallerBusy() bool

InstallerBusy is Windows-only.

func NativeArch

func NativeArch() string

NativeArch is the machine's architecture as a release-asset suffix (amd64 | arm64). On Windows it comes from IsWow64Process2, so an x64 build emulated on arm64 converges to the arm64 build.

func NewHTTPClient

func NewHTTPClient() *http.Client

NewHTTPClient returns the updater's client: the environment proxy vars first, then the WinHTTP machine proxy.

func Run

func Run(ctx context.Context, d *Deps) int

Run executes one updater tick (S0–S7). It never panics on bad state and always leaves a state the next tick converges from.

func RunSmoke

func RunSmoke(ctx context.Context, exe string, want updatestate.Version) error

RunSmoke runs `<exe> self-check` with the smoke time limit and checks that it exits 0 reporting version want, a loaded config and a device id.

func SetRunningVersion

func SetRunningVersion(string) error

SetRunningVersion is Windows-only (HKLM RunningVersion).

Types

type Asset

type Asset struct {
	File     string // updatestate.AgentFile etc.
	Remote   string // release asset name
	Checksum string // lowercase hex sha256
	Signed   string // signed_checksum transport value
}

Asset is one file of a release: the name it gets in versions\<v>, the release asset name, and its signed checksum.

type Client

type Client struct {
	HTTP          *http.Client
	APIEndpoint   string
	CustomerID    string
	APIKey        string
	AgentVersion  string
	Arch          string // native windows arch: amd64 | arm64
	LagBehind     int
	CooldownHours int
	MirrorURL     string // optional HTTPS mirror (config update_mirror_url)
	// ReleaseBaseURL and SigningKey default to the GitHub releases and the
	// pinned release key; only tests and selfupdate_testkeys builds change them.
	ReleaseBaseURL string
	SigningKey     string
}

Client talks to latest-binary and downloads release assets.

func (*Client) Download

func (c *Client) Download(ctx context.Context, v updatestate.Version, a Asset, dir string) error

Download fetches asset a of version v into dir\<a.File>: GitHub first, then the mirror. The written file's sha256 must equal the signed checksum. Local write failures (disk full) are returned unwrapped by ErrDownload so the caller reports them as stage failures.

func (*Client) Latest

func (c *Client) Latest(ctx context.Context) (*Release, error)

Latest resolves the target from one windows latest-binary response: agent, launcher and dmg-linux all come from the same resolution, so they always name one version. A missing checksum or signature for any asset is left empty for VerifySignatures to reject (update_verify_failed) before anything is downloaded.

func (*Client) VerifySignatures

func (c *Client) VerifySignatures(r *Release) error

VerifySignatures checks every asset's SSHSIG before anything is downloaded: one unverifiable asset rejects the whole release.

type Deps

type Deps struct {
	Layout  updatestate.Layout
	Self    updatestate.Version // version of this process
	SelfExe string
	Client  *Client
	// AutoUpdate=false still checks and reports update_disabled.
	AutoUpdate bool
	// VerifyPublisher checks a staged exe's Authenticode signature and
	// publisher (authenticode.SamePublisher against SelfExe).
	VerifyPublisher func(path string) error
	// Smoke runs `<exe> self-check` and checks it reports version want.
	Smoke func(ctx context.Context, exe string, want updatestate.Version) error
	// AcquireInstance takes the scan instance mutex without blocking.
	AcquireInstance func() (release func(), err error)
	// EnsureACLs re-asserts versions\, state\ and config.json ACLs and
	// returns what had drifted.
	EnsureACLs func() (drifted []string, err error)
	// RefreshDeviceID probes the hardware as SYSTEM and rewrites the
	// device-id file (M-9).
	RefreshDeviceID func(ctx context.Context)
	// Send posts one update event.
	Send func(ctx context.Context, ev updatestate.OutboxEvent) error
	// SetRunningVersion records HKLM RunningVersion (inventory only).
	SetRunningVersion func(v string)
	// VerifySeed checks an MSI seed's executables (authenticode
	// SameSeedPublisher); nil falls back to VerifyPublisher.
	VerifySeed func(path string) error
	// InstallerBusy reports a Windows Installer transaction in progress
	// (Global\_MSIExecute held); nil means never.
	InstallerBusy func() bool
	// FreeBytes reports free space on the volume holding path.
	FreeBytes func(path string) (uint64, error)
	Now       func() time.Time
	Logf      func(format string, args ...any)
}

Deps are the updater's side effects, injected so the state machine runs unchanged in tests and as SYSTEM.

type Release

type Release struct {
	Version updatestate.Version
	Assets  []Asset
}

Release is a latest-binary target with all three assets.

type SelfCheck

type SelfCheck struct {
	Version  string `json:"version"`
	DeviceID string `json:"device_id"`
	ConfigOK bool   `json:"config_ok"`
}

SelfCheck is the `agent self-check` output (spec Contracts: CLI).

Jump to

Keyboard shortcuts

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