policy

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDigest

func CalculateDigest(policyPath string) (string, error)

computes SHA256 hash of policy bundle content

Types

type OPAEvaluator

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

handles OPA policy evaluation using the Rego API

func NewOPAEvaluator

func NewOPAEvaluator(ctx context.Context, policyBundlePath string, schemasPath string, dataPath string) (*OPAEvaluator, error)

creates a new OPA evaluator instance

func (*OPAEvaluator) EvaluatePolicy

func (e *OPAEvaluator) EvaluatePolicy(ctx context.Context, signatures []oci.Signature) (*PolicyResult, error)

evaluates OPA policy against attestations

func (*OPAEvaluator) EvaluatePolicyWithBundles

func (e *OPAEvaluator) EvaluatePolicyWithBundles(ctx context.Context, bundles []map[string]interface{}) (*PolicyResult, error)

evaluates OPA policy with pre-formatted bundle data (for offline mode)

func (*OPAEvaluator) GetPolicyDetails

func (e *OPAEvaluator) GetPolicyDetails() map[string]interface{}

returns details about the loaded policy

func (*OPAEvaluator) ResolvedPolicyPath added in v0.20.1

func (e *OPAEvaluator) ResolvedPolicyPath() string

returns the resolved local path of the policy bundle (for digest calculation). unlike policyPath (the original URI used for display), this is a local filesystem path after resolution.

WARNING: for downloaded/extracted bundles this points into a temp directory that Stop() removes. Read it before calling Stop() (as generate.go does); a path read after Stop() may no longer exist.

func (*OPAEvaluator) Stop

func (e *OPAEvaluator) Stop(ctx context.Context)

shuts down the OPA evaluator, removing any temp directories created during path resolution

type PolicyResult

type PolicyResult struct {
	Result     string                 `json:"result"` // "PASSED" or "FAILED"
	Violations []PolicyViolation      `json:"violations"`
	Details    map[string]interface{} `json:"details"`
	Timestamp  time.Time              `json:"timestamp"`
}

result of OPA policy evaluation

type PolicyViolation

type PolicyViolation struct {
	Policy  string `json:"policy"`
	Message string `json:"message"`
}

policy violation

type ResolveOptions added in v0.20.1

type ResolveOptions struct {
	// DefaultAsset is the default asset name used for ghrel:// resolution
	// (e.g., "bundle.tar.gz", "schemas.tar.gz"). Stabilizing this on the
	// dispatcher signature lets new schemes (OCI, ghrel) be added as
	// independent cases without changing resolveBundlePath's signature.
	// Consumed by the ghrel:// case to pick the release asset when the
	// reference omits an explicit ?asset= query.
	DefaultAsset string
	// ExpectedDigest, when non-empty, pins the SHA-256 of the downloaded
	// ghrel:// bundle archive (sha256:hex or bare hex). The ghrel resolver
	// hard-fails on a mismatch. It is an opt-in integrity check on the archive
	// bytes, distinct from the SLSA-aligned digest of the extracted contents
	// computed by CalculateDigest, and is only set for the bundle path (never
	// the schemas asset).
	ExpectedDigest string
}

ResolveOptions configures path resolution behavior.

Jump to

Keyboard shortcuts

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