policy

package
v0.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package policy enforces a bundle: each policy of the bundle gets its own pipeline (mode, failure mode, timeout, skip paths, rules, body settings), and each request is inspected by the policy of its route. A Holder swaps the active set atomically when a new bundle arrives.

Index

Constants

View Source
const MaxBodyBytes = 10 << 20

MaxBodyBytes is the largest body a policy may inspect, as WAFPolicy's body.maxBytes allows; adapters in bundle mode accept bodies up to it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluators

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

Evaluators caches compiled rule sets by configuration (coraza.Config.Key, without exclusions): policies with the same rules share one (a Coraza WAF with the CRS holds megabytes) whatever their exclusions, and an unchanged policy isn't recompiled when a new bundle arrives. Cached evaluators have no exclusions.

func NewEvaluators

func NewEvaluators() *Evaluators

NewEvaluators returns an empty cache.

func (*Evaluators) Len

func (e *Evaluators) Len() int

Len returns the number of cached rule sets.

type Holder

type Holder struct {

	// DenyBeforeFirst rejects requests with 503 until the first set is
	// stored, instead of letting them through uninspected.
	DenyBeforeFirst bool
	// contains filtered or unexported fields
}

Holder holds the active Set, swapped atomically: Check runs entirely on the set it loaded. (An adapter's BodyLimit and Check calls may straddle a swap; the request is then inspected by the new set, with the body read to the old set's limit.) Before the first set it allows every request, with ReasonNoPolicy, or denies it with DenyBeforeFirst.

func (*Holder) BodyLimit

func (h *Holder) BodyLimit(r *request.Request, max int64) int64

BodyLimit implements pipeline.Inspector.

func (*Holder) Check

func (h *Holder) Check(ctx context.Context, r *request.Request) pipeline.Verdict

Check implements pipeline.Inspector.

func (*Holder) Load

func (h *Holder) Load() *Set

Load returns the active set, nil before the first.

func (*Holder) Store

func (h *Holder) Store(s *Set)

Store makes s the active set.

type Options

type Options struct {
	// Admission bounds concurrent evaluations across all policies.
	Admission *pipeline.Admission
	// Observer is told about every verdict (metrics).
	Observer pipeline.Observer
	// MaxArgs is the argument limit (coraza.Config.MaxArgs).
	MaxArgs int
	// BodyLimit is the body inspected for a policy that doesn't set one.
	BodyLimit int64
	// OnMatch is called for every matching rule (coraza.Config.OnMatch).
	OnMatch func(types.MatchedRule)
	// Evaluators reuses compiled rule sets across bundles; nil compiles
	// every bundle from scratch.
	Evaluators *Evaluators
	// Stats counts each policy's requests, for the operator (nil: not
	// counted).
	Stats *events.Stats
}

Options are the engine-wide settings every policy shares.

type Policy

type Policy struct {
	ID string
	// contains filtered or unexported fields
}

Policy is one compiled policy.

type Set

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

Set is a compiled bundle. It is immutable and safe for concurrent use.

func Compile

func Compile(b *bundlev1.Bundle, o Options) (*Set, error)

Compile compiles a bundle. An error names the policy that failed: the engine then keeps the set it has (and reports the error to the operator).

func (*Set) BodyLimit

func (s *Set) BodyLimit(r *request.Request, _ int64) int64

BodyLimit implements pipeline.Inspector: the policy's body limit, or 0 when its bodies, or the route's, are not inspected.

func (*Set) Check

func (s *Set) Check(ctx context.Context, r *request.Request) pipeline.Verdict

Check implements pipeline.Inspector.

func (*Set) Lookup

func (s *Set) Lookup(r *request.Request) *Policy

Lookup returns the policy for a request, or nil if no policy covers it.

func (*Set) Policies

func (s *Set) Policies() int

Policies returns the number of policies.

func (*Set) Version

func (s *Set) Version() uint64

Version is the bundle's version.

Jump to

Keyboard shortcuts

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