Skip to content

safekeys/dev-key-custody [built] ​

Development-stack key custody: no key material the coding agent's OS user can read as a plaintext file — the dev KEK in the macOS Keychain or a containerised OpenBao dev instance on Linux, and the token signing seed under the same ladder. A plaintext file survives only behind SAFEKEYS_ALLOW_INSECURE_KEYSTORE=1 with a loud startup warning and a permission check; dev-up refuses to start on stale plaintext key files; and a documented separate-user mode runs the sidecar as a dedicated user with peer-credential checks on the socket. The Keychain is a storage improvement, not an access boundary (measured); the separate-user mode is the boundary.

Status: built

Why this exists ​

The dev stack currently stores the KEK in a 0600 file owned by the same OS user as any coding agent, so an agent with file access can read it and the deployment's separate-user promise does not exist locally. The default dev flow must keep the KEK out of an agent-readable file — Keychain on macOS, the containerised dev OpenBao on Linux — with a plaintext file available only behind an explicit, loudly-warned opt-in, and a documented separate-user mode for hosts where the stronger boundary matters.

Design decisions ​

keep-insecure-keystore-name [accepted] ​

Decision: Keep SAFEKEYS_ALLOW_INSECURE_KEYSTORE as the file-mode opt-in rather than renaming to SAFEKEYS_DEV_INSECURE_KEYFILE.

Rationale: The variable already exists, is documented, and is asserted by the production refuse test. Renaming it would churn every reference for no security gain; the semantics being added (permission check, loud warning) do not require a new name.

Date: 2026-09-28

keychain-is-a-speed-bump-not-a-boundary [accepted] ​

Decision: Document the macOS Keychain as a storage improvement, not an access boundary, and name the separate-user mode as the strong local boundary.

Rationale: Measured on this machine (2026-09-28, macOS login keychain): a generic-password item created with security add-generic-password -T <binary> is readable WITHOUT any prompt by an arbitrary same-user process — both via the security CLI and via the Security framework (SecKeychainFindGenericPassword returns success silently). The -T ACL governs GUI-level partition lists and does not bind the trusted security tool or framework reads the way the design assumed. The red-team script caught this: the original test expected a denied silent read and measured success.

Consequences: The honest guarantee is: no plaintext key FILE exists in the repo or home directory by default, and key material lives outside the working tree. The red-team key-access section asserts the disk property and records the keychain finding as a measured note. Operators who need a same-host access boundary use scripts/separate-user-mode.sh, which mirrors the deployment's OS-user separation and is the control this feature names for that threat.

Date: 2026-09-28

openbao-dev-is-the-linux-default [accepted] ​

Decision: Make the containerised dev OpenBao the default Linux dev keystore instead of the local file.

Rationale: The dev Compose stack already runs OpenBao under its own container user; pointing the sidecar at Vault transit costs no new infrastructure and removes the plaintext file from the default path entirely.

Date: 2026-09-28

How it works ​

Dev KEK lives in the macOS Keychain (dev-kek-in-keychain) ​

  1. Setup — scripts/dev-up.sh creates or reuses a Keychain item whose ACL grants only the sidecar binary.
  2. Receive — The sidecar reads the KEK from the Keychain at startup; no plaintext KEK file exists on disk.
  3. Observe — A same-user process other than the sidecar reading the item triggers a user-visible ACL prompt or denial.
  4. Observe — .dev/ contains no KEK file and the sidecar resolves normally.

Dev KEK lives in the dev OpenBao instance (dev-kek-in-openbao) ​

  1. Setup — The dev Compose stack runs OpenBao in a container under its own user, as it already does.
  2. Receive — The sidecar uses Vault transit by default on Linux; the KEK never exists as a file the agent user can read.
  3. Observe — No KEK file appears in .dev/ or the home directory.

Plaintext key file is an explicit, loud opt-in (insecure-file-opt-in) ​

  1. Receive — SAFEKEYS_ALLOW_INSECURE_KEYSTORE=1 is the only way the local file keystore activates.
  2. Validate — The sidecar refuses to start when the key file is group- or world-readable.
  3. Observe — Startup prints a loud warning that the mode is not for real secrets.
  4. Observe — Documentation marks the mode as not for real secrets.

Separate-user local mode with peer-credential checks (separate-user-local-mode) ​

  1. Setup — A documented script creates a dedicated sidecar user and an agent group; the sidecar runs as the dedicated user.
  2. Validate — The sidecar checks the peer credential (uid/gid) of every socket connection, not only filesystem permissions.
  3. Observe — An agent in the group resolves; a process outside the group is denied even if socket permissions change.

Guarantees ​

default-dev-no-readable-kek ​

The default development flow must not leave a key-encryption key readable by the same OS user the coding agent runs as.

Acceptance criteria:

  • [ ] The default dev flow leaves no key material — KEK or token signing seed — readable by the agent user as a plaintext file in the repo or home directory
  • [ ] macOS stores the dev KEK and signing seed as Keychain items outside the working tree; the ACL raises the bar but is NOT an access boundary (measured: same-user processes read silently), so the separate-user mode is the named boundary
  • [ ] Linux stores the dev KEK in a containerised OpenBao dev instance running as its own user, never a plaintext file
  • [ ] The plaintext key-file path is removed from the default dev flow
  • [ ] dev-up refuses to start when a stale plaintext key file exists without the insecure opt-in, and prints the one-line migration command

insecure-file-strict ​

The plaintext key-file mode is opt-in, loud, and refuses unsafe permissions.

Acceptance criteria:

  • [ ] File mode requires SAFEKEYS_ALLOW_INSECURE_KEYSTORE=1 explicitly
  • [ ] Startup prints a loud warning naming the mode not for real secrets when file mode is active
  • [ ] The sidecar refuses to start with a key file that is group- or world-readable
  • [ ] Documentation marks file mode as not for real secrets

separate-user-socket ​

A documented local mode reproduces the deployment's user separation on a developer machine.

Acceptance criteria:

  • [ ] A documented mode runs the sidecar as a dedicated user with agents in a shared group
  • [ ] The sidecar verifies socket peer credentials on every connection
  • [ ] A process outside the allowed group is denied even if filesystem permissions change
  • [ ] Key material and .dev/ state are gitignored and excluded from image build contexts

Test specifications ​

default-dev-leaves-no-kek-file ​

Given:

  • command: "scripts/dev-up.sh"
  • platform: "macos"

When: dev-kek-in-keychain

Then:

  • assertion: no KEK file readable by the agent user exists at .dev/kek or ~/.safekeys/kek
  • assertion: the sidecar resolves a token successfully

Contracts verified: default-dev-no-readable-kek

insecure-file-refuses-loose-perms ​

Given:

  • keyfile_mode: "0644"

When: insecure-file-opt-in

Then:

  • assertion: the sidecar exits with an error and serves nothing

Contracts verified: insecure-file-strict

insecure-file-warns-loudly ​

Given:

  • keyfile_mode: "0600"
  • opt_in: true

When: insecure-file-opt-in

Then:

  • assertion: the startup log contains the not-for-real-secrets warning
  • assertion: resolution works

Contracts verified: insecure-file-strict

separate-user-denies-outsider ​

Given:

  • agent_user: "in-group"
  • other_user: "out-group"

When: separate-user-local-mode

Then:

  • assertion: the agent user in the group can connect and resolve
  • assertion: a user outside the group is denied even if socket permissions are relaxed

Contracts verified: separate-user-socket

Implementation ​

  • Primary: pkg/keystore/keychain_darwin.go
  • Test code: pkg/keystore/keystore_test.go
  • Test code status: manual

See Also ​

  • safekeys/envelope-encryption
  • safekeys/deployment-packaging
  • safekeys/sidecar-resolution