Documentation
¶
Overview ¶
Package imagefetch resolves a container image reference to its manifest digest, discovers the cosign signatures attached to it in the OCI registry, and reconstructs a sigstore-go verification bundle for each signature so the internal/imagetrust verifier can check it against the operator's configured keys or keyless identities.
Two discovery methods are supported, covering essentially every image cosign can sign today:
- Classic tag: cosign stores the signature manifest under the tag "sha256-<hex>.sig" alongside the image. This is the default cosign layout.
- OCI 1.1 referrers: cosign's referrers mode attaches the signature manifest as a referrer of the image digest. The signature manifest content is identical to the classic layout, so one parser handles both.
Each signature manifest layer carries a "simple signing" payload (the layer blob) plus cosign annotations: the raw signature, and — for keyless signatures — the Fulcio certificate and the Rekor inclusion bundle. The signature is computed over sha256(payload), and the payload itself names both the image digest and the source registry/repository (docker-reference) it vouches for. imagefetch enforces both bindings (rejecting any signature whose payload does not reference the exact resolved manifest digest, or whose docker-reference names a different registry/repository than the one being pulled from) before handing the bundle to the verifier. Digest binding alone stops a signature for image B being transplanted onto image A; docker-reference binding additionally stops a genuinely-signed manifest+signature pair — both public, non-secret data — from being copied byte-for-byte into an attacker-controlled repository and re-verifying there.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoSignatures = imagetrust.ErrNoSignatures
ErrNoSignatures is returned when an image resolves successfully but carries no cosign signature that binds to its manifest digest. Callers in enforce mode must treat this as a verification failure (deny).
Functions ¶
func PinnedReference ¶
PinnedReference rewrites imageRef (which may carry a mutable tag) to a digest-pinned reference of the form "registry/repo@sha256:<hex>", using the supplied digest ("sha256:<hex>"). Callers use this after a successful trust verification so the reference forwarded to dockerd resolves to exactly the digest that was verified, closing the verify→pull TOCTOU.
Types ¶
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher discovers and reconstructs image signatures. The zero value is not usable; construct one with NewFetcher.
func NewFetcher ¶
func NewFetcher() *Fetcher
NewFetcher returns a Fetcher with no dial-time address guard (production uses NewGuardedFetcher) that authenticates to registries using the ambient Docker keychain (mounted config.json), falling back to anonymous access for public images.
func NewFetcherWith ¶
NewFetcherWith builds a Fetcher with the given options.
func NewGuardedFetcher ¶
NewGuardedFetcher is NewFetcher with a dial-time address guard. Hosts in allowedHosts ("host" or "host:port", the allowed_registries spelling) may resolve to private addresses; every other destination, including token realms and blob redirects, must resolve to public addresses only. Environment proxies are disabled so the guard checks each actual destination.
func (*Fetcher) FetchCandidates ¶
func (f *Fetcher) FetchCandidates(ctx context.Context, logger *slog.Logger, imageRef string) ([]imagetrust.Candidate, error)
FetchCandidates resolves imageRef to its manifest digest, discovers cosign signatures, and reconstructs a verification bundle for each signature layer whose simple-signing payload binds to that digest. It returns ErrNoSignatures (wrapped) when the image is reachable but unsigned.
type Option ¶
type Option func(*Fetcher)
Option configures a Fetcher. Used by tests to point at an in-memory registry.
func WithNameOptions ¶
WithNameOptions appends name-parsing options (e.g. name.Insecure for plain-HTTP test registries).
func WithRegistryTransport ¶
func WithRegistryTransport(transport http.RoundTripper) Option
WithRegistryTransport replaces the base registry transport. Sockguard wraps it with the same metadata response-size boundary used in production.
func WithRemoteOptions ¶
WithRemoteOptions appends non-transport go-containerregistry options applied to every registry call. Use WithRegistryTransport for a custom transport so Sockguard can retain its metadata response-size boundary around it.