policy

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine implements the PolicyEngine interface using CEL expressions

func NewEngine

func NewEngine(logger *slog.Logger, config PolicyConfig) (*Engine, error)

NewEngine creates a new policy engine with a CEL-based policy

func (*Engine) Evaluate

func (e *Engine) Evaluate(ctx context.Context, imageRef string, result *scanner.ScanResult, tolerations []types.CVEToleration) (*PolicyDecision, error)

Evaluate determines if an image passes security policy using CEL expression

func (*Engine) SetExpiryWarningWindow

func (e *Engine) SetExpiryWarningWindow(duration time.Duration)

SetExpiryWarningWindow sets the duration before expiry to trigger warnings

type ExpiringToleration

type ExpiringToleration struct {
	CVEID     string
	Statement string
	ExpiresAt time.Time
	DaysUntil int
}

ExpiringToleration represents a toleration that is expiring soon

type PolicyConfig

type PolicyConfig struct {
	// Expression is the CEL expression that must evaluate to true for the policy to pass
	// Available variables:
	//   - vulnerabilities: list of enriched vulnerabilities with fields:
	//       id, severity, packageName, version, fixedVersion, description, tolerated, tolerationStatement, tolerationExpiry
	//   - imageRef: string reference to the image
	//   - criticalCount: number of critical vulnerabilities (not tolerated)
	//   - highCount: number of high vulnerabilities (not tolerated)
	//   - mediumCount: number of medium vulnerabilities (not tolerated)
	//   - toleratedCount: number of tolerated vulnerabilities
	Expression string `yaml:"expression" json:"expression"`

	// FailureMessage is the message to return when the policy fails (optional)
	FailureMessage string `yaml:"failureMessage" json:"failureMessage"`
}

PolicyConfig defines a CEL-based policy configuration

type PolicyDecision

type PolicyDecision struct {
	Passed              bool
	Reason              string
	ShouldSign          bool
	ShouldAttest        bool
	CriticalVulnCount   int
	ToleratedVulnCount  int
	UnfixedVulnCount    int
	ToleratedCVEs       []string
	ExpiringTolerations []ExpiringToleration
}

PolicyDecision represents the result of policy evaluation

type PolicyEngine

type PolicyEngine interface {
	// Evaluate determines if an image passes security policy
	// Applies CVE tolerations from regsync config for the target repository
	Evaluate(ctx context.Context, imageRef string, result *scanner.ScanResult, tolerations []types.CVEToleration) (*PolicyDecision, error)
}

PolicyEngine defines the interface for policy evaluation

Jump to

Keyboard shortcuts

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