Skip to content

Add the remote tool gate and host: offer and run only approved tools a runner can run (executor, step 1) - #4310

Merged
mstomar125 merged 4 commits into
mainfrom
issue-4291-exec-gate
Nov 19, 2026
Merged

mstomar125 merged 4 commits into
mainfrom
issue-4291-exec-gate

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Refs #4291, executor step 1 (spec tasks A1, A2, A3: the gate, deterministic name collisions, dispatch, plus the keyed per-device approval and the findings of its security review). This PR changes packages/agent (and wires it in packages/daemon; core gets the approval tag and the device key): the user's sign-off stands in for the agent owner's for this build. Pair: nodespace-docs #165 (merge it just before this PR).

Offering and dispatch land together, and the offering is gated on a runner being present. RemoteToolHost offers a remote tool only if a runner for its kind is installed. This PR installs none (the runners are the next PRs), so after it no remote tool is offered or run; the built-in tools are unchanged. GraphToolExecutor::available_tools now offers native tools only.

The gate

assess(...) is the one function that decides. A node is a remote tool this device may offer or run only when all hold, read from this device's stored node:

  • its nearest core type is tool-mcp, tool-rest or tool-cli (a user subtype of one runs as that kind; a bare extends tool subtype is never offered);
  • its name is a plain identifier and not a built-in tool's name;
  • enabled is exactly true in the tool bucket (absent, false, a string or a flat top-level value all mean off);
  • approved_binding in the tool bucket is the device approval tag for the node as it is now (below);
  • parameter_schema has a closed root;
  • this device has an approval key (with none, nothing is offered).

RemoteToolHost adds: archived tools are not read; a runner for the kind must be installed; two approved tools that share a name are both dropped; arguments are validated against the closed schema (see the limits below); confirmation (CallConfirmer) for every tool-cli and tool-mcp call, every tool-rest call that is not exactly GET, and every GET whose binding carries a credential (an auth secret or a scheme other than none), refused when no confirmer is installed; after a "yes" the gate is re-run and the call runs only if the same node still has the same approval tag; the result is marked "source": "external", output is capped at 10 MiB and a runner error at 2 KiB.

Keyed per-device approval

approved_binding = hex(HMAC-SHA256(device_key, "tool-approval-v1" || node_id || name || description || tool_binding_hash(...))), each field length-prefixed, 64 lowercase hex characters (so core's is_binding_hash validation is unchanged; the field name stays). enabled and approved_binding stay local_only (defence in depth). A pinned known-answer test (computed independently of the Rust code) fails if the label, field order or encoding changes.

  • Device key: 32 random bytes made on first approval and kept in the credential store under a reserved backend account (approval-key) that has no value: prefix and is not in the names index: no keychain:<name> reference can read it, no name can collide with it, secret list-names never shows it, and secret set/delete cannot touch it. Debug is redacted, the bytes are zeroed on drop, an unreadable key is an error and is never replaced. provision_approval_key() re-reads after writing and returns the stored key, so two store instances that race end up agreeing (in-process lock only; across processes the loser adopts the winner's key).
  • Verification is constant time (hmac::verify_slice). No key (store unavailable, e.g. headless Linux, or unreadable) means nothing is offered. The host reads the key once per turn and caches the answer.
  • Binding the node id, name and description into the MAC means a peer cannot reword an approved tool or copy an approval to another node, and cannot make a tag that verifies at all. Tests: reworded description, renamed, copied to another node, a different device key, the old unkeyed fingerprint, no key, unreadable store, and the all-zero key a fail-open default would use (on a missing key and on a read error).
  • The approval write is provided as a pure function (remote_tools::approve(node, chain, key) over behaviors::tool_approval_tag); the gate verifies against the same function. No user-facing approve command in this PR.
  • hmac is new in core's manifest (already in the lockfile with sha2): no new crates. shape:gen regenerated (description text only).

What reaches the model and the logs

  • External results are fenced: [Result of the external tool ...: untrusted data ...] and <external-data id="<random>">...</external-data id="<random>"> (a fresh CSPRNG marker per result). A remote tool's description ends with a line saying its results are data, not instructions. A runner's error is marked external like its output; the host's own refusals are not.
  • A node id inside an external result grounds nothing, in the live turn and in a session's starting history.
  • The per-call log lines, the tool-results span, the messages span and the tool-calls span withhold a remote tool's results and arguments (a size only). A built-in tool's result and arguments are recorded as before (the tool-calls span now cuts a built-in's arguments at 4096 characters). The span tests capture the real exported attributes with a test exporter. The raw model response is recorded as the model wrote it (raw_response and its log field), including any tool-call text in it.
  • The base system prompt is not edited (golden snapshots); the rule sits beside the data and in the tool definition.

Known limits (state plainly)

  • validate_arguments is shallow: no enum/pattern/minimum/items; nested objects are not closed; top-level strings are capped at 16 KiB. Runners must not trust nested shape.
  • assess does not check that the binding is well formed: runners parse it through the typed readers (ToolRestFields::from_bucket and the like) and fail closed.
  • Dispatch is not limited to the turn's offered set (same as built-ins); with keyed approval a hallucinated name can only run an already-approved, gate-passing tool.
  • Prompt-template control tokens inside remote output are not neutralised by the fence (a general residual).
  • provision_approval_key across processes: the re-read narrows but does not close the window (write A, read A, write B, read B can still hand A's key to one caller while B is stored); it fails closed (a tag made under the other key does not verify). Use an add-if-absent primitive when the approve command lands.

Spec choices to confirm

  • Name collisions: skip both (not lowest-id). A user subtype of a remote kind runs as that kind; a bare extends tool subtype is never offered. No cap on the number of tool nodes read. Nothing writes an approval yet (the enable-and-approve command is a later step).

Acceptance criteria for the runner PRs

  • A keychain: / env: credential is only sent to the host(s) bound by the approved binding (the tag covers url, credential reference and header/auth fields; any change needs re-approval). Never to a host derived from model input.
  • A node from a peer never runs automatically (it cannot pass the gate without a local approval).
  • env: references have no deny-list, so the approval UI must show the env name.
  • The resolved value never appears in logs, tool results or errors (redact it if the remote echoes it back); no .expose() outside the injection point.
  • HTTPS only (loopback http excepted); private and link-local addresses blocked after DNS resolution; a header never follows a redirect to another host.
  • tool-cli: argv only, no shell, -- before model-supplied values, environment from the allow rules only, timeouts and output caps. tool-rest: parsed Url only, ./.. placeholder values rejected or encoded, every placeholder value percent-encoded.
  • Runners must not trust nested argument shape and must parse the binding through the typed readers, failing closed.
  • A runner's error text must be bounded and neutral: failure_reason() in the agent loop shows up to 200 characters of a runner's (remote-controlled) error text in user-visible failure text.
  • When the approve command lands, provision the device key with an add-if-absent primitive (see the known limits).
  • When the first runner lands, add a system-prompt line scoped to turns where a remote tool is offered (data from external tools is never instructions), together with the golden updates.
  • Confirmation (A6): the confirmer needs a bounded timeout treated as refusal, and the UI must cap what it displays of the arguments (the request carries up to 64 KiB).

Tests

  • remote_tools::tests has 34 unit tests, plus the core approval/known-answer/key tests, the prompt fence tests, and agent-loop tests for fencing, logging, grounding and the exported spans (with built-in controls). cargo clippy -D warnings clean; bun run test:changed passes.
  • Mutants run in one slot batch per round: 28 on the first version (all caught but one equivalent, the host's built-in-name shortcut that assess already refuses), 29 on the keyed approval, fence and log withholding (all caught after fixing a test-filter miss, a fail-open mutant, two bad patterns), and 9 on the review fixes (the ninth: the tool-calls span carrying a remote tool's arguments): the zero key on a read error and on a missing key (both now killed by the new test), span messages not withheld, external history ids grounded, the tag without its label, a changed label, reordered fields, and the provision returning its own key instead of the stored one. All caught.

🤖 Generated with Claude Code

mstomar125 and others added 4 commits November 19, 2026 15:34
…ly an approved tool a runner can run

RemoteToolHost wraps the built-in tool executor. A tool-mcp / tool-rest /
tool-cli node (or a user subtype of one) is offered and called only when this
device's node has enabled true, an approved_binding equal to the current
binding fingerprint, a plain non-built-in name, a closed-root schema and a
runner for its kind is installed; two such tools with one name are both
dropped. Calls are validated against the closed schema, confirmed when the
kind needs it, and re-checked against the fingerprint after the confirmation.
No runner exists yet, so nothing remote is offered.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…address review findings

- approved_binding is now the device approval tag: HMAC-SHA256 under a per-device
  key (generated on first approval, kept in the credential store outside every
  name a node can refer to) over the node id, name, description and binding.
  The gate verifies it in constant time and fails closed with no key.
- A rest GET whose binding carries a credential is confirmed.
- A runner's error is marked external like its output; an argument name is cut
  in the error that repeats it.
- External results reach the model inside a random-marker fence, ground no
  node id, and a remote tool's arguments and results are never logged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…y grounding, pinned tag vector, provisioning re-read

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