Skip to content

Add the device credential store and nodespace secret commands (remote tools, step 2) - #4309

Merged
mstomar125 merged 2 commits into
mainfrom
issue-4291-secret-store
Nov 19, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-4291-secret-store

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Refs #4291, step 2 of the approved spec (task C9): the device store for the credentials that remote tools refer to. Core side only: no change under packages/agent. Nothing reads a credential yet; the executor PRs are the first consumer.

What it adds

  • nodespace_core::secrets: a SecretStore over a SecretBackend. The real backend is the OS credential store (macOS keychain, Windows Credential Manager) through keyring; an in-memory backend is provided for tests. resolve_credential resolves a keychain:<name> or env:<NAME> reference at call time. SecretValue has no Display/Clone/Serialize and a redacted Debug.
  • SecretService (gRPC, Set / Delete / ListNames) in the daemon, process-global (not routed by database).
  • nodespace secret set <name> / delete <name> / list-names. The value is read from a hidden terminal prompt, or from stdin when stdin is not a terminal; it is never an argument (clap rejects one). list-names prints names only; no command prints a value.
  • The one definition of the name and value rules sits in nodespace-types (is_secret_name, secret_value_problem, MAX_SECRET_VALUE_BYTES), shared by core, the daemon and the CLI.
  • CLI reference documented (bun run skill:gen); the secret subcommand is refused by the MCP passthrough (new test).

Design

  • Daemon owns the store, reached by the CLI over gRPC: one process creates and reads every item, so the OS does not prompt per binary. The value travels only in a Set request; SetSecretRequest has a hand-written Debug that prints <redacted>.
  • Names index. The OS store cannot be enumerated, so names are kept in one extra item (account index, a JSON array of names, sorted). Values live under value:<name>, so no name collides with the index. A failed index write rolls the value back; an unreadable index is an error, never an empty list. If a user deletes a value in the OS tool, its name still lists until secret delete is run.
  • Limits. Name: 1 to 64 characters from letters, digits, ., _, - (the keychain: grammar). Value: 1 to 16384 bytes, UTF-8, no NUL; one trailing line break is stripped from stdin input. Windows is stricter: the credential manager stores at most 2560 bytes per item (UTF-16), so a value is at most 1280 UTF-16 units there, and the names index (one item) holds roughly 19 names of full length or about 70 of 16 characters. A value or a new name over the platform limit is refused with "value too long for this platform" / "too many secrets for this platform", nothing is left behind, and keyring's TooLong maps to the same message. The index is not sharded.
  • Failed set. A failed index write puts back the value the account held (an unlisted old value is restored, not deleted).
  • Zeroize. SecretValue overwrites its value on drop, and the daemon overwrites the Set request's value after storing it.
  • Errors name the rule or the reference, never a value.
  • Same-user access. Any process of the same user (including a shell-capable agent) can call Set / Delete / ListNames over the daemon socket: the same boundary as every other daemon RPC. Values are never readable through any RPC. The rig/dev TCP gRPC mode exposes the service to any local process: do not use real credentials there.
  • env:: an empty variable counts as not set; no deny-list (the approval fingerprint and the per-call confirmation are the guard, as in the spec).

Needs attention

  • Compile break for other daemons built on BaseServices: it gains a secrets: SecretServiceImpl field (use SecretServiceImpl::keychain()). For the sync core-pin bump line. Also note sync's current core pin predates the remote tool types, so per-device local_only enforcement for enabled / approved_binding only takes effect after that bump.
  • Linux and other platforms: the store reports itself unavailable and env: references are the only option. Real Linux support needs libdbus-1-dev in core's CI (and the arm64 cross build), so it is left out on purpose.

Tests

  • Tests use the in-memory backend only; none touches the real keychain.
  • core secrets:: 19, daemon secret_service 5, proto secret_debug 1, CLI unit 4 + new secret_cli integration 5 (the compiled binary against an in-process service), plus the MCP passthrough decision test.
  • cargo check and clippy -D warnings over the workspace clean; bun run test:changed passes.
  • 24 mutants, all caught (the 17 listed below plus: keychain: falling back to env; value ceiling unchecked; ceiling counting bytes not UTF-16; index ceiling unchecked; rollback deleting the old value; old value not read; wipe a no-op) (one slot acquisition): name check removed; value check removed; empty / NUL / one-over-the-limit accepted; delete leaving the name; rollback removed; index holding values; index unsorted; SecretValue Debug leaking; env: reading the store; keychain: reading env; empty env counted as set; proto Debug leaking; CLI accepting a value argument; CLI stripping every trailing line break; daemon delete always reporting existed.

Not run here: node-types:check (no change to any node type or schema; skipped by the tool, no docs checkout beside the primary).

🤖 Generated with Claude Code

mstomar125 and others added 2 commits November 19, 2026 12:45
A tool node holds only a keychain:<name> or env:<NAME> reference. This adds
the store behind keychain: references (macOS keychain, Windows Credential
Manager), a SecretService in the daemon, and nodespace secret set / delete /
list-names. Values are never listed, never an argument, never in an error.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- Windows credential manager holds at most 2560 bytes per item as stored
  (UTF-16): a longer value, and a names index that would pass it, are refused
  with a clear error and rolled back; keyring's TooLong maps to the same
  message.
- A failed index write puts back the value the account held (an unlisted old
  value is no longer destroyed).
- SecretValue and the daemon's Set request overwrite the value when dropped.
- Tests: keychain reference never falls back to env; limits against a
  Windows-like backend; orphan restore.

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