Documentation
¶
Overview ¶
Package chef validates Chef cookbook archives and maintains their native index. A cookbook version is one archive, stored at <name>/<name>-<version>.tar.gz, whose one root folder, named for the cookbook, holds the metadata.json that names the cookbook, its version, its dependencies and its platforms; that manifest, read from the stored bytes, is what indexes the version. The item tree remains the source of truth.
Role ¶
artifacts module, ecosystem layer: the Chef cookbook archive validation and index of the Chef slice. Its Handler plugs into the item service through the format hooks (decision 0032), so every write in a Chef repository reaches it whichever API carried it; the slice's http package (artifacts/ecosystem/chef/http) serves the Supermarket protocol over what it keeps.
Inputs ¶
- Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for chef repositories to Handler, and the work queue, which runs every format's reindex through it; the protocol, which checks names, versions and paths (ValidName, ValidVersion, Path), reads a published or fetched archive (ReadArchive, MaxArchiveBytes), checks an upstream document's keys (UniqueFields) and manifest (ValidateManifest), and decodes the version metadata the index holds (Metadata); and the server's root file chef_item.go, which keeps the generic item routes from serving a remote's cached Supermarket metadata (Serves, IsMetadata).
- Driven: the format hooks' environment (format.Env): its blobs hold the archives, 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.
- Settings: none.
Outputs ¶
- Handler: the hooks that read an archive once before its transaction (Inspect), admit only a valid archive whose identity matches its path (Admit), index a version and set its properties once its archive is stored (Deployed), rebuild the index from the stored archives (Reindex), and keep a remote's cached metadata from leaving its repository by copy or move (GuardTransferSource). Deletes need no hook: the item service prunes a version whose archive is gone.
- The package index: a package per cookbook name, with a version per stored archive, whose metadata is the version's Metadata as JSON and whose file is the archive.
- The chef.name, chef.version and chef.sha256 item properties (PropName, PropVersion, PropSHA256) on each archive.
- The rules the protocol shares: Manifest, Metadata, ValidateManifest, ReadArchive, UniqueFields, ValidName, ValidVersion, Path, ParsePath, IsMetadata, ErrArchive and the archive bounds.
Invariants ¶
- An archive is read to its end, gzip checksum included, within fixed bounds (64 MiB compressed, 128 MiB unpacked, a 1 MiB metadata.json and 4,096 entries) before its manifest is trusted. Its entries are regular files and folders under one root named for the cookbook, with no link and no duplicate, absolute or traversing path, and nothing but zero padding follows the TAR terminator.
- A manifest is one JSON object with no repeated or case-aliased key, its dependencies and platforms included. Its version has two or three numeric parts, and it declares at most 256 dependencies and 256 platforms, each with a bounded constraint; a cookbook never depends on itself.
- A remote's cached Supermarket metadata (api/v1/...) is admitted as the protocol stored it and never leaves its repository by copy or move (403); any other write must be a cookbook archive in a local or federated repository, or one a remote caches.
- The index and the properties are derived from the stored archives, never from a client's claim. The property names are stored, so they stay byte-identical.
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).
- docs/testing/chef.md (connecting Knife and knife-art, the protocol and lifecycle, the archive checks and their bounds, and the evidence).
- JFrog Chef repositories: https://docs.jfrog.com/artifactory/docs/chef-repositories.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 236 (ecosystem/chef), 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/783 and https://github.com/weaveplatform/artifactweave/issues/1045
Status ¶
Implemented P9c, which delivered the plan's P33 group (issues #782 to #788). Moved here in P9d.
Testing ¶
- archive_test.go: whole-archive validation, names, paths and constraints, ambiguous manifests, and folders, padding and oversized manifests.
- handler_test.go: admission against the archive's identity and the repository class, stale or invalid content at deploy and reindex, and the cached metadata's transfer boundary.
- contract_test.go: the format contract suite (formattest), which keeps the index right through deploy, overwrite, delete, copy, move, restore and a remote's cache on every store.
Index ¶
- Constants
- Variables
- func IsMetadata(path string) bool
- func ParsePath(p string) (name, version string, ok bool)
- func Path(name, version string) string
- func Serves(t repo.PackageType) bool
- func UniqueFields(data []byte, known ...string) error
- func ValidName(name string) bool
- func ValidVersion(version string) bool
- func ValidateManifest(m Manifest) bool
- type Handler
- func (Handler) Admit(ctx context.Context, env format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) Deleted(context.Context, format.Env, repo.Config, []model.Item) error
- func (Handler) Deleting(context.Context, format.Env, repo.Config, model.Item) error
- func (Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error
- func (Handler) GuardTransferSource(_ context.Context, _ format.Env, _ repo.Config, it model.Item) error
- func (Handler) Inspect(ctx context.Context, env format.Env, c repo.Config, w format.Write) (any, error)
- func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- type Manifest
- type Metadata
Constants ¶
const ( // MaxArchiveBytes bounds a cookbook archive, published or fetched, at // 64 MiB compressed. MaxArchiveBytes = 64 << 20 // MaxUnpackedBytes bounds an archive's decompressed TAR stream at // 128 MiB, so a small archive cannot expand without limit. MaxUnpackedBytes = 128 << 20 // MaxManifestBytes bounds an archive's metadata.json at 1 MiB. MaxManifestBytes = 1 << 20 // MaxFiles bounds an archive at 4,096 TAR entries, folders included. MaxFiles = 4096 )
const ( // PropName is the property that holds an archive's cookbook name. PropName = "chef.name" // PropVersion is the property that holds an archive's cookbook version. PropVersion = "chef.version" // PropSHA256 is the property that holds an archive's SHA-256. PropSHA256 = "chef.sha256" )
The item properties Deployed and Reindex keep on every stored cookbook archive, from its verified metadata.json. The items keep these names, so they never change.
Variables ¶
var ( // ErrArchive is what ReadArchive, the manifest decoder and UniqueFields // return for every archive, manifest or document they refuse; Deployed // and Reindex wrap it when a stored archive no longer matches its path. ErrArchive = errors.New("chef: invalid cookbook archive") )
Functions ¶
func IsMetadata ¶
IsMetadata reports whether path lies in the tree where a remote caches Supermarket metadata (api/v1/). Those documents list versions outside any one caller's permissions, so only the native protocol, which filters them for the caller, may disclose them.
func ParsePath ¶
ParsePath splits an item path into the cookbook name and version whose archive it holds, and reports ok only when p is exactly Path(name, version) with a valid name and version.
func Path ¶
Path is the item path of the archive of cookbook name at version: <name>/<name>-<version>.tar.gz.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is the Chef package type.
func UniqueFields ¶
UniqueFields checks that data is exactly one JSON object whose keys are unique when compared without case, and that a key naming one of the known fields spells it exactly; it returns ErrArchive otherwise. encoding/json matches field names without case, so a repeated or case-aliased key would let the registry and a native client read different values. The protocol checks upstream Supermarket documents with it too.
func ValidName ¶
ValidName reports whether name is a cookbook name the registry accepts: a letter or digit followed by up to 127 letters, digits, underscores and hyphens.
func ValidVersion ¶
ValidVersion reports whether version is a cookbook version the registry accepts: two or three dot-separated numbers, each at most nine digits with no leading zero.
func ValidateManifest ¶
ValidateManifest reports whether m may enter the native index: a valid name and version, and at most 256 dependencies and 256 platforms, each keyed by a valid name, a dependency never the cookbook itself, with a constraint of at most 128 bytes: an optional operator (=, <, >, <=, >= or ~>) before a two- or three-part version. The client resolves the constraints; the registry bounds only their syntax.
Types ¶
type Handler ¶
Handler is the Chef format's hooks: it admits a cookbook archive only when its metadata.json matches its path, indexes each stored archive as a version of its cookbook, and keeps a remote's cached Supermarket metadata from leaving its repository. 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 and a remote's cached Supermarket metadata (api/v1/...). Any other write must go to a local or federated repository or be a remote's cached content (400), at a cookbook archive path (400), and the archive's metadata.json must name the cookbook and version its path does (409). A remote's copy at any other path is kept as a plain file (format.RemoteCopy). It reuses Inspect's reading when it covers the same content, and reads the stored archive itself otherwise.
func (Handler) Deleted ¶
Deleted does nothing: a version is one archive, so the item service's pruning of versions left without files is all a delete needs.
func (Handler) Deleting ¶
Deleting does nothing: the item service drops a removed archive's version link with it.
func (Handler) Deployed ¶
Deployed indexes a stored cookbook archive: it sets the archive's chef.* properties, creates the cookbook's package when it is new, and links the version to the archive, with its Metadata as the version's metadata. Folders and files at other paths change nothing. An archive whose metadata.json no longer matches its path fails with ErrArchive.
func (Handler) GuardTransferSource ¶
func (Handler) GuardTransferSource( _ context.Context, _ format.Env, _ repo.Config, it model.Item, ) error
GuardTransferSource keeps unfiltered remote catalog metadata behind the native permission-aware API when a caller copies, moves or reuses content.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (any, error)
Inspect reads and validates the stored archive of a write to a .tar.gz path before the write's transaction, and returns its metadata for Admit and Deployed, so an archive is read once per write. A checksum deploy, a remote's copy outside the archive layout and any other file inspect nothing. An invalid archive is refused with 400; an archive that cannot be opened fails the write.
type Manifest ¶
type Manifest struct {
Name string `json:"name"`
Version string `json:"version"`
Maintainer string `json:"maintainer,omitempty"`
Description string `json:"description,omitempty"`
License string `json:"license,omitempty"`
SourceURL string `json:"source_url,omitempty"`
Dependencies map[string]string `json:"dependencies"`
Platforms map[string]string `json:"platforms"`
}
Manifest is the client-visible, validated cookbook identity and dependencies.
func (*Manifest) UnmarshalJSON ¶
UnmarshalJSON refuses duplicate or case-aliased keys before the cookbook identity and dependency maps reach a native client with different JSON rules.
type Metadata ¶
type Metadata struct {
Name string `json:"name"`
Version string `json:"version"`
Manifest Manifest `json:"manifest"`
Path string `json:"path"`
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
}
Metadata is what the package index keeps for a cookbook version, as JSON, and what the protocol answers from: the cookbook's name and version, its validated manifest, and the stored archive's item path, SHA-256 and size. ReadArchive fills all but the path and SHA-256, which Deployed and Reindex take from the stored item.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package chefhttp serves the Chef Supermarket cookbook protocol at /artifactory/api/chef/{repoKey}/api/v1: the catalog and search, cookbook and version records, version archives, publishing by knife-art's raw upload or the Supermarket multipart form, and deletes.
|
Package chefhttp serves the Chef Supermarket cookbook protocol at /artifactory/api/chef/{repoKey}/api/v1: the catalog and search, cookbook and version records, version archives, publishing by knife-art's raw upload or the Supermarket multipart form, and deletes. |