net/netns: honor ALL_PROXY when netns is disabled

netns.SetEnabled(false) is for processes like userspace-only clients
whose traffic never routes back into themselves, so they don't need
the namespace setup. But FromDialer also skipped the ALL_PROXY SOCKS
wrapping when disabled, so such processes couldn't reach the internet
in environments that only allow egress via a proxy, such as ChatGPT
Work's sandbox.

Only skip the namespace setup when disabled, and still wrap the dialer
for the proxy.

Updates #22412

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: Ic2023a329c640a1e8de32b157ed608ba385000a1
This commit is contained in:
Brad Fitzpatrick authored and Brad Fitzpatrick committed 2026-11-15 18:14:08 -08:00
1 parent a6baab333a
commit 167d05bc82
2 files changed
+10 -7

No files matched your search

+3 -3
View File
@@ -109,10 +109,10 @@ func TestFromDialerControlContext(t *testing.T) {
}
}
got := FromDialer(t.Logf, netmon.NewStatic(), d)
if want := proxy && !disable; wrapped != want {
t.Errorf("proxy wrapped = %v; want %v", wrapped, want)
if wrapped != proxy {
t.Errorf("proxy wrapped = %v; want %v", wrapped, proxy)
}
if disable && got != d {
if disable && !proxy && got != d {
t.Error("disabled FromDialer did not return the original dialer")
}
if d.Control != nil {
+7 -4
View File
@@ -119,7 +119,8 @@ func NewDialer(logf logger.Logf, netMon *netmon.Monitor) Dialer {
//
// FromDialer modifies d and may wrap it to use SOCKS if configured by ALL_PROXY.
// The hooks apply to the underlying socket (to the proxy when using SOCKS).
// When netns is disabled, d is returned unchanged and without proxy wrapping.
// When netns is disabled, d gets no namespace setup but may still be wrapped
// to use SOCKS.
func FromDialer(logf logger.Logf, netMon *netmon.Monitor, d *net.Dialer) Dialer {
if netMon == nil {
panic("netns.FromDialer called with nil netMon")
@@ -127,10 +128,12 @@ func FromDialer(logf logger.Logf, netMon *netmon.Monitor, d *net.Dialer) Dialer
if d.Control != nil {
panic("netns.FromDialer: use ControlContext instead of Control")
}
if disabled.Load() {
return d
// Disabling netns only turns off the namespace setup. Processes that
// disable it, such as userspace-only clients that never route traffic
// back into themselves, may still need to honor ALL_PROXY.
if !disabled.Load() {
setNamespaceControl(d, control(logf, netMon))
}
setNamespaceControl(d, control(logf, netMon))
if wrapDialer != nil {
return wrapDialer(d)
}