Documentation
¶
Overview ¶
Package server is the ota release server: it chooses which publisher-signed offer each client sees, streams artifacts, and records what clients report. It holds no signing key and cannot create or alter an offer.
Index ¶
- Constants
- Variables
- func Bucket(program, channel, clientID string) int
- func ServeBlob(w http.ResponseWriter, r *http.Request, blobs BlobStore, sum string, ...)
- type Asset
- type BlobOptions
- type BlobStore
- type ClientRecord
- type FSBlobStore
- type FileStore
- type IngestResult
- type MemStore
- func (m *MemStore) AddReports(_ context.Context, rs []ota.Report) error
- func (m *MemStore) Clients(_ context.Context, program string) ([]ClientRecord, error)
- func (m *MemStore) DeletePin(_ context.Context, program, clientID string) error
- func (m *MemStore) GetPin(_ context.Context, program, clientID string) (*Pin, error)
- func (m *MemStore) Outcomes(_ context.Context, program, version string) (Outcomes, error)
- func (m *MemStore) PutOffer(so ota.SignedOffer) error
- func (m *MemStore) PutPin(_ context.Context, p Pin) error
- func (m *MemStore) PutRelease(_ context.Context, r Release) error
- func (m *MemStore) PutRollout(_ context.Context, r Rollout) error
- func (m *MemStore) Releases(_ context.Context, program string) ([]Release, error)
- func (m *MemStore) Rollouts(_ context.Context, program string) ([]Rollout, error)
- func (m *MemStore) TouchClient(_ context.Context, c ClientRecord) error
- type Options
- type Outcomes
- type Pin
- type Release
- type ReleaseView
- type Rollout
- type Server
- func (s *Server) AddOffer(ctx context.Context, so ota.SignedOffer, source, tag string) (Release, error)
- func (s *Server) Handler() http.Handler
- func (s *Server) Ingest(ctx context.Context) (IngestResult, error)
- func (s *Server) SetPin(ctx context.Context, p Pin) error
- func (s *Server) SetRollout(ctx context.Context, ro Rollout) error
- type Source
- type SourceRelease
- type Store
- type StoredOffer
- type Target
- type Targeter
Constants ¶
const ( DefaultHaltThreshold = 0.05 DefaultHaltMinAttempts = 50 )
Defaults for a rollout that does not set its own halt rule.
const ( ReleaseIngested = "ingested" ReleaseRejected = "rejected" )
Release status values.
const ( RolloutActive = "active" RolloutHalted = "halted" RolloutComplete = "complete" )
Rollout states.
const OfferAssetPrefix = "ota-offer"
OfferAssetPrefix names the offer files in a release. A release may carry several (the original and later rollback offers), each with its signature beside it as <name>.sigstore.json or <name>.sig.
Variables ¶
var ErrNoRelease = errors.New("server: no ingested signed offer for that version")
ErrNoRelease reports a version with no ingested signed offer.
var ErrNotFound = errors.New("server: artifact not found")
ErrNotFound reports an unknown artifact.
Functions ¶
func Bucket ¶
Bucket places a client in 0–99 for a program and channel. Stable, so a client stays in or out of a rollout across checks, and independent per channel, so the same clients are not always first.
func ServeBlob ¶
func ServeBlob(w http.ResponseWriter, r *http.Request, blobs BlobStore, sum string, opts BlobOptions)
ServeBlob streams one content-addressed artifact.
Exported so a host route that addresses artifacts differently (an installer asking by platform, say) serves the bytes the same way, with the ETag that lets a download resume and the compression a whole-file request gets.
Types ¶
type BlobOptions ¶
type BlobOptions struct {
// Name, when set, is offered as the download filename. The artifact route
// leaves it empty: an agent asked for a hash and stores it under one.
Name string
// Header is applied before anything is written, for a caller that wants to
// say where the bytes came from.
Header map[string]string
// Log receives stream interruptions. Optional.
Log *slog.Logger
}
BlobOptions tunes ServeBlob for a caller that is not the artifact route.
type BlobStore ¶
type BlobStore interface {
Open(ctx context.Context, sha256 string) (io.ReadSeekCloser, time.Time, error)
// Put stores r under sha256, refusing bytes that do not hash to it.
Put(ctx context.Context, sha256 string, r io.Reader) error
}
BlobStore holds artifact bytes keyed by SHA-256.
type ClientRecord ¶
type ClientRecord 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"`
LastSeen time.Time `json:"last_seen"`
LastReport *ota.Report `json:"last_report,omitempty"`
}
ClientRecord is the latest the server knows about one installation.
type FSBlobStore ¶
type FSBlobStore struct {
Dir string
}
FSBlobStore keeps artifacts as files named by their hash.
type FileStore ¶
type FileStore struct {
*MemStore
// contains filtered or unexported fields
}
FileStore is a MemStore saved to one JSON file after every change, for the standalone server. It is not encrypted: reports and client records link an installation to what it runs, so keep the directory private, or implement Store over an encrypted database for multi-tenant use.
func OpenFileStore ¶
OpenFileStore loads (or creates) the store at <dir>/state.json.
type IngestResult ¶
type IngestResult struct {
Ingested int `json:"ingested"`
Rejected int `json:"rejected"`
Known int `json:"known"`
Errors []string `json:"errors,omitempty"`
}
IngestResult summarises one ingest pass.
type MemStore ¶
type MemStore struct {
// contains filtered or unexported fields
}
MemStore keeps everything in memory. FileStore persists it.
func (*MemStore) AddReports ¶
AddReports implements Store.
func (*MemStore) PutOffer ¶
func (m *MemStore) PutOffer(so ota.SignedOffer) error
PutOffer ingests a signed offer directly, without verifying it. It is for tests and for hosts that verify elsewhere; servers ingest through Server.
func (*MemStore) PutRelease ¶
PutRelease implements Store, merging offers into an existing release.
func (*MemStore) PutRollout ¶
PutRollout implements Store; one rollout per program and channel.
func (*MemStore) TouchClient ¶
func (m *MemStore) TouchClient(_ context.Context, c ClientRecord) error
TouchClient implements Store.
type Options ¶
type Options struct {
Store Store
Blobs BlobStore
// Verifier checks every offer before it is stored. Required for
// ingest and admin uploads; a server that only serves pre-verified offers
// from its Store may leave it nil.
Verifier verify.Verifier
// Source is where releases are ingested from; optional.
Source Source
// Targeter, if set, decides per client in place of pins and rollouts.
Targeter Targeter
// Authorize admits a client request and may return the caller's client
// id, which then replaces whatever id the request body claims, so a client
// cannot report or check as another. Nil admits everything, which is only
// appropriate behind a host that already authenticates.
Authorize func(*http.Request) (clientID string, err error)
// AuthorizeAdmin admits admin requests. Nil disables the admin API.
AuthorizeAdmin func(*http.Request) error
// HTTPClient fetches artifacts during ingest. Defaults to a client with
// no overall timeout (artifacts are large); ingest uses context deadlines.
HTTPClient *http.Client
Logger *slog.Logger
Now func() time.Time
}
Options configures a Server.
type Outcomes ¶
Outcomes counts distinct clients per outcome for one version, which is what auto-halt decides on.
type Pin ¶
type Pin struct {
Program string `json:"program"`
ClientID string `json:"client_id"`
Version string `json:"version"`
}
Pin fixes one client to one version.
type Release ¶
type Release struct {
Program string `json:"program"`
Version string `json:"version"`
Tag string `json:"tag,omitempty"`
Source string `json:"source,omitempty"`
Status string `json:"status"`
Reason string `json:"reason,omitempty"`
IngestedAt time.Time `json:"ingested_at"`
Offers []StoredOffer `json:"offers"`
}
Release is a published version as the server knows it.
type ReleaseView ¶
ReleaseView is one release as GET /v1/admin/releases lists it. Offer bytes are for clients; the admin view says what was decided and why. Untagged, so its keys are the field names.
type Rollout ¶
type Rollout struct {
Program string `json:"program"`
Channel string `json:"channel"`
Version string `json:"version"`
Percent int `json:"percent"`
HaltThreshold float64 `json:"halt_threshold"`
HaltMinAttempts int `json:"halt_min_attempts"`
State string `json:"state"`
Reason string `json:"reason,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
Rollout offers a version to a share of a channel.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the /v1 API.
func (*Server) AddOffer ¶
func (s *Server) AddOffer(ctx context.Context, so ota.SignedOffer, source, tag string) (Release, error)
AddOffer verifies and stores one signed offer, fetching its artifacts from the URLs it lists. It is the admin upload path and the rollback path: a publisher-signed rollback offer can be posted without touching releases.
func (*Server) Handler ¶
Handler returns the API. Mount it at the root of a host's router or under a prefix with http.StripPrefix.
func (*Server) Ingest ¶
func (s *Server) Ingest(ctx context.Context) (IngestResult, error)
Ingest pulls every release from the Source and stores each offer that verifies, with its artifacts copied into Blobs after their hash is checked. An offer that fails is recorded as rejected, with the reason, and never served.
type Source ¶
type Source interface {
Name() string
Releases(ctx context.Context) ([]SourceRelease, error)
}
Source lists published releases, for example a project's GitHub Releases. Implementations live in server/source/*.
type SourceRelease ¶
SourceRelease is one tagged release and its downloadable files.
type Store ¶
type Store interface {
PutRelease(ctx context.Context, r Release) error
Releases(ctx context.Context, program string) ([]Release, error)
PutRollout(ctx context.Context, r Rollout) error
Rollouts(ctx context.Context, program string) ([]Rollout, error)
PutPin(ctx context.Context, p Pin) error
DeletePin(ctx context.Context, program, clientID string) error
GetPin(ctx context.Context, program, clientID string) (*Pin, error)
TouchClient(ctx context.Context, c ClientRecord) error
Clients(ctx context.Context, program string) ([]ClientRecord, error)
// AddReports stores reports, ignoring exact repeats (same client,
// version, offer and stage), and updates each client's record.
AddReports(ctx context.Context, rs []ota.Report) error
Outcomes(ctx context.Context, program, version string) (Outcomes, error)
}
Store persists what the server decides from. The server holds no key and stores offers only as the bytes the publisher signed. Hosts implement it over their own database; MemStore and FileStore are included.
Reports and client records link an installation to what it runs; a host whose installations belong to organisations should encrypt them at rest.
type StoredOffer ¶
type StoredOffer struct {
Signed ota.SignedOffer `json:"signed"`
IssuedAt int64 `json:"issued_at"`
// ExpiresAt is copied from the offer so an expired one is never served;
// clients would refuse it anyway, on every check.
ExpiresAt int64 `json:"expires_at,omitempty"`
Channels []string `json:"channels,omitempty"`
// Digest identifies the offer bytes, so re-ingesting is a no-op.
Digest string `json:"digest"`
}
StoredOffer is one publisher-signed offer, kept byte for byte.
type Target ¶
type Target struct {
// Deny offers nothing.
Deny bool
// Version, if set, is offered regardless of rollouts (a host-side pin).
Version string
// Channel, if set, replaces the client's claimed channel for rollouts.
Channel string
}
Target is a host's decision for one client. Returned with ok=false from a Targeter, the built-in rules decide instead.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
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. |
|
github
module
|