artifact

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 20 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 artifact implements the unpacker that reads dependency data embedded in built artifacts: executables carrying their build information, archives holding package metadata, and the like. It probes the files of a filesystem for the artifact flavors its decomposers understand and renders each artifact found as a graph rooted at the file.

Index

Constants

View Source
const HeaderSize = 64

HeaderSize is how many leading bytes of a file a decomposer gets to decide whether the file may be one of its artifacts. It covers every executable and archive magic number in common use.

View Source
const SubjectType = "artifact"

SubjectType is the DecomposableSubject type routed to the artifact unpacker.

Variables

View Source
var DefaultOptions = Options{
	Enabled:     true,
	Concurrency: defaultConcurrency,
}

DefaultOptions is the configuration used by NewUnpacker: everything enabled, nothing skipped, essential networking.

View Source
var DefaultSystemSkips = []string{
	"/bin/", "/sbin/", "/lib/", "/lib32/", "/lib64/", "/libx32/",
	"/usr/bin/", "/usr/sbin/", "/usr/lib/", "/usr/lib32/", "/usr/lib64/", "/usr/libx32/",
	"/usr/libexec/", "/usr/share/", "/usr/include/", "/usr/src/",
	"/etc/", "/var/", "/boot/", "/dev/", "/proc/", "/sys/", "/run/",
}

DefaultSystemSkips are the paths left out when scanning a whole system, such as a container image or a system root. They hold the distribution's own binaries and libraries, which belong to the installed packages the system decomposers inventory, and directories that never hold an application's executables. Skipping them keeps the scan to the places an application is installed in (/app, /opt, /usr/local, /home, the root) and keeps system components from being reported as artifacts.

Functions

This section is empty.

Types

type Decomposer

type Decomposer interface {
	api.Decomposer

	// Name returns the short, stable name the decomposer is registered and
	// addressed by, such as "gobinary". Options refer to decomposers by it.
	Name() string

	// Matches reports whether a file may be one of the decomposer's
	// artifacts, judging by its metadata and its first HeaderSize bytes
	// (fewer for a shorter file). It is the cheap filter that keeps the
	// unpacker from reading every file in a filesystem; false positives
	// are fine, ExtractArtifact settles them.
	Matches(info fs.FileInfo, header []byte) bool

	// ExtractArtifact reads the artifact and returns its dependency graph:
	// the package the artifact was built from as the root, with the
	// packages built into it as descendants. The unpacker relates the
	// result to a node it creates for the file itself. Returning
	// (nil, nil) means the file turned out not to be one of the
	// decomposer's artifacts, which is not an error.
	ExtractArtifact(ra io.ReaderAt, path string, opts *api.DecomposerOptions) (*sbom.NodeList, error)
}

Decomposer reads one flavor of artifact. It extends api.Decomposer with a content-based probe: the unpacker filters files through Matches, then asks ExtractArtifact to read the ones that pass.

type File

type File struct {
	Path string
}

File is a Source describing a single artifact on disk, for callers that point at one file: `unpack artifact ./bin/tool`.

func (*File) DecomposableType

func (f *File) DecomposableType() string

DecomposableType identifies this subject as an artifact, routing it to the artifact unpacker through the registry.

func (*File) FileSystem

func (f *File) FileSystem() (fs.FS, error)

FileSystem returns the file's directory as a filesystem.

func (*File) Paths

func (f *File) Paths() []string

Paths returns the file's name, the one entry to probe in its directory.

type Filesystem

type Filesystem struct {
	FS fs.FS

	// Only restricts the scan to these paths, relative to the FS root.
	Only []string
}

Filesystem is a Source wrapping an arbitrary fs.FS: a squashed container image, a directory, an archive. Unpackers that crack such things open use it to route the inner filesystem to the artifact unpacker through the registry. Every regular file is probed unless Only narrows the scan.

func (*Filesystem) DecomposableType

func (f *Filesystem) DecomposableType() string

DecomposableType identifies this subject as an artifact source, routing it to the artifact unpacker through the registry.

func (*Filesystem) FileSystem

func (f *Filesystem) FileSystem() (fs.FS, error)

FileSystem returns the wrapped filesystem.

func (*Filesystem) Paths

func (f *Filesystem) Paths() []string

Paths returns the paths the scan is restricted to, or nil for all files.

type Options

type Options struct {
	// Enabled is the master switch. When false no artifact is probed,
	// whatever the per-decomposer settings say.
	Enabled bool

	// Decomposers switches individual decomposers on or off by name. A
	// decomposer with no entry runs. DefaultsFor fills it from the
	// decomposers' own defaults for a given parent subject.
	Decomposers map[string]bool

	// Skip lists paths the scan leaves out, as gitignore-style patterns
	// relative to the source root: "/usr/lib/" prunes that directory tree,
	// "vendor/" prunes any directory of that name, "*.so" skips matching
	// files anywhere, and "!" negates. A pruned directory is never entered,
	// so as in git a negation cannot re-include anything below it. Paths
	// named explicitly (a File subject, a Filesystem restricted with Only)
	// are probed regardless.
	// DefaultsFor fills it with DefaultSystemSkips under parents that are
	// whole systems.
	Skip []string

	// Networking controls how much network access decomposers are allowed
	// when enriching what they read from the artifact.
	Networking api.NetworkLevel

	// IncludeBuild includes the dependencies that built an artifact, when
	// the artifact records them, related through buildDependency edges.
	IncludeBuild bool

	// Concurrency is how many files are probed at once.
	Concurrency int
}

Options configures the artifact unpacker.

type Source

type Source interface {
	api.DecomposableSubject

	// FileSystem returns the filesystem the artifacts are read from.
	FileSystem() (fs.FS, error)

	// Paths lists the files to probe, relative to the filesystem root. Nil
	// means every regular file in the filesystem.
	Paths() []string
}

Source is the DecomposableSubject consumed by the artifact unpacker: a filesystem holding artifacts, or a selection of files in one.

type Unpacker

type Unpacker struct {
	Options Options
	// contains filtered or unexported fields
}

Unpacker reads dependency data out of built artifacts. It probes the files of its subject with the registered decomposers and returns one NodeList per artifact found, each rooted at a node describing the file.

func NewUnpacker

func NewUnpacker() *Unpacker

NewUnpacker returns an artifact unpacker with the default options and the built-in artifact decomposers.

func (*Unpacker) DefaultsFor

func (u *Unpacker) DefaultsFor(parentSubjectType string) Options

DefaultsFor returns the option set the unpacker should run with under a parent subject of the given type, such as "image": DefaultOptions with each registered decomposer switched on or off according to its own defaults, and, under a parent that is a whole system, DefaultSystemSkips as the skip list. Decomposers that implement api.SubjectDefaults run only under the parents they list; the rest run everywhere. Parents call this, adjust the result to what their caller asked for, and set it as the unpacker's Options.

func (*Unpacker) Extract

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

Extract probes the files of the subject and returns one NodeList per artifact found. Each list is rooted at a file node carrying the artifact's path and SHA-256, related through a generatedFrom edge to the package graph the decomposer read out of it. A file no decomposer claims is skipped; an error reading one artifact does not stop the others and is returned, joined with the rest, alongside the lists that succeeded.

func (*Unpacker) RegisterDecomposer

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

RegisterDecomposer adds a decomposer to the unpacker, keyed by its name. The decomposer must implement the artifact Decomposer interface; others are ignored, since the Unpacker interface leaves no way to report them.

func (*Unpacker) UnregisterDecomposer

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

UnregisterDecomposer removes a decomposer from the unpacker.

Directories

Path Synopsis
Package gobinary implements the artifact decomposer for Go executables.
Package gobinary implements the artifact decomposer for Go executables.
internal
executable
Package executable holds what the artifact decomposers for compiled programs share: recognizing an executable by its magic number and reading a named section out of it, whatever its object format.
Package executable holds what the artifact decomposers for compiled programs share: recognizing an executable by its magic number and reading a named section out of it, whatever its object format.
exetest
Package exetest synthesizes minimal executables for tests: just enough ELF, PE or Mach-O structure for the standard library's debug packages to parse them and find a named section with the given contents.
Package exetest synthesizes minimal executables for tests: just enough ELF, PE or Mach-O structure for the standard library's debug packages to parse them and find a named section with the given contents.
Package rustbinary implements the artifact decomposer for Rust executables built with cargo-auditable.
Package rustbinary implements the artifact decomposer for Rust executables built with cargo-auditable.

Jump to

Keyboard shortcuts

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