operator/

directory
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0

README

inkwall-operator

The Kubernetes operator (design). It is being built in the milestones of 0004 §11; today it has the API, the validating webhook, and the bundle builder: it compiles WAFPolicy objects and the Ingresses they target into a signed bundle, and reports each policy's Accepted condition, and serves the bundle to the engines over gRPC, reporting Enforced from their acknowledgements.

Path What
api/v1alpha1/ The waf.inkwall.dev/v1alpha1 types: InkwallConfig, WAFPolicy, WAFRuleSet, ClusterWAFRuleSet
config/crd/bases/ The CRDs generated from the types (make generate); don't edit them by hand
config/rbac/, config/webhook/ The operator's RBAC and webhook configuration, generated from markers
config/samples/ One example of each kind
webhook/ The validating webhook and its certificate
manager/ Assembles the operator: controllers, webhooks, probes (../cmd/operator parses flags into it)
internal/resolver/ WAFPolicy + Ingresses + rule sets → bundle policies and Accepted conditions
internal/bundle/ Content hash, versions, ed25519 signing, the bundle and signing key Secrets
internal/controller/ The bundle builder (leader only)
internal/injection/ The engine sidecar, the trust ConfigMap and the RBAC grant
internal/wiring/ Traefik wiring: the Middleware, the Ingress annotation, Programmed
integrations/ The proxies Inkwall knows (Traefik)
internal/distribution/ The BundleService server, engine authentication, engine reports, Enforced
test/fakeengine/ A lightweight engine that speaks the bundle protocol, for tests
test/testenv/ Starts a local API server (envtest) for tests
../cmd/operator The inkwall-operator binary

Trying the API

The CRDs validate objects on their own, without the operator running:

kubectl apply --server-side -f operator/config/crd/bases
kubectl apply --server-side -f operator/config/samples
kubectl get inkwall -A

Validating webhook

The CRD schemas catch malformed objects. The webhook checks what they can't (0004 §3.1):

  • Rule sets (seclang) must compile with the engine's Coraza version, loaded after the Core Rule Set as the engine loads them, so exclusions of CRS rules are checked too. Errors name the line. Only rule directives are allowed (SecRule, SecAction, SecMarker, SecRuleRemoveBy*, SecRuleUpdate*): settings that change the engine as a whole or write files are rejected. Rules read from a ConfigMap are checked when the bundle is built; the webhook warns about that.
  • Policies: skip and exclusion paths must be clean, as the engine's router requires.

Updates that don't change the spec are always accepted, so an object stays editable and deletable. The webhook fails closed for the WAF kinds only (failurePolicy: Fail, 2 s timeout).

Its certificate is self-signed and rotated by the operator (cert-controller): the CA and serving certificate live in the inkwall-operator-webhook-tls Secret, the CA is injected into the webhook configuration, and each replica copies the certificate to its webhook server, so no volume mount is needed. With cert-manager instead, run with --webhook-certs=external.

Bundles

The leader rebuilds the bundle a second after any change to a WAFPolicy, a rule set, a targeted Ingress, a labeled ConfigMap or InkwallConfig, and every 10 minutes. It publishes a new version only when the content changed, signed with the cluster's ed25519 key, in the inkwall-bundle Secret. A policy that can't be resolved keeps its previous version in force and says why in its Accepted condition. Rules read from a ConfigMap need the label waf.inkwall.dev/rules=true.

kubectl get wafpolicy -A            # BUNDLE: the version that contains the current spec
kubectl -n inkwall-system get secret inkwall-bundle -o jsonpath='{.metadata.annotations}'

Engines

Every replica serves the bundle on port 9445 (gRPC, TLS). An engine authenticates with a projected ServiceAccount token for the audience inkwall-operator, and its ServiceAccount must be allowed to get the inkwall-bundle Secret, the same grant it needs to start from that Secret when the operator is down. The operator pushes each new bundle; the engine answers with an ack or a nack, and Enforced on each policy says how many engines run it:

kubectl get wafpolicy web -n web -o jsonpath='{.status.conditions[?(@.type=="Enforced")].message}'
# 3/3 engines on bundle 42

Injection

Traefik pods (app.kubernetes.io/name=traefik) created while the operator runs get the engine as a native sidecar, in bundle mode, connected to the operator; the operator keeps the inkwall-trust ConfigMap in their namespace and grants their ServiceAccount read access to the bundle. Pods that already ran are injected when they restart (kubectl rollout restart). Annotate a pod waf.inkwall.dev/inject: "false" to keep the engine out; --inject=false (chart: injection.enabled) turns injection off.

Wiring

For every Ingress a WAFPolicy targets that Traefik serves, the operator creates an inkwall-waf ForwardAuth Middleware in the namespace and adds it to the Ingress's traefik.ingress.kubernetes.io/router.middlewares annotation (first, keeping your own Middlewares); deleting the policy removes only that entry. Each policy then reports:

kubectl get wafpolicy -A        # READY: True once accepted, wired and enforced by every engine
kubectl -n shop get wafpolicy shop -o jsonpath='{.status.conditions[?(@.type=="Programmed")].message}'

Programmed=False explains what's missing, e.g. PendingRestart with the Traefik pods that need a restart to get the engine.

Changing the API

  1. Edit the types in api/v1alpha1/. Validation is written as kubebuilder markers: OpenAPI constraints and CEL rules (+kubebuilder:validation:XValidation).
  2. Run make generate to regenerate the deepcopy code and the CRDs, and commit both.
  3. Add cases to api/v1alpha1/validation_test.go. make test runs them against a real API server at the oldest supported Kubernetes version (ENVTEST_K8S_VERSION).

Directories

Path Synopsis
api
v1alpha1
Package v1alpha1 holds the Inkwall Kubernetes API (group waf.inkwall.dev): the cluster configuration, the policies app teams attach to their routes, and the rule sets those policies use.
Package v1alpha1 holds the Inkwall Kubernetes API (group waf.inkwall.dev): the cluster configuration, the policies app teams attach to their routes, and the rule sets those policies use.
Package integrations knows the proxies Inkwall wires into (0004 §4.2): how to recognise each one's IngressClass and pods, and which engine adapter its pods use.
Package integrations knows the proxies Inkwall wires into (0004 §4.2): how to recognise each one's IngressClass and pods, and which engine adapter its pods use.
internal
bundle
Package bundle builds, signs and stores policy bundles (0004 §4.6).
Package bundle builds, signs and stores policy bundles (0004 §4.6).
controller
Package controller holds the operator's reconcilers.
Package controller holds the operator's reconcilers.
distribution
Package distribution serves bundles to the engines (0004 §4.7): every operator replica runs the BundleService, pushes each new bundle to its connected engines, and records what they applied.
Package distribution serves bundles to the engines (0004 §4.7): every operator replica runs the BundleService, pushes each new bundle to its connected engines, and records what they applied.
injection
Package injection gets the engine into a proxy's pods (0004 §4.3): a Pod webhook adds it as a native sidecar, and a controller provides what the sidecar needs in the pod's namespace (the trust ConfigMap) and in the operator's (read access to the bundle Secret).
Package injection gets the engine into a proxy's pods (0004 §4.3): a Pod webhook adds it as a native sidecar, and a controller provides what the sidecar needs in the pod's namespace (the trust ConfigMap) and in the operator's (read access to the bundle Secret).
resolver
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.
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.
wiring
Package wiring sends a proxy's protected routes to the engine (0004 §4.4).
Package wiring sends a proxy's protected routes to the engine (0004 §4.4).
Package manager assembles the operator: the controllers and webhooks, in one controller-runtime manager.
Package manager assembles the operator: the controllers and webhooks, in one controller-runtime manager.
test
fakeengine
Package fakeengine is a lightweight engine for operator tests (0004 §9): it speaks the bundle protocol, verifies each bundle's signature and acknowledges it, without inspecting any traffic.
Package fakeengine is a lightweight engine for operator tests (0004 §9): it speaks the bundle protocol, verifies each bundle's signature and acknowledges it, without inspecting any traffic.
testenv
Package testenv starts a local API server (envtest) with the Inkwall CRDs installed, for operator tests.
Package testenv starts a local API server (envtest) with the Inkwall CRDs installed, for operator tests.
Package webhook holds the operator's admission webhooks.
Package webhook holds the operator's admission webhooks.

Jump to

Keyboard shortcuts

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