fix(gateway): move localhost routing behind an insecure debug flag - #831
Open
kvinwang wants to merge 1 commit into
Open
fix(gateway): move localhost routing behind an insecure debug flag#831kvinwang wants to merge 1 commit into
kvinwang wants to merge 1 commit into
Conversation
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.
Problem
core.proxy.localhost_enabledreads like a proxy convenience — "let the app addresslocalhostresolve to 127.0.0.1" — and it sits next to ordinary tuning likelisten_portandbuffer_size. Its blast radius is much wider than that placement suggests.App addresses do not only come from the platform's own
<app_id>.<base_domain>grammar.select_top_n_hostsis reached from both routing paths:So with the flag on, anyone who controls any DNS zone can publish
and have the gateway open a connection to 127.0.0.1:8111 on the gateway host, then pass their TLS through to it. Port 8111 is the default admin listener, which binds loopback precisely because unreachability is its access control; the debug RPC and the gateway's own RPC are next door.
port_policydoes not constrain it either — the shortcut is not a registered instance, and the code says so:so the caller picks the port.
The flag is off by default, which is the saving grace. But an operator turning it on for the base-domain case it advertises has no way to see that they are also opening the gateway's loopback to every domain owner on the internet.
Fix
Move it to
[core.debug] insecure_localhost_backend, next toinsecure_skip_attestationandinsecure_enable_debug_rpc, and warn at startup when it is set.The
insecure_prefix is earned here in a way it would not be for every switch: this one makes a relying party — the gateway — accept a routing target it would otherwise reject, and skips a policy check on the way. That is the same shape asinsecure_no_authandinsecure_allow_external_trust_anchors, and unlike, say, a switch that only narrows what a component asserts about itself.The doc comment and the
gateway.tomlcomment both state the custom-domain coupling explicitly, since that is the part that is not obvious from the name alone.No compatibility shim: an old config with
core.proxy.localhost_enablednow leaves the feature off, which is the safe direction, and this is a development-only switch.Not changed here, but worth a follow-up decision: the shortcut could be restricted to the base-domain path so the TXT path can never name it. That would keep the development use case while removing the exposure entirely, rather than relying on the operator reading a flag name.
Verification
test-run/test_proxy.sh— the gateway's proxy data-path integration suite — runs entirely on this shortcut (localhost-<port>[s].<base_domain>is how it avoids registering a CVM), so it exercises the renamed flag end to end:(the two skips are environmental: the TLS ULP is not removable on this host, and the Status RPC needs a real WireGuard device.)
cargo build,cargo fmtandcargo clippy -p dstack-gatewayare clean.