Documentation
¶
Overview ¶
Package build is the engine behind `patchy build`: it builds the first-party artifacts the patchy config's build: block lists — Dockerfile images and Flux manifest directories — scans them before anything is pushed, publishes them to every configured registry, and signs them with that registry's signing block. It is mirror's sibling for artifacts this project produces rather than vendors, and reuses mirror's seams wholesale: ocireg (pushes and existence probes), scan (archive scanners, the blocking policy, kubescape), allowlist (lint and regeneration), sign (the verify-then-sign Ensurer) and spec (registries, signing, the one scan block).
The flows: an image entry expands its tags and args (failing fast on an unset variable or an invalid tag), lints its allowlist (security/allowlists/<name>.yaml), builds an OCI layout with docker buildx, scans each platform image as a docker archive, and fails with nothing pushed if a blocking finding survives the allowlist. A manifests entry stages its filtered tree, sweeps it with kubescape, and packages it as a Flux OCI artifact (fluxartifact). Publishing never moves a tag: an absent tag is pushed, one already at this digest is skipped, and one at another digest is left alone with a warning. Dry runs build and scan but never contact a registry; UpdateAllowlist rebuilds and rescans to regenerate an allowlist without publishing anything.
The engine never discovers config files and never touches git: the CLI hands it a resolved config, and the calling pipeline owns commits.
Index ¶
- Constants
- func Platforms(archs []string) []string
- type AllowlistResult
- type Builder
- type Config
- type Engine
- func (e *Engine) AllowlistPath(name string) string
- func (e *Engine) Build(ctx context.Context, name string, opts Options) (*Result, error)
- func (e *Engine) Entries() []Entry
- func (e *Engine) Entry(name string) (Entry, error)
- func (e *Engine) SelectRegistries(names []string) ([]spec.Registry, error)
- func (e *Engine) UpdateAllowlist(ctx context.Context, name string) (*AllowlistResult, error)
- type Entry
- type Event
- type Image
- type Manifests
- type Options
- type Record
- type Result
- type ScanReport
- type Spec
Constants ¶
const ( // ActionPushed means the tag was absent and now points at the build. ActionPushed = "pushed" // ActionSkippedCurrent means the tag already points at this digest. ActionSkippedCurrent = "skipped-current" // ActionSkippedTagExists means the tag points at a different digest // and was left alone: tags never move. ActionSkippedTagExists = "skipped-tag-exists" // ActionWouldPush is the dry-run row: no registry was contacted. ActionWouldPush = "would-push" )
Publish actions, one per (registry, tag) record.
const ( // KindImage is a Dockerfile build published as an OCI image (index). KindImage = "image" // KindManifests is a Flux manifests directory published as a Flux OCI // artifact. KindManifests = "manifests" )
The build entry kinds.
const AllowlistDir = "security/allowlists"
AllowlistDir is where image entries' allowlists live, relative to the working directory: <AllowlistDir>/<name>.yaml.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AllowlistResult ¶
type AllowlistResult struct {
Name string `json:"name"`
// Path is the allowlist file, relative to the working directory.
Path string `json:"path,omitempty"`
// Generated is false when the entry was skipped (Note says why).
Generated bool `json:"generated"`
Kept int `json:"kept"`
Renewed []string `json:"renewed,omitempty"`
Added int `json:"added"`
Dropped []string `json:"dropped,omitempty"`
// Note explains a skip.
Note string `json:"note,omitempty"`
// Err carries a per-entry failure in --all summaries.
Err string `json:"error,omitempty"`
}
AllowlistResult reports one --update-allowlists regeneration.
type Builder ¶
Builder builds one image into an OCI layout directory; buildx.Builder in production, a fake writing a layout in tests.
type Config ¶
type Config struct {
// Workdir is the directory relative entry paths and the allowlists
// (security/allowlists/<name>.yaml) resolve against (default: the
// process working directory).
Workdir string
// Global is the resolved registries, signing and scan blocks.
Global *spec.Config
// Spec is the validated build block.
Spec *Spec
// Registry performs OCI operations (nil: ambient keychain).
Registry *ocireg.Client
// Tools runs external binaries — docker, scanners, cosign (nil: the
// real PATH).
Tools scan.ToolRunner
// ArchiveScanners overrides the image scanner roster (nil: built from
// the scan config).
ArchiveScanners []scan.ArchiveScanner
// Verify checks one signature subject (nil: cosign).
Verify func(context.Context, verify.Subject) error
// NewSigner builds a signer for a resolved signing config (nil: the
// real keyless/KMS signer).
NewSigner func(*spec.Signing) (sign.ArtifactSigner, error)
// Builder builds images (nil: docker buildx through Tools).
Builder Builder
// Now is the wall clock: the allowlist expiry horizon and the default
// PATCHY_TIMESTAMP.
Now func() time.Time
// LookupEnv resolves ${VAR} references and SOURCE_DATE_EPOCH (nil:
// os.LookupEnv).
LookupEnv func(string) (string, bool)
// OnEvent receives narration (nil discards it).
OnEvent func(Event)
}
Config wires an Engine. The seams mirror mirror.Config's, so the two engines are tested the same way.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine builds, scans, publishes and signs the configured entries.
func (*Engine) AllowlistPath ¶
AllowlistPath is an image entry's allowlist file.
func (*Engine) Build ¶
Build builds, scans and — when the scan passes — publishes and signs one entry. The result is returned even on failure (with whatever was learned: the scan report, the records pushed before an error).
func (*Engine) SelectRegistries ¶
SelectRegistries resolves registry names (nil: all); the CLI validates --registry through it.
func (*Engine) UpdateAllowlist ¶
UpdateAllowlist rebuilds and rescans an image entry and regenerates its security/allowlists/<name>.yaml from the blocking findings, for entries whose resolved scan.allowlist.generate is true. It never pushes or signs and never fails on findings: reviewing the allowlist diff in the PR is where the risk gets accepted.
type Entry ¶
type Entry struct {
Name string
Kind string
Repository string
// Tags are the unexpanded tag templates (entry over build default).
Tags []string
// Scan is the entry's own scan block.
Scan spec.ScanOverride
// Image is set for KindImage, Manifests for KindManifests.
Image *Image
Manifests *Manifests
// Platforms is the normalized platform list (images only).
Platforms []string
}
Entry is one build entry of either kind, resolved against the build-level defaults.
type Event ¶
type Event struct {
// Kind is "note" or "warn".
Kind string `json:"kind"`
Entry string `json:"entry,omitempty"`
Stage string `json:"stage,omitempty"`
// Message is the human-readable line.
Message string `json:"message"`
}
Event narrates engine progress for stderr; results are the data.
type Image ¶
type Image struct {
// Name is the entry's identity: CLI selection, results, and the
// allowlist file security/allowlists/<name>.yaml. Unique across images
// and manifests.
Name string `yaml:"name"`
// Repository is the path published under every registry URL:
// <registry.url>/<repository>:<tag>.
Repository string `yaml:"repository"`
// Dockerfile is relative to the working directory (default
// <context>/Dockerfile).
Dockerfile string `yaml:"dockerfile"`
// Context is the build context, relative to the working directory
// (default ".").
Context string `yaml:"context"`
// Target optionally names the build stage.
Target string `yaml:"target"`
// Architectures overrides the build-level default.
Architectures []string `yaml:"architectures"`
// Args are build args; values expand ${ENV}, keys keep their case.
Args map[string]string `yaml:"args"`
// Tags overrides the build-level default list.
Tags []string `yaml:"tags"`
// Scan overrides the config's scan block for this image.
Scan spec.ScanOverride `yaml:"scan"`
}
Image is one Dockerfile build.
func (*Image) ContextDir ¶
ContextDir resolves an image's build context (default ".").
func (*Image) DockerfilePath ¶
DockerfilePath resolves an image's Dockerfile (default <context>/Dockerfile).
type Manifests ¶
type Manifests struct {
// Name is the entry's identity, unique across images and manifests.
Name string `yaml:"name"`
// Repository is the path published under every registry URL.
Repository string `yaml:"repository"`
// Path is the directory packaged, relative to the working directory.
Path string `yaml:"path"`
// Ignore lists gitignore-syntax patterns excluded from the artifact
// (.git/ is always excluded).
Ignore []string `yaml:"ignore"`
// Source expands into the org.opencontainers.image.source annotation.
Source string `yaml:"source"`
// Revision expands into the org.opencontainers.image.revision
// annotation (Flux's <ref>@sha1:<sha> convention).
Revision string `yaml:"revision"`
// Tags overrides the build-level default list.
Tags []string `yaml:"tags"`
// Scan sets only enabled here: a manifests entry gets the kubescape
// configuration scan, and the image-scan fields are rejected.
Scan spec.ScanOverride `yaml:"scan"`
}
Manifests is one Flux manifests directory, published as-is.
type Options ¶
type Options struct {
// DryRun builds and scans, then reports would-push rows without
// contacting any registry.
DryRun bool
// Registries restricts publishing to the named registries (nil: all).
Registries []string
// Tags replaces the configured tag templates for this run (still
// expanded).
Tags []string
}
Options tunes one Build call.
type Record ¶
type Record struct {
// Registry is the configured registry name.
Registry string `json:"registry"`
// Ref is <registry.url>/<repository>:<tag>.
Ref string `json:"ref"`
// Digest is what the tag points at after the run (for
// skipped-tag-exists, the other digest it already held).
Digest string `json:"digest,omitempty"`
// Action is pushed, skipped-current, skipped-tag-exists or would-push.
Action string `json:"action"`
// Signed reports a signature created this run for the digest.
Signed bool `json:"signed"`
}
Record is one published tag's outcome at one registry.
type Result ¶
type Result struct {
Name string `json:"name"`
Kind string `json:"kind"`
// Digest is the built manifest (or index) digest.
Digest string `json:"digest,omitempty"`
// Tags are the expanded tags.
Tags []string `json:"tags,omitempty"`
Scan *ScanReport `json:"scan,omitempty"`
Records []Record `json:"records,omitempty"`
// Err carries a per-entry failure in --all summaries.
Err string `json:"error,omitempty"`
}
Result is one entry's build outcome.
type ScanReport ¶
type ScanReport struct {
// Skipped names why the vulnerability scan did not run, if it did not.
Skipped string `json:"skipped,omitempty"`
// Scanned lists the platforms scanned (images).
Scanned []string `json:"scanned,omitempty"`
// Blocking are blocking-severity findings the allowlist did not
// suppress; any entry here fails the build before anything is pushed.
Blocking []scan.Finding `json:"blocking,omitempty"`
// Suppressed counts findings the allowlist accepted.
Suppressed int `json:"suppressed"`
// Expired lists allowlist IDs whose expiry has lapsed; they no longer
// suppress anything.
Expired []string `json:"expired,omitempty"`
// ConfigScan reports the kubescape sweep (manifests): "clean",
// "failed", or "skipped: <reason>".
ConfigScan string `json:"configScan,omitempty"`
// ConfigScanFailed blocks under kubescape fail mode.
ConfigScanFailed bool `json:"configScanFailed,omitempty"`
}
ScanReport is one entry's pre-push scan outcome.
func (*ScanReport) Failed ¶
func (r *ScanReport) Failed() bool
Failed reports whether the scan gate blocks the publish.
type Spec ¶
type Spec struct {
// Architectures is the default platform list for image entries
// (amd64 means linux/amd64; os/arch[/variant] is kept verbatim).
Architectures []string `yaml:"architectures"`
// Tags is the default tag template list; an entry's own list replaces
// it. Templates expand ${ENV} references at build time.
Tags []string `yaml:"tags"`
Images []Image `yaml:"images"`
Manifests []Manifests `yaml:"manifests"`
}
Spec is the patchy config's build: block — the first-party artifacts patchy build produces, scans, publishes and signs.
func (*Spec) Validate ¶
Validate checks the build block against the config's scan defaults: names (well-formed, unique across both kinds), repositories, platforms, manifests paths, and each entry's scan block — including the resolved allowlist horizon for images, and the image-only fields a manifests entry may not set.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package buildx drives `docker buildx build` for patchy build: it builds the argv for one image entry and runs it through the same tool-runner seam the scanners use, exporting an OCI layout directory instead of loading into a daemon or pushing — nothing reaches a registry until the scan has passed.
|
Package buildx drives `docker buildx build` for patchy build: it builds the argv for one image entry and runs it through the same tool-runner seam the scanners use, exporting an OCI layout directory instead of loading into a daemon or pushing — nothing reaches a registry until the scan has passed. |
|
Package expand substitutes environment references into build tag, arg and annotation templates.
|
Package expand substitutes environment references into build tag, arg and annotation templates. |
|
Package fluxartifact packages a directory of Flux manifests as a Flux OCI artifact — the shape `flux push artifact` produces and an OCIRepository source consumes: an OCI image manifest whose config is application/vnd.cncf.flux.config.v1+json ({}) and whose single layer is the tree as application/vnd.cncf.flux.content.v1.tar+gzip, annotated with the source URL and revision.
|
Package fluxartifact packages a directory of Flux manifests as a Flux OCI artifact — the shape `flux push artifact` produces and an OCIRepository source consumes: an OCI image manifest whose config is application/vnd.cncf.flux.config.v1+json ({}) and whose single layer is the tree as application/vnd.cncf.flux.content.v1.tar+gzip, annotated with the source URL and revision. |