Documentation
¶
Overview ¶
Package ota holds the types shared by the ota client, server and CLI: the signed offer, update events and reports, and the sentinel errors callers branch on.
Index ¶
Constants ¶
const OfferSchema = "ota.offer/v1"
OfferSchema is the only offer schema this version understands. The major version is what a client checks; unknown fields are ignored so v1 clients survive additive changes such as deltas.
Variables ¶
var ( // ErrRefused: the offer failed verification, replay, expiry, channel or // downgrade rules. Nothing was downloaded or changed. ErrRefused = errors.New("ota: offer refused") // ErrDeferred: the host deferred or refused the offer. ErrDeferred = errors.New("ota: update deferred by host") // ErrDrainTimeout: the host's drain step overran its deadline; nothing was swapped. ErrDrainTimeout = errors.New("ota: host drain exceeded its deadline") // ErrDownload: the download failed or its bytes did not match the offer. ErrDownload = errors.New("ota: download failed") // ErrRolledBack: the new version was installed, failed its health gate and // was replaced by the previous one. ErrRolledBack = errors.New("ota: update rolled back") // ErrLocked: another updater holds the lock for this installation. ErrLocked = errors.New("ota: another update is in progress") // ErrRestartNeeded: the update is verified and staged, and applies on the // program's next start. ErrRestartNeeded = errors.New("ota: update staged; restart needed") )
Sentinels map one-to-one onto the CLI exit codes, so a caller branches with errors.Is and the CLI never parses a message.
Functions ¶
func ValidChannel ¶
ValidChannel reports whether s is a well-formed channel name.
func ValidSHA256 ¶
ValidSHA256 reports whether s is a lowercase hex SHA-256, the only form an artifact path segment may take before it reaches a store.
Types ¶
type Artifact ¶
type Artifact struct {
OS string `json:"os"`
Arch string `json:"arch"`
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
URLs []string `json:"urls,omitempty"`
}
Artifact is one platform's binary, identified by its content hash.
type CheckRequest ¶
type CheckRequest struct {
ClientID string `json:"client_id"`
Program string `json:"program"`
OS string `json:"os"`
Arch string `json:"arch"`
Channel string `json:"channel,omitempty"`
RunningVersion string `json:"running_version"`
LastOfferIssuedAt int64 `json:"last_offer_issued_at"`
}
CheckRequest is what a client tells the server when asking for an offer.
type Decision ¶
type Decision struct {
Action Action
// Until is when a deferred offer may be reconsidered.
Until time.Time
Reason string
}
Decision is what a BeforeApply hook returns. ota never prompts anyone; a host that wants a person to approve asks them inside the hook and answers here.
func DeferUntil ¶
DeferUntil postpones the offer; it is reconsidered at or after t.
func RefuseOffer ¶
RefuseOffer declines this offer; it is reported and not retried.
type Event ¶
type Event struct {
Stage Stage
Program string
Version string
// Bytes and Total are set on download progress events.
Bytes, Total int64
Err error
At time.Time
}
Event is emitted to Options.OnEvent at every stage transition.
type Offer ¶
type Offer struct {
Schema string `json:"schema"`
Program string `json:"program"`
Version string `json:"version"`
IssuedAt int64 `json:"issued_at"`
// ExpiresAt is optional and off by default; zero means the offer does not
// expire. See the accepted freeze risk in the security model.
ExpiresAt int64 `json:"expires_at,omitempty"`
// Downgrade must be set for an offer whose Version is lower than what a
// client runs, so a mislabelled offer cannot roll a machine back by accident.
Downgrade bool `json:"downgrade,omitempty"`
Channels []string `json:"channels,omitempty"`
// MinVersion is reserved; v1 clients ignore it.
MinVersion string `json:"min_version,omitempty"`
Artifacts []Artifact `json:"artifacts"`
TrustRootUpdate *TrustRootUpdate `json:"trust_root_update,omitempty"`
// Deltas is reserved for patch updates; v1 clients ignore it.
Deltas json.RawMessage `json:"deltas,omitempty"`
// contains filtered or unexported fields
}
Offer is the publisher-signed statement that clients may move to Version. The signature covers the exact bytes it was parsed from, never a re-serialisation, so there is no canonical form to get wrong.
func ParseOffer ¶
ParseOffer decodes and shape-checks an offer. Call it only on bytes whose signature has already verified: the fields are publisher input, and nothing here is a substitute for that check.
func (Offer) AdmitsChannel ¶
AdmitsChannel reports whether a client on channel may be shown this offer.
func (Offer) ArtifactFor ¶
ArtifactFor returns the artifact built for exactly this OS and architecture.
type Report ¶
type Report struct {
ClientID string `json:"client_id"`
Program string `json:"program"`
Version string `json:"version"`
OfferIssuedAt int64 `json:"offer_issued_at"`
Stage Stage `json:"stage"`
Error string `json:"error,omitempty"`
At int64 `json:"at"`
}
Report is one reported stage of one attempt, as sent to the server.
type SignedOffer ¶
type SignedOffer struct {
Offer []byte `json:"offer"`
Signature []byte `json:"signature"`
Kind string `json:"signature_kind"`
}
SignedOffer is an offer's exact bytes plus the publisher's signature over them. The server passes both through untouched; it cannot mint either.
type Stage ¶
type Stage string
Stage is a point in an update attempt, reported to the server and emitted as an event. The set is closed: rollout auto-halt counts specific stages, so an ad-hoc string would silently fall out of that arithmetic.
const ( StageOfferSeen Stage = "offer_seen" StageDeferred Stage = "deferred" StageRefused Stage = "refused" StageDownloading Stage = "downloading" StageDownloaded Stage = "downloaded" StageVerified Stage = "verified" StageSwapped Stage = "swapped" StageInstalled Stage = "installed" StageHealthy Stage = "healthy" StageCommitted Stage = "committed" StageRolledBack Stage = "rolled_back" StageFailed Stage = "failed" StageStaged Stage = "staged" )
type TrustRootUpdate ¶
type TrustRootUpdate struct {
Version int64 `json:"version"`
Kind string `json:"kind"`
Root json.RawMessage `json:"root"`
}
TrustRootUpdate carries replacement trust material. A client adopts it only from an offer that verified under the root it already trusts.
type Version ¶
type Version struct {
Major, Minor, Patch uint64
Pre []string
Build string
// contains filtered or unexported fields
}
Version is a parsed semantic version (semver 2.0). Build metadata is kept for display but ignored in comparisons, as the spec requires.
func MustParseVersion ¶
MustParseVersion is for constants in tests and examples.
func ParseVersion ¶
ParseVersion accepts "1.8.0", "v1.8.0", "1.9.0-rc.1+abc". A leading "v" is allowed because git tags carry one and offers are generated from tags.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cli gives a host program ota's commands as subcommands of its own binary, so updating never needs a second program:
|
Package cli gives a host program ota's commands as subcommands of its own binary, so updating never needs a second program: |
|
Package client checks for, verifies and applies updates to the running program.
|
Package client checks for, verifies and applies updates to the running program. |
|
examples
|
|
|
hello
command
Command hello is a program that keeps itself up to date: it prints its version, then checks the update server every -every and becomes the new version when a signed one is offered.
|
Command hello is a program that keeps itself up to date: it prints its version, then checks the update server every -every and becomes the new version when a signed one is offered. |
|
Package health decides whether a freshly installed version is healthy enough to keep.
|
Package health decides whether a freshly installed version is healthy enough to keep. |
|
internal
|
|
|
stage
Package stage owns everything that touches disk before a swap: the single-updater lock, the state directory, free-space checks, and the streamed, resumable, hash-verified download.
|
Package stage owns everything that touches disk before a swap: the single-updater lock, the state directory, free-space checks, and the streamed, resumable, hash-verified download. |
|
swap
Package swap replaces the installed binary with a verified new one and puts it back when the new one fails.
|
Package swap replaces the installed binary with a verified new one and puts it back when the new one fails. |
|
testkit/fixture
Package fixture builds sampleapp as v1 and v2, installs v1 and serves v2, for the suites that exercise real binaries.
|
Package fixture builds sampleapp as v1 and v2, installs v1 and serves v2, for the suites that exercise real binaries. |
|
lifecycle
module
|
|
|
otel
module
|
|
|
Package restart decides how a swapped-in version starts running.
|
Package restart decides how a swapped-in version starts running. |
|
Package server is the ota release server: it chooses which publisher-signed offer each client sees, streams artifacts, and records what clients report.
|
Package server is the ota release server: it chooses which publisher-signed offer each client sees, streams artifacts, and records what clients report. |
|
source/httpindex
Package httpindex reads releases from a static JSON index, which any host can publish: GitLab or Gitea release pages, an S3 bucket, a plain file server.
|
Package httpindex reads releases from a static JSON index, which any host can publish: GitLab or Gitea release pages, an S3 bucket, a plain file server. |
|
source/github
module
|
|
|
service
module
|
|
|
Package verify defines how an offer's signature is checked.
|
Package verify defines how an offer's signature is checked. |
|
ed25519
Package ed25519 verifies offers signed with a pinned ed25519 key.
|
Package ed25519 verifies offers signed with a pinned ed25519 key. |
|
sigstore
module
|