Documentation
¶
Overview ¶
Package resolver turns the cluster's WAF objects into bundle policies (0004 §4.5): each WAFPolicy's targets are expanded into concrete host / path matches, its rule sets resolved, and conflicts between policies settled. It is pure: the same objects always give the same result.
A policy that can't be resolved (a missing rule set, rules that don't compile, a conflict) keeps the version it has in the previous bundle, so a bad edit never removes or weakens protection already in force; a policy that was never resolved is left out until it is fixed. Its Accepted condition says why.
Index ¶
Constants ¶
const ( ReasonAccepted = "Accepted" ReasonInvalidRef = "InvalidRef" ReasonConflict = "Conflict" ReasonRuleCompileError = "RuleCompileError" ReasonTargetUnsupported = "TargetUnsupported" // ReasonTargetNotAttached: an HTTPRoute target no Gateway of an // integration accepted; the policy doesn't apply to it. ReasonTargetNotAttached = "TargetNotAttached" // ReasonRouteOverlap: a route of the policy overlaps a route of a // policy in another namespace that the engine can't tell apart from it. ReasonRouteOverlap = "RouteOverlap" // ReasonRuleSetsIncompatible: the policy's rule sets compile alone but // not together, as the engine loads them. ReasonRuleSetsIncompatible = "RuleSetsIncompatible" // ReasonInvalidSpec: the engine can't compile the policy's spec (a // value admission didn't refuse); in the bundle, it would make every // engine refuse the bundle. ReasonInvalidSpec = "InvalidSpec" // ReasonBundleTooLarge: the bundle with the policy as it is now // doesn't fit its Secrets, so the policy is held back (Input.Hold). ReasonBundleTooLarge = "BundleTooLarge" )
Condition reasons for Accepted.
const PolicyValid = "the policy is valid"
PolicyValid is the Accepted message of a policy that resolved with nothing to report.
const RulesLabel = "waf.inkwall.dev/rules"
RulesLabel must be set to "true" on a ConfigMap a rule set reads rules from: the operator only watches labeled ConfigMaps.
Variables ¶
This section is empty.
Functions ¶
func AttachedGateways ¶ added in v0.4.3
AttachedGateways returns the Gateways ("namespace/name") that accepted an HTTPRoute, as their status says: a parent of its parentRefs whose controller is an integration's, with Accepted True. A route no such Gateway accepted carries no traffic through a proxy the engine is in.
func CheckSpec ¶ added in v0.4.5
func CheckSpec(s wafv1alpha1.WAFPolicySpec) error
CheckSpec compiles what the engine compiles of a policy's spec besides its rules and the rule sets it binds, as the bundle builder checks it: for admission, so that a spec the bundle would leave out is refused when it is saved.
Types ¶
type Input ¶
type Input struct {
Policies []wafv1alpha1.WAFPolicy
Ingresses []networkingv1.Ingress
// IngressRoutes are Traefik's (traefik.io/v1alpha1); none when its
// CRD isn't installed.
IngressRoutes []unstructured.Unstructured
// HTTPRoutes are Gateway API's; none when its CRDs aren't installed.
HTTPRoutes []gatewayv1.HTTPRoute
// VirtualServices are Istio's (networking.istio.io); none when its
// CRD isn't installed.
VirtualServices []unstructured.Unstructured
RuleSets []wafv1alpha1.WAFRuleSet
ClusterRuleSets []wafv1alpha1.ClusterWAFRuleSet
// ConfigMaps rule sets read rules from (labeled RulesLabel).
ConfigMaps []corev1.ConfigMap
// Previous is the bundle in force; nil when there is none.
Previous *bundlev1.Bundle
// CheckRules checks SecLang read from a ConfigMap
// (coraza.CheckUserRules); inline rules were checked at admission.
CheckRules func(string) error
// AssumeAttached takes every HTTPRoute as accepted by its Gateways,
// for objects read from files, which have no status.
AssumeAttached bool
// CheckPolicy compiles a policy with its rule sets as the engine does
// (policy.CheckPolicy): rule sets valid alone may not be together
// (duplicate rule IDs). Nil: not checked.
CheckPolicy func(*bundlev1.Policy, []*bundlev1.RuleSet) error
// Hold names the policies the bundle doesn't take as they are now,
// with the message of their BundleTooLarge status: the bundle with
// them doesn't fit its Secrets (the builder decides which). Each keeps
// its previous version, as a policy that fails does, or is left out
// if it has none.
Hold map[types.NamespacedName]string
// HoldRuleSets names, by id, the rule sets the bundle doesn't take as
// they are now, with the message of their BundleTooLarge status: each
// ships as it is in Previous, and the policies that bind it are checked
// with that version. One Previous doesn't have isn't held.
//
// A held policy (Hold) whose previous version doesn't compile with the
// rule sets of its namespace that changed holds them too: they ship as
// they were. A ClusterWAFRuleSet is never held for a policy: when the
// previous version doesn't compile with one that changed, the policy is
// left out, and its status says so.
HoldRuleSets map[string]string
}
Input is the cluster state to resolve.
type Result ¶
type Result struct {
// Policies sorted by id; RuleSets are the ones they use, sorted by id.
Policies []*bundlev1.Policy
RuleSets []*bundlev1.RuleSet
// PolicyStatus is keyed by the WAFPolicy.
PolicyStatus map[types.NamespacedName]Status
// RuleSetStatus is keyed by RuleSet id (RuleSetID), for every rule set.
RuleSetStatus map[string]Status
}
Result is what goes into the bundle, and the status of each object.