Repository navigation
feat(kms,gateway): accept the PROXY protocol and log the client address - #1582
Merged
Merged
Conversation
kvinwang
force-pushed
the
feat/kms-proxy-protocol
branch
from
November 15, 2026 04:39
09866d6 to
10e80f7
Compare
This was referenced Nov 15, 2026
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>
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
force-pushed
the
feat/kms-proxy-protocol
branch
from
November 15, 2026 16:41
51b3446 to
50cd6a8
Compare
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
#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>
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.
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 asremote, so every prpc log line shows who called.rocket-proxy-listenercrate: 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'sTlsListenertakes connections from the inneraccept(), 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. ALOCALheader (health check) keeps the peer address.proxy_protocol = truein[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.proxy_protocol = trueat the top level ofgateway.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 = trueon the RPC (18700) and read-only (18702) listeners, off on the admin listener (18701):remotecurl --haproxy-clientip 203.0.113.7)203.0.113.7:51634TCP6header[2001:db8::9]:40000198.51.100.4:40000LOCALheader127.0.0.1:51656(peer)no valid proxy protocol header detected203.0.113.9:39078127.0.0.1:37256Attested 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 withproxy_protocoloff they launch as before.cargo testpasses forrocket-proxy-listener,ra-rpc,dstack-kmsanddstack-gateway, as do clippy with the CI flags andcargo 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 withsend-proxy-v2fronted the guest listeners of the KMS and the gateway.GetAppKey,SignCert) through haproxy: the KMS guest listener withproxy_protocol = trueaccepted its RA-TLS client certificate, and loggedremote=127.0.0.1:38172, the client haproxy logged, where a direct connection shows10.0.2.2:…. A connection without the header was dropped.