Skip to content

feat: approve a remote tool on this device, confirmed at the screen (nodespace tool approve, DescribeToolApproval/ApproveTool); credential changes confirmed too (#4291) - #4325

Merged
mstomar125 merged 11 commits into
mainfrom
issue-4291-approve
Nov 21, 2026
Merged

mstomar125 merged 11 commits into
mainfrom
issue-4291-approve

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #4291: the enable-and-approve step for remote tools (tool-cli, tool-rest, tool-mcp). The user signed off the agent-lane work in packages/agent for this issue.

The gate

A remote tool is offered to the model only after the person at this Mac approves it, and the daemon asks the operating system to confirm that a person is there. A same-user program (the model, a tool program, an agent, any other process of the user) cannot approve a tool or change a credential through the daemon on its own.

  1. nodespace tool approve <node-id> (CLI) shows the tool's name, kind, description, parameter schema, credential references (references only), every binding field, for a tool that starts a program the program file and its SHA-256, and on the line above the question what the tool runs or where it sends a call. It shows a code (XXXX-XXXX-XXXX) and asks the user to confirm only a dialog that starts with it. Control, invisible and bidi characters are escapes everywhere; in the binding, its target and the program file every character outside ASCII is an escape and flagged. It refuses without a terminal on both sides, before it contacts the daemon, and when the daemon gives no code (it cannot approve tools), before it asks. The MCP passthrough refuses tool. Typing the tool's name is a check on what the user meant, nothing more.
  2. DescribeToolApproval returns that preview, the digest (SHA-256 over a label and the length-prefixed node id, name, description, binding hash and program-file SHA-256), the code and the program. It writes nothing. The code is HMAC-SHA256(approval key, "tool-approval-code-v1" || digest), its first 48 bits: only the daemon can make one, so nothing can search offline for a second tool that shares a code, and searching through the RPC would take on the order of 2^48 node writes.
  3. ApproveTool, in this order:
    • the peer gate (SpawnedProcessGate, kept as defence in depth): a program the daemon started for a tool, or one descending from one, is refused before the request is read;
    • the daemon must hold an approval key (see below), or FAILED_PRECONDITION with the reason, and no dialog;
    • the node and its program file are read again and must still produce the shown digest, or ABORTED and no dialog is shown;
    • the person at the screen confirms: nodespaced calls LocalAuthentication evaluatePolicy(.deviceOwnerAuthentication) (Touch ID, a paired Watch or the login password in the system panel). The panel reads "nodespaced is trying to approve code XXXX-XXXX-XXXX for the remote tool “NAME”, which runs /full/path/to/program (that file's content is pinned), with the credentials TOKEN from keychain:tok, then " (for a web tool: "which sends POST https://host:port, with no credentials, then /path?query"). The daemon writes all of it, in this order: the code, the name, then the full program path or the method and scheme://host:port, kept whole, with what is said about the pin; then the credential references (at most 4 named, each cut at 64 characters, the others counted as "+N more"); then the arguments, or the rest of the address, cut at 120 characters. So the real code and the program or host come first, before anything long, and a panel that shortens a long reason cuts only what comes after them. The host is the one a call reaches, as a URL parser reads the text (Url::host_str() and the port): https://api.github.com%2eevil.com/x shows https://api.github.com.evil.com, https://[email protected]/ shows https://evil.com, a name outside ASCII shows in punycode, and a text the parser cannot read is shown as written with "(the host is not a plain address)". Node text is shown as ASCII with \u{..} escapes, and (, ), ;, any : that is not part of an address (https://, a port) and any dash between two four-hex-digit groups are escaped, so the text a node holds cannot be laid out as a second code or a "(code …):" of its own after the real one. A program file programs of this user can replace adds "WARNING: programs of this user can replace that file"; a #!/usr/bin/env X script adds, apart, "WARNING: it starts X from the PATH, which is not pinned". A program cannot answer the dialog;
    • the approval is written with the node version read before the dialog, as the approval's own write (NodeService::write_tool_approval, below): an edit made while the dialog was open is a conflict (ABORTED), nothing is approved, and the approval's record is taken back;
    • the node is read back and run through the offering gate; if that does not pass, ABORTED ("written but not in effect").
  4. SecretService.Set and Delete go through the same peer gate and then the same dialog ("nodespaced is trying to change the credential “NAME”"). A bad name or value is refused before anyone is asked. A request that is not confirmed changes nothing. A Set's value is wiped where it lies on every path that does not store it, including a client that hangs up while the dialog is open. ListNames is neither gated nor asked. The CLI says on standard error that a dialog is coming.

How the dialog is asked (packages/daemon/src/user_presence.rs):

  • A new LAContext per change, Touch ID reuse 0, on a blocking thread (never the main thread, which the tray owns, never an async worker), inside an autorelease pool. No answer in 60 s: the context is invalidated and it is a no.
  • The daemon runs in the logged-in user's session, so a request that comes in over SSH still puts the panel on the Mac's own screen, where only someone at the Mac can answer it. canEvaluatePolicy is never consulted. -1004 (the daemon itself runs outside a logged-in screen session), -4 (the screen locked, or the session switched to another user) and -5 (no login password) are "confirm at this Mac's own screen" (FAILED_PRECONDITION); every other failure is "not confirmed" (PERMISSION_DENIED).
  • One dialog at a time across approvals and credential changes; another request meanwhile is refused unshown (UNAVAILABLE). After a dialog that was not confirmed none is shown for 30 s, doubling with each further one within 10 minutes, up to 15 minutes. After a confirmed one none is shown for 5 s, so a program cannot slip a request in right behind the person's own. Both refusals are logged and say that another program on the Mac may be asking.
  • On other platforms there is no check, so approvals and credential changes are refused there.

Programs. A tool-cli program or a stdio tool-mcp command given as a bare name would be looked up on the daemon's PATH at every call. The preview resolves it on the daemon's PATH (on a blocking thread), shows the full path, the digest covers it, and the approval writes that full path into the tool. Either way the approval pins the program file's content: its SHA-256 is part of the digest the person approves, it is recorded with the approval, and the tool-cli and stdio tool-mcp runners hash the file again right before they start the program (process::check_program_file). A file that changed (an update, brew upgrade, a copy planted at the same path) is not started, and the call says to approve the tool again. A program with no pin is refused twice over: the gate does not offer the tool, and the runner does not start it. A name not on the PATH, a relative path, or a file that cannot be read cannot be approved. Hashing opens the file once (O_NONBLOCK | O_NOCTTY), requires a regular file of at most 256 MiB (checked on that open file, so a FIFO, a device such as /dev/zero or a directory is refused), reads it as a stream, and takes the #! line from the same bytes. Where the pin does not hold, the preview says so (a WARNING: line in the CLI, the program_warning field, and a warning in the dialog), each case apart: when the program file, any folder above it (as written, where a symbolic link lies, and as it resolves) or the interpreter its #! line names is owned by the user or writable by the user; and when a #!/usr/bin/env X script starts X from the PATH. It is a warning, not a refusal.

The approval key

  • The daemon makes the key at start from the operating system's random source, one per process, shared by every database, and keeps it only in memory. It is never stored and no RPC returns it. The keychain item nodespace.secrets/approval-key is gone, and so is everything that wrote or read it (approval_key, provision_approval_key, add_if_absent, has_add_only_write, the macOS add-only write, the direct security-framework dependency). A key planted in the keychain under that name has no effect, and nothing reads that item while a turn is offered tools or runs one. The per-turn keychain read is gone too: the host takes the key from the daemon.
  • Code identity check at start (packages/daemon/src/code_identity.rs): csops(getpid(), CS_OPS_STATUS). A release build makes a key only when its signature is valid and not ad hoc (neither codesign -s - nor a linker signature), the hardened runtime is on, get-task-allow is off and no debugger has attached. One that fails gets no key: nothing is approved or offered, and ApproveTool says "this nodespaced is not a signed release". A development build (debug assertions) makes a key with a loud warning that it is not a security boundary.
  • Homebrew formula installs run a daemon built and signed ad hoc by the formula's job, so they get no key and can never approve a tool. nodespace secret set still works there, since the dialog does not depend on the signature.
  • Windows and Linux: no key, ApproveTool refused with FAILED_PRECONDITION ("not available on this platform"), nothing offered.
  • Cost: approvals end when the daemon restarts (a reboot, an update, Quit in the tray). Every tool is off again until it is approved again. Acceptable until the data-protection keychain stage below.
  • Startup wiring: nodespace_daemon::install_approval_services(&shared) (in the library) installs the dialog check and the key before any database is opened, and returns the check for SecretServiceImpl::keychain_with_presence. A daemon that does not call it approves nothing and changes no credential: ApproveTool says no key is held and why, and SecretServiceImpl::keychain() refuses every Set and Delete, saying install_approval_services was not called. SecretServiceImpl::new and with_gate take the check too: there is no way to build the credential service that asks no one.

Every change to an approved tool ends its approval

An approval is a tag plus a record (nodespace_core::tool_approvals, in memory, per database file and node). The record is a one-shot token, and no decision about it rests on a version number:

  • NodeService::write_tool_approval (the only thing that opens a record) opens it as pending, then makes the approval's write inside a task-local mark that says "this task is writing the approval of this node in this database".
  • The first update the node service reports for that node inside the mark consumes the token: the record becomes live, holding the version and creation time that write left. Any other reported write to the node ends the record outright, whatever version it leaves: an update outside the mark (another task, another program through the daemon), a second update inside it, a create, a delete. A pending record never counts.
  • The store's notifier (writes made through the store itself, which it reads back after it released the write guard) ends the record unconditionally: the approval's own write never goes that way, and what the notifier reads back may not be what was written.
  • The record goes back when the approval's write does not land, however that happens (a conflict, a failure, a transaction that reported the write and then did not commit, a caller that gave up while the write waited for the database): a guard takes it back unless the write returned success.
  • A live record counts only while the stored node has exactly that version and creation time (remote_tools::assess_stored, used by the turn's host and by the approval's preview and read-back); a node that differs in either ends it.
  • Writes the node service does not report as node events end records too: a merge ends the record of the survivor and of the loser before it runs (it rewrites one and archives the other with raw SQL); a field rename rewrites the nodes of the type and the schema node written in the same transaction then ends every record of the database; and a write of a schema node (created, updated, deleted, through the service or through the store) ends every record of the database (a merge of two schema nodes ends only the records of those two ids, and a bare property write on a schema node is not covered), since a schema can change what a tool's type extends, or its fields, without writing the tool.

So any later write that changes what the approval covers ends the approval, through every path the daemon reports (a few writers are not reported: title-only and bookkeeping writes, and the store-level updates whose notification can be skipped by a failed read-back or cancellation; none of them touches what the tag covers, apart from the narrow cases listed in the follow-ups below): turning it off (which also removes the tag), an edit (and reverting it does not bring the approval back), archiving and bringing back, a change of type away and back, a merge, or writing the old tag back with enabled: true. The model's built-in update_node can write a tool's binding (it refuses only conversation records); with this, such a write only ever turns the tool off. A row put back afterwards by writing the database file directly, with its old version, fields and tag, is not approved: the reported write that changed the row ended the record, and lowering the stored version behind the service's back cannot make a later write look like the approval's own. A node made again under the same id has a new creation time as well. The record is per database, so a copy of an approved node in another database is not approved there. At most 4096 records per database are kept; the oldest goes first, which only ends that approval.

What this defends against, and its limits

It is a defence against the model, the tool programs the daemon starts, and any other same-user program acting through the daemon: an approval or a credential change needs a person at the screen to confirm the system's own dialog, the key that tags approvals and makes codes exists only in the daemon's memory, and every change to an approved tool ends its approval. It is not a defence against everything a same-user program can do:

  1. Consent phishing. This is stronger than a lookalike: a program can make the daemon show the person a real system dialog, for a request of its own (a tool it wrote, a credential it wants changed), and hope they confirm it. The code first in the reason, keyed so only the daemon can make it, then the name and the program or host (the host a call reaches), whole, before the credentials and the arguments, and node text shown with the characters it could fake a code with escaped, mean a person who compares the code and the program or host with what their own nodespace tool approve printed is not fooled by a dialog for another tool. That holds only while the nodespace they ran is the real one. A program of the user can shadow the command (a shell function or alias, an earlier PATH entry, a user-writable Homebrew or /usr/local/bin copy): the fake can call DescribeToolApproval for a tool of its own, print that tool's code next to the user's tool text, and send ApproveTool for its own tool. The dialog's code then matches, and its name can equal the user's unapproved tool's; only the program or host and the credentials in the dialog tell them apart. A person who does not compare those, or who confirms a dialog they did not start, can be fooled. A credential dialog names the credential but carries no code. A display the user can trust is the signed app's (Stage 5).
  2. Dialog pressure. A program can keep asking. A refusal while another dialog is open, or in the quiet time after one, comes back at once, so a program that polls can take the slot the moment each quiet time ends, and the person's own request may never get a dialog; that is not bounded by the 15-minute cap. Each dialog that is not confirmed keeps the next back longer (30 s doubling, up to 15 minutes, counted over 10 minutes), which limits how many dialogs the person sees, not how long their own request can be crowded out. The 5 s after a confirmed dialog only keep back a request placed right behind the person's own; after that only the code and the rest of the dialog tell them apart. A refusal says another program on the Mac may be asking, and the daemon logs it.
  3. Replacing the daemon. The .pkg installs its LaunchAgent in the root-owned /Library/LaunchAgents, but the app's own per-user LaunchAgent plist is user-writable, launchctl bootout stops the daemon either way, an Intel Homebrew install keeps it in a user-writable /usr/local/bin, and the user can run a daemon of their own build. Such a daemon approves whatever it likes. The code-identity check only stops an unsigned, ad hoc or debuggable release build from making a key.
  4. The program file is checked, then started by path. It is hashed right before it starts; a file replaced in the moment between the check and the start runs. For a file the user can write (a Homebrew prefix, ~/bin, node_modules) a loop that renames a copy into place wins that race on a real share of calls (around one in four when both copies are equally likely to be in place), so the pin is a real control only for a file the user cannot write; the preview and the dialog warn when the file, a folder above it or its #! interpreter is owned by or writable by the user, and do not refuse. The check cannot see every way a file can be replaced (an admin user can write a root-owned folder through sudo). A #!/usr/bin/env X script starts X from the daemon's PATH at each call, which is not pinned (warned apart), and no pin covers what a program loads (an interpreter's script, a package an npx command fetches).
  5. Credentials still live in the legacy login keychain, so the system's own security tool can still overwrite a credential's value directly. The dialog covers changes made through the daemon only.
  6. A restart ends every approval (see above).
  7. AnswerConfirmation (the per-call question) has the peer-gate gap. It is still gated by SpawnedProcessGate alone: a same-user program the gate does not recognise (an orphaned descendant of an in-app shell or ACP agent, an agent the user started outside the app, a program that left its process group) can read a pending question's id and digest from its card and answer it. Stage 5 below.
  8. Writing the database file directly. A direct write is not reported, so it is not seen when it is made. But every write the node service reports since the approval's own (an update at any version, a create, a delete, a merge, a schema change) has ended the record, and a live record counts only while the node has exactly the version and creation time the approval's write left. So a direct write can only put back the state that is approved now; one that moves the version ends the approval at the next check, and one that changes the name, description or binding fails the tag. A direct write that changes something the tag does not cover (a parent, a property outside the binding) and keeps the version leaves the approval in effect.
  9. Development builds are not a boundary. A debugger or another program of the user can read a debug daemon's key.
  10. Not verified here: the password path in the system panel against synthetic input (Accessibility keystrokes); if it turns out to be scriptable, the fallback is a biometrics-only policy. Root, SIP turned off, or a debugger allowed on the daemon are out of scope.
  11. Buffers. A Set's value is wiped in the daemon's own copies, but not in the gRPC receive buffers (tonic/h2) it arrived in.
  12. Peer data (the Sync product). Not checked in the sync repository itself. In core, a create always stores the time of the insert as the creation time (a peer cannot set it), an update always sets the version to the previous one plus one, enabled and approved_binding are declared local-only, and a tag is a MAC under this daemon's in-memory key. So a peer's write cannot make a record match: any write of it the node service reports ends the record, a node it creates is new, and it cannot supply a tag that verifies.
  13. ACP launches. AcpLaunch.secrets resolves keychain values into the environment of whatever program the launch names, with no approval and no pin. Nothing sets a launch from data a model or another program can write today; before anything does, the launch needs this same gate (a doc comment on the field says so).

Also, a command run from the in-app PTY terminal or by an ACP agent descends from a recorded program, so nodespace tool approve and nodespace secret set|delete are refused there. The user runs them from a normal terminal.

Gated and ungated RPCs

RPC Peer gate Dialog at the screen
LocalAgentService.ApproveTool gated required
SecretService.Set / Delete gated (Unix) required
LocalAgentService.AnswerConfirmation gated no (limit 7)
LocalAgentService.DescribeToolApproval ungated: read-only, what GetNode already shows, plus the code no
SecretService.ListNames ungated: names only no
every other RPC ungated, unchanged no

On Windows a named pipe carries no peer pid and there is no dialog, so ApproveTool, AnswerConfirmation and SecretService.Set/Delete are all refused there. That is a change for nodespace secret set|delete on Windows (and Linux, which has no store anyway): they no longer work there. A stored credential could only be used by an approved tool, and nothing is approved on those platforms; env: references still work.

Tests

Reproduce-first; every new test was mutation-checked on its own: each fails under a mutation of the code it guards and passes on the clean tree. 137 mutations in all, none left surviving: 28 for the dialog, 14 for the in-memory key, 7 for the first live record, 37 for the second review round, 20 for the third and 31 for the fourth. In the fourth round the version-based rule the reviewer broke (keep a record when a reported write leaves the approved version) was put back as a mutation: the new direct-write test and the one-shot unit test both fail under it. Two forgets added to the field-rename paths survived their mutations, because the schema node written in the same transaction already ends every record; they were removed, and the mutation of the schema-write rule then failed the test at the rename itself. In the second round three first survived, each because a second rule also stopped the test (a pruned record, a delete hook, a version check); those tests were changed to isolate one rule and the mutations then failed them. In the third round the mutation of the store notifier's update branch first survived: the tests' updates went through the node service, which reports them as emitted events (that branch's mutation was killed). A store-level update was added to the delete-path test, and the notifier mutation then failed it. A mutation that would show a real dialog was never used.

  • nodespace-core:
    • tool_approvals: an approval is live only for its tag, version, creation time and database, and a node that differs (a lower version as much as a higher one) ends it; a pending record never counts and a look at the node leaves it; the token is consumed once, only by a write inside the approval's own mark, and a write outside it, one for another node inside it, a second one inside it, or any later write at any version ends it; an approval whose write did not land takes its record back, pending or consumed, and no newer one; a schema change ends every record of its database and no other; at most 4096 records per database, oldest first.
    • Through the real store: an update through the node service and one through the store itself end the record, and so does a delete on every delete path (versioned, unchecked, bulk, pruned by an import); a merge ends the record of both tools; a field rename, a schema update, a field rename inside an update, a new schema, retargeting what a type extends, and a schema written through the store each end every record; a tool deleted and then put back by writing the database file directly, with its old version and creation time, is not approved.
    • The approval key is random each time and prints nothing.
  • nodespace-agent tool_approval:
    • The code is keyed by the daemon's key and absent without one.
    • A bare program name is shown and approved as its full path; a program not on the PATH cannot be approved; one that resolves elsewhere since the preview, or whose file changed since the preview, is refused as changed; a full path is not looked up but is pinned by content; a stdio MCP command is pinned and an HTTP server has nothing to pin.
    • The real PATH lookup finds sh, hashes the file and refuses a missing name or file; a relative program path cannot be approved.
    • Where the pin does not hold (a replaceable file, a script that starts a program from the PATH) the preview says so, and the approval still works; the dialog's parts name the program or the host apart from what may be cut; the dialog names the host a call reaches (an escaped dot, a user name before @, a backslash, a name outside ASCII, an upper-case scheme and a default port), and text a parser cannot read is shown as written and said so.
    • The approval records the program file's SHA-256 for the runner; an edit after the review is a conflict; a failed write takes back its record; an edit landing right after the write is not in effect; an approval under another key (a restart) is neither in effect nor approved; a tag written back after the tool was turned off is not approved.
  • nodespace-agent remote_tools, through the host and a real node service:
    • No key offers nothing; a key planted in the credential store approves nothing, and the planted item is never read while tools are offered and called (the store is the one the runners get, with a read counter).
    • A tool approved under an earlier daemon key is not offered.
    • Each revival is refused: a tag written back after turning off, an edit reverted, archived and brought back, retyped away and back, deleted behind the service's back and made again up to the approved version, a byte-for-byte copy in another database.
    • A tag with no record is not admitted; a program tool is admitted only with its program pin, which it carries to the runner.
    • A program file replaced after the approval is not run (the real tool-cli runner); in the MCP runner a stdio server whose file changed is not started and one that matches is.
    • A row written back directly into the database after the tool was turned off through the node service, with its old version, fields and tag, is not offered.
    • The reviewer's case: approve, lower the stored version directly, turn the tool off through the service (its write lands on exactly the approved version), write the approved row back directly at that version: not offered.
    • An approval whose write is given up while it waits for the database (another transaction holds it) leaves no record, and nothing is written.
  • nodespace-agent process: only a regular file of at most 256 MiB is hashed (/dev/zero, a FIFO, a directory and an oversized file are refused, none hangs); a program with no pinned content is not started; a file of this user is replaceable even when it is not writable, a system program is not, and an #!/usr/bin/env script names what it starts; the walk covers the folders above the path as written (a link in a folder of the user) and above what it resolves to; a script whose #! interpreter is replaceable is replaceable.
  • nodespace-daemon user_presence:
    • Only a confirmation lets a change through; a second dialog while one is open is refused unshown; a cancelled dialog keeps the next back for the cooldown, longer each time, capped; a confirmed one keeps the next back for a moment; a busy or quiet refusal says another program may be asking; a daemon that installed no check says so.
    • The reason is code, name, then the program or host, whole, then the credentials, then the arguments, cut; seven long credentials are cut to four named, each cut, and "+3 more"; the node's text is ASCII with its brackets, colons that are not an address's, ; and code-shaped dashes escaped, while an address keeps its :// and port; a replaceable program file and a script that starts a program from the PATH are flagged apart.
    • The macOS adapter, driven by an injected evaluation: only a yes confirms, only -1004/-4/-5 are "unavailable", an unanswered dialog is invalidated. The real-dialog smoke test is #[ignore] and, even in a run of the ignored tests, does nothing unless NODESPACE_SHOW_REAL_DIALOG=1; it was not run.
  • nodespace-daemon ApproveTool, with a fake dialog: the dialog's two program warnings follow the review's findings apart (a PATH lookup is not called a replaceable file); a wrong digest is refused with no dialog; a cancelled or unavailable dialog writes nothing; the dialog is the one built from the code, name and target; an edit while the dialog is open is a conflict; a second approval while one is open is refused; no key refuses with the reason and no dialog; a turn offers a tool approved here and not one tagged under another key even with a record in place; the check and the key the library installs reach every database's service, and without them nothing is asked or approved. Over a real socket the daemon's own gate refuses before any dialog, and an admitted peer approves what it was shown, with the same keyed code.
  • nodespace-daemon SecretService: a store that panics while writing fails the Set (and the request holds no value); not confirmed (cancelled or no screen) leaves the store unchanged and zeroes the Set value; a Set dropped while the dialog is open has its value zeroed where it lies; a confirmed change goes through and the dialog names the credential; a bad name or value is refused before anyone is asked; a refused peer is refused before any dialog; a service built without an installed check refuses every change and says why.
  • nodespace-daemon code_identity: a signed release needs a valid identity signature (not codesign -s -, not a linker signature), the hardened runtime, no get-task-allow and no debugger; a key only on macOS for a signed release or a development build; csops returns this test binary's real flags (valid, linker-signed).
  • nodespace-daemon main: every serve loop installs the check and the key before it opens a database, and builds the credential service with that check.
  • nodespace-cli: the question names the code; the pinned program file is shown with what the pin means, and the WARNING where it does not hold; a daemon that gives no code is not asked to approve.
  • Removed as vacuous: the approval_key-store tests whose code is gone; "an approval stores nothing in the credential store" (nothing touches that store); "the reason is handed to the system as given" (it tested the fake); the field check that stood in for the main wiring.

Not covered by an automated test: the real LocalAuthentication dialog and the objc block that carries its answer (compiled and clippy-clean, never run: it would show a dialog on this shared Mac), how the real panel lays out or shortens a long reason, csops on a signed release build, and the window between the program file's check and its start. That a panic in the store task wipes the value rests on Zeroizing (the buffer is freed with it, so it cannot be read back). O_NOCTTY has no test of its own. The own-write mark is task-local: it relies on the node service reporting the approval's write on the task that made it (true today, and every approval test depends on it); if that ever moves to another task, the approval fails closed ("written but not in effect"), it does not open.

Checks: cargo fmt; cargo clippy -p nodespace-core -p nodespace-agent -p nodespace-daemon -p nodespace-cli --all-targets -- -D warnings -D clippy::unused-async clean; bun run quality:fix clean (no changes); bun run skill:check up to date.

bun run test:changed was run directly with a scratch NODESPACE_HOME: the scripts tier passed; the skill tier failed only on the known plugin-session.test.ts › "takes a write from a script as the session's own through the journal", which fails whenever NODESPACE_HOME is set. Without that variable the skill suite passes, 312 of 312. The Rust tier was then run on its own under the machine slot with a scratch NODESPACE_HOME:

  • types:check up to date; shape:check in step (no schema or seed changed).
  • node-types:check skipped (no docs checkout beside the worktree; no node type changed). The docs repository's tool-registry.md and node-types.md still describe the stored key and need the new text (handed over separately; this PR does not touch the docs repository).
  • Workspace nextest: 6494 passed, 0 failed. As always it loads the embedding model in find_skills_schema_metadata_test.
  • App unit tests: 478 passed.

Verify by hand (signed .pkg, at the Mac's screen)

  1. nodespace tool approve <id> prints a code; the dialog starts with the same code, then the tool's name and the full program path or the host (with "that file's content is pinned" for a program), then its credentials, and the arguments last. Touch ID or the password approves; Cancel leaves it unapproved and not offered. Check how the panel shows a long reason (whether it cuts it), and that the code, name and program or host stay visible.
  2. From an SSH session the dialog appears on the Mac's own screen (confirm or cancel it there). With the screen locked, or another user at the console, the request is refused at once and nothing is written.
  3. From a Terminal that has Accessibility permission, keystrokes or clicks sent with osascript must not complete the dialog.
  4. codesign -dv --entitlements - /usr/local/bin/nodespaced shows the runtime flag and no get-task-allow; lldb -p $(pgrep nodespaced) is refused.
  5. After Quit in the tray and a relaunch, the tool is no longer offered; approving it again works.
  6. (Test user only) Plant a key with security add-generic-password -A -s nodespace.secrets -a approval-key -w <64 hex> and write a tag made with it through NodeService: the tool must not be offered.
  7. nodespace secret set <name> and delete show the credential dialog; Cancel leaves the stored value as it was.
  8. Approve a tool-cli tool, then replace its program file (or brew upgrade the formula it names): the next call is refused with "changed since the tool was approved"; approving again works.
  9. Approve a tool, edit its description, put the old description back: the tool is not offered until it is approved again.
  10. Approve a tool whose program is under /opt/homebrew/bin or ~/bin: the CLI and the dialog show the WARNING that programs of this user can replace the file. A #!/usr/bin/env python3 script under a root-owned folder shows only the PATH warning.
  11. A tool-rest tool with url_template https://api.github.com%2eevil.com/x: the CLI's binding shows the text as written; the dialog names https://api.github.com.evil.com.

Follow-ups (not here)

  • Stage 4: data-protection keychain. Keep the key (and the approval records) in a data-protection keychain item with a team keychain-access-groups entitlement, so approvals survive a restart and only the signed daemon can read the key. Needs the Apple account holder, a provisioning profile, an app-like bundle for the daemon, and build-pkg.sh / release.yml / LaunchAgent changes. Credentials could move there too (closes limit 5).
  • Stage 5: peer identity. Capture the peer's audit token in peer_auth.rs (LOCAL_PEERTOKEN) and restrict AnswerConfirmation to the signed app (SecCodeCheckValidity against the team id). It is also what makes the review the user reads come from a program they can trust (limit 1). Closes limit 7. The same check is part of what an ACP launch's binding needs (limit 13).
  • An ADR for the user-presence boundary: what needs a confirmation at the screen, the in-memory key and approval records, and the content pin.

Not merged; merging is the user's call.

🤖 Generated with Claude Code

Known follow-ups from the last review (low, fail closed or need the user's own approval to race with): a record goes live at buffer time, so a concurrent DescribeToolApproval poll can end a re-approval of a still-enabled tool (denial of service only); a merge forgets before it takes the write lock and a schema merge ends only the two merged ids; store-level updates notify after a read-back that can fail; begin, as_own_write and reported_update should be pub(crate); the replaceable-program warning does not walk every symlink hop, checks one interpreter level and reads 256 bytes of the #! line; credentials beyond the fourth are hidden in the dialog in an order the node chooses, so the code and the program or host are what the user can rely on; a very long program path can push the warnings out of a shortened panel; any schema write silently ends every approval in its database.

@mstomar125 mstomar125 changed the title feat: approve a remote tool on this device (nodespace tool approve, DescribeToolApproval/ApproveTool); peer gate on credential changes (#4291) feat: approve a remote tool on this device, confirmed at the screen (nodespace tool approve, DescribeToolApproval/ApproveTool); credential changes confirmed too (#4291) Nov 21, 2026
@mstomar125

Copy link
Copy Markdown
Contributor Author

Merge queue: #4325 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 4325.

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/a0330e891e733f4e-gfp_p384.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/ec/gfp_p384.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/a0330e891e733f4e-gfp_p384.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/ec/gfp_p384.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-21T12-27-53-107Z/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 11 commits November 21, 2026 13:42
… DescribeToolApproval/ApproveTool); peer gate on credential changes (#4291)

- agent: tool_approval module. preview() returns the name, kind,
  description, every binding bucket, the parameter schema and the
  credential references with a digest, writes nothing and creates no key;
  approve() re-reads the node, refuses a digest it no longer produces,
  provisions the device key and writes enabled + approved_binding (the
  existing HMAC tag via remote_tools::approve), version-checked.
- core: SecretBackend::add_if_absent, never replacing an item (macOS:
  SecKeychainAddGenericPassword, duplicate = present; Windows: read then
  write; default refuses). provision_approval_key writes the key with it.
- daemon: DescribeToolApproval (ungated) and ApproveTool (peer gate before
  routing); SecretService Set/Delete behind the same SpawnedProcessGate on
  unix, a refused Set wipes its value; peer_pid/peer_allowed shared in
  remote_confirmation; the turn's remote-tool host uses the service's
  SecretStore.
- cli: `nodespace tool approve <node-id>` shows the escaped preview and
  approves only after the exact name is typed; refuses without a terminal
  before contacting the daemon; refused by the MCP passthrough.
- skill: CLI reference regenerated, with an "Approve a remote tool" note.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…roval preview (#4291)

- behaviors::end_approval_unless_enabled, run in rebucket_and_validate_behaviors
  after validation: every write that leaves a tool's `enabled` anything but true
  removes `approved_binding`, so turning a tool off and on again needs a new
  approval. The tag formula is unchanged.
- SecretBackend::has_add_only_write. SecretStore::approval_key and
  provision_approval_key take no lock, and a backend without an add-only write
  is neither provisioned nor read. The Windows read-then-write add_if_absent is
  removed: no approval key is kept or trusted on Windows.
- tool_approval: preview and approve call the store through spawn_blocking.
  approve reads back the stored key and the stored node and runs the gate;
  ApprovalError::NotInEffect (ABORTED) when it does not pass. The simulated
  post-write check is gone. The preview carries a one-line target (proto
  DescribeToolApprovalResponse.target).
- nodespace tool approve: one-line fields show a line break as an escape; the
  binding, its target and the credential references show non-ASCII as escapes
  with a note; schema first, binding last, target right above the question.
- SecretService: Set runs through set_in_place, so a refused Set wipes the value
  in the request on the service's own path.
- Module docs and the skill reference state the same-user limits of the approval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on at the screen (#4291)

- nodespaced asks the system (LocalAuthentication, deviceOwnerAuthentication)
  before ApproveTool writes a tag and before SecretService Set/Delete change
  anything: new user_presence module with the macOS adapter (a new LAContext
  per change, Touch ID reuse 0, 60 s limit then invalidate, on a blocking
  thread inside an autorelease pool), an unavailable check for other
  platforms, and a fake for tests. -1004/-4/-5 map to "confirm at this Mac's
  screen"; canEvaluatePolicy is never consulted.
- One dialog at a time across approvals and credential changes, and a 30 s
  cooldown after one that was not confirmed. The reason is written by the
  daemon: tool name, code and target as ASCII with \u{..} escapes, cut.
- ApproveTool: peer gate, then review (digest must still match, no dialog
  otherwise), then the dialog, then the write with the version read before
  it (an edit during the dialog is a conflict), then the read-back gate.
  tool_approval splits into review() and write().
- DescribeToolApproval returns `code` (first 8 hex digits of the digest as
  XXXX-XXXX); the CLI shows it and asks to confirm only a dialog with it.
- A bare program name (tool-cli program, stdio tool-mcp command) is resolved
  on the daemon's PATH when shown; the preview and digest cover the full
  path and the approval writes it into the tool. A name not on the PATH
  cannot be approved.
- SecretService refuses a bad name or value before asking, and wipes the
  value of a Set that was not confirmed. The CLI says to confirm.
- Limits text updated in tool_approval, remote_confirmation and spawned;
  skill reference regenerated.

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

A test that goes wrong while a dialog is waiting now fails instead of
hanging on it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ty check at start (#4291)

- nodespaced makes the approval key at start from the OS random source
  (ApprovalKey::generate, getrandom), one per process for every database,
  and keeps it only in memory: nothing stores or reads
  nodespace.secrets/approval-key any more, so a key planted there has no
  effect. Deleted: the approval-key account, approval_key,
  provision_approval_key, add_if_absent, has_add_only_write, the macOS
  add-only keychain write and the direct security-framework dependency.
- RemoteToolHost takes the key from the daemon instead of reading the store
  on every turn; tool_approval::preview/write take the key, and write reads
  the node back and checks it under the same key (commit, then in_effect).
- New code_identity module: csops(getpid(), CS_OPS_STATUS). A release build
  makes a key only with a valid non-ad-hoc signature, the hardened runtime,
  no get-task-allow and no debugger attached; otherwise no key and
  ApproveTool says it is not a signed release. A debug build makes one with
  a warning that it is not a security boundary. Other platforms make none
  (ApproveTool: FAILED_PRECONDITION, nothing offered).
- SharedLocalAgent holds the key (installed once at startup, none until
  then); ApproveTool checks for it after the digest and before the dialog.
- The turn's host is built in remote_tool_host, so a test can see what a
  turn is offered.
- Approvals now end when the daemon restarts; the CLI and the skill
  reference say so.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e it (#4291)

- Core counts, on the write path itself and before the write is stored,
  every write that leaves a tool off (behaviors::tool_off_writes, in
  memory per process; tool_is_off). Not through the event bus.
- remote_tools::approve records each issued tag with the node's creation
  time and that count, read before the tag is written. The new
  assess_stored admits a tool only while both still hold (Refusal::NotLive);
  the host and tool_approval's preview and read-back use it.
- So a tag read before the tool was turned off and written back afterwards
  with enabled: true is not offered, and neither is a tool deleted and made
  again under the same id with its old tag. Approving it again works.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…approval, program content pinned (#4291)

- Code (M1): HMAC-SHA256 under the in-memory approval key over the preview
  digest, 48 bits as XXXX-XXXX-XXXX (behaviors::tool_approval_code); empty
  without a key, and the CLI then refuses before asking. The dialog reason
  starts with the code, then the name, then what the tool runs; in node
  text `(`, `)`, `:` and a dash between code-shaped hex groups are escaped.
- Approvals (M2, L1, L8, L9): new core tool_approvals ledger, keyed by
  database file and node, recording tag, version after the approval's own
  write, creation time and the program file's SHA-256. The gate
  (assess_stored, now given the NodeService) admits a tool only while its
  stored version and creation time match, so any later write (an edit,
  reverted or not, turning off, archiving, a type change) ends it. A delete
  the node service reports removes the record (store notifier and emitted
  events), so a row restored by writing the file directly is not approved.
  The record is written before the approval's update and taken back when the
  update fails. At most 4096 records per database, oldest first. The
  in-memory off-write counter is removed.
- Program content (M3): the preview resolves the program (bare name on the
  PATH, then the file hashed) on a blocking thread; the digest covers the
  SHA-256, DescribeToolApproval returns `program`, the CLI shows it and what
  the pin means. The cli and stdio-mcp runners check the file's SHA-256
  right before they start the program (process::check_program_file); a
  program-starting tool with no pin recorded is not offered.
- Presence (L2, L4): the cooldown doubles with each unconfirmed dialog in 10
  minutes (up to 15), 5 s of quiet after a confirmed one, refusals logged and
  saying another program may be asking; -1004/-4 wording no longer claims
  SSH is refused (the panel shows on the Mac's screen).
- Credentials (L3, L5): SecretServiceImpl::new/with_gate take the presence;
  keychain() with no check installed refuses every change and says why;
  keychain_with_presence is what daemons build. install_approval_services
  moves into the library. A Set's value is wiped on drop, including when the
  client hangs up while the dialog is open.
- Code identity: also rejects linker-signed (ad hoc) binaries.
- ACP launch secrets get a loud doc comment: no approval gates them yet.
- Tests: vacuous ones replaced (planted key now wired into the runners with
  a read counter, main wiring asserted, csops flags checked); new tests for
  each finding.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- The ledger unit test checks a moved version before a new creation time,
  so each rule is tested on its own record.
- The delete test also prunes a tool through a trusted import, the path
  whose delete is reported as an emitted event.
- The made-again test deletes behind the node service's back and writes the
  new node up to the approved version, so only the creation time tells them
  apart.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…shows credentials and program first, bounded hashing (#4291)

- F1: every write the node service reports that is not the approval's own
  ends its record on the spot (store notifier Updated at another version,
  Created, Deleted; emitted NodeUpdated/NodeCreated/NodeDeleted), so a row
  written back directly after the user ended an approval is not offered.
- F4: the record is still written before the approval's write, and a look at
  the node before that write lands no longer drops it: only a later version
  or another creation time does.
- F2: the dialog reads code, name, credentials, then the full program path or
  the method and scheme://host:port, kept whole; only the arguments or the
  rest of the address are cut. `://` after a scheme and a port's `:` stay
  readable; other colons, `(`, `)`, `;` and code-shaped dashes are escaped.
- F3: program files are opened non-blocking, must be regular files of at
  most 256 MiB (checked on the open file) and are hashed as a stream.
- F6: the preview, CLI (WARNING line, new `program_warning` field) and
  dialog say when the program file or its folder is writable by the user, or
  a `#!/usr/bin/env X` script starts X from the PATH.
- Nits: an unpinned program is refused at the runner too; a relative program
  path is refused at the preview; one keyless guard (in assess) instead of
  two; the planted-key read counter is documented as a tripwire; a Set's
  value is in Zeroizing for the store task, so a panic still wipes it.
- Docs: limits rewritten (shadowed CLI, polling pressure, check-to-start race
  for user-writable files, direct writes).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The delete-path test now also updates the tool through the store itself,
the path its notifier reports, besides an update through the node service.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The approval record no longer decides anything from a version number.
NodeService::write_tool_approval opens it as pending and makes the
approval's write inside a task-local mark; the first update reported for
the node inside that mark makes it live, and any other reported write
(an update at any version, a create, a delete) ends it. The store
notifier ends a record unconditionally. A guard takes the record back
unless the write returned success, including when the caller drops the
write while it waits for the database.

A merge ends the record of the survivor and the loser before it runs,
and any write of a schema node (through the service or the store) ends
every record of its database, which covers field renames and a type
retargeting what it extends.

The dialog now gives the code, the name and the program or host first,
then at most four credential references (each cut at 64 characters,
the rest counted), then the arguments. The host is read with a URL
parser, so escaped dots, user names and backslashes show the host a
call reaches. A replaceable program file and a script that starts a
program from the PATH are warned apart.

A program file is opened once (O_NONBLOCK | O_NOCTTY) for its hash and
its #! line. It counts as replaceable when the file, a folder above it
(as written or as it resolves) or its #! interpreter is owned by or
writable by the user.

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