Documentation
¶
Overview ¶
Package alpine implements Alpine APK v2 package and index metadata. It checks every package a repository stores or caches, keeps the package index and the alpine.* item properties in step with the packages, and derives the signed APKINDEX.tar.gz of each architecture folder of a local or federated repository.
Role ¶
artifacts module, ecosystem layer: the Alpine APK v2 package, index and signing rules of the Alpine slice. Its Handler plugs into the item service through the format hooks (decision 0032), so every write and delete in an Alpine repository reaches it whichever API carried it, and it rebuilds the indexes as queued work (decision 0033). The Alpine protocol is the http subpackage (alpinehttp), which builds a virtual repository's signed index and selects its packages with this package.
Inputs ¶
- Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for alpine repositories to Handler; the work queue, which runs the index rebuild (KindIndex) through Handler.Work and every format's reindex, the reindex operation's included, through Handler.Reindex; the protocol (alpinehttp), which reads member indexes (DecodeIndex) and writes a virtual repository's (EncodeIndex, SigningKey); and the item kit (artifacts/adapters/http/itemkit), whose remote source request checks an upstream index or package before a remote caches it (ParseIndexPath, DecodeIndex, ParsePath, ReadPackage), and whose item GET sends a remote's downloads through the remote source (Serves).
- Driven: the format hooks' environment (format.Env): its blobs hold the packages; its store holds the items, their properties and the package index (artifacts/core/pkgindex), and lists a repository's files by AQL (artifacts/core/aql); Enqueue asks for the index rebuild when the write commits; Derive and Underive write and remove the indexes; and Keys (access/api) reads the RSA signing pair, whose private key platform/keymaterial decodes. The generic deploy policy (artifacts/ecosystem/generic) is the first check Admit applies.
- Settings: none. A local or federated repository's primaryKeyPairRef, or a virtual repository's keyPair, names its signing pair; a repository that names none publishes unsigned indexes.
Outputs ¶
- Handler: the hooks that read a package before its transaction (Inspect), admit only a valid package at a valid path and refuse a write of an index to a repository that derives its own (Admit), keep the package index and properties in step with deploys and deletes (Deployed, Deleting, Deleted), class the indexes as derived (Classify), make an index read wait for its rebuild (Owed), derive the indexes (WorkKinds, Work) and rebuild the package index (Reindex).
- The package rules: Package, ParsePath and ReadPackage.
- The index rules: ParseIndexPath, DecodeIndex, EncodeIndex, Package.IndexRecord and SigningKey.
- The stored names: KindIndex, IndexName and the Prop* property names.
Invariants ¶
- A package's path is <branch>/<repository>/<architecture>/<name>-<version>.apk, and its .PKGINFO name, version and architecture must match it: a file name alone never gives a package its identity.
- A package's data stream must hash to the datahash its .PKGINFO declares, give every file the SHA-1 apk checks and every entry its parent folder, and stay within fixed bounds (8 MiB of control prefix, 200,000 data entries, 4 GiB expanded).
- An index's C: field is the SHA-1 of the package's compressed control stream, the value apk-tools binds a package with, never a digest of the whole archive.
- A signed index starts with a .SIGN.RSA.<key name> stream that holds an RSA PKCS #1 v1.5 signature over the SHA-1 of the compressed index, as abuild-sign writes it; the key name is the pair's alias (or name) ending .rsa.pub, the file apk looks for in /etc/apk/keys.
- A local or federated repository's indexes are derived from its packages, never uploaded; a remote caches the upstream's after the item kit's remote source request has checked it.
- The index work takes at most 100,000 packages per repository, and an index at most 32 MiB of records.
- KindIndex and the property names are stored, so they stay byte-identical.
References ¶
- Decision 0032: docs/research/decisions/0032-package-format-handlers.md (the format hooks and optional interfaces); decision 0033: docs/research/decisions/0033-persistent-work-queue.md (the index rebuild runs as queued work).
- docs/testing/alpine.md (connecting apk, signing keys and the acceptance evidence).
- JFrog Alpine Linux repositories: https://docs.jfrog.com/artifactory/docs/alpine-linux-repositories.
- The APK v2 package format: https://wiki.alpinelinux.org/wiki/Apk_spec.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 232 (ecosystem/alpine), line 379 (the slice row), line 405 (the protocol's home, ecosystem/alpine/http) and line 997 (the mapping row).
- Plan: docs/implementation/plan.md#p29-linux-package-repositories and #p9d-modular-monolith-migration, epic ECO (https://github.com/weaveplatform/artifactweave/issues/943).
- https://github.com/weaveplatform/artifactweave/issues/757 and https://github.com/weaveplatform/artifactweave/issues/1041
Status ¶
Implemented P9c, which delivered the plan's P29 group (issues #757 to #760). Moved here in P9d.
Testing ¶
- package_test.go and package_validation_test.go: ReadPackage binds an archive to its path and data, and refuses archives apk cannot install, invalid control metadata and unsafe control or data entries.
- decode_validation_test.go and index_test.go: index paths, invalid containers and records, native records kept byte for byte, and EncodeIndex's order, refusals and signature over the exact compressed index.
- handler_validation_test.go: packages kept apart from generated indexes, rebuilds queued only for a hosted repository's own package changes, and missing or invalid stored packages.
- work_validation_test.go: the index work over the current repository, signing through Env.Keys, unusable signing pairs, and derive and removal failures.
- contract_test.go: the format contract suite (artifacts/core/formattest) with KindIndex as the repository's work.
The protocol's native apk evidence is the @alpine acceptance partition (test/acceptance/features/alpine.feature).
Index ¶
- Constants
- func EncodeIndex(entries []Package, description, keyName string, key *rsa.PrivateKey) ([]byte, error)
- func ParseIndexPath(p string) (branch, component, arch string, ok bool)
- func ParsePath(p string) (branch, component, arch, file string, ok bool)
- func Serves(t repo.PackageType) bool
- func SigningKey(ctx context.Context, keys accessapi.Keys, c repo.Config) (string, *rsa.PrivateKey, error)
- type Handler
- func (Handler) Admit(ctx context.Context, env format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) Classify(_ repo.Config, path string) format.Class
- func (Handler) Deleted(ctx context.Context, env format.Env, c repo.Config, removed []model.Item) error
- func (Handler) Deleting(ctx context.Context, env format.Env, c repo.Config, it model.Item) error
- func (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) Owed(c repo.Config, cached bool, path string) []format.WorkRef
- func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- func (Handler) Work(ctx context.Context, env format.Env, work work.WorkItem) error
- func (Handler) WorkKinds() []string
- type Package
Constants ¶
const ( KindIndex = "alpine.index" IndexName = "APKINDEX.tar.gz" PropName = "alpine.name" PropVersion = "alpine.version" PropBranch = "alpine.branch" PropComponent = "alpine.repository" PropArchitecture = "alpine.architecture" )
KindIndex is the work kind that regenerates a local or federated repository's indexes (Work), keyed by the repository. IndexName is the file name of an architecture folder's index, <branch>/<repository>/<architecture>/APKINDEX.tar.gz. PropName, PropVersion, PropBranch, PropComponent and PropArchitecture are the item properties Deployed and Reindex set on every package from its .PKGINFO and path; PropComponent holds the path's second folder, which Alpine calls the repository (main or community) and this package the component. The work queue and the items keep these values, so they never change.
Variables ¶
This section is empty.
Functions ¶
func EncodeIndex ¶
func EncodeIndex( entries []Package, description, keyName string, key *rsa.PrivateKey, ) ([]byte, error)
EncodeIndex writes the APKINDEX.tar.gz stream, optionally prepending a signature stream using the same RSA wire form as abuild-sign. The key name must match the basename placed in the client's /etc/apk/keys directory.
func ParseIndexPath ¶
ParseIndexPath recognizes the branch/component/architecture APKINDEX layout.
func ParsePath ¶
ParsePath accepts the branch/component/architecture/name-version.apk layout documented by Artifactory. It does not infer identity from a filename alone.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is the Alpine package type.
func SigningKey ¶
func SigningKey( ctx context.Context, keys accessapi.Keys, c repo.Config, ) (string, *rsa.PrivateKey, error)
SigningKey selects the repository's configured apk signing pair, read through keys. Virtual repositories use keyPair; local and federated repositories use the primary keypair shared with Artifactory's public-key download endpoint. A repository that names no pair is unsigned: SigningKey returns "", nil, nil without reading keys.
Types ¶
type Handler ¶
Handler is the Alpine format's hooks: it checks every APK v2 package written to an Alpine repository, keeps the package index and alpine.* properties in step with the packages, and derives a local or federated repository's indexes as queued work (KindIndex), signed when the repository names a key pair.
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. No write may put an APKINDEX.tar.gz into a local or federated repository, which derives its own (409). A .apk path must be <branch>/<repository>/<architecture>/<name>-<version>.apk (400), and its package must pass the checks Inspect makes, which Admit repeats unless Inspect already read the same content at the same path. Any other file passes.
func (Handler) Classify ¶
Classify classes every APKINDEX.tar.gz as derived, so replication and federation skip it and each side generates its own, and every other path as unique.
func (Handler) Deleted ¶
func (Handler) Deleted( ctx context.Context, env format.Env, c repo.Config, removed []model.Item, ) error
Deleted re-syncs each removed package's version in the package index, once per name and version, from that version's remaining packages. A version with none left is not its concern: the item service has already pruned it.
func (Handler) Deleting ¶
Deleting queues the index rebuild when a local or federated repository's own package is about to be deleted, so the rebuild is asked for exactly when the delete commits.
func (Handler) Deployed ¶
Deployed sets a stored package's alpine.* properties, brings its version in the package index up to date and, for a local or federated repository's own write, queues the index rebuild. A version's files are every package in the repository whose .PKGINFO gives that name and version, so Deployed reads them all rather than trusting their paths. Folders and other files change nothing.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, _ repo.Config, w format.Write, ) (any, error)
Inspect reads and checks the stored package a write puts at a .apk path, before the write's transaction, and returns its metadata for Admit and Deployed, so a package is read once per write. A checksum deploy and any other path inspect nothing. A write with no content digest, or whose package is invalid or does not match its path, is refused with 400.
func (Handler) Owed ¶
Owed makes a read of a local or federated repository's index wait for its pending rebuild, so a client never reads an index that lags a completed write. A remote's cache owes nothing.
func (Handler) Reindex ¶
Reindex rebuilds repository c's package index from its packages (a remote's from its cache): a package per name and a version per version, whose files are its packages and whose creation time is the oldest file's. It reads every package, failing on the first that is missing or invalid, and restores the alpine.* properties. A local or federated repository's index rebuild is then queued.
type Package ¶
type Package struct {
Name, Version, Architecture string
Branch, Component string
Path string
ArchiveSize int64
InstalledSize int64
Description, URL, License string
Origin, Maintainer, Commit string
BuildTime int64
Depends, Provides, InstallIf []string
ControlSHA1 string
IndexRaw string
}
Package is the native metadata extracted from a validated APK v2 archive.
func DecodeIndex ¶
DecodeIndex validates an apk v2 index and returns the exact package records. Source records remain byte-for-byte intact when a virtual index is rebuilt.
func ReadPackage ¶
ReadPackage validates the bounded control streams and the optional datahash, then extracts only metadata that belongs in APKINDEX. The caller provides the stored blob, so the same check can guard local and remote data.
func (Package) IndexRecord ¶
IndexRecord renders the apk-tools v2 one-letter metadata fields. Values come from bounded .PKGINFO parsing, not from client-supplied index text.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package alpinehttp serves the Alpine protocol over the item kit: each architecture folder's APKINDEX.tar.gz, and a virtual repository's packages.
|
Package alpinehttp serves the Alpine protocol over the item kit: each architecture folder's APKINDEX.tar.gz, and a virtual repository's packages. |