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
- Variables
- func EnsureConfigACL(string) (bool, error)
- func Floor() updatestate.Version
- func FreeBytes(path string) (uint64, error)
- func InstallerBusy() bool
- func NativeArch() string
- func NewHTTPClient() *http.Client
- func Run(ctx context.Context, d *Deps) int
- func RunSmoke(ctx context.Context, exe string, want updatestate.Version) error
- func SetRunningVersion(string) error
- type Asset
- type Client
- type Deps
- type Release
- type SelfCheck
Constants ¶
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).
const ( ReasonBadRuns = "bad_runs" ReasonSmokeFailed = "smoke_failed" ReasonPointerInvalid = "pointer_invalid" ReasonInconclusive = "inconclusive" )
Rollback and quarantine reasons (error_message of update_rolled_back).
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).
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 ¶
var ErrCheck = errors.New("latest-binary check failed")
ErrCheck wraps every latest-binary failure (update_check_failed).
var ErrDownload = errors.New("download failed")
ErrDownload wraps a download that failed from every source (update_download_failed).
var ErrEventRejected = errors.New("update event rejected by the backend")
ErrEventRejected marks an event the backend refused (4xx); it is dropped rather than retried.
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.
var ErrVerify = errors.New("verification failed")
ErrVerify wraps every signature, checksum or publisher failure (update_verify_failed).
Functions ¶
func EnsureConfigACL ¶
EnsureConfigACL is Windows-only; elsewhere config.json keeps its mode.
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 ¶
NewHTTPClient returns the updater's client: the environment proxy vars first, then the WinHTTP machine proxy.
func Run ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.