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
- func CheckRuleSets(bp *bundlev1.Policy, ruleSets []*bundlev1.RuleSet) error
- func CheckSettings(bp *bundlev1.Policy, ruleSets []*bundlev1.RuleSet) error
- type Evaluators
- type Holder
- func (h *Holder) BodyLimit(r *request.Request, max int64) int64
- func (h *Holder) Check(ctx context.Context, r *request.Request) pipeline.Verdict
- func (h *Holder) CheckExchange(ctx context.Context, r *request.Request) (pipeline.Verdict, *pipeline.Exchange)
- func (h *Holder) GRPCStream(r *request.Request) pipeline.GRPCStream
- func (h *Holder) Load() *Set
- func (h *Holder) ProbeKey() []byte
- func (h *Holder) Redaction() *events.Redaction
- func (h *Holder) Store(s *Set)
- type Options
- type Policy
- type RuleChecker
- type Set
- func (s *Set) BodyLimit(r *request.Request, max int64) int64
- func (s *Set) Check(ctx context.Context, r *request.Request) pipeline.Verdict
- func (s *Set) CheckExchange(ctx context.Context, r *request.Request) (pipeline.Verdict, *pipeline.Exchange)
- func (s *Set) GRPCStream(r *request.Request) pipeline.GRPCStream
- func (s *Set) Lookup(r *request.Request) *Policy
- func (s *Set) Policies() int
- func (s *Set) ProbeKey() []byte
- func (s *Set) Version() uint64
Constants ¶
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.
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 ¶
func CheckRuleSets ¶ added in v0.4.5
CheckRuleSets checks that ruleSets has the rule sets policy bp binds, as Compile loads them, without compiling them (RuleChecker.Check does).
func CheckSettings ¶ added in v0.4.5
CheckSettings checks what of policy bp the engine compiles besides its rules, as Compile does: its skip paths, WebSocket rules, IP lists, CRS settings and exclusions; ruleSets has the rule sets it binds. A policy the engine refuses makes it refuse the whole bundle, every other policy's changes with it: the operator leaves out a policy that fails this (or RuleChecker.Check), whatever admitted it.
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.
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) 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) ProbeKey ¶ added in v0.4.0
ProbeKey is the active set's probe key, nil before the first 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
Check compiles the rules of policy bp, whose rule sets are among ruleSets, with its exclusions when they are compiled in. A policy without SecLang rule sets runs only the built-in rules and isn't compiled.
func (*RuleChecker) Prune ¶ added in v0.4.5
func (c *RuleChecker) Prune()
Prune forgets the results of the combinations no Check asked for since the last Prune, as Evaluators drops the rule sets a bundle doesn't use: called after each resolution, it keeps the results of the policies there are, however many, and none of those there were.
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 ¶
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 ¶
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) 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 ¶
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).