image

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 28 Imported by: 2 modules, 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 image implements the unpacker that extracts dependency data from container images. It pulls an image by its OCI reference, or reads it from a docker-archive tarball, squashes its layers into a single filesystem, and routes that filesystem to the SystemPackages unpacker to read the installed-package databases.

Index

Constants

View Source
const SubjectType = "image"

SubjectType is the DecomposableSubject type routed to the image unpacker.

Variables

View Source
var DefaultOptions = Options{}

DefaultOptions is the zero-value configuration used by NewUnpacker.

Functions

This section is empty.

Types

type ExtractionMode

type ExtractionMode int

ExtractionMode selects how the unpacker reads the image filesystem.

const (
	// ModeSquash flattens all layers into a single filesystem, the way a
	// container runtime presents the image, and extracts from the result.
	ModeSquash ExtractionMode = iota

	// ModePerLayer extracts from each layer individually. Not implemented
	// yet.
	ModePerLayer
)

type Options

type Options struct {
	// Mode selects squashed or per-layer extraction. Defaults to ModeSquash.
	Mode ExtractionMode

	// IncludeFiles is passed through to the system decomposers: when set,
	// every file installed by a package is emitted as a Node related to its
	// package.
	IncludeFiles bool

	// SkipArtifacts turns off the scan of the image filesystem for
	// artifacts carrying their own dependency data, such as Go executables.
	// The scan is on by default and runs the artifact decomposers that opt
	// into images (see api.SubjectDefaults).
	SkipArtifacts bool

	// ArtifactDecomposers switches individual artifact decomposers on or
	// off by name ("gobinary"), overriding their own defaults for images.
	// Decomposers without an entry keep their default.
	ArtifactDecomposers map[string]bool

	// ArtifactSkip adds paths the artifact scan leaves out, as
	// gitignore-style patterns relative to the image root ("/opt/vendor/",
	// "*.so"), on top of the system directories skipped by default (see
	// artifact.DefaultSystemSkips).
	ArtifactSkip []string

	// ScanSystemDirs drops the default skip list, so the artifact scan
	// also covers the distribution's own directories (/usr/bin, /usr/lib,
	// ...). ArtifactSkip still applies.
	ScanSystemDirs bool

	// Networking is the network access level handed to the artifact
	// decomposers, which may resolve and enrich what they read from an
	// artifact through package registries. The system decomposers work
	// offline and ignore it.
	Networking api.NetworkLevel

	// RecordLayers adds one structural node per image layer, related to
	// the image through a contains edge. Layers are identified by their
	// diff id — the digest of the uncompressed layer — and carry no
	// packages: the package inventory always reads from the squashed
	// filesystem.
	RecordLayers bool

	// Hooks receives download progress notifications, e.g. to render a
	// progress indicator. Optional.
	Hooks *PullHooks
}

Options configures the image unpacker.

type PullHooks

type PullHooks struct {
	// LayerStart fires when a layer blob starts downloading. total is the
	// compressed size in bytes, or -1 when unknown.
	LayerStart func(digest string, total int64)

	// LayerProgress fires as layer bytes arrive.
	LayerProgress func(digest string, complete, total int64)

	// LayerDone fires when a layer blob has been fully downloaded.
	LayerDone func(digest string)
}

PullHooks receives notifications while image blobs are downloaded. All callbacks are optional; nil hooks (or nil callbacks) are skipped. A text UI can register these to render download progress.

Callbacks may be invoked from concurrent goroutines (layers download in parallel) so implementations must be safe for concurrent use.

type Reference

type Reference struct {
	// Ref is the OCI reference of the image or image index.
	Ref string

	// Archive is the path to a docker-archive tarball (the `docker save`
	// format) holding the image. When set, the image is read from the
	// archive instead of pulled from a registry. Ref, when also set,
	// selects the tagged image in a multi-image archive and provides the
	// reference identity; left empty, the identity comes from the
	// archive's RepoTags, or from the image digest when it has none.
	Archive string
}

Reference is the DecomposableSubject consumed by the image unpacker: a container image addressed by an OCI reference, e.g. "alpine:3.24", "ghcr.io/org/app@sha256:..." or "registry.example.com/app:v1", or held in a docker-archive tarball on disk.

func (*Reference) DecomposableType

func (r *Reference) DecomposableType() string

DecomposableType identifies this subject as a container image, routing it to the image unpacker through the registry.

type Unpacker

type Unpacker struct {
	Options Options
}

Unpacker extracts dependency data from container images. It downloads the image, squashes its layers into the filesystem a running container would see, and reads the installed system packages and the artifacts carrying their own dependency data out of it.

func NewUnpacker

func NewUnpacker() *Unpacker

NewUnpacker returns an image unpacker with the default options.

func (*Unpacker) Extract

func (u *Unpacker) Extract(ctx context.Context, subject api.DecomposableSubject) ([]*sbom.NodeList, error)

Extract pulls the image referenced by the subject — or reads it from the subject's archive — and returns its dependency graph: a node describing the image with the system packages and the artifacts found in its filesystem as descendants.

func (*Unpacker) RegisterDecomposer

func (u *Unpacker) RegisterDecomposer(api.Decomposer)

RegisterDecomposer is a no-op: the image unpacker has no decomposers of its own; it delegates to the unpackers of the subjects it discovers inside the image.

func (*Unpacker) UnregisterDecomposer

func (u *Unpacker) UnregisterDecomposer(api.Decomposer)

UnregisterDecomposer is a no-op; see RegisterDecomposer.

Jump to

Keyboard shortcuts

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