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 Download(ctx context.Context, client HTTPClient, source, destination string, ...) error
- func ExtractArchive(archive, sha256Hex, destination string, limits Limits) (string, error)
- func ExtractArchiveWithLayout(archive, sha256Hex, destination string, limits Limits, ...) (string, error)
- func NewDownloadClient() *http.Client
- func SafeArchivePath(name string) bool
- func SealExecutable(options ExecutablePackage) (packagekit.Manifest, error)
- func WriteManifest(dir string, m packagekit.Manifest) error
- func WriteManifestAt(dir, manifestPath string, m packagekit.Manifest) error
- type Archive
- type ArchiveOptions
- type Check
- type CopyOptions
- type Entrypoint
- type ExecutablePackage
- type HTTPClient
- 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 Receipt
- type Store
- func (s *Store) Install(source string) (Installed, error)
- func (s *Store) InstallArchive(ctx context.Context, archive Archive, options ArchiveOptions) (Installed, error)
- func (s *Store) InstallWithOptions(source string, options CopyOptions) (Installed, error)
- func (s *Store) Layout() storelayout.Layout
- func (s *Store) List() ([]Installed, error)
- func (s *Store) ListUnverified() ([]Installed, []Check, error)
- func (s *Store) Load(id string) (Installed, error)
- func (s *Store) Receipt(id string) (Receipt, 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 DefaultMaxArchiveBytes int64 = cstore.DefaultMaxArchiveBytes
DefaultMaxArchiveBytes bounds a package archive, as downloaded or as a local file, when Limits does not.
const DefaultMaxArtifactBytes int64 = 4 << 30
DefaultMaxArtifactBytes bounds one artifact when Limits does not.
const ManifestName = storelayout.LegacyManifest
ManifestName is the legacy filename used by New and WriteManifest.
const MaxDownloadRedirects = cstore.MaxDownloadRedirects
MaxDownloadRedirects is how many redirects NewDownloadClient follows.
Variables ¶
var ( ErrExists = errors.New("plugin package already installed") ErrNotFound = errors.New("plugin package not installed") )
Functions ¶
func Download ¶
func Download(ctx context.Context, client HTTPClient, source, destination string, maxBytes int64) error
Download fetches source, an HTTPS URL without user information or a fragment, into the new file destination, which must not exist. It fails when the body is larger than maxBytes (DefaultMaxArchiveBytes when zero) and leaves no file behind on failure. A nil client uses NewDownloadClient. A caller's own client owns its redirect policy; the response is still refused when it did not come from an HTTPS URL. The content is not verified: check it against a pinned digest, as ExtractArchive does, before using it.
func ExtractArchive ¶
ExtractArchive checks the archive file against its pinned SHA-256 and extracts it into destination, which must not exist or must be an empty directory. It returns the package root inside destination: destination itself when ManifestName is at the top of the archive, or the single top-level directory that holds it.
The archive is a zip, a gzip-compressed tar or a plain tar, told apart by content and not by name; anything else is plugin.ErrUnsupported. A zip in the zip64 form and a tar that stops inside a block are refused. Only directories and regular files are extracted; a link, a device or any other special entry fails the extraction, as does a path that is absolute, leaves the destination, repeats another (whatever its case) or is not a SafeArchivePath. limits bounds the work: MaxArchiveBytes the archive file, MaxTreeFiles its entries, MaxTreeBytes the extracted total and MaxArtifactBytes one file. Files are written 0600, or 0700 when the entry has its owner-execute bit; nothing else of an entry's metadata is kept.
An empty sha256 skips the digest check, for an archive whose bytes the caller has already authenticated. Nothing is validated beyond finding the manifest: Install verifies the package. On failure destination may hold a partial tree.
func ExtractArchiveWithLayout ¶
func ExtractArchiveWithLayout(archive, sha256Hex, destination string, limits Limits, layout storelayout.Layout) (string, error)
ExtractArchiveWithLayout locates a package inside an archive using the caller's layout.
func NewDownloadClient ¶
NewDownloadClient returns the client Download uses when it is given none. It follows at most MaxDownloadRedirects redirects, each to an HTTPS URL without user information or a fragment, and removes Authorization, Cookie and Referer from every redirected request. It has no timeout of its own: the context passed to Download bounds the transfer.
func SafeArchivePath ¶
SafeArchivePath reports whether name is a slash-separated relative path that an archive entry may use on every supported platform: no empty, "." or ".." element, no backslash, colon or control character, no element ending in a dot or space, and no Windows device name.
func SealExecutable ¶
func SealExecutable(options ExecutablePackage) (packagekit.Manifest, error)
SealExecutable shares the same package authoring helper in both Go store builds. Installation and verification still use this store's engine route.
func WriteManifest ¶
WriteManifest validates m and writes it as ManifestName in dir, for authors assembling a package directory that Install will copy.
func WriteManifestAt ¶
WriteManifestAt writes the validated document at a package-relative path.
Types ¶
type Archive ¶
type Archive struct {
// Source is a local file path or an HTTPS URL.
Source string
// SHA256 is the required hexadecimal digest of the archive file.
SHA256 string
// ID, when set, is the package the archive must hold.
ID string
}
Archive names one pinned package archive.
type ArchiveOptions ¶
type ArchiveOptions struct {
// Client downloads an HTTPS source. Nil uses NewDownloadClient.
Client HTTPClient
// Copy is the copy policy of the install or upgrade.
Copy CopyOptions
}
ArchiveOptions adjusts InstallArchive. The zero value is ready to use.
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 ¶
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 ¶
Entrypoint is a verified executable selected for one protocol and platform.
type ExecutablePackage ¶
type HTTPClient ¶
HTTPClient is what Download needs from an HTTP client. *http.Client is one.
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 C engine's 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 or layouts differ: the view uses one configuration across 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, and the
// extracted total of one package archive.
MaxTreeBytes int64
// MaxArchiveBytes bounds one package archive file, downloaded or local.
MaxArchiveBytes int64
}
Limits are optional size bounds. Zero values use defaults.
type Receipt ¶
type Receipt struct {
// ID is the package.
ID string `json:"id"`
// Revision is the package revision the install produced.
Revision string `json:"revision"`
// SHA256 is the digest of the archive file, in lower case.
SHA256 string `json:"artifact_sha256"`
}
Receipt records which pinned archive produced an installed package.
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 NewWithLayout ¶
NewWithLayout opens a store using an application-supplied package layout.
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) InstallArchive ¶
func (s *Store) InstallArchive(ctx context.Context, archive Archive, options ArchiveOptions) (Installed, error)
InstallArchive installs the package in a pinned archive, or upgrades the installed package of the same ID to it. The archive is a local file or an HTTPS URL, in any format ExtractArchive reads; it is checked against archive.SHA256 before anything is extracted, extracted under the store's Limits as ExtractArchive describes, and then installed like a directory, so the package is verified against its manifest. An upgrade follows the rules of Upgrade. A package already installed at the archive's revision must have the archive's exact content.
A successful install leaves a Receipt. When the receipt of an installed package names this archive's digest and the package's current revision, and the package still verifies, the call returns it without reading or downloading the archive.
func (*Store) InstallWithOptions ¶
func (s *Store) InstallWithOptions(source string, options CopyOptions) (Installed, error)
InstallWithOptions installs a verified package using explicit copy policy.
func (*Store) Layout ¶
func (s *Store) Layout() storelayout.Layout
Layout returns the package layout used by this store.
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) Receipt ¶
Receipt returns the install receipt of a package, or ErrNotFound when no archive install recorded one. A receipt describes the install that wrote it: compare its Revision with the installed package before relying on it.
func (*Store) Replace ¶
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 ¶
func (s *Store) ReplaceWithOptions(source string, options CopyOptions) (Installed, error)
ReplaceWithOptions is Replace with explicit copy policy.
func (*Store) ResolveEntrypoint ¶
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. The selection is made by the C engine's package store (or by the pure-Go store behind it in a build without the C engine), which applies the rules of engine/plugin/host/store: runtime "argv", the protocol, an entrypoint named for another operating system skipped, and the artifact that names an os and an arch preferred. A failure is the same class of error as there (plugin.ErrDenied, ErrUnsupported, ErrNotFound and so on).
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 ¶
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.