Skip to content

Refuse a Unix socket peer whose user id is not the daemon's own (#4284, Unix part) - #4288

Merged
mstomar125 merged 2 commits into
mainfrom
issue-4284-peer-check
Nov 17, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-4284-peer-check

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This covers the Unix part of #4284: the daemon now refuses a connecting peer whose user id differs from its own effective uid, as ADR-052 section 2 decides.

A new module, peer_auth, reads each accepted connection's peer credentials (SO_PEERCRED on Linux, LOCAL_PEERCRED on macOS, through tokio) and serves the peer only when its uid equals geteuid(). The comparison is strict: root is not special-cased, and a peer whose credentials cannot be read is refused. A refused peer is dropped with a warning that carries its uid and pid, and the accept loop continues, because tonic treats an error from the incoming stream as fatal. Both Unix serving paths in main.rs (headless and tray) now serve through the wrapper. The header comment at the top of main.rs states what holds on Unix and that Windows relies on the owner-only pipe DACL.

Tests: pure-function tests for same uid, other uid, uid 0 against a non-root daemon, and unreadable credentials; a seam test with a real UDS server and a real tonic client that refuses one client (transport error, the server never sees an RPC, the server keeps running) and then serves the next client on the same server; and a same-user test through bind_uds_owner_only and the production check that makes one RPC. A test with a genuinely different user is not possible without a second account, so the production check is driven with a daemon uid that is not the caller's: owner_only_incoming_for_euid takes the uid, the production function calls it with geteuid, and a test over a real UDS shows a real same-user connection refused (transport error, zero RPCs) when the daemon uid differs and served when it matches. Because the two serving paths build routers with different layers, source-level tests pin that the daemon holds no raw listener stream, that both Unix serving paths serve through the peer check, and that the daemon's identity is geteuid (geteuid and getuid agree in every test process).

Stays open on #4284: the Windows check (no change here; it relies on the pipe DACL), the Sync daemon's serving path in the sync repo, and the ADR text update in the docs repo.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Merge queue: #4288 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 4288.

cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin
  CFLAGS_aarch64_apple_darwin = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin
  CFLAGS_aarch64-apple-darwin = None
  cargo:warning=sccache: error: Server startup failed: File exists (os error 17)
  cargo:warning=Run with SCCACHE_LOG=debug SCCACHE_NO_DAEMON=1 to get more information
  exit status: 2
  cargo:warning=ToolExecError: command did not execute successfully (status code exit status: 2): env -u IPHONEOS_DEPLOYMENT_TARGET LC_ALL="C" "/Users/mayanktomar/nodespace/core/.tools/bin/sccache" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-macosx" "-mmacosx-version-min=27.2" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/pregenerated" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-gfull" "-DNDEBUG" "-o" "/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/build/ring-02464c93aa49b344/out/00c879ee3285a50d-montgomery_inv.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/bn/montgomery_inv.c"
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  --- stderr
  error occurred in cc-rs: command did not execute successfully (status code exit status: 2): env -u IPHONEOS_DEPLOYMENT_TARGET LC_ALL="C" "/Users/mayanktomar/nodespace/core/.tools/bin/sccache" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-macosx" "-mmacosx-version-min=27.2" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/pregenerated" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-gfull" "-DNDEBUG" "-o" "/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/build/ring-02464c93aa49b344/out/00c879ee3285a50d-montgomery_inv.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/bn/montgomery_inv.c"
error: script "shape:check" exited with code 101
[stage exited with code 101]

  full output: /var/folders/3w/y9kj522n1_j9wqmt6vl_sb6r0000gp/T/nodespace-gate-logs/_gate-merge-2026-11-17T11-28-29-328Z/shape-check-built-in-shape-snapshot-and-change-log.log

✗ shape:check (built-in shape snapshot and change log) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

mstomar125 and others added 2 commits November 17, 2026 12:40
The daemon's trust boundary on Unix was the socket mode alone: every
accepted connection went straight to tonic. Read the peer's credentials
at accept time and serve it only when its uid equals the daemon's
effective uid (strict equality, root not special-cased, unreadable
credentials refused). A refused peer is dropped with a warning and the
accept loop continues, because tonic treats an error from the incoming
stream as fatal. Both Unix serving paths use the wrapper; the header
comment now states what holds on Unix and that Windows relies on the
owner-only pipe DACL.

Covers the Unix part of #4284.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… paths

The production check closure was never exercised against a foreign uid,
and reverting a serving call site to a raw listener stream passed every
test. Add owner_only_incoming_for_euid so a test runs the real closure
with a uid that is not ours (a real same-user connection is then refused,
zero RPCs reach the server) and with our own (served). Source-level tests
pin that the daemon holds no raw listener stream, that both Unix serving
paths go through the peer check, and that the daemon's identity is
geteuid, since getuid agrees with it in every test process.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.

1 participant