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 ¶
- func FetchImageConfig(ctx context.Context, repo Repository, manifestBytes []byte) (*ocispecv1.Image, error)
- func IsIndex(mediaType string) bool
- func IsManifest(mediaType string) bool
- func VerifyAlways(sysCtx *types.SystemContext) (*signature.PolicyContext, error)
- func VerifyIfPresent(sysCtx *types.SystemContext) (*signature.PolicyContext, error)
- func VerifyNever(_ *types.SystemContext) (*signature.PolicyContext, error)
- type CachingRepository
- func (s *CachingRepository) CachedDescriptors() []ocispecv1.Descriptor
- func (s *CachingRepository) Close() error
- func (s *CachingRepository) FetchBlob(ctx context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)
- func (s *CachingRepository) FetchManifest(ctx context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)
- func (s *CachingRepository) Resolve(ctx context.Context) (ocispecv1.Descriptor, error)
- type ContainersImageRepository
- func (c *ContainersImageRepository) Close() error
- func (c *ContainersImageRepository) FetchBlob(ctx context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)
- func (c *ContainersImageRepository) FetchManifest(ctx context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)
- func (c *ContainersImageRepository) Resolve(ctx context.Context) (ocispecv1.Descriptor, error)
- type Handler
- type Option
- type Repository
- type VerificationMode
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 ¶
IsIndex returns true if the media type represents an OCI index or Docker manifest list.
func IsManifest ¶
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 (s *CachingRepository) FetchBlob(ctx context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)
func (*CachingRepository) FetchManifest ¶
func (s *CachingRepository) FetchManifest(ctx context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)
func (*CachingRepository) Resolve ¶
func (s *CachingRepository) Resolve(ctx context.Context) (ocispecv1.Descriptor, error)
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 (c *ContainersImageRepository) FetchBlob(ctx context.Context, desc ocispecv1.Descriptor) (io.ReadCloser, error)
func (*ContainersImageRepository) FetchManifest ¶
func (c *ContainersImageRepository) FetchManifest(ctx context.Context, desc ocispecv1.Descriptor) ([]byte, string, error)
func (*ContainersImageRepository) Resolve ¶
func (c *ContainersImageRepository) Resolve(ctx context.Context) (ocispecv1.Descriptor, error)
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. |