Documentation
¶
Index ¶
- func PolicyVersion(version string, params EvalParams) string
- func Scope(scope string, params EvalParams) string
- type CELErrorLogLevel
- type CELErrors
- type CheckOpt
- func WithDefaultPolicyVersion(defaultPolicyVersion string) CheckOpt
- func WithDefaultScope(defaultScope string) CheckOpt
- func WithGlobals(globals map[string]any) CheckOpt
- func WithLenientScopeSearch() CheckOpt
- func WithNowFunc(nowFunc func() time.Time) CheckOpt
- func WithStrictEvaluation() CheckOpt
- func WithTraceSink(tracerSink tracer.Sink) CheckOpt
- type CheckOptions
- type Conf
- type EvalParams
- type Evaluator
- type StrictEvaluationError
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) 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 ¶
WithDefaultPolicyVersion sets the default policy version for the engine.
func WithDefaultScope ¶ added in v0.50.0
WithDefaultScope sets the default scope for the engine.
func WithGlobals ¶
WithGlobals sets the global variables for the engine.
func WithLenientScopeSearch ¶
func WithLenientScopeSearch() CheckOpt
WithLenientScopeSearch enables lenient scope search.
func WithNowFunc ¶
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 ¶
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 (*Conf) SetDefaults ¶
func (c *Conf) SetDefaults()
type EvalParams ¶
type EvalParams struct {
Globals map[string]any
NowFunc conditions.NowFunc
DefaultPolicyVersion string
DefaultScope string
CELErrorLogLevel CELErrorLogLevel
LenientScopeSearch bool
StrictEvaluation bool
}
type Evaluator ¶
type Evaluator interface {
Check(context.Context, []*enginev1.CheckInput, ...CheckOpt) ([]*enginev1.CheckOutput, error)
Plan(context.Context, *enginev1.PlanResourcesInput, ...CheckOpt) (*enginev1.PlanResourcesOutput, error)
}
type StrictEvaluationError ¶ added in v0.55.0
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