Documentation
¶
Overview ¶
Package crawl walks a registry over the OCI Distribution API and writes what it finds to the index: repos, then tags, then manifests and image configs. It never pulls layer blobs.
Every fetch is keyed by digest. A manifest already in the index is not fetched again, and a config shared by many images is fetched once, so a re-crawl costs a tag list and a HEAD per tag.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultRedactions = []string{
`(?i)((?:password|passwd|secret|token|api[_-]?key|access[_-]?key|private[_-]?key|credentials?)[A-Za-z0-9_]*\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)`,
`(?i)(://[^/\s:@]+:)([^@\s]+)(@)`,
`(?i)(authorization:\s*(?:bearer|basic)\s+)([^\s"']+)`,
}
DefaultRedactions match secrets that build arguments leave in history commands. Matches are replaced with "***" before anything is stored.
Functions ¶
func Glob ¶ added in v0.2.0
Glob compiles a repo or tag glob to an anchored regular expression. "*" and "?" stay within one path segment, "**" crosses segments, and "[...]" is a character class.
func ParsePlatform ¶ added in v0.2.0
ParsePlatform parses os/arch[/variant].
func RepoName ¶
func RepoName(r name.Repository) string
RepoName returns a repository's full name with the registry host, using docker.io rather than index.docker.io for Docker Hub.
Types ¶
type CallCounter ¶ added in v0.3.0
type CallCounter interface {
Calls() int64
}
CallCounter is a Lister that counts its API calls, so they show in the crawl's request totals.
type Filter ¶ added in v0.2.0
type Filter struct {
// IncludeRepos keeps only repos matching one of these globs. Empty
// keeps every repo.
IncludeRepos []string
// ExcludeRepos drops repos matching one of these globs.
ExcludeRepos []string
// IncludeTags keeps only tags matching one of these globs. Empty keeps
// every tag.
IncludeTags []string
// ExcludeTags drops tags matching one of these globs.
ExcludeTags []string
// Platforms keeps only these platforms, such as linux/amd64 or
// linux/arm64/v8. A platform without a variant matches every variant.
// Empty keeps every platform.
Platforms []string
// PushedSince skips images pushed longer ago than this. It needs a
// registry that reports push times, such as ECR; zero keeps every
// image.
PushedSince time.Duration
}
Filter narrows what a crawl fetches. Every check runs before the requests it would save: repos before their tags are listed, tags before they are resolved, and platforms before their manifests are read.
type Listed ¶ added in v0.2.0
type Listed struct {
Digest string
MediaType string
Tags []string
// PushedAt and LastPulled are zero when unknown.
PushedAt time.Time
LastPulled time.Time
// Subject is the manifest an artifact, such as an SBOM or a
// signature, is attached to; ArtifactType says what it is.
Subject string
ArtifactType string
}
Listed is one manifest a Lister reports.
type Lister ¶ added in v0.2.0
type Lister interface {
// Repos lists every repository, named without the registry host.
Repos(ctx context.Context) ([]string, error)
// Images lists every manifest in a repository, tagged or not.
Images(ctx context.Context, repo string) ([]Listed, error)
}
Lister lists a registry through its own API.
type ManifestFetcher ¶ added in v0.3.0
type ManifestFetcher interface {
// Manifests returns the raw manifests it found, by digest.
Manifests(ctx context.Context, repo string, digests []string) (map[string][]byte, error)
}
ManifestFetcher is a Lister that can also fetch many manifests in one call, as ECR's BatchGetImage does. The crawl uses it for every manifest it needs in a repo, so only image configs are fetched one by one; a manifest it does not return is fetched the usual way.
type Options ¶
type Options struct {
// Registry is the registry host, such as reg.io or localhost:5000.
Registry string
// Repos limits the crawl to these repositories (without the host).
// Empty means every repo the catalog lists.
Repos []string
// External are full refs of bases outside the registry, such as
// docker.io/library/debian:bookworm-slim, fetched so roots resolve.
External []string
// Workers bounds concurrent requests.
Workers int
// RequestsPerSecond limits the request rate; zero means unlimited.
RequestsPerSecond float64
// Insecure allows plain HTTP.
Insecure bool
// Referrers fetches SBOMs, signatures and attestations per image.
Referrers bool
// Provenance reads the SLSA provenance BuildKit attaches to images,
// which names the images a build started from.
Provenance bool
// FetchBases fetches, by digest, the base images provenance names
// that are not indexed, so lineage can walk up to them even when they
// live in another registry or their tag has since moved.
FetchBases bool
// IndexedHosts are the registries the index crawls. A base fetched
// from one of them is not marked external.
IndexedHosts []string
// EnvAllowlist names environment variables whose values are safe to
// store.
EnvAllowlist []string
// Filter narrows which repos, tags, platforms and images are fetched.
Filter Filter
// Lister lists repos and images through the registry's own API, such
// as ECR's, instead of the catalog, tag list and one request per tag.
// It also reports push and pull times.
Lister Lister
// Redactions are regular expressions scrubbed from history commands.
Redactions []string
// BatchSize is how many images are written per transaction.
BatchSize int
// Keychain resolves registry credentials.
Keychain authn.Keychain
// Transport overrides the HTTP transport, for tests.
Transport http.RoundTripper
// UserAgent identifies strata to the registry.
UserAgent string
// Logger receives progress.
Logger *slog.Logger
// Progress, when set, is called with the running totals after each
// repo finishes. Calls come from crawl workers, one at a time.
Progress func(Stats)
// Now returns the current time, for tests.
Now func() time.Time
}
Options configures a crawl.
type Redactor ¶
type Redactor struct {
// contains filtered or unexported fields
}
Redactor scrubs secrets from build history.
func NewRedactor ¶
NewRedactor compiles redaction patterns. Each pattern's second capture group, or its whole match if it has none, is replaced with "***".
type Stats ¶
type Stats struct {
// ReposTotal is how many repos this crawl will visit, once known.
ReposTotal int64 `json:"repos_total"`
Repos int64 `json:"repos"`
Skipped int64 `json:"repos_resumed"`
Tags int64 `json:"tags"`
Images int64 `json:"new_images"`
TagMoves int64 `json:"tag_moves"`
Requests int64 `json:"requests"`
Referrers int64 `json:"referrers"`
// BasesFetched counts bases fetched by digest because provenance
// named them; BasesMissing counts those that could not be.
BasesFetched int64 `json:"bases_fetched"`
// ProvenanceBackfilled counts indexes indexed before provenance was
// read whose provenance this crawl read.
ProvenanceBackfilled int64 `json:"provenance_backfilled"`
BasesMissing int64 `json:"bases_missing"`
// Filtered counts what the filter skipped before fetching it.
ReposFiltered int64 `json:"repos_filtered"`
TagsFiltered int64 `json:"tags_filtered"`
ImagesFiltered int64 `json:"images_filtered"`
}
Stats summarize a crawl.
func Crawl ¶
Crawl indexes a registry. A crawl that stops part way is resumed by the next call: repos it finished are skipped.
func (Stats) RequestsPerImage ¶ added in v0.2.0
RequestsPerImage is the registry requests the crawl made for each new image, or zero when it found none.