policy

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 22 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 DefaultResponseBytes = 64 << 10

DefaultResponseBytes is the response body a policy that inspects responses inspects when it sets no limit, as for request bodies: the CRS response rules cost about 0.3 ms per KiB of HTML (BenchmarkEvaluateExchange), so Coraza's recommended 512 KiB would take most of the default deadline. A policy may inspect up to MaxBodyBytes.

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 and CRS settings): policies with the same rules share one (a Coraza WAF with the CRS holds megabytes) whatever their exclusions, paranoia level, threshold and body limits, and an unchanged policy isn't recompiled when a new bundle arrives. Cached evaluators have no exclusions, and the CRS settings of the policy that compiled them.

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
	// Observer, if set, is told about the verdicts before the first set
	// (metrics); a set tells its own Options.Observer.
	Observer pipeline.Observer
	// 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) CheckExchange added in v0.4.0

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

CheckExchange implements pipeline.ExchangeInspector.

func (*Holder) GRPCStream added in v0.6.0

func (h *Holder) GRPCStream(r *request.Request) pipeline.GRPCStream

GRPCStream implements pipeline.GRPCStreamInspector: the active set's, nil before the first. Without it an engine in bundle mode would buffer every gRPC call whatever its policy's grpcStreams (#646).

func (*Holder) Load

func (h *Holder) Load() *Set

Load returns the active set, nil before the first.

func (*Holder) ProbeKey added in v0.4.0

func (h *Holder) ProbeKey() []byte

ProbeKey is the active set's probe key, nil before the first set.

func (*Holder) Redaction added in v0.5.0

func (h *Holder) Redaction() *events.Redaction

Redaction is the active set's events redaction, nil before the first set or without one.

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 RuleChecker added in v0.4.3

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

RuleChecker checks that a policy's rule sets compile together, as Compile compiles them: rule sets that are valid alone may not be (the same rule ID in two). It remembers each combination's result, not the compiled rules.

func NewRuleChecker added in v0.4.3

func NewRuleChecker() *RuleChecker

NewRuleChecker returns a RuleChecker that has checked nothing.

func (*RuleChecker) Check added in v0.4.3

func (c *RuleChecker) Check(bp *bundlev1.Policy, ruleSets []*bundlev1.RuleSet) error

Check compiles the rules of policy bp, whose rule sets are among ruleSets. A policy without SecLang rule sets runs only the built-in rules and isn't compiled.

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, max int64) int64

BodyLimit implements pipeline.Inspector: the policy's body limit, at most max (the adapter's own) when max is positive, or 0 when its bodies, or the route's, are not inspected. A request inspected by several policies is read to the largest of their limits.

func (*Set) Check

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

Check implements pipeline.Inspector.

func (*Set) CheckExchange added in v0.4.0

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

CheckExchange implements pipeline.ExchangeInspector. The response's verdict names the policy and is counted as its own denied or detected request, not as another allowed one. A request inspected by several policies has its response inspected by each that inspects responses.

func (*Set) GRPCStream added in v0.6.0

func (s *Set) GRPCStream(r *request.Request) pipeline.GRPCStream

GRPCStream implements pipeline.GRPCStreamInspector: r's policy's, if it inspects r's messages one by one (#315). Each message's verdict is counted as the policy's, as a request's. A call the forms of whose path select several policies isn't streamed: each inspects it buffered.

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: the policy of its decoded, cleaned path, when the forms of its path select several (policiesFor).

func (*Set) Policies

func (s *Set) Policies() int

Policies returns the number of policies.

func (*Set) ProbeKey added in v0.4.0

func (s *Set) ProbeKey() []byte

ProbeKey is the key of the operator's HAProxy probe, nil if the bundle has none.

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