Documentation
¶
Overview ¶
Package vagrant validates Vagrant boxes and indexes their deployment properties. A box is one archive, a TAR, gzip-compressed TAR or ZIP at any .box path, deployed with exactly one box_name, box_provider and box_version property; its root metadata.json, read from the stored bytes, must name the provider box_provider does. Once a box is stored, its provider, architecture and SHA-256 are recorded as derived properties, and the package index is rebuilt from the properties alone.
Role ¶
artifacts module, ecosystem layer: the Vagrant box validation and catalog index of the Vagrant slice. Its Handler plugs into the item service through the format hooks (decision 0032), so every write and property change in a Vagrant repository reaches it whichever API carried it; the slice's http package (artifacts/ecosystem/vagrant/http) serves the box catalog over what it keeps, and the boxes.
Inputs ¶
- Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for vagrant repositories to Handler, and the work queue, which runs every format's reindex through it; and the protocol, which tells a box file's path from a box name (IsBoxPath), checks a box name (ValidName) and reads each box's identity and provider from its properties (Verified).
- Driven: the format hooks' environment (format.Env): its blobs hold the boxes, and its store holds the items, their properties and the package index (artifacts/core/pkgindex). The generic deploy policy (artifacts/ecosystem/generic), which Handler embeds, is the first check Admit applies. A ZIP box is spooled to a temporary file, and its central directory checked (platform/archivecheck) before it is read.
- Settings: none.
Outputs ¶
- Handler: the hooks that read a box once before its transaction (Inspect), admit only a valid box with a valid identity whose provider its metadata.json confirms (Admit), record a stored box's derived properties and rebuild the index (Deployed), refuse a client's change to a derived property (AdmitAnnotation), rebuild the index when an identity property changes (Annotated) or a box is deleted (Deleted), and read every stored box again before rebuilding (Reindex).
- The package index: a package per box_name, with a version per box_version, whose files are the boxes whose recorded properties verify.
- The derived vagrant.provider, vagrant.architecture and vagrant.sha256 item properties on each stored box.
- The rules the protocol shares: Identity, Box, IsBoxPath, ValidName, ValidComponent, Properties, Verified, ReadBox, the identity property names (PropName, PropProvider and PropVersion) and MaxArchiveBytes.
Invariants ¶
- A box is read to its end within fixed bounds (16 GiB compressed, 64 GiB expanded, 100,000 entries, a 64 KiB metadata.json and, for a ZIP, a 32 MiB central directory) without extracting a path or running its Vagrantfile. Its entries are regular files and folders, with no link, special file or duplicate, and no absolute, non-canonical or traversing path or one holding a backslash, NUL or colon. A TAR's extension headers count toward the expanded bound, and nothing but zero padding may follow its end; every ZIP member's checksum is checked.
- Only local and federated repositories take a box, and every write but a checksum deploy must be one (400). A box is stored only at a path IsBoxPath accepts (400), which the protocol serves as a box file. A box_name is <name> or <namespace>/<name>, each part at most 128 letters, digits, dots, underscores and hyphens, starting with a letter or digit; a box_version is a dotted version of at most 128 bytes, with an optional hyphenated pre-release.
- The index is rebuilt from the recorded properties alone, so a property change never decompresses a VM disk; a box whose recorded SHA-256 or provider no longer agrees with it is not indexed. Only the hooks write the derived properties (400 for a client's change), and the items keep every property name, so the names never change.
References ¶
- Decision 0032: docs/research/decisions/0032-package-format-handlers.md (the format hooks); decision 0007: docs/research/decisions/0007-remote-repositories.md (remote repositories, which this format refuses: Admit takes a box only in a local or federated repository).
- docs/testing/vagrant.md (publishing and installing, updates and the lifecycle, the archive checks and their bounds, and the evidence).
- JFrog Vagrant repositories: https://docs.jfrog.com/artifactory/docs/vagrant-repositories.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 236 (ecosystem/vagrant), line 385 (the slice row) and line 997 (the mapping row).
- Plan: docs/implementation/plan.md#p33-automation-and-source-repositories and #p9d-modular-monolith-migration, epic ECO (https://github.com/weaveplatform/artifactweave/issues/943).
- https://github.com/weaveplatform/artifactweave/issues/785 and https://github.com/weaveplatform/artifactweave/issues/1049
Status ¶
Implemented P9c, which delivered the plan's P33 group (issues #782 to #788). Moved here in P9d.
Testing ¶
- box_test.go: TAR, gzip-compressed TAR and ZIP boxes and their identity, unsafe and corrupt input, hidden TAR extension headers, the payload and padding bounds, the entry limit, cancellation and resource failures.
- handler_test.go: admission's boundaries, index failures that propagate, and a reindex that pages and skips boxes whose properties do not verify.
- contract_test.go (external, vagrant_test): the format contract (artifacts/core/formattest), with the box_* properties a client's upload carries.
Index ¶
- Constants
- func IsBoxPath(path string) bool
- func Serves(t repo.PackageType) bool
- func ValidComponent(s string) bool
- func ValidName(s string) bool
- func Verified(p model.Properties, sha string) (Identity, Box, bool)
- type Box
- type Handler
- func (Handler) Admit(ctx context.Context, env format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) AdmitAnnotation(_ context.Context, _ format.Env, _ repo.Config, _ model.Item, ...) error
- func (Handler) Annotated(ctx context.Context, env format.Env, c repo.Config, it model.Item, ...) error
- func (Handler) Deleted(ctx context.Context, env format.Env, c repo.Config, _ []model.Item) error
- func (Handler) Deleting(context.Context, format.Env, repo.Config, model.Item) error
- func (h Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error
- func (Handler) Inspect(ctx context.Context, env format.Env, _ repo.Config, w format.Write) (any, error)
- func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- type Identity
Constants ¶
const ( // MaxArchiveBytes bounds a box at 16 GiB compressed, and its content at // 64 GiB expanded; a box's VM disk is streamed through the checks, never // held in memory. MaxArchiveBytes int64 = 16 << 30 // PropName is the property that names a box, <name> or // <namespace>/<name>. The items keep this name, PropProvider's, // PropVersion's and the derived vagrant.* names below, so they never // change. PropName = "box_name" // PropProvider is the property that names a box's provider, which its // metadata.json must confirm. PropProvider = "box_provider" // PropVersion is the property that holds a box's version. PropVersion = "box_version" )
Variables ¶
This section is empty.
Functions ¶
func IsBoxPath ¶
IsBoxPath reports whether a box may be stored at path: it ends .box. The hooks admit and index a box only at such a path, and the native route serves such a path as a box file, so every box the catalog lists is one that route serves.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is the Vagrant package type.
func ValidComponent ¶
ValidComponent reports whether s is one part of a box name, or a provider or architecture: at most 128 letters, digits, dots, underscores and hyphens, starting with a letter or digit.
func ValidName ¶
ValidName reports whether s is a box name: one valid component, or two joined by a slash (<namespace>/<name>).
func Verified ¶
Verified returns the identity and the recorded box that p gives a stored box whose content has the SHA-256 sha, and reports whether they agree: the identity is valid (Properties), the recorded vagrant.sha256 is sha, the recorded vagrant.provider is box_provider, and any recorded architecture is valid. The index and the catalog take a box only when they do.
Types ¶
type Box ¶
type Box struct {
Provider string `json:"provider"`
Architecture string `json:"architecture,omitempty"`
}
Box is what a box's root metadata.json says of it: the provider it runs on and, optionally, its architecture.
type Handler ¶
Handler is the Vagrant format's hooks: it admits a box only with a valid identity whose provider its metadata.json confirms, records the box's metadata as derived properties, and indexes each box as a version of its box_name from those properties alone. It embeds the generic hooks, so every path is classed as generic content is.
func (Handler) Admit ¶
func (Handler) Admit( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (format.Write, error)
Admit applies the generic deploy policy, wrapping its refusal, then passes a checksum deploy. Any other write must be to a local or federated repository (400), at a .box path (400), with exactly one valid box_name, box_provider and box_version property (400), and of a valid box (400) whose metadata.json names the provider box_provider does (400). It reuses Inspect's reading when it covers the same content, and reads the stored box itself otherwise.
func (Handler) AdmitAnnotation ¶
func (Handler) AdmitAnnotation( _ context.Context, _ format.Env, _ repo.Config, _ model.Item, a format.Annotation, ) error
AdmitAnnotation refuses (400) a property change that sets or removes a derived property (vagrant.provider, vagrant.architecture or vagrant.sha256), which only the hooks write; any other change passes.
func (Handler) Annotated ¶
func (Handler) Annotated( ctx context.Context, env format.Env, c repo.Config, it model.Item, a format.Annotation, ) error
Annotated rebuilds the package index when a change to a stored box sets or removes box_name, box_provider or box_version, which place the box in the index. Folders, a remote's cached items and other changes leave the index as it is.
func (Handler) Deployed ¶
Deployed records a stored box's provider, architecture and SHA-256 as its derived vagrant.* properties, then rebuilds the package index from every box's properties. Folders, a remote's cached items and files at other paths change nothing; a box that no longer reads as valid fails with 400.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, _ repo.Config, w format.Write, ) (any, error)
Inspect reads and validates the stored box of a write to a .box path before the write's transaction, and returns its metadata for Admit and Deployed, so a box is read once per write. A checksum deploy and any other path inspect nothing. An invalid box is refused with 400; one that cannot be opened fails the write.
type Identity ¶
type Identity struct{ Name, Provider, Version string }
Identity is a box's identity as its properties give it: the box_name, box_provider and box_version a client deploys it with.
func Properties ¶
func Properties(p model.Properties) (Identity, bool)
Properties returns the identity p gives a box and reports whether it is complete and valid: exactly one value each for box_name, box_provider and box_version, a valid name (ValidName) and provider (ValidComponent), and a dotted version of at most 128 bytes with an optional hyphenated pre-release.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package vagranthttp serves the native Vagrant routes at Artifactory's prefix, /artifactory/api/vagrant/{repo}, on Vagrant local and federated repositories.
|
Package vagranthttp serves the native Vagrant routes at Artifactory's prefix, /artifactory/api/vagrant/{repo}, on Vagrant local and federated repositories. |