evaluator

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PolicyVersion

func PolicyVersion(version string, params EvalParams) string

func Scope added in v0.50.0

func Scope(scope string, params EvalParams) string

Types

type CELErrorLogLevel added in v0.54.0

type CELErrorLogLevel string
const (
	CELErrorLogLevelNone  CELErrorLogLevel = "none"
	CELErrorLogLevelDebug CELErrorLogLevel = "debug"
	CELErrorLogLevelInfo  CELErrorLogLevel = "info"
	CELErrorLogLevelWarn  CELErrorLogLevel = "warn"
	CELErrorLogLevelError CELErrorLogLevel = "error"
)

type CELErrors added in v0.54.0

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

func NewCELErrors added in v0.54.0

func NewCELErrors(level CELErrorLogLevel) *CELErrors

func (*CELErrors) Add added in v0.54.0

func (c *CELErrors) Add(ctx context.Context, expression string, err error)

func (*CELErrors) All added in v0.54.0

func (c *CELErrors) All() []*enginev1.EvaluationError

type CheckOpt

type CheckOpt func(*CheckOptions)

CheckOpt defines options for engine Check calls.

func WithDefaultPolicyVersion

func WithDefaultPolicyVersion(defaultPolicyVersion string) CheckOpt

WithDefaultPolicyVersion sets the default policy version for the engine.

func WithDefaultScope added in v0.50.0

func WithDefaultScope(defaultScope string) CheckOpt

WithDefaultScope sets the default scope for the engine.

func WithGlobals

func WithGlobals(globals map[string]any) CheckOpt

WithGlobals sets the global variables for the engine.

func WithLenientScopeSearch

func WithLenientScopeSearch() CheckOpt

WithLenientScopeSearch enables lenient scope search.

func WithNowFunc

func WithNowFunc(nowFunc func() time.Time) CheckOpt

WithNowFunc sets the function for determining `now` during condition evaluation. The function should return the same timestamp every time it is invoked.

func WithStrictEvaluation added in v0.55.0

func WithStrictEvaluation() CheckOpt

WithStrictEvaluation enables strict evaluation.

func WithTraceSink

func WithTraceSink(tracerSink tracer.Sink) CheckOpt

type CheckOptions

type CheckOptions struct {
	TracerSink tracer.Sink
	EvalParams EvalParams
}

func NewCheckOptions

func NewCheckOptions(ctx context.Context, conf *Conf, opts ...CheckOpt) *CheckOptions

func (*CheckOptions) DefaultPolicyVersion

func (co *CheckOptions) DefaultPolicyVersion() string

func (*CheckOptions) DefaultScope added in v0.50.0

func (co *CheckOptions) DefaultScope() string

func (*CheckOptions) Globals

func (co *CheckOptions) Globals() map[string]any

func (*CheckOptions) LenientScopeSearch

func (co *CheckOptions) LenientScopeSearch() bool

func (*CheckOptions) NowFunc

func (co *CheckOptions) NowFunc() func() time.Time

type Conf

type Conf struct {
	// Globals are environment-specific variables to be made available to policy conditions.
	Globals map[string]any `yaml:"globals" conf:",example={\"environment\": \"staging\"}"`
	// DefaultPolicyVersion defines what version to assume if the request does not specify one.
	DefaultPolicyVersion string `yaml:"defaultPolicyVersion" conf:",example=\"default\""`
	// DefaultScope defines what scope to assume if the request does not specify one.
	DefaultScope string `yaml:"defaultScope" conf:",example=\"\""`
	// CELErrorLogLevel is the level at which CEL runtime errors raised during policy evaluation are logged. Valid values are none, debug, info, warn (default) and error.
	CELErrorLogLevel CELErrorLogLevel `yaml:"celErrorLogLevel" conf:",example=warn"`
	// LenientScopeSearch configures the engine to ignore missing scopes and search upwards through the scope tree until it finds a usable policy.
	LenientScopeSearch bool `yaml:"lenientScopeSearch" conf:",example=false"`
	// StrictEvaluation denies the affected action when an error is raised during policy evaluation, instead of ignoring the erroring rule.
	StrictEvaluation bool `yaml:"strictEvaluation" conf:",example=false"`
	// PolicyLoaderTimeout is the timeout for loading policies from the policy store.
	PolicyLoaderTimeout time.Duration `yaml:"policyLoaderTimeout" conf:",example=2s"`
	NumWorkers          uint          `yaml:"numWorkers" conf:",ignore"`
}

Conf is optional configuration for engine.

func GetConf

func GetConf() (*Conf, error)

func (*Conf) Key

func (c *Conf) Key() string

func (*Conf) SetDefaults

func (c *Conf) SetDefaults()

func (*Conf) Validate

func (c *Conf) Validate() (outErr error)

type EvalParams

type EvalParams struct {
	Globals              map[string]any
	NowFunc              conditions.NowFunc
	DefaultPolicyVersion string
	DefaultScope         string
	CELErrorLogLevel     CELErrorLogLevel
	LenientScopeSearch   bool
	StrictEvaluation     bool
}

type StrictEvaluationError added in v0.55.0

type StrictEvaluationError struct {
	Err        error
	Expression string
}

StrictEvaluationError is raised when strict evaluation mode is enabled and a CEL runtime error occurs during evaluation. It never escapes the engine: the check and plan evaluators convert it into a DENY for the affected action.

func (StrictEvaluationError) Error added in v0.55.0

func (e StrictEvaluationError) Error() string

func (StrictEvaluationError) Is added in v0.55.0

func (e StrictEvaluationError) Is(target error) bool

func (StrictEvaluationError) Unwrap added in v0.55.0

func (e StrictEvaluationError) Unwrap() error

Jump to

Keyboard shortcuts

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