evaluator

package
v0.76.0 Latest Latest
Warning

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

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

Documentation

Overview

Package evaluator is L5 of the SigComply CLI: runs each policy's rule against the records collected for it and emits a PolicyResult. Hosts the rule registry, the Rego runner, the Go rule runner, and the YAML DSL transpiler. Rules are pure functions over RuleInput; they do no I/O.

See docs/architecture/02-layers.md for the full layer contract.

Package evaluator is L5 of the SigComply CLI: runs each policy's rule with the records collected for it and emits PolicyResult. Hosts the Rego runner and the Go rule runner; the YAML DSL transpiler is deferred (post-M6).

See docs/architecture/02-layers.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(ctx context.Context, in *Input) ([]core.PolicyResult, error)

Evaluate runs the rule for every planned policy and returns the per-policy results. Exception suppression (na / waived) is applied here so the caller never sees a rule's raw output for a fully-waived policy.

Types

type GoRule

type GoRule struct {
	IDValue string
	Fn      func(ctx context.Context, in core.RuleInput) (core.RuleResult, error)
}

GoRule is a thin core.Rule implementation backed by a closure. It exists so framework packages can register hand-written Go rules without each defining its own type.

func (*GoRule) Evaluate

func (r *GoRule) Evaluate(ctx context.Context, in core.RuleInput) (core.RuleResult, error)

Evaluate delegates to the closure.

func (*GoRule) ID

func (r *GoRule) ID() string

ID returns the rule's registered identifier.

type Input

type Input struct {
	Plan                  *planner.RunPlan
	Rules                 *registry.Registry[core.Rule]
	RecordsByPolicy       map[string]map[string][]core.EvidenceRecord
	EnvelopesByPolicy     map[string][]string
	CollectErrorsByPolicy map[string]error
	Now                   time.Time

	// RosterUsage, when set, accumulates which experimental.roster
	// account names actually matched a collected account. It is the one
	// run-scoped output of evaluation: the caller allocates it, reads it
	// after Evaluate returns, and warns about the keys that matched
	// nothing. Nil disables the bookkeeping entirely.
	RosterUsage *RosterUsage
}

Input is the per-run input to Evaluate. RecordsByPolicy is keyed by PolicyID; the inner map is keyed by slot name. CollectErrorsByPolicy holds collector-side errors (network, auth, schema-validation); a non-empty entry forces the policy's status to "error" without invoking the rule.

type RegoRule

type RegoRule struct {
	// contains filtered or unexported fields
}

RegoRule wraps an OPA Rego module. The module is prepared once at New; each Evaluate call instantiates a fresh evaluator with the per-policy input. Pure-function semantics are preserved by OPA's sandbox.

func NewRegoRule

func NewRegoRule(id, module, query string) (*RegoRule, error)

NewRegoRule prepares the module for repeated evaluation. The query is a Rego reference, e.g. "data.sigcomply.rules.manual_presence.v1.result"; the rule's result document must expose a "status" string and an optional "violations" array of {resource_id, reason, details}.

func (*RegoRule) Evaluate

func (r *RegoRule) Evaluate(ctx context.Context, in core.RuleInput) (core.RuleResult, error)

Evaluate marshals the rule input to JSON, hands it to OPA, and projects the returned document back into a RuleResult.

func (*RegoRule) ID

func (r *RegoRule) ID() string

ID returns the registered rule reference.

type RosterKey added in v0.76.0

type RosterKey struct {
	SourceID string
	Name     string
}

RosterKey identifies one declared roster entry: the source ID keying the aliases / non_human map and the account name inside it. Both are already lowercased by the config loader.

type RosterUsage added in v0.76.0

type RosterUsage struct {
	// contains filtered or unexported fields
}

RosterUsage accumulates, across a whole run, which experimental.roster account names actually met a collected account.

The source-ID half of a typo is fatal at plan time (planner.checkRosterSourceKeys). The account-name half cannot be: only the evaluator ever sees the universe of account names, and it sees it one record at a time. So the keys are recorded as they match and the leftovers — declared minus matched — are what the orchestrator warns about.

It must be run-scoped, not per-policy. The planner copies the same Aliases/NonHuman maps into every roster policy's RosterLink, but each policy gets its own evalCtx over its own bound accounts; a per-policy verdict would call an alias unused in the policy whose accounts slot did not bind that source even though the sibling policy used it.

Nothing here crosses the aggregation boundary: these are account names and source IDs, which is identity data. It reaches local stdout only.

The zero value is not usable; call NewRosterUsage. A nil *RosterUsage is a no-op accumulator, which is what every caller that does not care (rule: policies, most tests) passes.

func NewRosterUsage added in v0.76.0

func NewRosterUsage() *RosterUsage

NewRosterUsage returns an empty, ready-to-use accumulator for one run. It collects which experimental.roster alias and non_human keys actually matched a collected account, run-scoped across every policy evaluated, so the orchestrator can warn about the keys that matched nothing — the typo half no plan-time check can catch.

func (*RosterUsage) Declare added in v0.76.0

func (u *RosterUsage) Declare(link *planner.RosterLink)

Declare records every key a policy's roster link carries. It is called for each policy the run actually evaluates — never for one that is carried forward or excepted, which looks at no account and so can prove nothing about a key. Idempotent: every roster policy in a run declares the same maps.

func (*RosterUsage) UnusedAliases added in v0.76.0

func (u *RosterUsage) UnusedAliases() []RosterKey

UnusedAliases returns the declared alias keys no collected account carried, sorted by source then name. Nil when there are none.

func (*RosterUsage) UnusedNonHuman added in v0.76.0

func (u *RosterUsage) UnusedNonHuman() []RosterKey

UnusedNonHuman is UnusedAliases for the non_human map.

Jump to

Keyboard shortcuts

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