Skip to content

Security: adevinta/ingress-allowlisting-controller

Security

docs/security.md

Security considerations

Gateway vs HTTPRoute allowlisting — do not mix (Istio)

The Gateway controller creates an AuthorizationPolicy with action: ALLOW targeting the Gateway directly — L4-level protection (IP-only, no hostname matching).

The HTTPRoute controller creates AuthorizationPolicy resources scoped per-hostname — L7-level protection.

Istio evaluates multiple ALLOW policies with OR logic. A request is allowed if it matches ANY ALLOW policy targeting that resource:

Request from 5.5.5.5 → app.example.com

Gateway AP:   ALLOW from [10.0.0.0/8]                        → no match
HTTPRoute AP: ALLOW from [5.5.5.5/32] host app.example.com   → match → ALLOWED

The HTTPRoute AP bypasses the Gateway AP entirely. Do not annotate both a Gateway and its HTTPRoutes. Pick one level:

  • Gateway-level — uniform allowlist for all traffic through the gateway, regardless of hostname.
  • HTTPRoute-level — per-route control with different CIDRs per service.

Protecting a cross-namespace Gateway with a DENY policy (Istio)

When using HTTPRoute-level allowlisting on a cross-namespace gateway, each HTTPRoute produces an ALLOW policy scoped to its hostnames. Any hostname without an ALLOW policy defaults to Istio's implicit deny — unless another policy creates a gap.

Add an explicit DENY policy to block anything not matching expected hostname patterns:

apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: protect-gateway-hostnames
  namespace: infra
spec:
  action: DENY
  rules:
  - to:
    - operation:
        notHosts:
        - '*.public.ns-staging00.example.com'
        - '*.public.ns-staging01.example.com'
  targetRefs:
  - group: gateway.networking.k8s.io
    kind: Gateway
    name: cross-namespace-gateway

DENY rules take precedence over all ALLOW rules in Istio — this ensures traffic to unexpected hostnames is blocked even if an ALLOW policy is misconfigured or overly broad.

This protects tenants from each other only if each namespace has its own subdomain, as in the example. With one wildcard domain shared by all namespaces (notHosts: ['*.example.com']), it blocks hosts outside the domain, but nothing between the tenants inside it. See below.


Restricting which namespaces can attach to a cross-namespace Gateway

A cross-namespace Gateway accepting routes from arbitrary namespaces is a lateral movement risk. Restrict attachment using the Gateway's allowedRoutes listener configuration:

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: cross-namespace-gateway
  namespace: infra
spec:
  gatewayClassName: istio
  listeners:
  - name: http
    port: 80
    protocol: HTTP
    allowedRoutes:
      namespaces:
        from: Selector
        selector:
          matchLabels:
            cross-gateway-access: "true"

Only namespaces with cross-gateway-access: "true" can attach HTTPRoutes. All other routes are rejected by the Gateway controller (Accepted=False) and no traffic flows regardless of any AuthorizationPolicy that may exist.

allowedRoutes is the trust boundary for allowlists (Istio). Every namespace that a listener lets attach can open any hostname of that listener to any CIDRs. Its route lists the hostname (or a wildcard such as *.example.com), its CIDRs object lists the CIDRs (inline spec.cidrs skip the breadth limit, so 0.0.0.0/0 is accepted), and the controller writes an ALLOW for them on the Gateway. Istio ORs ALLOW policies, so this opens the hostname whatever the allowlist of the namespace that serves it says. Gateway API still sends the traffic to that namespace's route. Nobody's traffic is taken over, but its allowlist no longer protects it. On a listener without hostname, or with one wildcard hostname shared by all namespaces, that means every hostname of every namespace on it.

This is not something the controller can check: it doesn't know which namespaces trust each other, and some clusters share hostnames between namespaces on purpose. So:

  • Namespaces run by the same people as the Gateway can share a listener: they are trusted like the Gateway owner anyway.
  • Tenants who don't trust each other need a listener each, with a hostname for their subdomain and allowedRoutes for their namespace. The controller then gives each route only the hostnames of its listener (see Gateway API — HTTPRoute). Or check HTTPRoute hostnames at admission (e.g. Gatekeeper or a ValidatingAdmissionPolicy, against a hostname list per namespace). A constraint that covers only Ingress doesn't cover HTTPRoutes.
  • --httproute-label-selector is not a boundary. It only filters what the controller caches. If tenants set the label on their own routes, every tenant can opt in.

Traefik HTTPRoutes are not affected: their Middleware is on the route's own rules, so it can only narrow that route's traffic. Ingress, Service and NetworkPolicy allowlists are on the object itself.

Defence in depth — combine all three layers:

  1. Namespace label selector on the Gateway listener — controls who can attach, and so who is trusted to open hostnames of that listener (see above)
  2. HTTPRoute-level ALLOW policies — add the IPs that can reach each service; on a shared listener, any namespace attached to it can add IPs for any of its hostnames
  3. Gateway-level DENY policy on unexpected hostnames — prevents gaps from missing ALLOW policies; between tenants only with a subdomain per namespace

AWS: preserving client IP for IP-based filtering (Istio)

AuthorizationPolicy rules match on remoteIpBlocks — this requires the original client IP to reach the Istio proxy. On AWS, NLBs replace the source IP with the LB's own address unless Proxy Protocol is enabled.

Without this, all requests appear to come from the load balancer's IP and no allowlist rule matches correctly — making the allowlist useless.

Solution: Proxy Protocol

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: my-gateway
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
    proxy.istio.io/config: '{"gatewayTopology": {"proxyProtocol": {}}}'

Both annotations are required — the first enables Proxy Protocol on the AWS NLB, the second tells Envoy to parse the header and extract the real client IP for remoteIpBlocks matching.

Which IP is checked: X-Forwarded-For and numTrustedProxies

remoteIpBlocks is matched against the client IP as Envoy on the gateway determines it, not always the IP of the TCP connection. That depends on the gateway's numTrustedProxies (gatewayTopology.numTrustedProxies in proxy.istio.io/config, or mesh-wide in meshConfig.defaultConfig). Envoy trusts that many entries from the right of the X-Forwarded-For header:

numTrustedProxies Checked IP
0 (the default) the TCP peer, or the PROXY protocol address. X-Forwarded-For is ignored for this.
the number of proxies in front that add to X-Forwarded-For the real client IP
higher than that an IP the client wrote itself. A client sends X-Forwarded-For: <an allowlisted IP> and passes the allowlist.
lower than that a proxy's IP. Legitimate clients are refused, or, if the proxy's range is allowlisted, everyone gets in.

The controller only writes the CIDRs; which IP they are compared with is gateway configuration, and the controller can't see or check it.

  • Recommended: an NLB with Proxy Protocol as above, and numTrustedProxies left at 0. The real client IP is checked, and X-Forwarded-For can't be spoofed.
  • Behind L7 proxies or a CDN that add X-Forwarded-For: set numTrustedProxies to exactly the number of those hops, and make sure nothing can reach the gateway around them.
  • Another hop in front of the gateway (an internal load balancer behind a CDN or proxy): without Proxy Protocol from the client side or numTrustedProxies, the checked IP is that hop's. Allowlist the hop's ranges (e.g. the CDN's), not the end users'.

Check it from an IP that is not allowlisted. The forged header must not help:

curl -s -o /dev/null -w '%{http_code}\n' -H 'X-Forwarded-For: <an allowlisted IP>' https://<host>/
# expected: 403

A 200 means the gateway trusts X-Forwarded-For from clients, so anyone can pass the allowlist.


Merge mode security warning

Merge mode (ipam.adevinta.com/merge) is designed for staging environments only. Any namespace in the cluster that sets the same merge key and points to the same gateway is pulled into the shared AuthorizationPolicy. A team controlling a different namespace could add their application's hostnames and CIDRs to your policy, potentially opening access to their service through your allowlist.

Do not use merge mode in production.


Stale cross-namespace resources

Kubernetes does not support cross-namespace owner references, so cross-namespace AuthorizationPolicy resources cannot be garbage-collected automatically when their HTTPRoute is deleted.

Which resources are the controller's: every AuthorizationPolicy and Traefik Middleware it creates carries these labels, <prefix> being --annotation-prefix:

Label Value
app.kubernetes.io/managed-by ingress-allowlisting-controller
<prefix>/owner-kind Gateway, HTTPRoute or Merged
<prefix>/owner-namespace, <prefix>/owner-name the owner (MERGED and the merge key for a merge group)

The labels under the prefix are what makes a resource the controller's, so two instances with different prefixes don't touch each other's resources.

Names are predictable, so a resource with the same name can already exist: another instance's, one an admin or a tenant created, or, in one namespace, another route's or Gateway's (see same-namespace names). The controller only writes or deletes a resource with its labels, for the same owner. Anything else under that name is left as it is: the object that needs it gets no allowlist, a Warning Event AllowlistPolicyConflict and a log warning, and the reconcile is not retried. Once the other resource is removed or renamed, the next reconcile of the object (a change to it or to its CIDRs) writes the allowlist. For the same reason, a route keeps its filter to a Middleware named like the route that isn't the controller's.

Automatic cleanup on restart: every time the controller starts it runs a one-time sweep over the HTTPRoute resources it owns. Any resource whose owner no longer exists is deleted. Restarting the controller is sufficient to clean up orphans.

Hard reset (here for the default prefix; only this instance's resources):

kubectl delete authorizationpolicies -A -l app.kubernetes.io/managed-by=ingress-allowlisting-controller,ipam.adevinta.com/owner-name
kubectl rollout restart deployment/ingress-allowlisting-controller -n <namespace>

Declarative tooling conflict — intermittent allowlist disable

Applies to: Traefik Middleware only.

The Traefik writer mutates spec.rules[].filters at runtime by injecting an extensionRef entry pointing to the Middleware. If the HTTPRoute is managed by a declarative tool — ArgoCD, Flux, a Helm release, or any CI/CD pipeline that applies manifests — the tool may detect this field as drift from the declared manifest and revert it on the next reconcile or helm upgrade.

Note: In practice, most modern tools do not revert fields that are absent from the declared manifest. Verify the behaviour of your specific tooling and version.

The result is a recurring security gap: the allowlist filter is absent and the route is unprotected during every reconcile window. Because reconciles can be triggered automatically (by a push, a webhook, or a scheduled refresh), the firewall can be disabled frequently and silently.

This is not a theoretical edge case — any team using declarative tooling to manage HTTPRoutes with Traefik will hit this loop unless an ignore rule is configured.

Fix: configure your tooling to ignore the controller-injected extensionRef filters. See Declarative tooling conflict in the Gateway API docs for the exact configuration for ArgoCD, Flux, and Helm.


Secrets sent as headers (headersFrom)

A remote CIDR source can send the keys of a Secret or ConfigMap as HTTP headers. Whoever writes a CIDRs or ClusterCIDRs object picks both the Secret and the URL, so without limits it could send any Secret the controller can read to a host of their choosing. The controller therefore:

  • has it off by default (--http-headers-enabled=false): no access to Secrets or ConfigMaps;
  • when it is on, reads only labelled Secrets and ConfigMaps: it reads through its cache, which holds only those matching --secret-label-selector (default <annotation-prefix>/cidr-header-source=true). RBAC can't filter by label and still grants cluster-wide read; the selector is what limits it;
  • when it is on, refuses to start without --cidr-source-allowlist: header values only go to listed origins;
  • lets a CIDRs object read only from its own namespace, and a ClusterCIDRs only from --cluster-cidrs-headers-namespace (default: the controller's namespace), never kube-system or another tenant's namespace;
  • drops the headers on a redirect to another origin, which Go doesn't do for custom headers.

Label only the Secrets meant as headers, or list the header keys in headersFrom[].keys so the other keys of a shared Secret are not sent. Keep them in namespaces whose writers you trust with them: anyone who can create a CIDRs object in a namespace can send its labelled Secrets to an allowlisted origin.

See Headers from Secrets and ConfigMaps.

Breadth limit on remote CIDR sources

Applies to: CIDRs/ClusterCIDRs objects with a remote location.uri source.

A remote source can silently widen an allowlist to the entire internet if it breaks, changes format, or is fed a bad transform expression. The controller requires every externally-fetched prefix to be no wider than a minimum mask — /8 for IPv4 and /20 for IPv6 by default. If any entry is wider (0.0.0.0/0, any /1, /3, …), the fetch is rejected wholesale, the object keeps its last-known-good status, and the breach is logged.

This is a guardrail against human mistakes, not a security control. We trust the sources we fetch from (AWS, Akamai, …); a well-tailored single /32 from a trusted feed is allowed by design, and there is no defending against a source you have chosen to trust. What the check prevents is the common accident where a feed breaks, a transform expression misfires, or a feed is misconfigured to return 0.0.0.0/0 — and the firewall effectively turns off without anyone noticing. Treat it as blast-radius containment for misconfiguration, alongside the trust you already place in the source.

Notes:

  • It is a per-entry mask check, not an address-count sum. It catches every single over-broad block (including the /1//3 splits, whose masks are themselves too wide) but does not add up coverage across many narrow blocks — an accepted trade-off for a fast, allocation-light check.
  • It applies only to remotely fetched CIDRs. Inline spec.cidrs is trusted; an admin may deliberately allow 0.0.0.0/0 there.
  • Known gap — deprecated v4-in-v6 notations. A prefix is scored by its IPv6 mask width, and only the v4-mapped form (::ffff:0.0.0.0/96) is re-scored in IPv4 space. The deprecated 6to4 (2002::/16) and IPv4-compatible (::/96) forms are not, so a block like ::/96 or 2002:c000::/20 reads as a narrow IPv6 prefix and passes even though it encodes a broad IPv4 range. ::/0 and ::/16-scale blunders are still caught (their IPv6 mask is below the limit). This is left as-is on purpose: both notations are deprecated (RFC 7526, RFC 4291) and no trusted feed emits them, so it is not a realistic human mistake.
  • Defaults are calibrated against real feeds: the widest prefix observed is /11 for IPv4 (AWS ip-ranges.json and Akamai) and /24 for IPv6 (Akamai; AWS tops out at /32), so the /8 and /20 defaults do not reject legitimate feeds and keep headroom above the widest real block.

See CIDRs — Breadth limit on remote sources for the full behaviour.


Delay for new CIDRs from a remote source (supply chain)

Applies to: CIDRs/ClusterCIDRs objects with a remote location.uri source, when --cidr-source-apply-delay is set (off by default).

The breadth limit doesn't help when a trusted source itself is compromised: its host, the repository a list is kept in, or the CDN in front of it. A narrow /32 added by an attacker passes every check, and without a delay it is in the allowlists at the next fetch.

With --cidr-source-apply-delay=24h (Helm: cidrSource.applyDelay), a CIDR new to the source waits in status.pending for 24 hours from when it was first seen, and is used only if the source still returns it then. That leaves a day to see the change and fix or remove the source.

  • Only additions wait. A CIDR the source removes is taken out right away: delaying a removal would keep access open, possibly for a range that now belongs to someone else.
  • But the list never goes empty. If a source replaces all its CIDRs with new ones, the update is refused and the last CIDRs stay until the new ones are due, as when a source returns nothing: a bad response must not lock out the traffic it allows. Removing one CIDR out of many is safe; removing all of them at once is more likely a broken feed than a real change.
  • Only changes of the response wait, not changes of the spec. spec.cidrs is written by people with RBAC and checked by the API server, and is used at once. So is a source changed in the spec (location.uri, cel, jsonPath, format), and the first list of a new object. What the delay covers is a change nobody made in the cluster: new content, or a redirect, behind the same uri.
  • So it doesn't protect against someone who can edit the object. Whoever can change location.uri can point it at their own list and have it used at once, as they could with spec.cidrs. Restrict who can write CIDRs and ClusterCIDRs with RBAC, and the origins with --cidr-source-allowlist.
  • A delay only helps if someone looks. Alert on the ingress_allowlisting_controller_cidr_source_pending_cidrs metric, or on the warning the controller logs for each change, and review the CIDRs in status.pending. Unnoticed, the change is used when the delay ends.
  • Legitimate changes wait too. A provider adding a range means clients from it are refused until the delay ends. To allow one at once, add it to spec.cidrs. Pick the delay to match how quickly you can review a change.

See CIDRs — Delaying new CIDRs from a source for the full behaviour.


Resource limits on remote CIDR sources

Applies to: CIDRs/ClusterCIDRs objects with a remote location.uri source.

A remote fetch runs in the controller's single reconcile worker. A source that never answers, streams an enormous body, or is combined with a very expensive CEL expression would block every allowlist update in the cluster, or exhaust the pod's memory. The controller therefore applies a 30 s timeout to connecting and reading the response, a 5 MiB cap on the response body, a cost limit on CEL evaluation, and, because a JSONPath expression has no cost limit and the timeout doesn't interrupt processing, a depth limit of 32 on the response and checks on the expression (recursive descent .. at most once, bounded unions). A memory guard covers what the size cap can't: a 5 MiB body of tiny values ([[],[],…]) grows the heap by about 500 MiB, so the decoder stops when processing needs more than 30 times the cap, or half of the memory still free under GOMEMLIMIT (set by the chart from the container's limit), whichever is smaller. It works with a small memory limit too, and without a limit only the 30 times applies. When one is hit, the fetch fails, the object keeps its last-known-good status, and the reason is shown in the object's condition. The limits on the timeout, size and CEL cost are configurable with the --cidr-source-* flags (Helm: cidrSource); see CIDRs — Configuring the guardrails.

The limits above are guardrails, not access control. Where location.uri may point is controlled separately:

  • Destination guard (on by default). Connections to non-public addresses — loopback, private, link-local including the cloud metadata address, carrier-grade NAT, and the IPv6 blocks that are not globally reachable (local-use NAT64, Teredo, documentation ranges) — are refused, checked on the address actually dialled. Use --cidr-source-allow-private-destinations only for feeds that are really internal. It doesn't know your cluster's own address space. On a cluster whose pods or nodes have global unicast IPv6 addresses (for example EKS in IPv6 mode), those addresses pass as public, so with an empty origin allowlist anyone who can create a CIDRs object can make the controller send a GET to them, and read back whether it answered. Set the origin allowlist there.
  • Origin allowlist (optional). --cidr-source-allowlist restricts fetches to the listed scheme://host[:port] origins, with exact host matching and no wildcards. When it is empty, any public host is allowed, and the controller logs a warning at startup. Set it to the feeds you actually use.

Without an allowlist, anyone who can create a CIDRs or ClusterCIDRs object can still make the controller request any public URL. Only the values in the response that are CIDRs or IP addresses reach status.cidrs, and the text of an error names a type or a status code, never a fetched value. The text of a CEL expression that fails on a response is not shown at all: the condition says only that it failed, and the details go to the controller log (they can quote the response, so that log can hold parts of one).

This does not make a response unreadable for whoever writes the object. The same person writes the CEL expression, and an expression can turn other parts of the response into addresses that pass the checks and reach status.cidrs. So treat everything the controller can reach and fetch with a GET as readable by whoever can create a CIDRs object: that matters for hosts that trust the controller's source address (for example the cluster's NAT egress address), and, with global unicast IPv6 pod networks or --cidr-source-allow-private-destinations, for internal endpoints. The origin allowlist is the control that limits it: with it set, the author can only read the hosts the admin listed. Treat creating these objects as a privileged operation. See CIDRs — Restricting where sources can be fetched from.

See CIDRs — Resource limits on remote sources.


ClusterCIDRs' CIDRs are readable by every namespace

Applies to: every ClusterCIDRs object.

A ClusterCIDRs can be named in the annotations of any namespace's objects: nothing limits which namespaces may reference it. The controller then writes its CIDRs into objects that the users of that namespace can read:

Annotated object Where the CIDRs show up, in the same namespace
Ingress the nginx.ingress.kubernetes.io/whitelist-source-range annotation
Service spec.loadBalancerSourceRanges
NetworkPolicy the ipBlock entries
HTTPRoute (Traefik) the Middleware's ipAllowList.sourceRange
HTTPRoute or Gateway (Istio), Gateway in the same namespace the AuthorizationPolicy's remoteIpBlocks

So anyone who can create one of these objects in some namespace can read the CIDRs of any ClusterCIDRs: annotate an object with its name, then read the object back. A name that doesn't exist gives deny-all and an AllowlistGroupNotFound Event, so names can be guessed too.

The <release>-clustercidrs-viewer ClusterRole, which the chart doesn't add to view, still keeps the objects themselves from other users: the feed URI, the CEL or JSONPath, the headersFrom references, and the status conditions. It doesn't keep the CIDRs from them.

Treat a ClusterCIDRs' CIDRs as readable by every namespace allowed to create these objects. For CIDRs only some namespaces may see, use CIDRs objects in those namespaces: a CIDRs object can only be referenced from its own namespace.


What the controller can't check

  • A proxy hides the destination. With HTTP_PROXY/HTTPS_PROXY set, the destination guard checks the connection to the proxy, not where the proxy connects: a source URL that resolves to a private address is then reached through the proxy. The origin allowlist is still checked against the URL. See CIDRs — Restricting where sources can be fetched from.
  • Namespace labels are read with a delay. For a listener with allowedRoutes.namespaces: Selector, the controller reads the route namespace's labels without a watch and keeps them for 10 minutes. A label change reaches the allowlists at the route's first reconcile once the kept labels have expired: up to 10 minutes later, or later still if nothing reconciles the route meanwhile. Until then, a namespace that lost the label keeps its routes' allowlists on that Gateway, although the Gateway stops routing for them at once. See HTTPRoute → Istio AuthorizationPolicy.
  • Only spec.cidrs is checked when the object is written, and only its form. The CRD refuses an entry that isn't a CIDR or an IP address (10.0.0, 192.0.2.0/33, ::ffff:10.0.0.1), so kubectl apply fails with the entry's index. Whether a CIDR is the one meant, or too wide, is not checked: inline CIDRs skip the breadth limit, so 0.0.0.0/0 is accepted. CIDRs from a remote source are checked by the controller after the fetch (see Resolved CIDR behaviour).

There aren't any published security advisories