Help us shape the future of Go! Take the 2026 Go Developer Survey

ruleengine

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Copyright 2020-2026 Project Capsule Authors SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnforceBodiesFromNamespaceRules

func EnforceBodiesFromNamespaceRules(
	bodies []*api.NamespaceRuleBodyNamespace,
) []*api.NamespaceRuleEnforceBody

func FilterEnforcementConditions added in v0.15.0

func FilterEnforcementConditions(
	ctx context.Context,
	evaluator *ConditionEvaluator,
	object any,
	bodies []*rules.NamespaceRuleEnforceBody,
	applies func(*rules.NamespaceRuleEnforceBody) bool,
) ([]*rules.NamespaceRuleEnforceBody, error)

FilterEnforcementConditions filters the applicable enforcement rules. It preserves rule order and cache-owned bodies, with no allocation when ungated.

func FilterNamespaceEnforcementConditions added in v0.15.0

func FilterNamespaceEnforcementConditions(
	ctx context.Context,
	evaluator *ConditionEvaluator,
	object any,
	bodies []*rules.NamespaceRuleBodyNamespace,
	applies func(*rules.NamespaceRuleEnforceBody) bool,
) ([]*rules.NamespaceRuleBodyNamespace, error)

FilterNamespaceEnforcementConditions gates enforcement-derived mutations while retaining independent mutate entries. It copies only bodies whose gate is false.

func ValidateRuleStatusBody

func ValidateRuleStatusBody(
	mapper k8smeta.RESTMapper,
	bodies []*rules.NamespaceRuleBodyNamespace,
	compilers ...ConditionCompiler,
) error

func WorkloadEnforcement added in v0.15.0

WorkloadEnforcement selects property policies for the admitted kind. It preserves order and never changes rules owned by the cache. The ordinary Pod-only path returns the input without copying it.

Types

type ConditionCompiler added in v0.15.0

type ConditionCompiler interface {
	GetOrCompileCondition(expression string, mode environment.Type) (*celruntime.CompiledExpression, error)
}

ConditionCompiler is backed by the controller's shared CEL cache.

type ConditionEvaluator added in v0.15.0

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

ConditionEvaluator owns request-local metadata, never evaluation results.

func NewConditionEvaluator added in v0.15.0

func NewConditionEvaluator(compiler ConditionCompiler, request admissionv1.AdmissionRequest) *ConditionEvaluator

func (*ConditionEvaluator) Matches added in v0.15.0

func (e *ConditionEvaluator) Matches(ctx context.Context, object any, conditions []rules.AdmissionCondition) (bool, error)

Matches evaluates a block against its current object. A false condition takes precedence over errors, independently of condition order. A nil object uses the full admission request object, for callers that decode only metadata.

func (*ConditionEvaluator) ResetObject added in v0.15.0

func (e *ConditionEvaluator) ResetObject()

ResetObject invalidates only the current request's object view after mutation.

func (*ConditionEvaluator) WithVolume added in v0.15.0

WithVolume attaches the already-read PV without performing any API I/O. Conversion is deferred until a condition needs evaluation.

type Decision

type Decision struct {
	SetName     string
	EventReason string
	Action      api.ActionType
	Value       Value

	MatchedValue any

	// MatchedRule is the human-readable rule description returned by Set.RuleDescription.
	MatchedRule string

	// MatchDetail is the human-readable detail returned by Match.Detail.
	MatchDetail string

	Message string
}

type DecisionError

type DecisionError struct {
	Decision *Decision
}

func (*DecisionError) Error

func (e *DecisionError) Error() string

type Evaluation

type Evaluation struct {
	// Final is the last matching allow/deny decision.
	Final *Decision

	// Blocking is set when the final result blocks admission.
	Blocking *Decision

	// Audits contains all matching audit decisions.
	Audits []*Decision
}

func EvaluateEnforce

func EvaluateEnforce[R any, T any](
	obj T,
	enforceBodies []*api.NamespaceRuleEnforceBody,
	set Set[R, T],
) (*Evaluation, error)

func (*Evaluation) Append

func (e *Evaluation) Append(other *Evaluation)

func (*Evaluation) BlockingError

func (e *Evaluation) BlockingError() error

type Match

type Match struct {
	Matched      bool
	MatchedValue any

	// Detail is optional human-readable matcher context.
	// Example: "10.0.171.239 is contained in 10.0.0.0/16".
	Detail string
}

type Set

type Set[R any, O any] struct {
	Name        string
	EventReason string

	Values func(O) []Value

	// EvaluateEmptyValues includes empty strings in matching. By default they
	// represent unset resource fields and are skipped. Metadata keys can be
	// present with an empty value and must opt in to evaluation.
	EvaluateEmptyValues bool

	// Rules extracts rules when extraction cannot fail.
	Rules func(*api.NamespaceRuleEnforceBody) []R
	// RulesWithError extracts rules that require runtime parsing or matching.
	// When set, it takes precedence over Rules.
	RulesWithError func(*api.NamespaceRuleEnforceBody) ([]R, error)
	Matches        func(R, Value) (Match, error)

	// Message can fully override the default message.
	// Prefer leaving this nil unless a rule requires very specific wording.
	Message func(api.ActionType, Value, any) string

	// RuleDescription returns a human-readable representation of one rule.
	// It is used only for admission/audit messages.
	RuleDescription func(R) string

	// AllowedDescription optionally overrides the "Allowed values" label.
	// Example: "Allowed CIDRs", "Allowed ranges", "Allowed hostnames".
	AllowedDescription string
}

type Value

type Value struct {
	Value string
	Path  string
	// Data optionally carries a structured value without serializing it for matching.
	Data any
}

Jump to

Keyboard shortcuts

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