Documentation
¶
Overview ¶
Package store installs, upgrades, lists and removes reviewed packages under a caller-supplied root. A package is a packagekit manifest plus the artifacts it lists. The store has no default location and no product vocabulary; it copies and re-verifies content but never launches it or grants authority. Concurrent mutation from several processes is the caller's responsibility.
Index ¶
- Constants
- Variables
- func SealExecutable(options ExecutablePackage) (packagekit.Manifest, error)
- func WriteManifest(dir string, m packagekit.Manifest) error
- type Check
- type CopyOptions
- type Entrypoint
- type ExecutablePackage
- type Installed
- func (p Installed) ArtifactPath(name string) (string, error)
- func (p Installed) Digest() (string, error)
- func (p Installed) Executable() (string, error)
- func (p Installed) IsExecutable() bool
- func (p Installed) Name() string
- func (p Installed) Supports(name, version string) bool
- func (p Installed) Verify() error
- func (p Installed) Version() string
- type Layered
- type Limits
- type Store
- func (s *Store) Install(source string) (Installed, error)
- func (s *Store) InstallWithOptions(source string, options CopyOptions) (Installed, error)
- func (s *Store) List() ([]Installed, error)
- func (s *Store) ListUnverified() ([]Installed, []Check, error)
- func (s *Store) Load(id string) (Installed, error)
- func (s *Store) Remove(id string) error
- func (s *Store) Replace(source string) (Installed, error)
- func (s *Store) ReplaceWithOptions(source string, options CopyOptions) (Installed, error)
- func (s *Store) ResolveEntrypoint(id, contract, version, protocol, reviewedDigest string) (Entrypoint, error)
- func (s *Store) Root() string
- func (s *Store) Upgrade(source string) (Installed, error)
- func (s *Store) UpgradeWithOptions(source string, options CopyOptions) (Installed, error)
- func (s *Store) Verify() ([]Check, error)
Constants ¶
const ( // DefaultMaxTreeFiles bounds the files in one tree artifact. DefaultMaxTreeFiles = 250000 // DefaultMaxTreeBytes bounds the total size of one tree artifact. DefaultMaxTreeBytes int64 = 16 << 30 )
Defaults for Limits.
const DefaultMaxArtifactBytes int64 = 4 << 30
DefaultMaxArtifactBytes bounds one artifact when Limits does not.
const ManifestName = "plugin.json"
ManifestName is the manifest file at the top of every package directory: the ext.package/v1 document. A package.json at the top level is an ordinary file, which a package may ship as an artifact (an npm package, say) like any other; only this name is read as the manifest. An artifact may not use this path, whatever its case, and a tree may hold a file of this name of its own.
Variables ¶
var ( ErrExists = errors.New("plugin package already installed") ErrNotFound = errors.New("plugin package not installed") )
Functions ¶
func SealExecutable ¶ added in v0.2.0
func SealExecutable(options ExecutablePackage) (packagekit.Manifest, error)
SealExecutable publishes a package template without installing or trusting it. The caller chooses the protocol and descriptor; no product is selected.
func WriteManifest ¶
WriteManifest validates m and writes it as ManifestName in dir, for authors assembling a package directory that Install will copy.
Types ¶
type Check ¶
type Check struct {
// ID is the package ID, or the directory name when it is not a valid one.
ID string
// Directory is where the entry lives.
Directory string
// Err is why the entry failed: a manifest that does not decode or validate,
// an artifact that is missing, changed, linked or oversized, an unlisted
// file, a directory that does not match its manifest, or an entry that is
// not a package directory. Nil means the package verified.
Err error
}
Check is the verification result for one entry under a store root.
type CopyOptions ¶ added in v0.2.0
type CopyOptions struct {
PreserveExecutableArtifacts bool
}
CopyOptions lets a consumer retain executable helper artifacts in addition to declared entrypoints. The default install keeps non-entrypoint files non-executable; hosts using this option must authorize those helpers.
type Entrypoint ¶ added in v0.2.0
Entrypoint is a verified executable selected for one protocol and platform.
type ExecutablePackage ¶ added in v0.2.0
type ExecutablePackage struct {
Descriptor plugin.Descriptor
Protocol string
Binary string
OutputDir string
OS string
Arch string
}
ExecutablePackage describes a compiled guest to seal as an ext.package/v1. The descriptor's revision is set to the executable's SHA-256 digest.
type Installed ¶
type Installed struct {
Manifest packagekit.Manifest
Directory string
// contains filtered or unexported fields
}
Installed is one package directory. Methods re-verify content on use.
func (Installed) ArtifactPath ¶
ArtifactPath verifies the named artifact and returns its filesystem path (under Directory): a file, or for a tree artifact its directory. Use it to locate source files, a vendored tree or an executable.
func (Installed) Digest ¶
Digest returns the directory digest of the verified package directory, for consumers that record trust against exact installed content.
func (Installed) Executable ¶
Executable returns the digest-verified path of the first entrypoint's artifact. A package without entrypoints returns plugin.ErrNotFound.
func (Installed) IsExecutable ¶
IsExecutable reports whether the package declares an entrypoint, as opposed to shipping source files the consumer runs under a runtime it owns.
type Layered ¶
type Layered struct {
// contains filtered or unexported fields
}
Layered is a read-only view over several stores. Earlier stores shadow later ones: a package ID is served from the first store that holds it, so a user installation can override a system one. It has no default roots and no product vocabulary; the consumer decides which roots exist and their order, for example a user root followed by a read-only system root.
Layered never writes. Install, upgrade and remove stay on the Store the caller owns, so a system root is never created or modified through it.
Shadowing is by ID only. If the winning copy fails verification, Load and List fail closed instead of falling back to a copy in a later store: a damaged override must not silently turn into a different package. A shadowed copy is never read or verified.
func NewLayered ¶
NewLayered returns a view over stores in priority order, highest first. It needs at least one store and rejects nil entries, repeated roots and stores whose limits differ: the view applies one set of limits to all its roots.
func (*Layered) List ¶
List verifies and returns one package per ID, sorted by ID, each from the highest-priority store that holds it. It fails closed on the first bad package or unexpected entry in any store. A missing root is empty.
func (*Layered) ListUnverified ¶
ListUnverified returns one package's manifest per ID, each from the highest-priority store that holds it, without verifying any content, and reports the packages it could not read separately. See Store.ListUnverified: the result is unverified, content is checked only by Installed.Verify, host.Open and ArtifactPath, and that check is against the manifest read at listing time. Shadowing is as in List and Verify: an ID belongs to the highest-priority store whose directory holds it, even if that copy cannot be read, in which case it is reported rather than replaced by a copy in a later store; a shadowed copy is never read. An entry that is not a package directory is reported in the store it sits in. Results are sorted by ID. The error is only for a root that cannot be read.
func (*Layered) Load ¶
Load returns the verified package from the first store that holds id. ErrNotFound means no store holds it.
func (*Layered) Roots ¶
Roots returns the store roots in priority order. An Installed package's Directory lies under the root of the store that served it.
func (*Layered) Verify ¶
Verify checks what Load and List would serve and reports every failure instead of stopping at the first. A package is checked in the highest-priority store that holds it; shadowed copies are skipped, as in List. An entry that is not a package directory is reported in the store it sits in. It runs nothing and changes nothing. Results are sorted by ID, then by store priority. The error is only for a root that cannot be read.
type Limits ¶
type Limits struct {
// MaxArtifactBytes bounds one file, including each file inside a tree.
MaxArtifactBytes int64
// MaxTreeFiles bounds the files in one tree artifact.
MaxTreeFiles int
// MaxTreeBytes bounds the total bytes of one tree artifact.
MaxTreeBytes int64
}
Limits are optional size bounds. Zero values use defaults.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func New ¶
New returns a store rooted at root. The directory is created on first install. root must be supplied by the consumer.
func (*Store) Install ¶
Install copies the package in source (a directory holding ManifestName and the listed artifacts) into the store. It never replaces an existing package.
func (*Store) InstallWithOptions ¶ added in v0.2.0
func (s *Store) InstallWithOptions(source string, options CopyOptions) (Installed, error)
InstallWithOptions installs a verified package using explicit copy policy.
func (*Store) List ¶
List verifies every installed package and fails closed on the first bad one. A missing root is an empty store. Staging directories (leading ".") are skipped.
func (*Store) ListUnverified ¶
ListUnverified returns every installed package's manifest and directory without verifying any content, and reports the packages it could not read separately. It is for a caller that needs to know what is installed, such as a catalog or a picker, and cannot afford to hash every artifact: it costs one directory listing and one small manifest read per package, whatever the size of the artifacts, where List hashes them all.
THE RESULT IS UNVERIFIED. A returned package has a manifest that decodes and validates and a directory that matches it, nothing more: artifacts may be missing, changed, linked, unlisted or oversized. Content is checked only by Installed.Verify, by host.Open (which verifies before it launches) and by ArtifactPath and Executable (which verify the artifact they return). Do not launch, load or trust anything from this result directly, and do not take its presence as proof that the package would pass List or Load. Name, Version, Supports and IsExecutable read only the manifest and are safe to use.
A returned Installed carries the manifest read at listing time, and Verify, host.Open and ArtifactPath check content against that manifest, not against whatever plugin.json holds later. If the manifest on disk changes after the listing, list again to see the change.
A package that cannot be read does not hide the others. Each one is reported in the second result, in the same form Verify uses: its ID (the directory name when that is not a valid ID), its directory and why, which is a manifest that does not decode or validate, a directory that does not match its manifest, or an entry that is not a package directory. Every Check returned here has a non-nil Err. Both results are sorted by ID. The error is only for a root that cannot be read; a missing root is empty. Staging directories (leading ".") are skipped.
List and Load are unchanged and still fail closed.
func (*Store) Replace ¶ added in v0.2.0
Replace installs or replaces a package of the same ID, including changes to its contracts or assets. Consumers must re-review trust after replacement.
func (*Store) ReplaceWithOptions ¶ added in v0.2.0
func (s *Store) ReplaceWithOptions(source string, options CopyOptions) (Installed, error)
ReplaceWithOptions is Replace with explicit copy policy.
func (*Store) ResolveEntrypoint ¶ added in v0.2.0
func (s *Store) ResolveEntrypoint(id, contract, version, protocol, reviewedDigest string) (Entrypoint, error)
ResolveEntrypoint loads a sealed package, checks its exact contract and caller-reviewed digest, then selects a compatible executable. The caller owns the trust record and supplies its digest; no package is trusted merely because it is installed.
func (*Store) Upgrade ¶
Upgrade replaces an installed package with a new revision of the same ID. Contract names and versions must match; operations may change, so the caller must re-review authority. The previous installation survives any failure.
func (*Store) UpgradeWithOptions ¶ added in v0.2.0
func (s *Store) UpgradeWithOptions(source string, options CopyOptions) (Installed, error)
UpgradeWithOptions upgrades a package using explicit copy policy.
func (*Store) Verify ¶
Verify checks every package under the root and reports each one. Unlike List it does not stop at the first bad package, so a caller can show everything that is wrong. It runs nothing and changes nothing. Results are sorted by ID. The error is only for a root that cannot be read; a missing root is empty.