controls

package
v0.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPredicateTracks

func BuildPredicateTracks(ctrls []*Control) map[string][]Track

BuildPredicateTracks is the exported wrapper used by tests to build a PredicateTracks map from a flat slice of controls. Production code uses the loader, which calls the same logic internally.

func SpecVersionOf

func SpecVersionOf(cat Category) string

SpecVersionOf returns the SLSA spec version segment of a core category ("source/1.2/core" > "1.2"). Non-core and unversioned categories rerturn an empty string.

Types

type Catalog

type Catalog struct {
	Controls        map[Category][]*Control
	PredicateTracks map[string][]Track
}

Catalog is a loaded set of controls grouped by category.

PredicateTracks is a predicate-type to track mapping assembled at load time by walking every control's checks. A predicate type may appear under more than one track (because a VSA applicable to both build and source) when that happens, the verifier requires the caller to disambiguate via VerificationOptions.ForceTrack.

This need to be exported for tests can construct synthetic catalogs.

func LoadEmbedded

func LoadEmbedded() (*Catalog, error)

LoadEmbedded loads the controls compiled into the binary.

func (*Catalog) Get

func (c *Catalog) Get(cat Category) []*Control

Get returns the controls registered under the given category.

func (*Catalog) ResolveCore

func (c *Catalog) ResolveCore(track Track, spec string) (Category, string, error)

ResolveCore returns the core category holding the track's controls for the requested SLSA spec version, along with the version it resolved to.

Criteria carry forward across spec releases, so the newest catalog version at or below the requested one wins ("1.2" resolves to the build track's 1.0 catalog, whose criteria are unchanged since).

An empty spec means "use the latest available". Requesting a version older than every catalog the track has returns an error.

func (*Catalog) TracksOf

func (c *Catalog) TracksOf(predicateType string) []Track

TracksOf returns the tracks associated with the given predicate-type URI in this catalog. The empty slice means no loaded control references the predicate type. A slice of length > 1 means the predicate type is declared under multiple tracks and callers must use ForceTrack (or the CLI's --track flag) to disambiguate.

type Category

type Category string

Category groups controls by their location in the embedded catalog tree. The string value matches the relative directory under catalogRoot. Core categories carry the SLSA spec version whose criteria they implement as their middle path segment (track/version/core). buildType categories are unversioned: they hold builder-specific custom controls, not spec-defined criteria.

const (
	// BuildCore groups SLSA spec-defined controls applied to build
	// provenance, as defined since SLSA v1.0 (the criteria are unchanged
	// through v1.2). Prefer ResolveCore over naming the category directly.
	BuildCore Category = "build/1.0/core"

	// BuildType groups custom controls keyed to specific build types.
	BuildType Category = "build/buildType"

	// SourceCore groups SLSA spec-defined controls applied to SLSA source
	// attestations, introduced with the SLSA v1.2 source track. Prefer
	// ResolveCore over naming the category directly.
	SourceCore Category = "source/1.2/core"
)

type Check

type Check struct {
	PredicateType      string   `yaml:"predicateType"`
	Expression         string   `yaml:"expression"`
	Parameters         []string `yaml:"parameters,omitempty"`
	OptionalParameters []string `yaml:"optionalParameters,omitempty"`
	BuildTypes         []string `yaml:"buildTypes,omitempty"`
}

Check binds a CEL expression to a specific in-toto predicate type along with the names of parameters the expression expects to find on `params`.

Parameters lists params the expression requires: evaluating the check without one of them is an error. OptionalParameters lists params the expression needs to run but that the caller may legitimately omit: when one is missing the check is skipped instead of erroring, so the control drops out of the roster without failing verification.

BuildTypes, when set, narrows the check further to only fire when the statement's build provenance buildType is one of the listed URIs (OR-matched, exact). It is intended for controls under the build/buildType catalog category that are specific to one or more builders. Leaving it empty makes the check apply to any buildType whose predicateType matches.

func (*Check) Validate

func (c *Check) Validate() error

Validate checks the check's structural integrity.

type Control

type Control struct {
	ID          string  `yaml:"id"`
	Title       string  `yaml:"title"`
	Description string  `yaml:"description,omitempty"`
	Track       string  `yaml:"track"`
	SLSALevel   int     `yaml:"slsaLevel,omitempty"`
	Checks      []Check `yaml:"checks"`
}

Control models a single verification control: a labelled bundle of CEL checks, each pinned to a specific predicate type.

Track names the SLSA spec track this control targets ("build" or "source"). Every check's predicateType must belong to a predicate type registered under the same track — the load-time cross-validation in the embed loader rejects misclassified controls.

func Load

func Load(path string) ([]*Control, error)

Load reads user-supplied controls from a YAML file or a directory of YAML files. It uses the same multi-document schema as the embedded catalog, validates every control, and returns a flat list (no category grouping — user controls aren't categorised).

func (*Control) Validate

func (c *Control) Validate() error

Validate checks the control's structural integrity. Cross-validation against the eval predicate registry (track ↔ check.predicateType match) lives in the loader so this package can stay leaf-level.

type Track

type Track string

Track names a SLSA spec track. Every control declares the track it targets via its `track` field; the catalog assembles the predicate-type → track mapping from those declarations rather than a hard-coded list.

const (
	TrackBuild  Track = "build"
	TrackSource Track = "source"
)

Jump to

Keyboard shortcuts

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