oci

package
v1.235.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package oci implements the oci/registry and oci/layout artifact repositories on the pkg/oci transport boundary.

Both kinds share one implementation core. A backend supplies the content store for an artifact name (an ORAS registry repository, or the single shared OCI layout), how versions are named, and how references are removed; everything else is common: classification of a resolved root, manifest assembly for new Atmos packages, metadata-only inspection, verified reads, guarded publication, name-scoped and collection listing, tag-safe deletion, signature attachments as OCI referrers, host and delegated write locks, and byte-identical graph transfer.

A resolved root is exactly one of four things, and the package never confuses them:

  • an Atmos package, whose config blob is the canonical portable Record;
  • a legacy Atmos plugin release (immutable; never listed as a generic artifact, never overwritten, even with force);
  • a foreign image or artifact manifest;
  • a foreign image index (for example a multi-platform image).

Foreign graphs are inspected without pretending they have an Atmos config blob, are never repackaged, and are transferred with every original manifest, blob, and referrer unchanged, so their resolved digests and signatures survive registry, layout, and second-registry hops.

Signature evidence is stored as Sigstore bundle referrers. A Record signature binds the Record to the addressed manifest's config descriptor; an image signature binds to the original manifest or index digest. Cryptography is delegated to an injected artifact.Verifier; this package neither imports Sigstore libraries nor implements cryptography.

The package registers nothing by itself. A composition root calls Register explicitly, and the go-containerregistry and ORAS types never appear in this package's API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Descriptor

func Descriptor(kind string, opts ...Option) artifact.KindDescriptor

Descriptor returns the static descriptor of an OCI kind: the built-in descriptor refined with the capabilities the registered backend actually provides (delete scope, enumeration, evidence formats of the verifier). It needs no I/O.

func Kinds

func Kinds() []string

Kinds lists the repository kinds this package registers.

func PluginImmutability

func PluginImmutability() service.ImmutabilityPolicy

PluginImmutability returns the service.ImmutabilityPolicy that keeps legacy Atmos plugin releases immutable. Register it with service.WithImmutabilityPolicy. The service consults it for the stored artifact and for the incoming one, so a generic publication or copy can neither overwrite a plugin release nor turn an existing generic artifact into one, with or without force.

A candidate is a plugin release when its original OCI root carries the plugin release annotations, when a layer or config uses the plugin media types, or when an incoming prepared artifact stages a plugin bundle or labels itself with the plugin namespace. The repositories enforce the same rule on their own writes, so this seam and the storage layer agree.

func Register

func Register(opts ...Option) error

Register registers the oci/registry and oci/layout repository kinds in the process-wide registry. A composition root calls it explicitly; nothing registers from init. Options such as WithTransport and WithVerifier apply to every repository the registered factories build.

func RegisterWith

func RegisterWith(registry *artifact.RepositoryRegistry, opts ...Option) error

RegisterWith registers the OCI kinds in the given registry. A kind that is already registered is an error, so double registration is caught instead of silently replaced.

Types

type ImportOptions

type ImportOptions struct {
	// Select picks the root inside the payload by its reference name or digest. Empty requires
	// the payload to hold exactly one root.
	Select string

	// ExpectedPrior is the reference the caller observed at the destination; nil means none.
	ExpectedPrior *artifact.PinnedReference

	// Force permits replacing a conflicting reference. It never replaces a plugin release.
	Force bool

	// Lock is the writer lock already held by the caller.
	Lock artifact.LockHandle
}

ImportOptions control importing a graph from an OCI layout payload.

type Option

type Option func(*settings)

Option configures an OCI repository or its registration.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency bounds how many manifests listing inspects at once. The default is artifact.DefaultConcurrency.

func WithLockDir

func WithLockDir(dir string) Option

WithLockDir sets the directory holding the host-scope write guards. The default is a directory below the user's data directory, so the guard is shared by every process on the host.

func WithOwner

func WithOwner(owner string) Option

WithOwner sets the owner recorded in lock requests when the caller does not supply one. The default is "<hostname>:<pid>".

func WithPageSize

func WithPageSize(n int) Option

WithPageSize sets the list page size used when a query does not choose one.

func WithTransport

func WithTransport(transport atmosoci.Transport) Option

WithTransport supplies the registry transport used by every oci/registry repository the registered factory constructs. Tests inject an in-process registry client; a transport that also implements atmosoci.RegistryCatalog enables collection enumeration.

func WithTransportFactory

func WithTransportFactory(factory TransportFactory) Option

WithTransportFactory supplies a per-repository transport factory that binds the repository's identity. It takes precedence over WithTransport. A repository that configures an identity requires a factory, so an identity is never silently ignored.

func WithVerifier

func WithVerifier(verifier artifact.Verifier) Option

WithVerifier injects the cryptographic verifier used by Verify. The formats it understands are the evidence formats the repository advertises. Without a verifier the repository stores no evidence, and Sign and Verify return unsupported-capability errors.

func WithoutCollectionEnumeration

func WithoutCollectionEnumeration() Option

WithoutCollectionEnumeration stops an oci/registry repository from advertising or attempting registry-wide repository enumeration, for registries known not to support it.

type Package

type Package struct {
	// Config describes the config blob. Its digest is the Record digest.
	Config ocispec.Descriptor

	// ConfigBytes are the canonical Record bytes.
	ConfigBytes []byte

	// Manifest describes the manifest.
	Manifest ocispec.Descriptor

	// ManifestBytes are the exact manifest bytes whose digest is Manifest.Digest.
	ManifestBytes []byte

	// Blobs are the payload and document blobs in manifest layer order.
	Blobs []artifact.StagedBlob
}

Package is an assembled Atmos package ready to upload: the config blob (the canonical Record bytes), the deterministic manifest, and the staged blobs in manifest layer order.

func Assemble

func Assemble(prepared *artifact.PreparedArtifact) (*Package, error)

Assemble builds the manifest of a new Atmos package from a prepared artifact.

The config blob is the canonical Record, byte for byte what local and S3 records store. The layers are the single archive payload followed by the README and CHANGELOG documents as separate Markdown blobs with explicit roles and titles. The creation time is the Record's captured time, so assembly reads no clock and identical input yields an identical manifest digest.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository is an OCI-backed artifact.Repository. One implementation serves both oci/registry and oci/layout; the backend decides where content lives and how versions are named.

A Repository is safe for concurrent use. It keeps two small in-memory tables, both derived only from verified content: a bounded cache of manifests and configs addressed by name and digest, and the roots it has resolved, which locate the manifest a signature subject is attached to.

func NewRepository

func NewRepository(ctx context.Context, alias string, cfg *schema.ArtifactRepositoryConfig, opts ...Option) (*Repository, error)

NewRepository builds one repository from its configuration without going through a registry.

func (*Repository) CanCopyFrom

func (r *Repository) CanCopyFrom(source artifact.Repository) bool

CanCopyFrom implements artifact.Copier. Another OCI repository from this package can always transfer a graph natively: every original manifest, blob, and referrer is copied byte for byte, so the resolved digest and the signatures survive.

func (*Repository) Capabilities

func (r *Repository) Capabilities() artifact.Capabilities

Capabilities implements artifact.Repository. It needs no network access. Repository-scope locks are not advertised here: an OCI tag is not a distributed lease, so that scope exists only through a configured lock delegate, which the service adds when it describes the repository.

func (*Repository) CopyFrom

CopyFrom implements artifact.Copier. It copies the pinned root with its whole graph and every referrer (signatures, SBOMs) to this repository through the policy-aware transport. Nothing is repackaged: an Atmos package and a foreign image alike keep their original raw manifests, so the destination resolves to the source digest. A registry that cannot list or copy the required referrers fails the copy; signature material is never silently omitted.

func (*Repository) Delete

Delete implements artifact.Repository with tag-safe semantics.

Deleting by tag inspects every other tag of the name that resolves to the same digest. A registry can only delete a manifest, which removes all of its tags, so a tag delete that would also remove a sibling reference is rejected as an unsupported tag-only deletion. A layout removes just the named reference. Deleting by digest is explicitly manifest-scoped and reports every reference that stopped resolving. Blobs are never deleted directly, because other manifests may share them.

func (*Repository) ExportLayout

func (r *Repository) ExportLayout(ctx context.Context, pinned artifact.PinnedReference, directory string) (ocispec.Descriptor, error)

ExportLayout exports the pinned graph, with every referrer, to a standard OCI image layout directory holding exactly one root, so it can travel as a payload and be imported again with its digest intact. It returns the exported root descriptor.

func (*Repository) ImportLayout

func (r *Repository) ImportLayout(ctx context.Context, directory string, ref artifact.Ref, options ImportOptions) (*artifact.PublishResult, error)

ImportLayout imports an OCI content graph from a standard OCI image layout directory (the carrier used for plugin releases, offline media, and graph payloads) under ref. The layout is opened read-only. The original manifests, blobs, and referrers are copied unchanged, so the imported root keeps its digest and signatures; a foreign graph is never repackaged.

func (*Repository) Inspect

Inspect implements artifact.Repository. It reads the manifest and, for an Atmos package, the Record config blob; it never fetches a payload layer or a document. A foreign image, index, or plugin release is described from its own manifest without pretending it has an Atmos config blob: the inspection has no Record and carries the original root descriptor with its annotations and artifact type, which is what immutability and signing decisions need.

func (*Repository) List

List implements artifact.Repository. A name-scoped listing enumerates the name's tags and works without any catalog. A collection listing uses the registry's repository listing scoped to the collection prefix, or the layout's references; a registry that cannot enumerate returns an unsupported-capability error that says direct named operations still work, never an empty page. Only Atmos packages are listed: legacy plugin releases and foreign images that share the prefix are never presented as generic artifacts.

func (*Repository) Lock

Lock implements artifact.LockProvider.

By default it is a host-scope guard: an OS file lock keyed by registry, repository, and tag in the user data directory (or the configured lock directory). That excludes other Atmos processes on this host only; a registry tag is not a distributed lease, so repository scope is never claimed here. When the repository configures `locking.repository`, every lock is taken from that delegate, which keeps its own identity and storage root and reports its own scope. A canceled wait leaks no ownership, and no lock is ever stolen.

func (*Repository) LockNamespace

func (r *Repository) LockNamespace() string

LockNamespace implements artifact.LockNamespacer.

func (*Repository) OpenDocument

OpenDocument implements artifact.Repository. It reads the manifest and the Record, then streams only the selected document layer, bounded and verified against the Record. The payload is never downloaded. A foreign object has no documents.

func (*Repository) Pin

Pin implements artifact.Repository. It returns the immutable reference for consumer lockfiles: the original manifest or index digest, plus the portable Record and content digests bound through the config descriptor and the evidence descriptors known now. It takes no lock and grants no trust.

func (*Repository) Publish

Publish implements artifact.Repository. The service has already compared intent and applied the force policy under the writer lock; this method still enforces the reference contract itself: the expected prior reference must still be current, replacement needs force, and a legacy plugin release is never replaced, with or without force.

OCI tags have no compare-and-swap, so the prior reference is checked immediately before the tag moves, and the repository does not advertise conditional updates. A write whose outcome is unknown is reconciled by resolving the tag; there are no blind retries.

func (*Repository) Read

Read implements artifact.Repository. An Atmos package yields verified payload and document streams; a foreign graph or plugin release yields a graph source rooted at the original manifest or index, so it can be transferred byte-identically. A pinned platform narrows the graph to that child below the unchanged original index.

func (*Repository) ReadEvidence

func (r *Repository) ReadEvidence(ctx context.Context, pinned *artifact.PinnedReference) ([]artifact.EvidenceBlob, error)

ReadEvidence implements artifact.EvidenceReader: it exports the bundle referrers bound to the pinned artifact, so a copy through the shared staging path can carry them along. The evidence is untrusted until verified.

func (*Repository) Resolve

Resolve implements artifact.Repository. A tag or digest becomes a pinned handle; every later read uses the resolved digest, so a tag moved mid-operation is never followed. A digest reference selects the OCI manifest or index digest; for an Atmos package the portable Record digest, which is the config descriptor digest, also names the artifact.

func (*Repository) SelectPlatform

SelectPlatform narrows a pinned multi-platform image to one platform without rewriting its root. The returned reference keeps the original index digest and evidence, so the original signature keeps covering what is verified and transferred; reading it yields a graph whose root is the unchanged index and whose only child is the selected platform. A reconstructed single-platform index would have a new digest and no signature, and this never builds one.

func (*Repository) Sign

Sign implements artifact.Repository. The signer produces evidence over the subject; the repository stores it as a referrer of the addressed manifest. A Record signature is bound to the manifest's config descriptor; an image or plugin signature is bound to the original manifest or index digest. Signing never changes the Record, the manifest, or any tag.

func (*Repository) Verify

Verify implements artifact.Repository. It collects the subject's bundle referrers, drops any not bound to the subject (reporting them), and hands the rest to the injected verifier together with the policy. Invalid or unrelated attachments cannot override valid matching evidence; malformed ones are bounded and reported. No evidence, an unverifiable format, or an unsatisfied policy is a failure.

func (*Repository) WriteEvidence

WriteEvidence implements artifact.EvidenceWriter: it imports evidence for an artifact this repository already holds. Each item must bind to the pinned manifest (a Record signature to its config descriptor, an image signature to its digest) and carry bytes matching their descriptor. Evidence the manifest already carries is not duplicated.

type TransportFactory

type TransportFactory func(ctx context.Context, alias string, cfg *schema.ArtifactRepositoryConfig, resolve artifact.IdentityResolver) (atmosoci.Transport, error)

TransportFactory builds the registry transport of one configured repository. The resolve argument is the composition root's identity resolver; an implementation binds the repository's identity to the transport it returns, so the credentials of one repository are never presented for another. Credentials are resolved when a repository is opened for an operation, not here.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL