Repository navigation
feat(bridge): listen on a Unix socket with --unix and name consomme in the --wsl refusal - #479
Merged
Merged
Conversation
`wmux bridge --wsl` lets a container reach wmux by listening on 0.0.0.0 inside the distro, and refuses to do that unless `wslinfo --networking-mode` says `nat`. On managed networks that require `networkingMode=virtioproxy` (called `consomme` in the WSL docs) the answer is neither `nat` nor `mirrored`, so the bridge exits with "could not determine this distro's networking mode" and the container gets no wmux. Binding the Docker bridge address with `--host` is not a way around it either: in WSL 3.0.5 under `consomme`, bind() to an explicit port on an address only the distro has fails with EINVAL (microsoft/WSL#42223, fixed by microsoft/WSL#42230). And what a 0.0.0.0 listener exposes under `consomme` is not documented, so picking it would be a guess. `wmux bridge --unix <path>` is the same bridge without an address. It listens on a Unix socket on the distro's own filesystem; the container gets the socket's directory bind-mounted and sets WMUX_PIPE=<path in the container> and WMUX_PIPE_TOKEN. The clients need no change: connectTransport and wmux-hook.js already dial a Unix socket when WMUX_PIPE starts with "/". No networking mode is read, so none can make the answer unknown. This is not the cross-boundary Unix socket that docs/DEVCONTAINER.md says was tried first. That was a socket on the Windows side, and 9P does not forward AF_UNIX. Here the socket is created by a process in the distro and used by a container on the same kernel; a path on a 9P mount (/mnt/<drive>) is refused. The rules live in a pure module (bridge-unix.ts) so they run on any platform: * not combinable with --host, --wsl or --port, each of which describes a TCP listener; * an absolute path of at most 107 bytes, not the pipe the bridge relays to; * the parent directory exists and is not group- or world-writable, sticky bit or not, because a socket's own mode does not stop another user replacing it; * the socket is created under umask 077 and chmod 0600; * a socket nobody listens on (connect gets ECONNREFUSED) is replaced, which is what SIGKILL or a WSL shutdown leaves behind; a live listener, a regular file or a probe that proves nothing makes the bridge exit instead; * the socket is unlinked on SIGINT, SIGTERM and exit, but only while it is still the bridge's own inode. resources/cli/bridge-unix.js is added to the checked-in CLI copies (regenerated with `npm run build:main`) and to electron-builder.json, which is what keeps a new CLI module from failing with MODULE_NOT_FOUND in an installed build. Tests: the rules as a table; and end to end against the compiled CLI, through a real socket with a stand-in pipe: the stock `wmux ping` with WMUX_PIPE and WMUX_PIPE_TOKEN, the 0600 mode, SIGTERM cleanup, a stale socket after SIGKILL, a live listener, a regular file, a replaced socket, and each refusal. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`wslinfo --networking-mode` prints `consomme` on a host running that mode (the WSL docs say it used to be called `virtioproxy`, and `.wslconfig` files still spell it that way). parseNetworkingMode only knew `nat` and `mirrored`, so it answered "unknown" and `--wsl` refused with "could not determine this distro's networking mode ... needs WSL 2.0.5 or newer", which sends the reader to check the WSL version when the version is fine. The mode is now recognised, and `--wsl` refuses it by name: what a 0.0.0.0 listener exposes to the Windows host and its networks is not documented for consomme, so it is not treated as NAT, and the message says so and points at `--unix <path>` (no address at all) or `--host <addr>`. An explicit `--host` under consomme is still honoured, with a notice that the reach is undocumented instead of the generic "beyond localhost" one. Nothing is added to the set of modes that bind 0.0.0.0 on its own. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Summary
wmux bridge --unix <path>: the bridge listens on a Unix socket on the distro's own filesystem instead of a TCP port. A container gets the socket's directory bind-mounted and setsWMUX_PIPEandWMUX_PIPE_TOKEN. Clients need no change, sinceconnectTransportandwmux-hook.jsalready dial a Unix socket whenWMUX_PIPEstarts with/.--wslnow recognisesconsomme(formerlyvirtioproxy) and refuses it by name, pointing at--unix <path>or--host <addr>, instead of the misleading "could not determine this distro's networking mode".Why
Under
networkingMode=virtioproxy/consomme,wslinfo --networking-modeis neithernatnormirrored, so--wslexits and the container gets no wmux.--hostis no workaround on WSL 3.0.5 (bind() fails with EINVAL, microsoft/WSL#42223, fixed by microsoft/WSL#42230), and what a 0.0.0.0 listener exposes under consomme is undocumented.This is not the cross-boundary socket
docs/DEVCONTAINER.mdsays was tried first: that one lived on the Windows side and 9P does not forward AF_UNIX. Here a process in the distro creates the socket and a container on the same kernel uses it; paths on a 9P mount (/mnt/<drive>) are refused.Safety rules (pure module
bridge-unix.ts)--host,--wslor--portresources/cli/bridge-unix.jsis added to the checked-in CLI copies (npm run build:main) and toelectron-builder.json, so an installed build does not fail with MODULE_NOT_FOUND.Test plan
tests/unit/bridge-unix.test.ts,wsl-network.test.ts.wmux-bridge-transport.test.ts: real socket with a stand-in pipe, stockwmux ping, 0600 mode, SIGTERM cleanup, stale socket after SIGKILL, live listener, regular file, replaced socket, each refusal.🤖 Generated with Claude Code