Skip to content

Limit answering a remote tool's confirmation to the team-signed app by audit token and code signature (#4327) - #4368

Merged
mstomar125 merged 1 commit into
mainfrom
issue-4327-peer-sig
Nov 25, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-4327-peer-sig

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Refs #4327. Security-sensitive. The owner signed off agent-lane work for this batch and decided 2026-11-25 to build this with what exists here; what needs a signed build is split into new issues.

What changed

The per-call confirmation answer (AnswerConfirmation) was gated only by the recorded-process peer gate, which admits orphaned descendants of recorded programs and agents the user started outside the app. Now, on macOS:

  • peer_auth.rs: the daemon reads the peer's audit token (LOCAL_PEERTOKEN, getsockopt at level SOL_LOCAL) at accept time, before anything is read from the peer, and carries it with the connection (PeerStream, tonic Connected with a PeerInfo carrying credentials and the token). peer_pid reads the same info.
  • New peer_signature.rs: asks the Security framework for the running code the token names (SecCodeCopyGuestWithAttributes with the audit attribute, so a reused pid cannot match) and checks it against a designated requirement: Apple Developer ID chain, leaf OU = the NodeSpace team, identifier fixed per scope. Team id and identifier are validated before they enter a requirement string.
  • AnswerConfirmation needs the team-signed app (com.nodespace.desktop). ApproveTool needs the team-signed app or the team-signed nodespace command (identifier nodespace); the person at the screen still confirms. This check is in addition to the existing process gate.
  • Fails closed: no token, no code for the token, a requirement that does not parse, a failed check: refusal. A development build refuses unsigned peers too; a developer sets NODESPACE_DEV_ALLOW_UNSIGNED_PEER=1 on the daemon to keep only the process gate (logged on each use). Release builds have no such switch (it is compiled under debug_assertions only).
  • Windows and Linux are unchanged (the process gate stays the only check there; out of scope).

Tests and mutation results

Real code paths, no signing needed: an Apple-signed peer (/usr/bin/nc -U) is checked against anchor apple (accepted) and the team requirement (refused), so the SecCode path is exercised end to end both ways; the unsigned test binary is refused; unknown token, no token and a bad requirement are refusals; socket tests drive the real accept stream, a gate that admits the peer and the real TeamSigned check (refused), and a recording check for scope and token.

Mutation checks, each applied alone and reverted:

  • drop the ApproveTool signature check: a_peer_that_is_not_the_signed_app_cannot_approve_and_nobody_is_asked fails
  • drop the answer signature check: a_peer_the_process_gate_admits_but_that_is_not_the_signed_app_cannot_answer and the_answer_is_judged_with_the_connections_token_and_its_own_scope fail
  • answer judged with the wrong scope: the_answer_is_judged_with_the_connections_token_and_its_own_scope fails
  • check_requirement ignores a failed validity check: the Apple-peer and the unsigned-peer tests fail
  • token read returns none: the token, Apple-peer and unsigned-peer tests fail
  • requirement text validation removed: text_that_could_change_the_requirement_is_not_put_into_one fails
  • connect info not read for the token: the scope/token and approve tests fail

Commands run: cargo test -p nodespace-daemon --lib (peer filters), cargo clippy -p nodespace-daemon --all-targets -- -D warnings, cargo fmt, bun run test:changed (passed).

Not verified here

No Developer ID identity exists on the dev Mac, so the positive case for the team's own signature is not run. One issue per check, assigned to Michael:

The team id in the requirement is the one the release workflow already signs with.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (static review of d880fe5; nothing built or run)

No blocking finding. Follow-ups below, M1 and L1 I would file before the signed-build checks.

Checked, holds:

  1. TOCTOU. The token is read with getsockopt(LOCAL_PEERTOKEN) in PeerStream::new (peer_auth.rs:115-124, called at accept, before any read) and carried in the connection's PeerInfo connect info (peer_auth.rs:136-142). Each request reads it back from its own connection (remote_confirmation.rs:903-918). It is the connector's audit token, not a pid. SecCodeCopyGuestWithAttributes is given the audit attribute (peer_signature.rs:356-361), so pid reuse cannot match. After a connect-then-exec, the token names the old pid-version, so the lookup fails and the peer is refused (NoCode). I believe exec bumps the pidversion, but I could not test that. An fd handed to another process keeps the original connector's token.
  2. Requirement string. Anchors are correct: anchor apple generic, intermediate 1.2.840.113635.100.6.2.6 (Developer ID CA), leaf 1.2.840.113635.100.6.1.13 (Developer ID Application), subject.OU = team, identifier. Ad hoc and self-signed code cannot satisfy anchor apple generic plus the Developer ID OIDs. Injection is closed by the character whitelist and length caps (peer_signature.rs:318-326), and the test covers the quote/space/empty/11-char cases.
  3. The dev escape sits behind #[cfg(debug_assertions)] (peer_signature.rs:430-434, 448-453). [profile.release] does not set debug-assertions, and the daemon reads the variable from its own environment, not the peer's. A release daemon has no such branch.
  4. Fail-open scan. No unwrap_or(true). A missing token, a SecCode error, a bad requirement and a missing peer_info all return false. allows returns true only when not macOS, which is the stated unchanged path. peer_pid still prefers PeerInfo.cred, then UdsConnectInfo, and the process gate still runs first. The Windows named-pipe connect info is untouched.
  5. The constants match the repo.
  6. Tests. The pid-in-word-5 check is correct. The Apple-signed nc test proves the check can say yes (anchor apple) and no (team requirement). The unsigned/ad hoc peer test and the no-token, bad-requirement and no-code tests are meaningful. The service tests use a Scoped check that proves the scope and the token reach the check. I did not re-run the 7 mutations.

Findings:

  • M1 (medium, follow-up): the requirement does not demand the hardened runtime, and a Developer ID requirement cannot express it. A team-signed binary built without --options runtime, or with get-task-allow or allow-dyld-environment-variables (an older release, a test build), still passes and can be driven by same-user DYLD injection or task_for_pid. Today's build-pkg.sh does use --options runtime (lines 100-110), and I found no entitlements file. Suggest also reading SecCodeCopySigningInformation flags and requiring CS_RUNTIME (0x10000), and refusing the get-task-allow entitlement. Alternatively add a minimum-version or cdhash allowlist.
  • L1 (low): the nodespace identifier is shared by the team's bare nodespace binary and the Tauri sidecar copy. That is fine, but any other team-signed binary named nodespace would be admitted for ApproveTool. The person-at-screen dialog still applies.
  • L2 (low): the check runs per request, not once per connection. This is correct, only slower (two SecCode lookups for ApproveTool by the CLI). A refused app logs once per scope.
  • L3 (info): the branch is behind main. The diff against current main shows unrelated hunks (user_presence.rs test removal, skill_retrieval goldens, secrets.rs, cli secret.rs). Rebase before the gate and confirm the diff is only the 8 PR files.

Could not verify: the positive case (a real team-signed app and CLI passing; tracked in #4365/#4367), exec bumping the pidversion on this macOS, security-framework 3.7's copy_guest_with_attribues and set_audit_token behaviour, and the claimed mutations.

…y the peer's audit token and code signature

The daemon reads the peer's audit token (LOCAL_PEERTOKEN) when it accepts a
connection, carries it with the connection, and checks the connecting program
with SecCode against a Developer ID requirement for the NodeSpace team. An
answer needs the signed app; approving a tool needs the signed app or the
signed nodespace command. A development build refuses unsigned peers unless
NODESPACE_DEV_ALLOW_UNSIGNED_PEER=1; a release build has no switch.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 merged commit 66717ab into main Nov 25, 2026
@mstomar125
mstomar125 deleted the issue-4327-peer-sig branch November 25, 2026 11:46
@malibio

malibio commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Follow-up: the two cases this PR couldn't run without a Developer ID identity (the signed app can still answer a confirmation, was #4365; a non-team program, an ad hoc copy and an orphaned descendant are refused on a signed install, was #4366) are now tracked in NodeSpace and assigned for checking on a signed v0.3.14 install. #4367 (the signed nodespace command can approve) is in the same set. The GitHub issues were closed when tracking moved to NodeSpace.

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.

2 participants