Skip to content

feat(proxy): send PROXY protocol v2 on TCP routes that ask for it - #238

Merged
vishr merged 3 commits into
mainfrom
feat/tcp-proxy-protocol
Nov 25, 2026
Merged

vishr merged 3 commits into
mainfrom
feat/tcp-proxy-protocol

Conversation

@vishr

@vishr vishr commented Nov 25, 2026

Copy link
Copy Markdown
Member

What this changes

Adds a TCP route field, proxyProtocol: 2. With it, the managed proxy writes a PROXY protocol v2 header naming the client at the start of each connection. Without it, a TCP route (including TLS passthrough) shows the backend the proxy as the peer of every client, so per-address limits are shared by all clients and nothing carries the real address. The first user is a TLS-passthrough mTLS device endpoint whose server now reads PROXY v2 from a trusted proxy.

routes:
  - {hostname: device.example.com, port: 7581, protocol: tcp, tls: passthrough, proxyProtocol: 2}
  • Spec (internal/app): Route.ProxyProtocol (proxy_protocol, authored as proxyProtocol). The loader accepts only 2, only on protocol: tcp (an HTTP route already forwards X-Forwarded-For) and only with a Onebox-managed proxy. That last rule exists because the managed proxy is what defines the transport the route names. The schema enforces the enum and the tcp requirement. The managed-proxy rule is cross-block, so it is listed in beyondJSONSchema.
  • Labels: the route's service gets traefik.tcp.services.<svc>.loadbalancer.serverstransport=onebox-proxy-protocol-v2, which ob preview shows. The deprecated loadbalancer.proxyprotocol.version is not generated.
  • Discovery (internal/discovery): when a TCP service selects that transport, the generated onebox.yml defines tcp.serversTransports.onebox-proxy-protocol-v2.proxyProtocol.version: 2 and sets serversTransport on the service. Traefik documents this form for v3.7 (the pinned traefik:v3.7), and per-service loadBalancer.proxyProtocol has been deprecated since v3.5.2. Any other transport value is refused, as an unknown scheme already is.
  • Rolling deploys: a transport belongs to the service, not to a server, so old and new containers cannot share a service while they disagree on it. The newest healthy container decides, the same rule discovery uses for routers, and only servers that agree with it stay in the service. When the setting is turned on or off, old containers leave rotation as soon as the first new container is healthy. They never get a header they do not expect, and a new container that requires the header never gets a connection without one.
  • Proxy (internal/proxy): the transport name is reserved in proxy.config dynamic files, as onebox-compress already is.
  • Docs: a new "PROXY protocol on TCP routes" section in the project-file reference, plus the regenerated field reference and schema.

No issue filed. This is the smallest change that lets a Onebox-deployed TCP backend see client addresses. There is no changelog file, so release notes come from the commit.

Why this is correct

  • internal/discovery: tests cover the transport being defined and selected, with the YAML Traefik reads asserted literally. They also cover no transport when the field is unset, enable and disable mid-roll (only agreeing, healthy servers remain, and the transport is defined only when selected), and refusal of an unknown transport label.
  • internal/app: the generated runtime carries the label only on the route that sets it, and never the deprecated label. The canonical form keeps the field. Refusals for an HTTP route, version 1 and proxy.managed: false report routes[0].proxyProtocol. There are four new conformance cases with frozen verdicts, and every existing verdict digest is unchanged, because the field is omitempty and leaves existing projects byte-identical.
  • internal/proxy: a dynamic extension that redefines tcp.serversTransports.onebox-proxy-protocol-v2 is refused.
  • I checked the Traefik reference pages for TCP servers transports (proxyProtocol.version, v1 and v2 supported) and TCP services (loadBalancer.serversTransport). I did not run it against a live Traefik.

Effect on the safety envelope

Existing projects are unaffected: without the field, the labels, the discovery output and the workload revisions do not change. A project that sets it changes what the managed proxy sends to that backend, and only that backend. The new discovery output needs the matching onebox-discovery image, which is pinned to the runner release. No capability moves between "schema accepts" and "binary does", so /docs/reference/capabilities is unchanged.

Checklist

  • just check passes locally (and just ci: lint, govulncheck, actionlint, env-namespace).
  • Tests cover the new behaviour, including the failure paths.
  • Generated documentation is current (just check verifies this).
  • I have accepted the CLA, or will when the bot asks on my first pull request.

Not run: just e2e (Docker suite), or a real deploy against Traefik v3.7. The first real deploy should confirm that the backend receives a v2 header and that openssl s_client still reaches the passthrough backend.

🤖 Generated with Claude Code

vishr and others added 2 commits November 25, 2026 09:30
A TCP route forwards bytes, so the backend sees the proxy as the peer of
every client. Behind TLS passthrough that defeats any per-address limit,
and there is no header to carry the address. The route field
proxyProtocol: 2 makes the managed proxy write a PROXY protocol v2 header
before each connection.

Discovery defines one TCP servers transport, onebox-proxy-protocol-v2,
with proxyProtocol.version 2, and the route's service selects it through
the serverstransport label. That is the form Traefik documents for v3.7;
the per-service loadBalancer.proxyProtocol option is deprecated since
v3.5.2 and is not generated.

The transport is a service setting, so containers that disagree on it
cannot share a service. During a rolling deploy that changes it, the
newest healthy container decides and only agreeing servers stay in the
service, so old containers leave rotation instead of receiving a header
they do not expect.

The field accepts only 2, only on protocol tcp, and only with a managed
proxy, which is what defines the transport it names. The transport name
is reserved in proxy.config dynamic files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Render a release with a TCP passthrough route that sets proxyProtocol: 2,
build discovery's document from the web service's labels, and load it
into the managed proxy's default Traefik image with the file provider. A
busybox backend records its first bytes, which must be a PROXY v2 TCPv4
header. Without the serverstransport label the backend sees the client's
TLS ClientHello instead, so the test fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishr

vishr commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Added an e2e case in 7f1e171: TestTCPRouteSendsProxyProtocolV2 (e2e/proxy_protocol_test.go). It renders a release with a TCP passthrough route that sets proxyProtocol: 2, builds discovery's document from the rendered labels, and loads it into the managed proxy's default Traefik image (traefik:v3.7) via the file provider. A busybox backend records its first bytes, and the test checks they are a PROXY v2 TCPv4 header. With the serverstransport label removed it fails: the backend gets the raw TLS ClientHello (16 03 01 ...).

ONEBOX_E2E=1 go test ./e2e/ -run TestTCPRouteSendsProxyProtocolV2 passes locally, and so does just ci. The "Check" failure here is govulncheck flagging GO-2026-6859 (net/http) against go 1.27.3. It should pass once #239 (Go 1.27.4) is merged and this branch is rebased.

🤖 Generated with Claude Code

@vishr
vishr merged commit 51262df into main Nov 25, 2026
6 checks passed
@vishr
vishr deleted the feat/tcp-proxy-protocol branch November 25, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant