Repository navigation
Replace host-side socat bridges with in-process net.Server listeners - #257
Closed
dylan-conway wants to merge 1 commit into
Closed
dylan-conway wants to merge 1 commit into
dylan-conway wants to merge 1 commit into
Conversation
The two host-side socat processes only do one thing: accept on a Unix
socket and forward each connection to the local proxy server's TCP port.
They run on the host, in the same trust domain as the node process that
already hosts both proxy servers, so there's no reason for them to be
separate OS processes.
Replace them with net.Server listeners on the same event loop, forwarding
via socket.pipe(). This drops:
- the runtime dependency on socat for the host side (the in-sandbox socat
relays are unchanged and still required)
- two spawned processes per session
- ~120 lines of process-lifecycle management in reset(): the SIGTERM /
SIGKILL escalation, the 'exit'-event-already-fired race handling, and
the BRIDGE_EXIT_TIMEOUT_MS workaround for a Bun pidfd notification bug
- the "poll for the socket file to appear" loop in
initializeLinuxNetworkBridge: server.listen()'s callback is the ready
signal
The bridge sockets also move from `/tmp/claude-{http,socks}-<rand>.sock`
into a private mode-0700 mkdtemp directory (`/tmp/srt-bridge-XXXXXX/`).
The previous layout left a window where the socket file existed in
world-writable /tmp with default permissions; the new layout makes the
sockets unreachable to other local users at every point in their
lifetime.
Collaborator
Author
|
Superseded — going with the full launcher replacement instead (proxies listen on the unix socket directly on Linux, vendored |
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.
The two host-side
socatprocesses only do one thing: accept on a Unix socket and forward each connection to the local proxy server's TCP port. They run on the host, in the same trust domain as the node process that already hosts both proxy servers, so there's no reason for them to be separate OS processes.This replaces them with
net.Serverlisteners on the same event loop, forwarding viasocket.pipe(). The in-sandboxsocatrelays (theTCP-LISTEN → UNIX-CONNECTones started bybuildSandboxCommandinside bwrap) are unchanged and still required.What goes away
socatfor the host side. (checkLinuxDependencies()is unchanged because the in-sandbox relays still use it.)reset():killBridgeProcess(), the SIGTERM → SIGKILL escalation, the "exit event already fired" race handling, and theBRIDGE_EXIT_TIMEOUT_MSworkaround for process: drop EPOLLONESHOT for Linux pidfd exit poll oven-sh/bun#30301. Closing anet.Serveris synchronous and can't get into the missed-event state that motivated fix(sandbox): make reset() resilient to missed bridge 'exit' events #255.initializeLinuxNetworkBridge.server.listen()'s callback is the ready signal; there's no race against an external process creating the file.Socket placement
The bridge sockets move from
/tmp/claude-{http,socks}-<rand>.sockinto a private mode-0700mkdtempdirectory (/tmp/srt-bridge-XXXXXX/). The previous layout created the socket file in world-writable/tmpwithumask-derived permissions and never tightened them; the new layout makes the sockets unreachable to other local users for their whole lifetime, with no post-creationchmod()race. bwrap bind-mounts the socket files into the sandbox where the uid is identity-mapped, so the sandbox side is unaffected.Behavioral note
The bridge data plane is now on the node event loop. While a sandboxed command runs the host process is idle, so this doesn't change anything in practice — but it does mean a hypothetical caller that blocks the event loop while a sandboxed command is mid-network-call (e.g.
execSyncon the wrapped command) would see that traffic stall. The existing asyncspawn-based callers are unaffected.