Skip to content

feat(kms,gateway): accept the PROXY protocol and log the client address - #1582

Merged
kvinwang merged 5 commits into
nextfrom
feat/kms-proxy-protocol
Nov 15, 2026
Merged

kvinwang merged 5 commits into
nextfrom
feat/kms-proxy-protocol

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1580.

A proxy in front of the KMS has to pass TLS through, because the KMS verifies RA-TLS client certificates itself, so the KMS only ever sees the proxy's address. Its request logs also had no client address at all.

  • ra-rpc: the request span now records the TCP peer as remote, so every prpc log line shows who called.
  • New rocket-proxy-listener crate: a Rocket listener that reads a PROXY v1/v2 header and reports its source address as the connection's remote endpoint, beneath Rocket's TLS listener. Rocket's TlsListener takes connections from the inner accept(), which runs serially, so headers are read in per-connection tasks with a 5s timeout and handed over through a channel; a silent client cannot stall the listener. A LOCAL header (health check) keeps the peer address.
  • KMS: proxy_protocol = true in [rpc], [core.admin] or [core.readonly] turns it on for that listener (off by default). With it on, connections without a header are dropped. The header is trusted as sent, so the listener must be reachable only through the proxy; the README says so.
  • The gateway's PROXY header reader moves into the new crate unchanged, with its tests; the gateway uses it from there.
  • Gateway: its RPC, admin and debug listeners launch the same way, so proxy_protocol = true at the top level of gateway.toml, in [core.admin] or in [core.debug] turns it on (off by default). This is separate from [core.proxy] inbound_pp_enabled, which covers the app traffic the gateway proxies. launch() takes a Rocket in any phase, since the admin listener is ignited first.

Testing

A local dev KMS (auth_api = "dev", enforce_self_authorization = false, attest_rpc_cert = false, auto-bootstrapped), proxy_protocol = true on the RPC (18700) and read-only (18702) listeners, off on the admin listener (18701):

Case Result Logged remote
RPC, v1 header (curl --haproxy-clientip 203.0.113.7) served 203.0.113.7:51634
Read-only, v1 TCP6 header served [2001:db8::9]:40000
RPC, v2 header served 198.51.100.4:40000
RPC, v2 LOCAL header served 127.0.0.1:51656 (peer)
RPC, no header dropped, no valid proxy protocol header detected
RPC, a client that sends nothing, plus a normal request meanwhile the request is served in 0.01s; the silent one is dropped after 5s 203.0.113.9:39078
Admin (off), no header served 127.0.0.1:37256
Admin (off), with header fails, as before

Attested RA-TLS client certificates through the PROXY listener were verified on TDX (below).

The gateway was not run locally (it needs a guest agent and WireGuard); its listeners use the same launch() as the KMS above, and with proxy_protocol off they launch as before. cargo test passes for rocket-proxy-listener, ra-rpc, dstack-kms and dstack-gateway, as do clippy with the CI flags and cargo fmt --check.

Verified on TDX

Run on the tdxlab TDX host with real TDX CVMs (guest OS dstack 0.6.0), from one local build of #1580, #1582, #1585 and #1587 merged with #1583 and #1588: the official 0.6.3 KMS and gateway images with these binaries (and the gateway's new entrypoint.sh). The KMS ran in a CVM with a local key provider and a webhook auth backend (allow all but one app; this KMS's root epoch 0 registered); haproxy with send-proxy-v2 fronted the guest listeners of the KMS and the gateway.

  • An app CVM got its keys (GetAppKey, SignCert) through haproxy: the KMS guest listener with proxy_protocol = true accepted its RA-TLS client certificate, and logged remote=127.0.0.1:38172, the client haproxy logged, where a direct connection shows 10.0.2.2:…. A connection without the header was dropped.
  • A gateway-enabled app CVM registered with the gateway through haproxy (mutual TLS on the guest listener); the gateway logged the client haproxy saw. A direct connection without the header was dropped.

@kvinwang
kvinwang force-pushed the feat/kms-proxy-protocol branch from 09866d6 to 10e80f7 Compare November 15, 2026 04:39
@kvinwang kvinwang changed the title feat(kms): accept the PROXY protocol and log the client address feat(kms,gateway): accept the PROXY protocol and log the client address Nov 15, 2026
@kvinwang
kvinwang added this pull request to stack #1586 November 15, 2026 04:54
Base automatically changed from feat/kms-public-listener to next November 15, 2026 16:40
The request span carried only the method, so the logs of a service such
as the KMS did not show who called it. Record the TCP peer as `remote`.

Signed-off-by: Kevin Wang <wy721@qq.com>
A proxy in front of the KMS must pass TLS through for RA-TLS client
authentication, so the KMS sees only the proxy's address. Add a
rocket-proxy-listener crate whose listener reads a PROXY v1/v2 header
off the accept loop, with a timeout, and reports its source address as
the connection's remote endpoint, beneath Rocket's TLS listener. The KMS
launches its RPC, admin and read-only listeners through it, opted in per
listener with `proxy_protocol = true`.

The header reader moves there from the gateway, which now uses it.

Signed-off-by: Kevin Wang <wy721@qq.com>
Also drop a dead variable and gateway-specific wording from the moved
header reader.

Signed-off-by: Kevin Wang <wy721@qq.com>
…listeners

Launch them through rocket-proxy-listener, so proxy_protocol = true at
the top level of gateway.toml, in [core.admin] or in [core.debug] reads
the client address from a PROXY header, and the prpc request logs carry
it as remote. launch() now takes a Rocket in any phase, since the admin
listener is ignited first.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the feat/kms-proxy-protocol branch from 51b3446 to 50cd6a8 Compare November 15, 2026 16:41
@kvinwang
kvinwang merged commit 46b9893 into next Nov 15, 2026
23 checks passed
@kvinwang
kvinwang deleted the feat/kms-proxy-protocol branch November 15, 2026 17:00
kvinwang added a commit that referenced this pull request Nov 16, 2026
Runs the product tests added for launch tickets (#1577), the dstack-mr
lite check and dstack-verifier-wasm (#1555), the SEV-SNP key provider
(#1526), the PROXY header reader (#1582) and the refusal of old listener
settings (#1585, #1587). A row matching no test fails.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 16, 2026
tc-gw-internal-009 checks that the gateway refuses the old listener
locations (#1587), restarts it with proxy_protocol on the admin listener
(#1582), and checks the admin audit (#1588) and access (#1589) lines.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 16, 2026
#1582 moved the gateway's PROXY header reader and its tests into the
rocket-proxy-listener crate; the gateway kept two pp::tests, below the
nine the case requires.

Signed-off-by: Kevin Wang <wy721@qq.com>
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