Batch A6: #3 key encryption at rest, #29 issuer store #54

Merged
amiryahaya merged 2 commits from fix/a6-ca-key-protection into main 2026-11-15 12:06:30 +01:00
Owner

Batch A6: #3 key encryption at rest, #29 issuer store

#3 — new MdidWs.KeyVault: every stored private key (Root/Sub CA, OCSP responder, JWT signing key) is AES-256-GCM encrypted under MDID_KEY_ENCRYPTION_KEY (required in prod; fixed non-secret key for dev/test). Ciphertext is bound to table + row id. Boot runs migrate_stores!/0: upgrades legacy plaintext rows, re-encrypts rows under MDID_KEY_ENCRYPTION_KEY_PREVIOUS (rotation), then dumps the Mnesia log. Plaintext is accepted only by the migration, never on normal reads. Runbook: docs/key-management.md.

#29 — Issuer store uses sync_transaction, wait_for_tables on init, and a protocol-conformant find(context, {:by_type, t}, opts); IssuerManager goes through the facade (:ambiguous_issuer on duplicates).

Not done

  • Root CA is still online on the host (no offline/HSM ceremony). #3 stays open on that point.
  • Backups taken before the upgrade still hold plaintext keys: destroy them (documented).
  • runtime.exs env parsing has no automated test.

Breaking

Prod needs MDID_KEY_ENCRYPTION_KEY (openssl rand -base64 32) in .env; compose and start-docker-prod.sh refuse to start without it.

Review

Pass 1 (ponytail) and Pass 2 (correctness) done; fixed: empty PREVIOUS crashing compose boot, plaintext accepted forever, :safe decode on cold VM, dead find branches, log dump, duplicated dev/test key. Fixes were not re-reviewed by a second Pass 1.

Tests / coverage

280/282 pass; the 2 failures are pre-existing live-site TrustgateLifecycleTest. KeyVault 93.8%, project total 73.8%. Issuer/SigningKey protocol impls were 55%/60% at the first coverage run (unchanged paths dominate).

🤖 Generated with Claude Code

## Batch A6: #3 key encryption at rest, #29 issuer store **#3** — new `MdidWs.KeyVault`: every stored private key (Root/Sub CA, OCSP responder, JWT signing key) is AES-256-GCM encrypted under `MDID_KEY_ENCRYPTION_KEY` (required in prod; fixed non-secret key for dev/test). Ciphertext is bound to table + row id. Boot runs `migrate_stores!/0`: upgrades legacy plaintext rows, re-encrypts rows under `MDID_KEY_ENCRYPTION_KEY_PREVIOUS` (rotation), then dumps the Mnesia log. Plaintext is accepted only by the migration, never on normal reads. Runbook: `docs/key-management.md`. **#29** — `Issuer` store uses `sync_transaction`, `wait_for_tables` on init, and a protocol-conformant `find(context, {:by_type, t}, opts)`; `IssuerManager` goes through the facade (`:ambiguous_issuer` on duplicates). ### Not done - Root CA is still online on the host (no offline/HSM ceremony). #3 stays open on that point. - Backups taken before the upgrade still hold plaintext keys: destroy them (documented). - `runtime.exs` env parsing has no automated test. ### Breaking Prod needs `MDID_KEY_ENCRYPTION_KEY` (`openssl rand -base64 32`) in `.env`; compose and `start-docker-prod.sh` refuse to start without it. ### Review Pass 1 (ponytail) and Pass 2 (correctness) done; fixed: empty `PREVIOUS` crashing compose boot, plaintext accepted forever, `:safe` decode on cold VM, dead find branches, log dump, duplicated dev/test key. Fixes were not re-reviewed by a second Pass 1. ### Tests / coverage 280/282 pass; the 2 failures are pre-existing live-site `TrustgateLifecycleTest`. `KeyVault` 93.8%, project total 73.8%. Issuer/SigningKey protocol impls were 55%/60% at the first coverage run (unchanged paths dominate). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Refs #3, #29. KeyVault (AES-256-GCM, AAD bound to row) under MDID_KEY_ENCRYPTION_KEY,
startup migration/rotation, issuer store uses sync_transaction + wait_for_tables and
a protocol-conformant find. Runbook in docs/key-management.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix: A6 review — empty PREVIOUS key, plaintext only during migration, dump log, leaner store
All checks were successful
Lint / lint (pull_request) Successful in 2m36s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 26s
Security / Secret scan (gitleaks) (pull_request) Successful in 12s
Unit tests / test (pull_request) Successful in 3m22s
f7e7549093
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.