Documentation
¶
Overview ¶
Package imagesrc reads a container image for `vulnesis scan image`: from a registry, from a local docker or podman image store, or from an archive, and unpacks its filesystem so the image's own package databases can be read.
Registry credentials come from the user's own docker configuration and credential helpers (authn.DefaultKeychain), the same ones `docker pull` uses; nothing is stored or sent anywhere else. A signed in run may first ask Vulnetix for a short-lived pull token for the organisation's own registry connection (tenantauth.go); the login behind it never reaches the CLI. A local image is exported with the engine's own `save` command rather than through a daemon client library, which keeps the engine's API out of the CLI.
Index ¶
Constants ¶
const DefaultMaxBytes int64 = 8 << 30
DefaultMaxBytes caps an unpacked image. Images past it are usually build toolchains, and reading them should be a deliberate choice (--max-size).
Variables ¶
var ( // ErrNoConnection means the organisation has not connected this registry host // and repository (or the plan has no registry credentials, or the caller may // not use them): there is nothing to add to the user's own credentials. ErrNoConnection = errors.New("no registry connection for this repository") // ErrNoEphemeral means there is a connection but the registry has no token // service, so no short-lived credential can be issued for it. ErrNoEphemeral = errors.New("the registry cannot issue a short-lived credential") )
Errors a TokenSource reports. Everything else is an unexpected failure.
var ErrTooLarge = errors.New("image is larger than the unpack limit")
ErrTooLarge stops an unpack that would exceed the cap.
Functions ¶
func Flatten ¶
func Flatten(img v1.Image, dir string, opts FlattenOptions) error
Flatten applies the image's layers in order into dir, as a container runtime would: a whiteout (.wh.<name>) deletes what lower layers put there, an opaque whiteout (.wh..wh..opq) empties its directory. Nothing is written outside dir: entries whose path climbs out are refused, and links are recreated, never followed. Device nodes are skipped.
Types ¶
type FlattenOptions ¶
type FlattenOptions struct {
MaxBytes int64
// AfterLayer is called once a layer is applied, with its index and whether
// it wrote a package database; a caller reads the databases then to learn
// which layer installed each package.
AfterLayer func(index int, touchedPackageDB bool) error
}
FlattenOptions control an unpack.
type Image ¶
type Image struct {
Image v1.Image
Meta Meta
Config *v1.ConfigFile
// contains filtered or unexported fields
}
Image is an opened image.
type Meta ¶
type Meta struct {
Ref string
Registry string
Repository string
Tag string
// Digest is the platform manifest digest.
Digest string
// ManifestListDigest is the index the platform manifest was reached through.
ManifestListDigest string
Platform string
ReadFrom Source
}
Meta is what identifies the image that was read.
type Options ¶
type Options struct {
Source Source
// Platform is os/arch[/variant], e.g. linux/amd64; empty means the host's
// linux architecture.
Platform string
// Tenant, when set, is asked for a short-lived pull token before the user's
// own docker credentials are used, for a registry read (tenantauth.go).
Tenant TokenSource
// Warn receives a one line note when the organisation's connection could not
// be used and the run fell back to the user's credentials. It never carries a
// credential. Nil prints nothing.
Warn func(string)
// TempDir holds a local engine's export while it is read.
TempDir string
}
Options select the image.
type Source ¶
type Source string
Source says where to read the image from.
const ( // SourceAuto tries a local engine for a reference it holds, then the registry. SourceAuto Source = "auto" SourceRegistry Source = "registry" SourceDocker Source = "docker" SourcePodman Source = "podman" // SourceArchive reads a `docker save` / `podman save` tarball. SourceArchive Source = "archive" )
type TenantToken ¶
type TenantToken struct {
Token string
// ExpiresAt is when the registry stops accepting it. Zero means unknown, and
// is treated as about to expire.
ExpiresAt time.Time
}
TenantToken is a short-lived pull token for one repository.
type TokenSource ¶
type TokenSource interface {
OCIToken(ctx context.Context, registry, repository string) (*TenantToken, error)
}
TokenSource asks Vulnetix for a pull token for registry (a host with an optional port) and repository (the path in it, such as acme/api).