fix(pam): bind local proxies to loopback#282
Conversation
The database, redis, and kubernetes local PAM proxies created their TCP
listener with an empty host (":0" / ":<port>"), which Go resolves to all
interfaces. These proxies are only meant to be used by the client on the
same machine, so they should not be reachable from elsewhere.
Bind the listeners to 127.0.0.1 so they accept local connections only,
and advertise 127.0.0.1 in the printed connection strings and kubeconfig
so the client connects to exactly the address the proxy listens on. This
matches the ssh and rdp proxies, which already bind loopback.
|
💬 Discussion in Slack: #pr-review-cli-282-fix-pam-bind-local-proxies-to-loopback Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel. |
|
| Filename | Overview |
|---|---|
| packages/pam/local/database-proxy.go | Binds TCP listener to 127.0.0.1 (loopback-only) for both ephemeral and fixed ports; straightforward and correct. |
| packages/pam/local/redis-proxy.go | Binds listener to 127.0.0.1 and updates printed connection strings from localhost to 127.0.0.1; consistent with the other proxies. |
| packages/pam/local/kubernetes-proxy.go | Binds listener to 127.0.0.1 and updates the kubeconfig Server URL from http://localhost to http://127.0.0.1; pre-existing use of plain HTTP for the loopback tunnel is unchanged. |
| packages/pam/local/access.go | Updates all user-facing connection strings and host display from localhost to 127.0.0.1 across all five database types; changes are uniform and correct. |
| packages/pam/local/proxy_loopback_test.go | New test that calls Start(0) on each proxy and asserts addr.IP.IsLoopback(); covers all five proxy types and properly closes listeners via defer. |
Reviews (1): Last reviewed commit: "fix(pam): bind local proxies to loopback" | Re-trigger Greptile
Context
The local PAM proxies for database, redis, and kubernetes sessions create their TCP listener with an
empty host (
":0"/":<port>"), which Go resolves to all interfaces (0.0.0.0/[::]). Theseproxies are consumed by the local client on the same machine, so they should only accept loopback
connections. This binds them to
127.0.0.1and advertises127.0.0.1in the printed connectionstring, so the client connects to exactly the address the proxy listens on. The ssh and rdp proxies
already bind and advertise
127.0.0.1; this brings the other three in line.This change targets the
pam-revampbranch. The user-facing connection strings have moved intopackages/pam/local/access.go(the per-resource display configs), so the127.0.0.1advertisementis applied there rather than in each proxy file.
Behavior: the proxy now accepts connections only from the local host. A client running on the same
machine connects via the printed
127.0.0.1URL, as it already does for ssh and rdp sessions.Reaching the proxy from another host, or from outside a container via a published port, no longer
works (run the client on the same machine). The printed connection string changes from
localhost:<port>to127.0.0.1:<port>.:0/:<port>(all interfaces); connection string usedlocalhost.127.0.0.1:0/127.0.0.1:<port>(loopback only); connection string uses127.0.0.1.Changed files:
packages/pam/local/database-proxy.go(bind)packages/pam/local/redis-proxy.go(bind + printed connection string)packages/pam/local/kubernetes-proxy.go(bind + kubeconfig server URL)packages/pam/local/access.go(printed connection strings / usage examples / host display)packages/pam/local/proxy_loopback_test.go(test)Screenshots
Steps to verify the change
go test ./packages/pam/local/ -run TestLocalProxiesBindLoopback.It drives each proxy's
Start()and asserts the listener binds a loopback address, covering allfive local proxies (database, redis, kubernetes, ssh, rdp).
127.0.0.1only (for examplelsof -iTCP -sTCP:LISTENornetstat), and that the local clientstill connects via the printed
127.0.0.1URL.Type
Checklist
type(scope): short description(scope is optional, e.g.,fix: prevent crash on syncorfix(api): handle null response).