Skip to content

fix(pam): bind local proxies to loopback#282

Merged
x032205 merged 1 commit into
pam-revampfrom
pam-revamp-local-proxy-loopback-bind
Jun 26, 2026
Merged

fix(pam): bind local proxies to loopback#282
x032205 merged 1 commit into
pam-revampfrom
pam-revamp-local-proxy-loopback-bind

Conversation

@Vligai

@Vligai Vligai commented Jun 25, 2026

Copy link
Copy Markdown

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 / [::]). These
proxies are consumed by the local client on the same machine, so they should only accept loopback
connections. This binds them to 127.0.0.1 and advertises 127.0.0.1 in the printed connection
string, 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-revamp branch. The user-facing connection strings have moved into
packages/pam/local/access.go (the per-resource display configs), so the 127.0.0.1 advertisement
is 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.1 URL, 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> to 127.0.0.1:<port>.

  • Before: listener on :0 / :<port> (all interfaces); connection string used localhost.
  • After: listener on 127.0.0.1:0 / 127.0.0.1:<port> (loopback only); connection string uses
    127.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

  • Unit test (included in this PR): go test ./packages/pam/local/ -run TestLocalProxiesBindLoopback.
    It drives each proxy's Start() and asserts the listener binds a loopback address, covering all
    five local proxies (database, redis, kubernetes, ssh, rdp).
  • Manual: start a database / redis / kubernetes PAM session and confirm the proxy port listens on
    127.0.0.1 only (for example lsof -iTCP -sTCP:LISTEN or netstat), and that the local client
    still connects via the printed 127.0.0.1 URL.

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

  • Title follows the conventional commit format: type(scope): short description (scope is optional, e.g., fix: prevent crash on sync or fix(api): handle null response).
  • Tested locally
  • Updated docs (if needed)
  • Updated CLAUDE.md files (if needed)
  • Read the contributing guide

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.
@infisical-review-police

Copy link
Copy Markdown

💬 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.

@Vligai Vligai requested a review from x032205 June 25, 2026 23:34
@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR tightens the attack surface of the local PAM proxies (database, Redis, Kubernetes) by binding their TCP listeners to 127.0.0.1 instead of all interfaces, and updates every user-facing connection string and the Kubernetes kubeconfig Server URL to match. SSH and RDP proxies were already loopback-bound; this brings the remaining three in line.

  • database-proxy.go, redis-proxy.go, kubernetes-proxy.go: net.Listen address changed from ":port" (all interfaces) to "127.0.0.1:port" (loopback only).
  • access.go: All printed connection strings, host labels, and CLI usage examples updated from localhost to 127.0.0.1.
  • proxy_loopback_test.go: New regression test that starts each of the five proxies on an ephemeral port and asserts addr.IP.IsLoopback().

Confidence Score: 4/5

Safe to merge. The change correctly restricts proxy listeners to loopback and keeps all five proxies consistent; the new test guards against regressions.

The binding change is applied correctly and uniformly across all three previously-unbound proxies, and the printed connection strings are updated to match. The only non-blocking concern is that hardcoding 127.0.0.1 means the proxy won't start on IPv6-only hosts — a narrow edge case but worth noting before merging into a broadly distributed CLI.

No files require special attention; the IPv6 note applies equally to database-proxy.go, redis-proxy.go, and kubernetes-proxy.go.

Important Files Changed

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

Comment thread packages/pam/local/database-proxy.go
@x032205 x032205 merged commit cbb9e1f into pam-revamp Jun 26, 2026
28 of 29 checks passed
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.

2 participants