The ipAllowList middleware in Traefik v3 (renamed from ipWhiteList in v2) restricts a route to specific source IP ranges. It is the right primitive for restricting a dashboard to the office VPN, an admin path to a bastion, or a webhook endpoint to a partner’s egress CIDR. The trap is correctly identifying the source IP — behind a CDN or a load balancer the immediate peer is the upstream, not the user, and getting ipStrategy wrong either blocks legitimate traffic or admits spoofed traffic. This article covers both halves.
How to verify
# A request from an allowed IP returns 2xx
curl -sI https://admin.example.com/ | head -1
# A request from a denied IP returns 403
curl -sI --interface 10.10.10.10 https://admin.example.com/ | head -1
# Confirm the middleware sees the right client IP
curl -sI https://admin.example.com/ -H "X-Forwarded-For: 203.0.113.1, 10.0.0.1" | head -1
# Without trustedIPs, Traefik takes peer IP; with trustedIPs, it walks the chain
What’s happening
ipAllowList matches on a source IP and admits or denies based on a CIDR list. The source IP comes from one of two places: the immediate TCP peer (the default), or one of the addresses in X-Forwarded-For walked from the right. The ipStrategy.depth setting says “how many entries from the right of X-Forwarded-For to skip before believing the value”. Behind one trusted hop (a single LB or CDN), depth: 1. Behind two trusted hops (e.g. Cloudflare → ALB → Traefik), depth: 2.
The peer-IP default is safe but only correct when Traefik is the first hop. The moment any proxy sits in front, the peer is the proxy, not the client — every check sees the proxy IP and either allows everyone or no one. Switching to ipStrategy.depth fixes this, but only if the trust boundary is set correctly.
The trust boundary lives on the entrypoint, not the middleware. forwardedHeaders.trustedIPs is the list of upstream networks whose forwarded headers Traefik will believe. Anything outside that list has its forwarded headers stripped before the middleware runs. Skip this and any internet client can add X-Forwarded-For: 192.168.1.1 and bypass an internal allow-list.
There is also ipStrategy.excludedIPs which pops specific IPs out of consideration — useful when one of the trusted hops sometimes appears in the forwarded chain itself.
The procedure
-
Direct edge (Traefik on the internet, no upstream). Just match on peer IP.
http: middlewares: office-only: ipAllowList: sourceRange: - "203.0.113.0/24" - "198.51.100.42/32" - "2001:db8::/32" routers: admin: rule: "Host(`admin.example.com`)" entryPoints: [websecure] service: admin-backend middlewares: [office-only] -
Behind one trusted hop (single load balancer in front of Traefik). Set
forwardedHeaders.trustedIPson the entrypoint anddepth: 1on the middleware.entryPoints: websecure: address: ":443" forwardedHeaders: trustedIPs: - "10.0.0.0/8" http: middlewares: office-only: ipAllowList: sourceRange: - "203.0.113.0/24" ipStrategy: depth: 1 -
Behind two trusted hops (CDN + load balancer). Increment
depth.entryPoints: websecure: address: ":443" forwardedHeaders: trustedIPs: - "10.0.0.0/8" # internal LB - "173.245.48.0/20" # Cloudflare ranges - "103.21.244.0/22" # ... rest of Cloudflare CIDRs http: middlewares: office-only: ipAllowList: sourceRange: - "203.0.113.0/24" ipStrategy: depth: 2 -
When the CDN injects a single-IP header like Cloudflare’s
CF-Connecting-IP, you can avoidX-Forwarded-Forentirely by routing on that header — but Traefik’sipAllowListonly reads source IPs, so you would need a plugin or a custom approach. The cleaner path: use the CDN’s own IP-allow-list features upstream and let Traefik trust everything from the CDN. -
Kubernetes IngressRoute equivalent.
apiVersion: traefik.io/v1alpha1 kind: Middleware metadata: name: office-only namespace: my-app spec: ipAllowList: sourceRange: - "203.0.113.0/24" ipStrategy: depth: 1 --- apiVersion: traefik.io/v1alpha1 kind: IngressRoute metadata: name: admin namespace: my-app spec: entryPoints: [websecure] routes: - match: Host(`admin.example.com`) kind: Rule middlewares: - name: office-only services: - name: admin port: 8080 -
TCP routes use the same primitive name with a slightly different config. For raw TCP, there is no Forwarded-For — only peer IP.
tcp: middlewares: office-only-tcp: ipAllowList: sourceRange: - "203.0.113.0/24"
Common pitfalls
- Setting an allow-list without
trustedIPson the entrypoint when Traefik sits behind a proxy — the middleware sees the proxy IP, not the client, and admits everyone or no one. - Listing all of Cloudflare’s IP ranges as
trustedIPsbut forgetting to update them when Cloudflare adds new ranges — a fresh Cloudflare IP shows up as the immediate peer and the middleware refuses to walk the chain. - Forgetting IPv6 — modern clients are dual-stack; an IPv4-only allow-list silently drops IPv6 traffic from your office.
- Using a /24 in development and forgetting to tighten it before production — the dashboard’s allow-list inherited from staging is wider than intended.
- Putting the allow-list middleware after a middleware that has already side-effected (set headers, started compression) — order matters; the allow-list should be early in the chain.
IP allow-listing is one of the highest-confidence guardrails at the edge, but only if the trust topology is documented and the trustedIPs list rotates with the upstreams. That documentation and rotation discipline is part of how Stack Harbor runs managed operations. For country-level filtering see traefik-geoip-blocking.