Repository navigation
Refuse a Unix socket peer whose user id is not the daemon's own (#4284, Unix part) - #4288
Merged
Merged
Conversation
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 |
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]>
mstomar125
force-pushed
the
issue-4284-peer-check
branch
from
November 17, 2026 11:40
af80b49 to
7e109bf
Compare
This was referenced Nov 17, 2026
Closed
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.
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