Skip to content

feat(security): hardware-rooted identity — real command-backed keystore + enforcement (Pillar 1) - #235

Merged
sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a
Jul 5, 2026
Merged

sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Description

Makes hardware-root of trust real and enforceable — the pillar that closes the same-UID key-theft boundary kit's own threat model documents (a same-UID attacker can read the 0600 key files).

The KeyStore port existed but was inert: resolveKeyStore had no callers, the hardware backends were honest stubs, and all signing still used the same-UID-readable file key. This wires it in for real.

Type of Change

  • New feature (non-breaking change that adds functionality)

Changes Made

ExternalCommandKeyStore (kind command) — the first real hardware-rooted backend, needing no native code. The private key lives in operator-fronted hardware (TPM 2.0 / PKCS#11 / YubiKey / ssh-agent / Secure Enclave helper) behind KIT_KEYSTORE_SIGN_CMD; kit holds only KIT_KEYSTORE_PUBKEY and shells out per signature. A same-UID attacker finds no key file to steal. Every signature is self-verified against the advertised pubkey before use, so a wrong/compromised signer fails closed. Mirrors the proven commandExternalAnchor pattern; fail-closed on non-zero exit / empty / garbled output.

Wired into resolveKeyStore — preferred over file in AUTO when configured; forced via KIT_KEYSTORE=command.

Enforcement (keystore/active.ts) — the half that makes it matter: isHardwareRooted, hardwareRequiredByEnv (KIT_REQUIRE_HARDWARE_IDENTITY), assertHardwareIdentity (fail-closed), a keystoreSign facade, and activeKeyStoreStatus. A hardware mandate now refuses to sign with a file key (no false green).

Routing + surfacing — kit policy sign now signs through the resolved keystore (a hardware backend signs the org policy; mandate enforced), and kit identity keystore surfaces the honest backend / hardware-rooted status / how to enable it.

Testing

Test Coverage

  • Added new tests
  • All tests pass (npm test)

A real end-to-end Ed25519 command signer exercises sign / self-verify / wrong-key-rejection / non-zero-exit / empty-output / rotate-refusal, plus the enforcement matrix and status surfacing. Full suite green: 2256 tests.

Breaking Changes

None / N/A — default behavior is unchanged (AUTO resolves to the file backend and signs exactly as before). Hardware routing/enforcement activate only when KIT_KEYSTORE=command / KIT_REQUIRE_HARDWARE_IDENTITY are set.

Notes for reviewers

This is a foundation: kit policy sign is routed through the keystore as the flagship enforcement point. Routing the remaining signers (audit line signing, memory-shared, control-plane) through keystoreSign so a fleet-wide require_hardware mandate covers every signature is the natural follow-up.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2


Generated by Claude Code

…re + enforcement (Pillar 1)

The KeyStore port existed but was inert: resolveKeyStore had no callers, the hardware
backends were honest stubs, and all signing still used the same-UID-readable 0600 file
key. This makes hardware-root of trust real and enforceable — the pillar that closes
the same-UID key-theft boundary kit's threat model documents.

- ExternalCommandKeyStore (kind "command"): the first REAL hardware-rooted backend, and
  one that needs NO native code. The private key lives in operator-fronted hardware
  (TPM 2.0 / PKCS#11 / YubiKey / ssh-agent / Secure Enclave helper) behind
  KIT_KEYSTORE_SIGN_CMD; kit holds only KIT_KEYSTORE_PUBKEY and shells out per signature.
  A same-UID attacker finds no key file to steal. Every signature is SELF-VERIFIED
  against the advertised pubkey before use, so a wrong/compromised signer fails closed.
  Mirrors the proven commandExternalAnchor pattern; fail-closed on exit/empty/garbled.

- Wired into resolveKeyStore (preferred over file in AUTO when configured; forced via
  KIT_KEYSTORE=command).

- Enforcement (keystore/active.ts) — the half that makes it matter:
  isHardwareRooted, hardwareRequiredByEnv (KIT_REQUIRE_HARDWARE_IDENTITY),
  assertHardwareIdentity (fail-closed), keystoreSign facade, activeKeyStoreStatus.
  A hardware mandate now refuses to sign with a file key (no false green).

- Routed `kit policy sign` through the keystore (hardware backend signs the org policy;
  mandate enforced) and surfaced honest status via `kit identity keystore`.

Tests: real end-to-end Ed25519 command signer (sign/self-verify/wrong-key/exit/empty/
rotate), enforcement matrix, status. Full suite green (2256 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

…found false green)

Adversarial verify found the mandate was a false green: KIT_REQUIRE_HARDWARE_IDENTITY
was enforced ONLY in `kit policy sign`, while audit-chain entries, shared-memory notes,
and revocations kept signing with the same-UID-readable file key — and `init` still minted
a file key that coexists. So a mandate operator got a green light over a key an attacker
could still read and use. Fixed so NO file-key signature escapes under the mandate.

- Universal backstop: signWithIdentity() (the file-key primitive) now FAILS CLOSED under
  KIT_REQUIRE_HARDWARE_IDENTITY — every caller that reaches it (revocations, elevation,
  any un-routed signer) refuses the file key. mandate.js is a zero-import module so
  identity.ts can guard without an import cycle.
- loadOrCreateIdentity refuses to MINT a file key under the mandate (Finding #4: no
  coexisting same-UID key to steal).
- Routed the audit-chain signer (audit.ts) and shared-memory signer (memory/shared.ts)
  through the keystore: a `command` backend now signs them via hardware, and under a
  mandate with only a file key they fall back to KEYLESS (chain still protects them)
  rather than emitting a forbidden file-key signature. Also unifies the signing kid.
- Command signer no longer receives kit's env wholesale (Finding #3): minimal allowlist
  (PATH/HOME/KIT_SIGN_ALGO), so KIT_* secrets/vault tokens aren't exposed to the signer
  subprocess — the comment now matches the code.
- Honesty (Findings #2/#6): the command backend and `kit identity keystore` no longer
  claim "hardware-rooted" (kit can't attest the operator's command fronts a secure
  element) — labeled "external key — operator-fronted" with an explicit caveat.

Regression tests: comprehensive-mandate suite (signWithIdentity / loadOrCreate /
recordRevocation fail closed; audit falls back to keyless) + signer env-isolation.
Full suite green (2261 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

Second adversarial pass confirmed the routed core (audit/memory/policy/revocation) holds
and found the remaining edges. Closed:

- Attestation Ed25519 file key (the one literal break of "no file-key signature anywhere
  under the mandate"): loadOrCreateEd25519Key now returns null under the mandate, so
  attestation receipts fall through to HMAC or an honest sig_alg:"none" and never mint or
  sign with the same-UID Ed25519 file key. (check-attestation.ts)
- rotateIdentity re-minted the forbidden file key under the mandate (asymmetry with
  loadOrCreateIdentity) → now fails closed. (identity.ts)
- recordRevocation was file-key-direct → split-brain kid on a command backend and no
  hardware revocation. Added keystoreRecordRevocation (keystore-routed: signs+attributes
  via the active backend, honors the mandate), and `kit panic` now uses it. Cycle-safe
  (lives in keystore/, not identity.ts). (keystore/revoke.ts, commands/panic.ts)
- Silent keyless downgrade: audit signLineHash now SURFACES a failure of a configured
  non-file backend (a stealthy de-attribution an attacker could induce) instead of
  swallowing it; expected mandate-keyless stays silent. (audit.ts)
- Honesty: active.ts no longer implies a `.kit-policy` fleet mandate is wired (it isn't),
  and states plainly the env mandate enforces operator intent, not a same-UID defense.

Regression tests: rotate guard, keystore-routed revocation attribution + mandate,
attestation-no-file-key-under-mandate. Full suite green (2264 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit 1b9c918 into main Jul 5, 2026
17 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a branch July 5, 2026 08:12
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.

2 participants