image

package
v0.0.0-...-41c2ede Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 21 Imported by: 2 modules, 1 package

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 image provides OCI registry access, content caching, and layer extraction for container images. It defines the Repository interface for fetching manifests and blobs, a CachingRepository wrapper that deduplicates and caches fetched content, and a Handler interface for format-specific content identification and unpacking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchImageConfig

func FetchImageConfig(ctx context.Context, repo Repository, manifestBytes []byte) (*ocispecv1.Image, error)

FetchImageConfig fetches and decodes the OCI image config from manifest bytes. It parses manifestBytes to find the config descriptor, fetches the config blob from repo, and decodes it into an ocispecv1.Image.

Returns an error if manifestBytes is not valid JSON, if the config blob cannot be fetched, or if the config blob is not a valid OCI image config.

func IsIndex

func IsIndex(mediaType string) bool

IsIndex returns true if the media type represents an OCI index or Docker manifest list.

func IsManifest

func IsManifest(mediaType string) bool

IsManifest returns true if the media type represents an OCI manifest or Docker schema2 manifest.

func VerifyAlways

func VerifyAlways(sysCtx *types.SystemContext) (*signature.PolicyContext, error)

VerifyAlways loads the signature policy from the types.SystemContext. Construction fails if no policy file is found or parsing fails.

func VerifyIfPresent

func VerifyIfPresent(sysCtx *types.SystemContext) (*signature.PolicyContext, error)

VerifyIfPresent verifies when a policy file is found, skips if no file exists. Fails if the file exists but cannot be parsed.

func VerifyNever

func VerifyNever(_ *types.SystemContext) (*signature.PolicyContext, error)

VerifyNever disables signature verification entirely. All images are accepted regardless of signatures.

Types

type CachingRepository

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

CachingRepository wraps a Repository with in-memory manifest caching and on-disk blob caching. Concurrent fetches for the same digest are deduplicated via singleflight. The cache is stored in a temporary directory that is removed when CachingRepository.Close is called.

func NewCachingRepository

func NewCachingRepository(client Repository) (*CachingRepository, error)

NewCachingRepository wraps client with a local cache. It creates a temporary directory for blob storage; the caller must call CachingRepository.Close to clean it up. Returns an error if the temporary directory cannot be created.

func (*CachingRepository) CachedDescriptors

func (s *CachingRepository) CachedDescriptors() []ocispecv1.Descriptor

CachedDescriptors returns descriptors for all content currently in the cache, including both manifests and blobs. The returned slice is a snapshot; subsequent fetches will not be reflected.

func (*CachingRepository) Close

func (s *CachingRepository) Close() error

func (*CachingRepository) FetchBlob

func (*CachingRepository) FetchManifest

func (s *CachingRepository) FetchManifest(ctx context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)

func (*CachingRepository) Resolve

type ContainersImageRepository

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

ContainersImageRepository implements Repository using the containers/image library. It wraps a types.ImageSource and verifies blob content against the requested descriptor using size-checked readers. When constructed with a signature policy (see WithSignatureVerification), it verifies image signatures on every manifest encountered.

func NewContainersImageRepository

func NewContainersImageRepository(ctx context.Context, imgRef types.ImageReference, srcCtx *types.SystemContext, opts ...Option) (*ContainersImageRepository, error)

NewContainersImageRepository creates a Repository backed by a types.ImageReference. The reference can use any transport supported by the containers/image library (docker, oci-layout, oci-archive, etc.). The caller must call Close on the returned repository to release the underlying image source.

By default, signature verification is enabled (VerifyAlways) and requires a valid policy.json reachable via srcCtx. Use WithSignatureVerification to change this behavior.

Returns an error if the image source cannot be created (e.g. authentication failure, network error, invalid reference) or if policy loading fails.

func (*ContainersImageRepository) Close

func (c *ContainersImageRepository) Close() error

func (*ContainersImageRepository) FetchBlob

func (*ContainersImageRepository) FetchManifest

func (c *ContainersImageRepository) FetchManifest(ctx context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)

func (*ContainersImageRepository) Resolve

type Handler

type Handler interface {
	// Name returns a human-readable identifier used in error messages and logs.
	Name() string

	// Matches inspects the resolved descriptor and manifest to determine
	// whether this handler can unpack the content.
	Matches(ctx context.Context, repo Repository, desc ocispecv1.Descriptor, manifestBytes []byte) (bool, error)

	// Discover walks the image tree and returns the complete set of descriptors
	// that [Handler.Unpack] would need to process. It fetches the minimum
	// necessary to discover the full graph (manifests and configs, not layer
	// blobs) and does not write anything to disk. When used with a
	// [CachingRepository], everything fetched during Discover is cached and
	// reused by Unpack for free.
	Discover(ctx context.Context, repo Repository, desc ocispecv1.Descriptor, manifestBytes []byte) ([]ocispecv1.Descriptor, error)

	// Unpack extracts the image content into dest. Returns an error if
	// unpacking fails (e.g. blob fetch failure, corrupt layer, I/O error).
	// Unpack is _not_ expected to implement semantic validation. It's sole
	// job is to faithfully manifest the OCI content into a filesystem
	// representation.
	Unpack(ctx context.Context, repo Repository, desc ocispecv1.Descriptor, manifestBytes []byte, dest string) error
}

Handler knows how to identify and unpack a specific type of OCI content.

type Option

type Option func(*options)

Option configures a ContainersImageRepository.

func WithSignatureVerification

func WithSignatureVerification(mode VerificationMode) Option

WithSignatureVerification sets the signature verification mode. The default (when not called) is VerifyAlways.

type Repository

type Repository interface {
	// Resolve resolves the repository reference to a content descriptor.
	// The returned descriptor contains the digest, media type, and size
	// of the manifest. Returns an error if the reference cannot be resolved
	// (e.g. network failure, image not found).
	Resolve(ctx context.Context) (ocispecv1.Descriptor, error)

	// FetchManifest fetches a manifest by digest and returns the raw bytes
	// and media type. Returns an error if the digest is not found or cannot
	// be fetched.
	FetchManifest(ctx context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)

	// FetchBlob fetches a blob by digest. The caller must close the returned
	// reader. Returns an error if the blob is not found or cannot be fetched.
	FetchBlob(ctx context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)

	// Close releases any resources held by the repository (network
	// connections, temporary files, etc.).
	Close() error
}

Repository provides read access to an OCI image repository. Implementations handle the transport-specific details of resolving references, fetching manifests, and fetching blobs.

Callers must call Repository.Close when done to release resources.

type VerificationMode

type VerificationMode func(*types.SystemContext) (*signature.PolicyContext, error)

VerificationMode produces a signature.PolicyContext from a types.SystemContext. The built-in modes are VerifyAlways, VerifyNever, VerifyIfPresent, and VerifyWithPolicy.

func VerifyWithPolicy

func VerifyWithPolicy(policy *signature.Policy) VerificationMode

VerifyWithPolicy returns a VerificationMode that uses the provided signature.Policy directly, bypassing the types.SystemContext file lookup.

Directories

Path Synopsis
Package bundle provides support for OLM operator bundle images.
Package bundle provides support for OLM operator bundle images.
Package catalog provides support for OLM catalog images.
Package catalog provides support for OLM catalog images.
internal
testutil
Package testutil provides shared test infrastructure for image handler tests.
Package testutil provides shared test infrastructure for image handler tests.

Jump to

Keyboard shortcuts

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