Expand description
srv’s secret storage: account API keys, OAuth accounts, MuxBus credentials, browser-pane logins.
Backs SecretRef::Keychain { service, account }, which names an entry in
this store, wherever it keeps secrets; the DB holds just the pointer plus
non-secret metadata + a masked tail. Reads return a Zeroizing<String> so
the plaintext is wiped from memory on drop.
Two backends, chosen once at startup:
- The OS keychain (macOS Keychain / Windows Credential Manager / Linux
Secret Service via the
keyring-corecrate). The default, and what the desktop app always uses. - A file store (
use_file_store): one0600file per entry in a0700directory, for machines with no keychain — a container, a server, CI. Headless srv uses it unless told otherwise (docs/specs/SPEC_SRV_HEADLESS_MODE_2026_09_26.md §3.6). Secrets are protected by file permissions (and the volume’s own encryption), not encrypted by srv: a key kept beside them would add nothing.
There is no silent downgrade from one to the other: failures surface as errors. See docs/specs/archive/SPEC_TRUST_CENTER_2026_06_15.md §7 and §12.2.
The rest of this comment is about the keychain backend.
macOS: srv never shows the keychain’s consent dialog
([keychain_without_dialogs]). A keychain item trusts the code identity
that wrote it, plus any the person allowed. One written by a build with
another identity (every srv before v0.59.16 had a versioned one; a
task dev build changes identity on each rebuild) used to bring up “AgentMux
Server wants to use your confidential information…” unasked, at startup,
after an upgrade. Now such a read fails at once with NEEDS_CONSENT,
and each caller decides: the MuxBus sign-in counts as signed out
(get_optional_if_trusted; signing in again writes a fresh entry), and
everything else reports it. A write
over such an item replaces it (put), so the new one trusts this build.
docs/analysis/ANALYSIS_MACOS_KEYCHAIN_PROMPT_AFTER_UPGRADE_2026_10_21.md.
Reads are bounded by [TIMEOUT]; writes are not — see below. Every
operation here can require interactive OS consent (“App wants to access
your confidential information…”) the first time a given code
signature touches a given entry, and that consent call has no
cancellation mechanism: an unanswered prompt (headless process, dialog
on another Space, no attached display session) blocks the underlying
platform call indefinitely. Confirmed live — see
docs/retro/retro-macos-muxbus-keychain-prompt-storm-2026-08-19.md §5.
get/get_optional run the real platform call on a detached thread and
give up waiting after TIMEOUT, so a stuck prompt bounds how long the
CALLER waits (and any lock it’s holding) instead of hanging it forever.
This is safe specifically because a read has no side effect: if the
timeout fires, the detached thread’s eventual (possibly much later)
result is just discarded — nothing acts on a stale read. At most one
read per account is in flight ([SharedReads]): a retry while one is
still waiting on a dialog joins it rather than queueing another dialog
behind it.
put/delete deliberately do NOT use this timeout (reagent + Codex,
PR #2679 round 2): the same “detached thread keeps running after the
caller gives up” behavior is unsafe for a MUTATION. A caller that treats
a timed-out write as failure and proceeds — e.g. skipping a dependent DB
write, or a rollback in muxbus.rs writing a different value to the
same entry — can have the orphaned original write land afterward and
silently clobber whatever the caller did next, with no ordering
guarantee between them. There is no cancellation-equivalent compensation
available (the platform call truly cannot be cancelled), so until one
exists, an unbounded wait — the pre-existing, safe-if-slow behavior — is
the correct tradeoff for anything that mutates state. A stuck consent
prompt on a write still blocks its caller indefinitely; only reads are
protected today.
Modules§
- file
- The file store. Each entry is one file named by the SHA-256 of its account key, so no key text (ids, hostnames) reaches a file name and no key can escape the directory. No timeouts: file operations don’t wait on a user.
Enums§
- Keychain
Probe - What a try of the OS keychain found (
probe_keychain).
Constants§
- NEEDS_
CONSENT - What a keychain read or write of an item this build isn’t trusted for
fails with on macOS, instead of asking the person (
is_needs_consent). - SERVICE
- Keychain service string — constant across all AgentMux secrets.
Functions§
- account_
key - Build the keychain account string for an identity-account id.
- backend_
name - Which backend this process uses, for logs:
"keychain"or"file". - delete
- Delete the secret for
account_id. A missing entry is treated as success (idempotent delete). - get
- Read the secret for
account_id. Returned wrapped inZeroizingso it is wiped on drop. Resolved at agent spawn time when injecting env vars. - get_
optional - Read the secret for
account_id, distinguishing “no entry stored yet” (Ok(None)) from a real storage failure (Err) — a locked keychain, no Secret Service daemon running, permission denied, etc.getcollapses both into the sameErrvariant, which is correct for its own callers (a spawn-time credential resolve should fail either way), but is the wrong shape for a caller that needs to tell “genuinely never logged in” apart from “storage is transiently broken” — treating a transient failure as “no credential” can silently present as a full logout. Use this variant when that distinction matters. - get_
optional_ if_ trusted get_optional, except that an entry this build may not read without asking (NEEDS_CONSENT) counts as absent, and is logged. For the MuxBus sign-in: one saved by an older build is then signed out, and signing in again writes a fresh entry this build owns, so no dialog ever shows. Never for a key whose absence makes the caller create a new one (the Vault).- is_
needs_ consent - Whether
err(fromget,get_optionalorput) isNEEDS_CONSENT: the entry exists, but this build may not use it without the person’s consent. Not a transient failure, and not “no entry”. - isolate_
for_ home_ override - An isolated instance (started with
AGENTMUX_HOME_OVERRIDE, astask devalways is) keeps its secrets in files under its own home and never in the person’s OS keychain. The keychain is the person’s: a test build that saved the first Vault entry would make the real Vault key there, trusted only by that build, and the person’s own AgentMux could not read it (nor would an account key it saved be theirs). Called once at startup, before anything reads a secret; true when it chose the file store. - probe_
keychain - Try the OS keychain as the server would use it: make the store, then store one test entry, read it back and delete it,
giving up after
wait. A call that waits on a prompt is left running on its own thread (the caller is a short program that then ends), never waited for. - put
- Store (or overwrite) the secret for
account_idin the OS keychain. - use_
file_ store - Keep every secret in files under
dirinstead of the OS keychain, for the rest of this process. Called once at startup, before anything reads or writes a secret. Createsdir(mode0700) if needed.