Skip to content

gw: implement proxy protocol with server-side control#649

Closed
kvinwang wants to merge 1 commit intomasterfrom
feat/gateway-proxy-protocol
Closed

gw: implement proxy protocol with server-side control#649
kvinwang wants to merge 1 commit intomasterfrom
feat/gateway-proxy-protocol

Conversation

@kvinwang
Copy link
Copy Markdown
Collaborator

Summary

Supersedes #361. Adds PROXY protocol support to the gateway with a security fix:

  • Inbound PP (inbound_pp_enabled): reads PP headers from upstream load balancers (e.g. Cloudflare)
  • Outbound PP (outbound_pp_enabled): forwards PP headers to backend apps

Security fix vs #361

The original PR used a p suffix in the SNI subdomain (e.g. app-8080p.domain.com) to toggle outbound PP per-connection. This is client-controlled and introduces a source address spoofing vulnerability: a client can connect to a PP-expecting backend port without the p suffix, bypassing the PP header and letting the backend misinterpret raw TCP data or fall back to the direct connection address. Both PP flags are now server-side config only.

Changes

  • New gateway/src/pp.rs module: PP header parsing (v1/v2) and synthetic header creation
  • Config: inbound_pp_enabled, outbound_pp_enabled, pp_header timeout
  • PP header is read (or synthesized) at connection start, then forwarded on outbound if enabled
  • No p suffix in SNI parsing — PP decision is purely server-side

Test plan

  • cargo check -p dstack-gateway passes
  • All 8 existing gateway tests pass
  • Manual test with inbound_pp_enabled = true behind a PP-aware proxy
  • Manual test with outbound_pp_enabled = true with a PP-aware backend

Add PROXY protocol support to the gateway with two server-side config
options instead of client-controlled SNI suffixes:

- inbound_pp_enabled: read PP headers from upstream load balancers
- outbound_pp_enabled: send PP headers to backend apps

The original PR#361 used a 'p' suffix in the SNI subdomain to toggle
outbound PP per-connection. This is a security flaw: a client could
connect to a PP-expecting port without sending PP headers, allowing
source address spoofing. Both flags are now server-side config only.
@kvinwang kvinwang closed this Apr 16, 2026
@kvinwang kvinwang deleted the feat/gateway-proxy-protocol branch April 16, 2026 03:02
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