Documentation
¶
Overview ¶
Package addons holds signed data packs (languages, themes, template packs, docs, backgrounds): files only, verified by hash and schema, never executed.
Index ¶
- Constants
- Variables
- func EncodePack(pkg Package) ([]byte, error)
- func EncodeSignedPack(pkg Package, keyID, sig string) ([]byte, error)
- func InstallFile(st *Store, data []byte, keys []plugin.TrustedKey, idx *Index, lim Limits, ...) (Installed, FileSigner, error)
- func KeysFromIndex(idx Index) []plugin.TrustedKey
- func ManifestSignedMessage(manifestRaw []byte) []byte
- func ParseOperatorRoot(b64 string) (ed25519.PublicKey, error)
- func PinnedRoots() []ed25519.PublicKey
- func ReadPack(r io.Reader, e IndexEntry) ([]byte, error)
- func Roots(pinned []ed25519.PublicKey, operator []string) []ed25519.PublicKey
- func SignIndex(priv ed25519.PrivateKey, idx Index) ([]byte, error)
- func SignManifest(priv ed25519.PrivateKey, manifestRaw []byte) string
- func TrustRoot(b64 string, pinned []ed25519.PublicKey) (ed25519.PublicKey, error)
- type Client
- func (c *Client) AutoUpdate(ctx context.Context, st *Store, indexURL string, roots []ed25519.PublicKey, ...) (UpdateResult, error)
- func (c *Client) Cached(roots []ed25519.PublicKey, lim Limits) (Index, error)
- func (c *Client) Install(ctx context.Context, st *Store, idx Index, id, version string, lim Limits) (Installed, error)
- func (c *Client) InstallIfPresent(ctx context.Context, st *Store, idx Index, id, version string, lim Limits) (Installed, error)
- func (c *Client) Refresh(ctx context.Context, indexURL string, roots []ed25519.PublicKey, lim Limits) (Index, error)
- type Entry
- type File
- type FileSigner
- type Index
- type IndexEntry
- type IndexState
- type Installed
- type Limits
- type Manifest
- type Package
- type Revocation
- type StorageError
- type Store
- func (s *Store) Inspect(kind, id string) (Manifest, error)
- func (s *Store) Install(v Verified, pkg Package) (Installed, error)
- func (s *Store) InstallIfPresent(v Verified, pkg Package) (Installed, error)
- func (s *Store) List() ([]Installed, error)
- func (s *Store) ReadFile(kind, id, rel string) ([]byte, error)
- func (s *Store) Reconfigure(keep int, lim Limits)
- func (s *Store) Remove(kind, id string) error
- func (s *Store) Rollback(kind, id string) (Installed, error)
- func (s *Store) SetIndex(idx Index)
- func (s *Store) Sweep(idx Index) ([]Swept, error)
- type Swept
- type UpdateResult
- type Updated
- type Verified
Constants ¶
const ( KindLanguage = "language" KindTheme = "theme" KindTemplatePack = "template_pack" KindDocs = "docs" KindBackground = "background" )
Pack kinds. Anything else is refused, including code kinds, which stay in the out-of-process plugin runtime.
const ManifestAPIVersion = 1
ManifestAPIVersion is the manifest schema version this build accepts.
Variables ¶
var ( ErrManifest = errors.New("addons: the manifest is invalid") ErrUnknownKind = errors.New("addons: the add-on kind is not supported") ErrUnsafePath = errors.New("addons: a file path is not allowed") ErrTooLarge = errors.New("addons: the pack is larger than the allowed size") ErrHash = errors.New("addons: a file does not match its declared hash or size") ErrContent = errors.New("addons: a file has content that is not allowed") )
Failures. Callers match with errors.Is.
var ( ErrStorage = errors.New("addons: a storage operation failed") ErrPointer = errors.New("addons: the current pointer is unreadable") ErrNotInstalled = errors.New("addons: the add-on is not installed") ErrNoPrevious = errors.New("addons: there is no previous version to roll back to") ErrIdentity = errors.New("addons: the pack does not match the verified manifest") )
Store errors. Callers match with errors.Is.
var ErrBadSignature = errors.New("addons: the manifest signature does not verify")
ErrBadSignature means a detached manifest signature did not verify.
var ErrDowngrade = errors.New("addons: the pack is not newer than the installed version")
ErrDowngrade means a pack file is not newer than the installed version and no downgrade was allowed.
var ErrFetch = errors.New("addons: the download failed")
ErrFetch means a download failed before anything could be verified.
var ErrIndexStale = errors.New("addons: the index is too old")
ErrIndexStale means the index is older than the allowed age.
var ErrInsecureURL = errors.New("addons: the index url must be https")
ErrInsecureURL means the index address is not a plain https URL.
var ErrNoIndex = errors.New("addons: no index has been fetched yet")
ErrNoIndex means no verified index is cached yet.
var ErrNotListed = errors.New("addons: the entry is not listed in the index")
ErrNotListed means the entry is not exactly what the signed index lists.
var ErrRevoked = errors.New("addons: the add-on is revoked by the index")
ErrRevoked means the index revokes the add-on version or its manifest hash.
var ErrUntrustedKey = errors.New("addons: the publisher key is not trusted")
ErrUntrustedKey means the publisher key is not vouched for by the index root.
Functions ¶
func EncodePack ¶
EncodePack builds the container bytes a publisher uploads.
func EncodeSignedPack ¶
EncodeSignedPack builds a pack container that carries its publisher key id and manifest signature for an offline install.
func InstallFile ¶
func InstallFile(st *Store, data []byte, keys []plugin.TrustedKey, idx *Index, lim Limits, allowDowngrade bool) (Installed, FileSigner, error)
InstallFile installs a local pack container. The manifest must carry a valid signature from a key in keys, that key must belong to the manifest publisher and to any index entry for the same id, and the pack must not be revoked by idx or older than what is installed unless allowDowngrade is set. There is no unsigned path.
func KeysFromIndex ¶
func KeysFromIndex(idx Index) []plugin.TrustedKey
KeysFromIndex lists the publisher keys a verified index vouches for, as the trust list an offline install checks.
func ManifestSignedMessage ¶
ManifestSignedMessage is the byte string a publisher signs: a domain tag and the sha256 of the manifest bytes as shipped.
func ParseOperatorRoot ¶
ParseOperatorRoot checks one base64 ed25519 public key an operator wants to pin.
func PinnedRoots ¶
PinnedRoots returns a copy of the roots compiled into this build.
func ReadPack ¶
func ReadPack(r io.Reader, e IndexEntry) ([]byte, error)
ReadPack reads a downloaded pack body, enforcing the size and hash the signed index promises. It never reads more than PackSize+1 bytes.
func Roots ¶
Roots joins the pinned roots with the operator's list. Entries that no longer parse are skipped, because the setting validates on write.
func SignIndex ¶
func SignIndex(priv ed25519.PrivateKey, idx Index) ([]byte, error)
SignIndex validates idx and returns the signed envelope bytes.
func SignManifest ¶
func SignManifest(priv ed25519.PrivateKey, manifestRaw []byte) string
SignManifest produces the detached addon.sig content.
Types ¶
type Client ¶
type Client struct {
FetchIndex plugin.IndexFetchFunc
FetchFile plugin.FetchFunc
Now func() time.Time
// contains filtered or unexported fields
}
Client fetches the signed index and packs. The default fetchers are the plugin marketplace's SSRF-guarded ones, so redirects, timeouts and size caps match.
func (*Client) AutoUpdate ¶
func (c *Client) AutoUpdate(ctx context.Context, st *Store, indexURL string, roots []ed25519.PublicKey, lim Limits) (UpdateResult, error)
AutoUpdate refreshes the signed index, applies revocations, then installs newer listed versions of installed data packs. A refresh that fails verification or is stale returns the error and changes nothing.
func (*Client) Cached ¶
Cached re-verifies the cached index, so a removed root or an aged-out index stops being served without a network call.
func (*Client) Install ¶
func (c *Client) Install(ctx context.Context, st *Store, idx Index, id, version string, lim Limits) (Installed, error)
Install downloads the pack for id@version from idx, checks size and hash, verifies the manifest against the index, then hands it to the store.
func (*Client) InstallIfPresent ¶
func (c *Client) InstallIfPresent(ctx context.Context, st *Store, idx Index, id, version string, lim Limits) (Installed, error)
InstallIfPresent is Install for an add-on that must still be installed when the swap happens.
func (*Client) Refresh ¶
func (c *Client) Refresh(ctx context.Context, indexURL string, roots []ed25519.PublicKey, lim Limits) (Index, error)
Refresh fetches the index over https, verifies it against roots, enforces sequence and age, then caches it. A failed fetch never replaces the last good index.
type Entry ¶
type Entry struct {
Locale string `yaml:"locale,omitempty"`
Dir string `yaml:"dir,omitempty"`
Tokens string `yaml:"tokens,omitempty"`
Modes []string `yaml:"modes,omitempty"`
Templates []string `yaml:"templates,omitempty"`
Index string `yaml:"index,omitempty"`
Image string `yaml:"image,omitempty"`
}
Entry holds the per-kind fields. Fields that do not belong to the kind are refused.
type File ¶
type File struct {
Path string `yaml:"path"`
SHA256 string `yaml:"sha256"`
Size int64 `yaml:"size"`
}
File is one declared pack file.
type FileSigner ¶
type FileSigner struct {
KeyID, Publisher string
}
FileSigner names who signed an installed pack file, for the audit trail.
type Index ¶
type Index struct {
Version int `json:"version"`
GeneratedAt string `json:"generated_at"`
Sequence int64 `json:"sequence"`
PublisherKeys []plugin.IndexKey `json:"publisher_keys"`
Addons []IndexEntry `json:"addons"`
Revoked []Revocation `json:"revoked"`
}
Index is the signed catalog payload. Sequence only ever grows.
func ParseIndex ¶
func ParseIndex(raw []byte, root ed25519.PublicKey, last IndexState, lim Limits, now time.Time) (Index, string, error)
ParseIndex verifies the envelope against root, then enforces freshness: the sequence must not go back, an equal sequence must carry the same payload, and generated_at must be within lim.IndexMaxAge (zero disables the age check). It returns the index plus the sha256 of the signed payload.
func (Index) Find ¶
func (idx Index) Find(id, version string) (IndexEntry, bool)
Find returns the listed entry for an id and version.
type IndexEntry ¶
type IndexEntry struct {
ID string `json:"id"`
Kind string `json:"kind"`
Version string `json:"version"`
Publisher string `json:"publisher"`
PublisherKeyID string `json:"publisher_key_id"`
Summary string `json:"summary"`
MinLevelrail string `json:"min_levelrail"`
ManifestSHA256 string `json:"manifest_sha256"`
ManifestSig string `json:"manifest_signature"`
PackSHA256 string `json:"pack_sha256"`
PackSize int64 `json:"pack_size"`
URLs []string `json:"urls"`
}
IndexEntry is one listed add-on version. Everything in it is covered by the index signature.
type IndexState ¶
IndexState is what the caller last accepted, persisted between fetches.
type Installed ¶
type Installed struct {
Kind string `json:"kind"`
ID string `json:"id"`
Version string `json:"version"`
ManifestSHA256 string `json:"manifest_sha256"`
Previous []string `json:"previous"`
}
Installed describes one installed add-on.
type Limits ¶
type Limits struct {
MaxPackBytes int64
MaxFiles int
MaxFileBytes int64
// AllowedExt narrows the per-kind set; it can never widen it.
AllowedExt []string
// IndexMaxAge is the oldest generated_at an index may carry; zero skips the check.
// The runtime setting feeds it, there is no built-in value.
IndexMaxAge time.Duration
}
Limits are the operator-tunable ceilings, seeded from runtime settings by the caller.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits seeds Limits when no setting overrides them.
type Manifest ¶
type Manifest struct {
APIVersion int `yaml:"api_version"`
ID string `yaml:"id"`
Kind string `yaml:"kind"`
Version string `yaml:"version"`
MinLevelrail string `yaml:"min_levelrail"`
Publisher string `yaml:"publisher"`
Capabilities []string `yaml:"capabilities,omitempty"`
Entry Entry `yaml:"entry"`
Files []File `yaml:"files"`
}
Manifest is addon.yaml.
func ParseManifest ¶
ParseManifest decodes and validates addon.yaml. Unknown fields are an error so a typo can never silently drop a restriction.
func (*Manifest) FileByPath ¶
FileByPath returns the declared file.
type Package ¶
Package is the bytes of one add-on: its manifest and every declared file.
func DecodePack ¶
DecodePack parses container bytes already checked against the signed size and hash.
type Revocation ¶
type Revocation struct {
ID string `json:"id"`
Version string `json:"version"`
ManifestSHA256 string `json:"manifest_sha256"`
Reason string `json:"reason"`
}
Revocation names one add-on version or one manifest hash to disable.
type StorageError ¶
StorageError hides the on-disk path from callers; Detail is for logs only.
func (*StorageError) Detail ¶
func (e *StorageError) Detail() string
Detail returns the underlying error text, which may hold a path.
func (*StorageError) Error ¶
func (e *StorageError) Error() string
func (*StorageError) Unwrap ¶
func (e *StorageError) Unwrap() error
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps verified packs under <data dir>/addons/<kind>/<id>/<version>.
func NewStore ¶
NewStore creates the layout under dataDir. keep is how many versions stay on disk, current included.
func (*Store) Inspect ¶
Inspect re-checks the current version of an installed add-on against its recorded hashes and returns its manifest. It ignores revocation on purpose, so a health check can tell tampering from a withdrawn release.
func (*Store) Install ¶
Install writes a verified pack to a staging directory, re-checks every file by hash, then swaps the current pointer. Any failure leaves the previous version current and no staging data behind.
func (*Store) InstallIfPresent ¶
InstallIfPresent is Install for an unattended update: it refuses with ErrNotInstalled when the add-on was removed meanwhile, so an update can never bring back something an operator deleted.
func (*Store) ReadFile ¶
ReadFile returns one declared file of the current version, re-checked against the manifest hash so on-disk tampering is never served.
func (*Store) Reconfigure ¶
Reconfigure applies new settings to the one live store, so a settings change never rebuilds it (a rebuild would sweep the staging directory of an install still running).
type Swept ¶
type Swept struct {
Kind, ID string
// Version is the new current version, empty when the add-on was removed.
Version string
Removed bool
}
Swept reports one add-on changed by a revocation sweep.
type UpdateResult ¶
type UpdateResult struct {
Sequence int64
Updated []Updated
Swept []Swept
// Failed holds per add-on install errors; one failure never stops the others.
Failed map[string]error
}
UpdateResult reports one auto-update pass.
type Updated ¶
type Updated struct {
ID, Kind, From, To string
}
Updated is one add-on moved to a newer version.
type Verified ¶
type Verified struct {
// contains filtered or unexported fields
}
Verified is proof that a manifest passed signature, revocation and identity checks. Only the Verify functions build it, and Store.Install requires it.
func VerifyOffline ¶
func VerifyOffline(keys []plugin.TrustedKey, keyID string, manifestRaw []byte, sigB64 string, cached *Index) (Verified, error)
VerifyOffline checks a pack's detached signature against an operator trust list, for installs from a local file with no index. cached is the last verified index (nil when none was ever fetched) and its revocations apply.