source

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package source resolves image references to the platform images to scan, pulling directly from the registry without a Docker daemon.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPlatform = errors.New("no matching platform")

ErrNoPlatform is returned when the filter matches no platform of an image.

Functions

func ParseAllowPrivate added in v0.2.0

func ParseAllowPrivate(entries []string) ([]string, error)

ParseAllowPrivate checks entries of Network.AllowPrivate.

func Resolve

func Resolve(ctx context.Context, ref string, opts Options) (repository, digest string, err error)

Resolve returns the repository and the digest a reference points to now, without fetching the image: for a tag, the digest of the manifest or index the registry serves, as the kubelet would pull it. If only the lookup fails, the repository is returned with the error.

Types

type Image

type Image struct {
	// Ref is the reference, or for a local input the name of the image in
	// it (the input path if it names none).
	Ref string
	// Input is the path of a local layout or archive, empty for a registry.
	Input string
	// Digest of the manifest or index the reference points to.
	Digest    string
	Platforms []PlatformImage
	// contains filtered or unexported fields
}

Image is a resolved image reference.

func Fetch

func Fetch(ctx context.Context, ref string, opts Options) (*Image, error)

Fetch resolves ref and returns the selected platform images. Layers are fetched lazily when they are read; a layer download that breaks off is resumed with an HTTP Range request.

func (*Image) Close

func (i *Image) Close() error

Close releases a local input once its layers are read; a no-op for registry images.

type Mirror

type Mirror struct {
	Registry string
	Prefix   string
}

Mirror serves the images of Registry under Prefix, e.g. a Harbor proxy cache project for Docker Hub: docker.io=harbor.example.com/dockerhub pulls docker.io/library/nginx from harbor.example.com/dockerhub/library/nginx. A mirror is trusted for tags; digests are verified.

func ParseMirror

func ParseMirror(s string) (Mirror, error)

ParseMirror parses "registry=host[/path]".

func (Mirror) String

func (m Mirror) String() string

type Network added in v0.2.0

type Network struct {
	Restrict bool
	// AllowPrivate lists registries that may use private addresses: a host
	// ("harbor.example.com"), a host with port, a wildcard for subdomains
	// ("*.dkr.ecr.eu-central-1.amazonaws.com", e.g. for VPC endpoints) or a
	// network ("10.0.0.0/8").
	AllowPrivate []string
}

Network limits where meles connects to when it pulls images. In a cluster the references come from anyone who may create a pod (operator) or a run (server); without limits they would let meles send requests to internal services and the cloud metadata endpoint, and show the answers in reports and events (SSRF).

With Restrict, meles

  • never connects to loopback, link-local (169.254.0.0/16 with the cloud metadata endpoint, fe80::/10), unspecified or multicast addresses,
  • connects to private addresses (10/8, 172.16/12, 192.168/16, 100.64/10, fc00::/7) only for hosts and networks in AllowPrivate,
  • speaks plain HTTP only with Options.Insecure,
  • keeps at most a short, printable excerpt of the body of an error response.

The check applies to the resolved address of every connection, so it holds for redirects, token realms and DNS names alike. Hosts of mirrors and of the HTTP(S)_PROXY are allowed. Through a proxy, meles connects only to the proxy; the proxy has to enforce its own rules for the targets.

type Options

type Options struct {
	Platforms PlatformFilter
	Keychain  authn.Keychain
	// Insecure allows plain HTTP registries (for tests and local registries).
	Insecure bool
	// Mirrors are tried in order before the registry itself, which is the
	// fallback if all fail (as containerd does).
	Mirrors []Mirror
	// Logger notes failed mirrors; nil for none.
	Logger *slog.Logger
	// Network restricts the addresses meles connects to (operator, server
	// and Harbor adapter); the zero value restricts nothing (CLI).
	Network Network
	// Input reads the image from a local OCI image layout or docker save
	// archive instead of a registry; the reference then names the image in
	// it, empty for the only one. Close the Image when done.
	Input string
}

Options configure Fetch.

type PlatformFilter

type PlatformFilter struct {
	// contains filtered or unexported fields
}

PlatformFilter selects the platforms of a multi-arch image. The zero value selects all platforms.

func ParsePlatforms

func ParsePlatforms(s string) (PlatformFilter, error)

ParsePlatforms parses "all", "host" or a comma-separated list such as "linux/amd64,linux/arm64".

func (PlatformFilter) Match

func (f PlatformFilter) Match(p v1.Platform) bool

Match reports whether p is selected.

func (PlatformFilter) String

func (f PlatformFilter) String() string

type PlatformImage

type PlatformImage struct {
	Platform string
	Digest   string
	Image    v1.Image
}

PlatformImage is the image of one platform.

Jump to

Keyboard shortcuts

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