Repository navigation
feat(proxy): add proxy.trustedProxies for forwarded-header trust - #241
Merged
Merged
Conversation
Behind a CDN or another reverse proxy, the managed Traefik sees the front proxy as every request's peer and overwrites the X-Forwarded-For it wrote, so applications cannot learn the client address. proxy.trustedProxies lists the front proxy's CIDR prefixes, and Onebox renders them as forwardedHeaders.trustedIPs on every entrypoint in its generated static configuration: web, websecure and each proxy.entrypoints listener. Entries must be canonical IPv4 or IPv6 prefixes. Bare addresses, prefixes with host bits set (the error names the canonical form), IPv4-mapped IPv6 prefixes and 0.0.0.0/0 or ::/0 are refused; the list is sorted and deduplicated so its order never changes the configuration. The field requires a Onebox-managed proxy and cannot be combined with a project-owned traefik.yml, mirroring proxy.dnsChallenge. An absent or empty list renders the static configuration byte for byte as before, pinned by digest, so upgrading does not restart anyone's proxy. Declaring it changes only the configuration identity, which the plan reports as "restart Traefik (configuration changed)". ob preview prints the effective list. An opt-in e2e test runs the real Traefik image and checks that a trusted peer keeps its X-Forwarded-For while an untrusted one has it replaced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refusing /0 alone let a pair such as 0.0.0.0/1 and 128.0.0.0/1 trust every peer. Trusted prefixes must now be at least /8 for IPv4 and /16 for IPv6; no CDN publishes ranges anywhere near that wide. The no-managed-proxy error blamed an operator-owned proxy even when the cause was that no route is declared or that proxy.kind is none; each case now says what it is and what to do. The docs now state that trusted peers also control X-Forwarded-Proto and X-Forwarded-Host, including that X-Forwarded-Proto: https on the web entrypoint suppresses the HTTPS redirect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Adds
proxy.trustedProxies: [CIDR, ...]to the project file. When a CDN or another reverse proxy sits in front of the managed Traefik, every request's peer is the front proxy, and Traefik overwrites theX-Forwarded-Forthe front proxy wrote. Listing the front proxy's prefixes makes the managed proxy keep those forwarded headers instead.Rendering: for the Onebox-rendered static configuration, the list is written as
entryPoints.<name>.forwardedHeaders.trustedIPson every entrypoint:web,websecure, and eachproxy.entrypointslistener. This covers both the default-managed case andproxy.configdirectories that hold only dynamic files.Validation: each entry goes through
netip.ParsePrefixand must be in canonical masked form.10.20.0.5/24is refused with "write 10.20.0.0/24". IPv4 and IPv6 are accepted. These are refused:/32or/128)0.0.0.0/0and::/0::ffff:0:0/96matches every IPv4 peer under Go'snetcomparisonThe list is sorted (IPv4 first) and deduplicated in the spec, so the order it is written in never changes the bytes.
Conflicts: using the field without a managed proxy is an error. That covers
proxy.managed: false,kind: None, and projects with no routes and no explicitmanaged: true. Using it with a project-ownedtraefik.yml/traefik.yamlinproxy.configis also an error, mirroringdnsChallenge.Preview:
ob previewprints# proxy trustedProxies <effective list>: …. The JSON envelope gainsproxy.trustedProxies. Both appear only when the field is declared, so preview output without it is unchanged.Docs: generated field reference, plus a new "Trusted proxies in front of the managed proxy" section next to "PROXY protocol on TCP routes". The section covers:
X-Forwarded-ForX-Forwarded-Forright to leftX-Real-IpExamples use the documentation ranges 192.0.2.0/24 and 2001:db8::/32.
Out of scope: PROXY protocol on entrypoints, an insecure mode, and per-entrypoint lists.
Why this is correct
TestStaticConfigWithoutTrustedProxiesIsUnchangedpins, by sha256, the static config and the proxyIdentity(config and compose) taken frommainbefore this change. Both nil and empty lists reproduce them, so upgrading restarts no one's proxy.TestTrustedProxiesRenderIntoEveryEntrypointcompares the full rendered file, including an additional entrypoint, and parses it back as YAML.Identity.Config; Compose is unchanged, so the change is a restart and not a recreate.TestPlanProxyRestartsTraefikWhenTrustedProxiesChangeshows the plan linerestart Traefik (configuration changed), andunchangedwhen the field is absent.internal/app/trusted_proxies_test.gocovers the canonical-form cases,/0for v4 and v6, bare v4 and v6 addresses, duplicates, sort order, IPv4-mapped, zone, the empty list, the unmanaged/no-proxy conflicts and the authored camelCase spelling. Error paths are checked asspec.proxy.trustedProxies[i].TestTrustedProxiesRefuseProjectOwnedStaticConfigcoverstraefik.ymlandtraefik.yaml.TestPreviewShowsTrustedProxiescovers the text and JSON output, and checks that a project without the field never mentions it.TestTrustedProxiesKeepForwardedHeadersOnlyFromTrustedPeersstages the managed config and runstraefik:v3.7on a fixed-subnet Docker network with a busybox CGI backend.X-Forwarded-For: 203.0.113.7, and the backend sees203.0.113.7, <peer>.<peer>.Ran:
just check(passes),golangci-lint run ./...(0 issues), andONEBOX_E2E=1 go test ./e2e -run TestTrustedProxiesKeepForwardedHeadersOnlyFromTrustedPeers(passes). Not run: the fulljust e2esuite.Effect on the safety envelope
proxy: restart Traefik (configuration changed)plan line.Notes for review:
HostOwnerMismatchError/HostEnvironmentMismatchErrorrefuse any other app or environment before the proxy is staged), andproxycannot be overridden per environment. Two co-hosted apps with different lists therefore can't happen today, and I added no new conflict code. If co-hosting ever arrives, this field must join whatever host-proxy agreement check is built for it.ping: {}without anentryPoint, so Traefik opens its internaltraefikentrypoint on:8080. Aproxy.entrypointslistener on port 8080 then fails to bind. Validation does not reserve 8080 today. It belongs in its own PR.Checklist
just checkpasses locally.just checkverifies this).🤖 Generated with Claude Code