scan

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package scan is part of the Redoubt control plane. See CLAUDE.md for its role.

Package scan runs Trivy (vulnerabilities) and Syft (SBOM) against a built or pulled image before it is started (E2.5). Both tools run as one-shot hardened job containers (docker.ContainerSpec) against an image tarball exported through the socket-proxy's allow-listed GET /images/get, so neither scanner ever touches the Docker socket.

Index

Constants

View Source
const (
	PolicyOff   = "off"   // no scan, no SBOM
	PolicyWarn  = "warn"  // scan + SBOM, never block
	PolicyBlock = "block" // a CRITICAL finding or a scanner failure fails the deployment
)

Policies.

View Source
const (
	DefaultTrivyImage = "aquasec/trivy:0.70.0"
	DefaultSyftImage  = "anchore/syft:v1.33.0"
	// DefaultNetwork is the dedicated egress network scanners use for vulnerability-DB
	// downloads; apps never join it.
	DefaultNetwork = "redoubt-scan"
)

Pinned scanner images (overridable via REDOUBT_SCAN_TRIVY_IMAGE / REDOUBT_SCAN_SYFT_IMAGE).

Variables

View Source
var ErrBlocked = errors.New("blocked by scan policy")

ErrBlocked wraps a policy block.

Functions

func ValidPolicy

func ValidPolicy(p string) bool

ValidPolicy reports whether p is a known policy.

Types

type Counts

type Counts struct{ Critical, High, Medium, Low, Unknown int }

Counts holds vulnerability counts by severity.

func ParseTrivy

func ParseTrivy(r io.Reader) (Counts, string, error)

ParseTrivy counts findings by severity in a Trivy JSON report stream.

type Fake

type Fake struct {

	// Results maps image ref → counts; unmatched refs use Default.
	Results map[string]Counts
	Default Counts
	// Err, when set, is returned as a scanner failure (policy decides whether it blocks).
	Err error
	// DataDir, when set, makes the fake write SBOM files like the real runner.
	DataDir string
	Calls   []Request
	// contains filtered or unexported fields
}

Fake is a Scanner for tests: it returns canned counts per image (or Result for all when Results is nil), records requests, and optionally writes SBOM files under DataDir/sboms.

func (*Fake) Requests

func (f *Fake) Requests() []Request

Requests returns a copy of the recorded requests.

func (*Fake) Scan

func (f *Fake) Scan(_ context.Context, req Request) (Result, error)

Scan implements Scanner.

type Request

type Request struct {
	ImageRef     string
	App          string
	DeploymentID string
	Policy       string
	// Logs receives one-line progress and the final summary (already redacted upstream).
	Logs io.Writer
}

Request describes one scan.

type Result

type Result struct {
	Critical          int           `json:"critical"`
	High              int           `json:"high"`
	Medium            int           `json:"medium"`
	Low               int           `json:"low"`
	Unknown           int           `json:"unknown"`
	Blocked           bool          `json:"blocked"`
	Policy            string        `json:"policy"`
	Skipped           bool          `json:"skipped,omitempty"`
	ScannerError      string        `json:"scanner_error,omitempty"`
	TrivyVersion      string        `json:"trivy_version,omitempty"`
	SBOMSPDXPath      string        `json:"sbom_spdx_path,omitempty"`
	SBOMCycloneDXPath string        `json:"sbom_cyclonedx_path,omitempty"`
	Duration          time.Duration `json:"duration_ns"`
	Summary           string        `json:"summary"`
}

Result summarises a scan; SummaryJSON is what releases.scan_summary_json stores.

func (Result) SummaryJSON

func (r Result) SummaryJSON() string

SummaryJSON renders the result for storage.

type Runner

type Runner struct {
	Docker  *docker.Client
	DataDir string
	// HostDataDir is DataDir as the daemon sees it (see docker.ContainerSpec.HostDataDir).
	HostDataDir string
	TrivyImage  string
	SyftImage   string
	Network     string
	// Timeout bounds each scanner container.
	Timeout time.Duration
	// Test labels the job containers redoubt.test=1.
	Test bool
	// AppArmorProfile for the scanner containers (default docker-default).
	AppArmorProfile string
}

Runner scans with real Trivy/Syft containers.

func NewRunner

func NewRunner(d *docker.Client, dataDir string) *Runner

NewRunner returns a Runner with the pinned defaults.

func (*Runner) Scan

func (r *Runner) Scan(ctx context.Context, req Request) (Result, error)

Scan exports the image, runs Trivy and Syft, applies the policy.

type Scanner

type Scanner interface {
	Scan(ctx context.Context, req Request) (Result, error)
}

Scanner is what the deploy pipeline depends on.

Jump to

Keyboard shortcuts

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