Repository navigation
feat(security): hardware-rooted identity — real command-backed keystore + enforcement (Pillar 1) - #235
Merged
Conversation
…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
|
✅ Docker image built successfully
|
…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
|
✅ Docker image built successfully
|
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
|
✅ Docker image built successfully
|
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
0600key files).The KeyStore port existed but was inert:
resolveKeyStorehad 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
Changes Made
ExternalCommandKeyStore(kindcommand) — 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) behindKIT_KEYSTORE_SIGN_CMD; kit holds onlyKIT_KEYSTORE_PUBKEYand 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 provencommandExternalAnchorpattern; fail-closed on non-zero exit / empty / garbled output.Wired into
resolveKeyStore— preferred overfilein AUTO when configured; forced viaKIT_KEYSTORE=command.Enforcement (
keystore/active.ts) — the half that makes it matter:isHardwareRooted,hardwareRequiredByEnv(KIT_REQUIRE_HARDWARE_IDENTITY),assertHardwareIdentity(fail-closed), akeystoreSignfacade, andactiveKeyStoreStatus. A hardware mandate now refuses to sign with a file key (no false green).Routing + surfacing —
kit policy signnow signs through the resolved keystore (a hardware backend signs the org policy; mandate enforced), andkit identity keystoresurfaces the honest backend / hardware-rooted status / how to enable it.Testing
Test Coverage
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_IDENTITYare set.Notes for reviewers
This is a foundation:
kit policy signis routed through the keystore as the flagship enforcement point. Routing the remaining signers (audit line signing, memory-shared, control-plane) throughkeystoreSignso a fleet-widerequire_hardwaremandate covers every signature is the natural follow-up.🤖 Generated with Claude Code
https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2
Generated by Claude Code