Unreleased documentation. Choose your installed release in the version menu. Features described here may be absent from that release.
Protect Gateway routes¶
Attach a HAProxyRoutePolicy to an HTTPRoute or GRPCRoute rule to restrict client
addresses, authenticate requests, share a rate limit across the fleet, select a
web application firewall (WAF) policy, or cache HTTP responses. Install HAPTIC and
the Gateway API CRDs first. This example assumes an HTTPS Gateway named public
and a Service named api on port 8080 in namespace apps.
Require an API key¶
-
Create the credential Secret.
-
Make the credentials immutable.
-
Create the policy.
-
Attach the policy to a route rule.
kubectl apply -f - <<'YAML' apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: api namespace: apps spec: parentRefs: - name: public hostnames: - api.example.com rules: - matches: - path: type: PathPrefix value: / filters: - type: ExtensionRef extensionRef: group: haproxy-haptic.org kind: HAProxyRoutePolicy name: api-access backendRefs: - name: api port: 8080 YAML -
Inspect the route conditions.
For the
publicparent, check thatAcceptedandResolvedRefsareTrue. If either isFalse, read its message before testing requests. -
Test authentication through the Gateway's HTTPS address.
DNS for
api.example.commust point to the Gateway, and its certificate must cover that hostname. In the same shell where you generatedkey, run:The first request returns 401. The second reaches your
apiService.
The policy and its credential Secret must share the route's namespace. Requests
without a valid X-API-Key receive 401. The authenticated request forwards
X-Authenticated-Consumer: example-client; a caller can't supply its own value.
Restrict client networks¶
-
Allow a private network and a virtual private network range on the existing policy.
kubectl patch haproxyroutepolicy api-access -n apps --type=merge \ -p '{"spec":{"sourceAddress":{"allow":["10.0.0.0/8","100.64.0.0/10"]}}}'Clients outside either range receive 403. Authentication and other configured policy checks still apply to admitted clients.
-
Create an immutable ConfigMap when you want to version the lists separately.
kubectl apply -f - <<'YAML' apiVersion: v1 kind: ConfigMap metadata: name: api-networks-v1 namespace: apps immutable: true data: source-address.yaml: | allow: [10.0.0.0/8, 100.64.0.0/10] deny: [100.64.0.0/16] YAMLThe deny list takes precedence when an address matches both lists.
-
Replace the inline list with the ConfigMap reference.
-
Create the next version with its new lists.
-
Change the policy reference.
Admission rejects invalid CIDRs and unavailable references. If a referenced ConfigMap is deleted or replaced by a mutable or malformed one, affected rules return 503 while valid sibling rules continue serving. Restore a valid immutable ConfigMap or change the reference to recover. See Source address for the field reference.
Rotate credentials¶
-
Create the replacement Secret.
-
Make the replacement immutable.
-
Change the policy reference.
For an attached policy, admission validates the replacement before accepting the reference change. Keep the previous Secret until every policy has moved to the replacement. For an overlap window, include both old and new API keys in the replacement, then publish another version containing only the new keys after clients have switched.
Add a shared rate limit¶
-
Enable the shared rate-limit infrastructure on the existing release.
-
Add a consumer budget to the policy.
Every rule that references apps/api-access shares this budget across HAProxy
replicas. Each authenticated consumer has its own budget. Requests without a
consumer identity fail authentication before quota enforcement.
Add WAF inspection¶
-
Configure a WAF catalog in your release's values file.
spoaHub: plugins: coraza: enabled: true controller: config: templatingSettings: extraContext: waf: policies: inline: api-headers: enforcement: deny requestBody: mode: noneApply these settings through your existing Helm or GitOps release workflow. See WAF policies for catalog sources and body inspection.
-
Select the catalog entry.
GRPCRoute supports header and request metadata inspection with mode: none.
Policies that buffer request bodies are rejected for GRPCRoute because a stream
may never complete its body.
Rotate a namespace WAF catalog¶
Enable controller.config.templatingSettings.extraContext.waf.policies.selfService.enabled
in your release values and apply the change through your existing release workflow.
The following example uses the api-access policy created above.
-
Create an immutable catalog version.
-
Select the new catalog.
-
Create the next version with its new policy settings.
-
Update the reference.
Admission validates the new selection against every attached route. Rejected
changes leave the old reference in place. Catalog creation alone doesn't change
traffic. Keep the previous version while any policy references it; deleting a
referenced catalog makes those rules return 503. Roll back by changing the
reference to api-waf-v1.
Kubernetes rejects edits to immutable catalog data. Create a new catalog and change the policy reference for each update.
Recover an invalid policy¶
Inspect the route conditions and Events, then repair the named policy or
dependency. A missing policy, malformed credential, or unavailable enforcement
component denies requests to the affected rule with 503. Valid sibling rules
continue serving; PartiallyInvalid identifies a route with both valid and
invalid rules. Admission rejects proposed changes that would introduce these
failures.
The policy reference lists all settings, including JWT verification and private caching.