addons

package
v1.5.17 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 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 addons holds signed data packs (languages, themes, template packs, docs, backgrounds): files only, verified by hash and schema, never executed.

Index

Constants

View Source
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.

View Source
const ManifestAPIVersion = 1

ManifestAPIVersion is the manifest schema version this build accepts.

Variables

View Source
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.

View Source
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.

View Source
var ErrBadSignature = errors.New("addons: the manifest signature does not verify")

ErrBadSignature means a detached manifest signature did not verify.

View Source
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.

View Source
var ErrFetch = errors.New("addons: the download failed")

ErrFetch means a download failed before anything could be verified.

View Source
var ErrIndexStale = errors.New("addons: the index is too old")

ErrIndexStale means the index is older than the allowed age.

View Source
var ErrInsecureURL = errors.New("addons: the index url must be https")

ErrInsecureURL means the index address is not a plain https URL.

View Source
var ErrNoIndex = errors.New("addons: no index has been fetched yet")

ErrNoIndex means no verified index is cached yet.

View Source
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.

View Source
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.

View Source
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

func EncodePack(pkg Package) ([]byte, error)

EncodePack builds the container bytes a publisher uploads.

func EncodeSignedPack

func EncodeSignedPack(pkg Package, keyID, sig string) ([]byte, error)

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

func ManifestSignedMessage(manifestRaw []byte) []byte

ManifestSignedMessage is the byte string a publisher signs: a domain tag and the sha256 of the manifest bytes as shipped.

func PackSignerHint

func PackSignerHint(data []byte) (keyID, publisher string)

PackSignerHint returns the key id and publisher a pack claims, so a verify against one explicit root can name it.

func ParseOperatorRoot

func ParseOperatorRoot(b64 string) (ed25519.PublicKey, error)

ParseOperatorRoot checks one base64 ed25519 public key an operator wants to pin.

func ParsePrivateKey

func ParsePrivateKey(b64 string) (ed25519.PrivateKey, error)

ParsePrivateKey decodes a base64 ed25519 private key (64 bytes) or seed (32 bytes) read from a key file.

func PinnedRoots

func PinnedRoots() []ed25519.PublicKey

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

func Roots(pinned []ed25519.PublicKey, operator []string) []ed25519.PublicKey

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.

func SignPackFile

func SignPackFile(data []byte, priv ed25519.PrivateKey, keyID string) ([]byte, error)

SignPackFile signs the manifest of an encoded pack and returns the pack with publisher_key_id and manifest_signature set.

func TrustRoot

func TrustRoot(b64 string, pinned []ed25519.PublicKey) (ed25519.PublicKey, error)

TrustRoot parses a base64 root key and accepts it only when it is one of the pinned roots, or when this is an addons_dev build.

func VerifyPackFile

func VerifyPackFile(data []byte, keys []plugin.TrustedKey, idx *Index) (Manifest, FileSigner, error)

VerifyPackFile runs the checks an offline install does before it writes anything: signature, trusted key, key-to-publisher binding, the size cap and the per-file hash and count checks of InstallFile. Revocation applies only through idx. A pack with no signature fails closed.

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 NewClient

func NewClient(dataDir string) *Client

NewClient keeps the last good index under dataDir/addons-index.

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

func (c *Client) Cached(roots []ed25519.PublicKey, lim Limits) (Index, error)

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.

func (Index) IsRevoked

func (idx Index) IsRevoked(id, version, manifestSHA string) (Revocation, bool)

IsRevoked reports whether the index disables this version or manifest hash.

func (Index) Verify

func (idx Index) Verify(e IndexEntry, manifestRaw []byte) (Verified, error)

Verify checks manifestRaw against an index entry: hash, revocation, a publisher key the index vouches for, and the detached signature. Fails closed.

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

type IndexState struct {
	Sequence   int64
	PayloadSHA string
}

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

func ParseManifest(raw []byte, lim Limits) (Manifest, error)

ParseManifest decodes and validates addon.yaml. Unknown fields are an error so a typo can never silently drop a restriction.

func (*Manifest) FileByPath

func (m *Manifest) FileByPath(p string) (File, bool)

FileByPath returns the declared file.

func (*Manifest) VerifyFile

func (m *Manifest) VerifyFile(f File, data []byte) error

VerifyFile checks bytes against the declared size and hash, then the content rules for the kind. It is the only gate between pack bytes and disk.

type Package

type Package struct {
	ManifestRaw []byte
	Files       map[string][]byte
}

Package is the bytes of one add-on: its manifest and every declared file.

func DecodePack

func DecodePack(data []byte) (Package, error)

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

type StorageError struct {
	Op  string
	Err error
}

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) Is

func (e *StorageError) Is(t error) bool

Is matches ErrStorage.

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

func NewStore(dataDir string, keep int, lim Limits) (*Store, error)

NewStore creates the layout under dataDir. keep is how many versions stay on disk, current included.

func (*Store) Inspect

func (s *Store) Inspect(kind, id string) (Manifest, error)

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

func (s *Store) Install(v Verified, pkg Package) (Installed, error)

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

func (s *Store) InstallIfPresent(v Verified, pkg Package) (Installed, error)

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) List

func (s *Store) List() ([]Installed, error)

List returns every installed add-on, sorted by kind then id.

func (*Store) ReadFile

func (s *Store) ReadFile(kind, id, rel string) ([]byte, error)

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

func (s *Store) Reconfigure(keep int, lim Limits)

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).

func (*Store) Remove

func (s *Store) Remove(kind, id string) error

Remove deletes every version of an add-on.

func (*Store) Rollback

func (s *Store) Rollback(kind, id string) (Installed, error)

Rollback flips current to the newest previous version.

func (*Store) SetIndex

func (s *Store) SetIndex(idx Index)

SetIndex records the last verified index so rollback and reads refuse revoked versions.

func (*Store) Sweep

func (s *Store) Sweep(idx Index) ([]Swept, error)

Sweep records idx and disables every installed version it revokes: current falls back to the newest unrevoked version, or the add-on is removed.

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.

Jump to

Keyboard shortcuts

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