verifier

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 39 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultVerificationOptions = VerificationOptions{
	EvaluatorOptions: options.Default,

	DefaultEvaluator: cel.Class,

	ResultsAttestationPath: "results.intoto.json",

	GitCommitShaHack: true,

	ContextProviders: []context.Provider{},

	EnforceExpiration: true,

	AllowEmptySetChains: true,

	AttestFormat: "ampel",

	LazyBlockEval: false,
}
View Source
var ErrMissingAttestations = errors.New("required attestations missing to verify subject")
View Source
var ErrUnverifiedAttestations = errors.New("no verified attestations available to evaluate the policy")

ErrUnverifiedAttestations is returned (wrapped) when evidence was supplied but none of it could be admitted because no signature verified: the attestations are unsigned, or signed with keys the verifier does not hold.

View Source
var ResultsAttestationFormats = []string{
	"ampel",
	"vsa",
	"svr",
}
View Source
var WithCollector = func(repository attestation.Repository) fnOpt {
	return func(a *Ampel) error {
		return a.Collector.AddRepository(repository)
	}
}
View Source
var WithCollectorInit = func(init string) fnOpt {
	return func(ampel *Ampel) error {
		if err := ampel.Collector.AddRepositoryFromString(init); err != nil {
			return err
		}
		return nil
	}
}

WithCollectorInit adds a collector from an init string

View Source
var WithCollectorInits = func(init []string) fnOpt {
	return func(ampel *Ampel) error {
		for _, s := range init {
			if err := ampel.Collector.AddRepositoryFromString(s); err != nil {
				return err
			}
		}
		return nil
	}
}

WithCollectorInit adds multiple collectors from a list of init strings

View Source
var WithCollectors = func(repos []attestation.Repository) fnOpt {
	return func(a *Ampel) error {
		return a.Collector.AddRepository(repos...)
	}
}
View Source
var WithDefaultPublishers = func(load bool) fnOpt {
	return func(ampel *Ampel) error {
		ampel.publisher.SetLoadDefaults(load)
		return nil
	}
}

WithDefaultPublishers controls whether the built-in emitter types are registered when the verifier is created. It is enabled by default; pass false to manage the emitter registry yourself.

View Source
var WithKeys = func(keys ...key.PublicKeyProvider) fnOpt {
	return func(a *Ampel) error {
		a.Collector.AddKeys(keys...)
		return nil
	}
}
View Source
var WithPublisherInit = func(init string) fnOpt {
	return func(ampel *Ampel) error {
		ampel.publisher.AddEmitterInit(init)
		return nil
	}
}

WithPublisherInit adds an emitter from an init string ("moniker:spec"). The emitter is built when the verifier is created, after the default emitter types are registered.

View Source
var WithPublisherInits = func(init []string) fnOpt {
	return func(ampel *Ampel) error {
		ampel.publisher.AddEmitterInit(init...)
		return nil
	}
}

WithPublisherInits adds multiple emitters from a list of init strings.

Functions

This section is empty.

Types

type Ampel

type Ampel struct {
	Collector *collector.Agent
	// contains filtered or unexported fields
}

Ampel is the attestation verifier

func New

func New(opts ...fnOpt) (*Ampel, error)

func (*Ampel) AttestResult

func (ampel *Ampel) AttestResult(w io.Writer, result *papi.Result) error

AttestResult writes an attestation capturing an evaluation result.

func (*Ampel) AttestResults

func (ampel *Ampel) AttestResults(w io.Writer, results papi.Results) error

AttestResults writes an attestation capturing one or more evaluation results. Result and ResultGroup inputs are wrapped into a single-entry ResultSet by the attester so every output shape is consistent.

func (*Ampel) CheckStatus

func (ampel *Ampel) CheckStatus(ctx context.Context, opts *StatusOptions, catalog *oscal.Catalog, subject attestation.Subject) (*Status, error)

CheckStatus matches an artifacts requirements against an OSCAL catalog or profile

func (*Ampel) Verify

func (ampel *Ampel) Verify(
	ctx context.Context, opts *VerificationOptions, policy any, subject attestation.Subject,
) (papi.Results, error)

Verify checks a subject against a policy using the available evidence. The policy argument may be a single policy, a policy group or a policy set; the results are published once per call, regardless of the material kind.

func (*Ampel) VerifySubjectWithPolicy

func (ampel *Ampel) VerifySubjectWithPolicy(
	ctx context.Context, opts *VerificationOptions, policy *papi.Policy, originalSubject attestation.Subject,
) (*papi.Result, error)

VerifySubjectWithPolicy verifies a subject against a single policy

func (*Ampel) VerifySubjectWithPolicyGroup added in v1.1.0

func (ampel *Ampel) VerifySubjectWithPolicyGroup(
	ctx context.Context, oOpts *VerificationOptions, group *papi.PolicyGroup, originalSubject attestation.Subject,
) (*papi.ResultGroup, error)

VerifySubjectWithPolicyGroup evaluates a policy group and its blocks

func (*Ampel) VerifySubjectWithPolicySet

func (ampel *Ampel) VerifySubjectWithPolicySet(
	ctx context.Context, originalOptions *VerificationOptions, policySet *papi.PolicySet, subject attestation.Subject,
) (*papi.ResultSet, error)

VerifySubjectWithPolicySet runs a subject through a policy set.

type AmpelStatusChecker

type AmpelStatusChecker interface {
	GatherResults(context.Context, *StatusOptions, attestation.Subject) ([]attestation.Envelope, error)
	ParseAttestedResults(context.Context, *StatusOptions, []attestation.Envelope) ([]attestation.Predicate, error)
	CheckIdentities(*StatusOptions, []attestation.Envelope) (bool, error)
	ComputeComplianceStatus(*oscal.Catalog, []attestation.Predicate) (*Status, error)
}

type AmpelVerifier

type AmpelVerifier interface {
	// CheckPolicy verifies the policy is sound to evaluate before running it
	CheckPolicy(context.Context, *VerificationOptions, *papi.Policy) error
	CheckPolicySet(context.Context, *VerificationOptions, *papi.PolicySet) error
	CheckPolicyGroup(context.Context, *VerificationOptions, *papi.PolicyGroup) error
	GatherAttestations(context.Context, *VerificationOptions, *collector.Agent, *papi.Policy, attestation.Subject, []attestation.Envelope) ([]attestation.Envelope, error)
	ParseAttestations(context.Context, *VerificationOptions, attestation.Subject) ([]attestation.Envelope, error)
	BuildEvaluators(*VerificationOptions, *papi.Policy) (map[class.Class]evaluator.Evaluator, error)
	BuildGroupEvaluators(*VerificationOptions, *papi.PolicyGroup) (map[class.Class]evaluator.Evaluator, error)
	BuildTransformers(*VerificationOptions, *papi.Policy) (map[transformer.Class]transformer.Transformer, error)
	Transform(*VerificationOptions, map[transformer.Class]transformer.Transformer, *papi.Policy, attestation.Subject, []attestation.Predicate) (attestation.Subject, []attestation.Predicate, error)

	// CheckIdentities verifies that attestations are signed by the policy identities
	CheckIdentities(context.Context, *VerificationOptions, []*sapi.Identity, []attestation.Envelope) (bool, []admission, []error, error)

	FilterAttestations(*VerificationOptions, attestation.Subject, []attestation.Envelope, []admission) ([]attestation.Predicate, error)
	AssertResult(*papi.Policy, *papi.Result) error

	// VerifySubject runs the verification process.
	VerifySubject(context.Context, *VerificationOptions, map[class.Class]evaluator.Evaluator, *papi.Policy, map[string]any, attestation.Subject, []attestation.Predicate) (*papi.Result, error)

	// ProcessChainedSubjects proceses the chain of attestations to find the ultimate
	// subject a policy is supposed to operate on
	ProcessChainedSubjects(context.Context, *VerificationOptions, map[class.Class]evaluator.Evaluator, *collector.Agent, papi.ChainProvider, map[string]any, attestation.Subject, []attestation.Envelope) (attestation.Subject, []*papi.ChainedSubject, bool, error)

	// ProcessPolicySetChainedSubjects executesd a PolicySet's ChainLink and returns
	// the resulting list of subjects from the evaluator.
	ProcessPolicySetChainedSubjects(context.Context, *VerificationOptions, map[class.Class]evaluator.Evaluator, *collector.Agent, *papi.PolicySet, map[string]any, attestation.Subject, []attestation.Envelope) ([]attestation.Subject, []*papi.ChainedSubject, bool, error)

	// AssembleEvalContextValues builds the policy context values by mixing defaults and defined values
	AssembleEvalContextValues(context.Context, *VerificationOptions, map[class.Class]evaluator.Evaluator, map[string]*papi.ContextVal) (map[string]any, error)
}

AmpelImplementation

type PolicyError

type PolicyError struct {
	Guidance string
	// contains filtered or unexported fields
}

type Status

type Status struct{}

type StatusOptions

type StatusOptions struct {
	ResultFiles []string
}

type VerificationOptions

type VerificationOptions struct {
	// Embed the evaluator options
	options.EvaluatorOptions

	// Collectors is a collection of configured attestation fetchers
	Collectors []attestation.Fetcher

	// ContextProviders has a list of providers to read contextual data
	ContextProviders []context.Provider

	// AttestationFiles are additional attestations passed manually
	AttestationFiles []string

	// Attestations are preparsed attestations the policy evaluator receives
	// when called, usually preparsed by the PolicySet evaluator.
	Attestations []attestation.Envelope

	// DefaultEvaluator is the default evaluator we use when a policy does
	// not define one.
	DefaultEvaluator class.Class

	// AttestResults will generate an attestation of the evaluation results
	AttestResults bool

	// AttestFormat specifies the format used when AttestResults is true
	AttestFormat string

	// ResultsAttestationPath stores the path to write the results attestation
	ResultsAttestationPath string

	// SetExitCode sets a non-zero exit code on artifact verification
	SetExitCode bool

	// Policies to evaluate from a PolicySet. Default is to evaluate all.
	Policies []string

	// GitCommitShaHack enables a hack to duplicate gitCommit subjects of read
	// attestations as sha1 when reading attestations
	GitCommitShaHack bool

	// IdentityStrings feeds the signature identities to add to the policy
	// definitions when verifying signatures.
	IdentityStrings []string

	// Keys is a list of public key providers that will be used to verify signed
	// items. These keys will be supplied to verifiers when checking signatures of
	// signed stuff (ie DSSE envelopes). It is up to the policy to recognize any
	// of the matched keys as valid identities.
	//
	// Note that each signature will be verified against all keys loaded, so clients
	// are advised to load only those keys required for each policy evaluation.
	Keys []key.PublicKeyProvider

	// EnforceExpiration forces evaluations to fail when the policy or policy set
	// expiration date has passed. If no expiration date is set, this setting is ignored.
	EnforceExpiration bool

	// AllowEmptySetChains prevents the policy from failing if the chain selectors
	// don't return any mutated subjects.
	AllowEmptySetChains bool

	// LazyBlockEval causes block evaluations to stop as soon as the blocks status
	// is known. This makes evaluation faster but also means that some policies in
	// the block may not be evaluated (and missing from the group's resultSet)
	LazyBlockEval bool

	// ErrOnMissingAttestations causes the verifier to return ErrMissingAttestations
	// (as a Go error wrapped via errors.Join) the moment any tenet cannot be
	// evaluated due to missing attestations. The EvalResult is still populated
	// in Error.Message so callers retain diagnostic detail.
	//
	// The default (false) causes the missing attestations error to surface
	// only as a failed EvalResult, not as a top-level Go error.
	//
	// Intended for programmatic callers that want to detect this condition
	// distinctly from policy violations or signature failures (for example,
	// to drive a wait+retry loop while attestations land).
	ErrOnMissingAttestations bool

	// AdmitUnverified admits attestations that were passed explicitly to the
	// verifier (through Attestations or AttestationFiles) even when they are
	// unsigned or their signature could not be verified, provided the policy
	// pins no signer identities. It exists for callers that hand the verifier
	// evidence on purpose, such as the ampel CLI's --attestation flag, and
	// never applies to attestations fetched by collectors. Admitted
	// unverified attestations reach policies with verification.verified set
	// to false. When the policy (or IdentityStrings) pins signer identities,
	// unverified attestations are always skipped.
	AdmitUnverified bool
}

func NewVerificationOptions

func NewVerificationOptions() VerificationOptions

func (*VerificationOptions) Validate

func (opts *VerificationOptions) Validate() error

Validate checks the options set

func (*VerificationOptions) WithContextProvider

func (vo *VerificationOptions) WithContextProvider(provider context.Provider) *VerificationOptions

Jump to

Keyboard shortcuts

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