Add crypto inventory and proposed-profile config boundary (K01, #5) #59

Merged
amiryahaya merged 13 commits from feat/5-crypto-config into main 2026-10-26 17:15:24 +01:00
Owner

Refs #5

What

Adds the crypto inventory and the versioned, purpose-based profile boundary for K01, without implementing any crypto protocol.

  • crates/crypto-config (std-only, no dependencies; a test enforces it): Purpose, a compiled-in catalog (set dev-synthetic.1, five profiles, all Proposed), and ProfileSet::from_env which fails closed on a missing, unknown, untrimmed, duplicate-purpose, missing-purpose or not-approved set. Errors never echo the input.
  • Metadata identifiers cm1:<profile-id>:<key-ref> (KeyRef, CryptoMetadata, ProfileSet::resolve) for rotation and migration. KeyRef refuses secret-shaped values. Nothing persists these yet.
  • INVENTORY: 22 entries covering all 11 SRS criterion-11 components, each with peers, protocols, provider/version, key refs, data scope/lifetime, owner, evidence and migration state; unsupported or unassessed PQ endpoints are tracked (PqStatus has no "protected" variant, so a PQ claim cannot be written down).
  • docs/security/crypto-inventory.md is generated by render() and compared byte for byte by a test (UPDATE_CRYPTO_INVENTORY=1 regenerates); docs/security/crypto-profile.md documents the boundary.
  • rag-api startup now requires CRYPTO_PROFILE_SET (after the RAG_ENV and loopback guards, before any database connection). .env.example updated.

Things to know

  • Only rag-api startup enforces the set today. rag-migrate (the one binary that can run with verify-full TLS in production) does not read CRYPTO_PROFILE_SET; gating it is left to K02/K03 and the docs say so.
  • No profile can be Approved until D01 decisions land (OD-04 profile, ID-10 approver); both stay open in docs/decisions.md, with evidence added only.
  • Inventory facts were checked against code and Cargo.lock. Corrections found on the way: Postgres and SMTP use compiled-in webpki-roots, not the platform store; session digests use sha2 while the profile named ring (the profile now names both). Not verified: negotiated TLS version and key-exchange group (marked unmeasured), and the "unless a root certificate is supplied in the URL" hedge.
  • Run UPDATE_CRYPTO_INVENTORY=1 cargo test -p rag-crypto-config --test inventory_doc after editing INVENTORY.

Verification

  • cargo test -p rag-crypto-config: 32 unit + 1 boundary + 3 doc tests; cargo test -p rag-api --test startup: 7/7; cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --all --check clean.
  • scripts/coverage.sh rust (real PostgreSQL): 91.36% workspace line coverage (minimum 80%), 0 failed suites. Changed files: inventory.rs 99.5%, metadata.rs 100%, profile.rs 83.6%.
  • Dual-pass review (Ponytail complexity + opus correctness). Pass 2 found a broken Markdown table row (unescaped ||) and the migrate-binary scope gap; both fixed, with the cell-count test failing first. Pass 1 re-check of the fixes was clean.

Not in this PR

  • Wiring existing ring/rustls/webauthn-rs call sites to read the profile (K02/K03).
  • Gating rag-migrate and other binaries; any approved profile; KMS/HSM; audit event at boot.
  • Needs the user: ID-10 approver and cadence, OD-04 profile, whether to open a follow-up to move rustls to its aws-lc-rs provider (PQ-hybrid candidate), the KMS/HSM source for the three env-var keys (ID-11) and a key-label format to replace the KeyRef shape heuristic.

🤖 Generated with Claude Code

Refs #5 ## What Adds the crypto inventory and the versioned, purpose-based profile boundary for K01, without implementing any crypto protocol. - `crates/crypto-config` (std-only, no dependencies; a test enforces it): `Purpose`, a compiled-in catalog (set `dev-synthetic.1`, five profiles, **all `Proposed`**), and `ProfileSet::from_env` which fails closed on a missing, unknown, untrimmed, duplicate-purpose, missing-purpose or not-approved set. Errors never echo the input. - Metadata identifiers `cm1:<profile-id>:<key-ref>` (`KeyRef`, `CryptoMetadata`, `ProfileSet::resolve`) for rotation and migration. `KeyRef` refuses secret-shaped values. Nothing persists these yet. - `INVENTORY`: 22 entries covering all 11 SRS criterion-11 components, each with peers, protocols, provider/version, key refs, data scope/lifetime, owner, evidence and migration state; unsupported or unassessed PQ endpoints are tracked (`PqStatus` has no "protected" variant, so a PQ claim cannot be written down). - `docs/security/crypto-inventory.md` is generated by `render()` and compared byte for byte by a test (`UPDATE_CRYPTO_INVENTORY=1` regenerates); `docs/security/crypto-profile.md` documents the boundary. - `rag-api` startup now requires `CRYPTO_PROFILE_SET` (after the RAG_ENV and loopback guards, before any database connection). `.env.example` updated. ## Things to know - **Only `rag-api` startup enforces the set today.** `rag-migrate` (the one binary that can run with verify-full TLS in production) does not read `CRYPTO_PROFILE_SET`; gating it is left to K02/K03 and the docs say so. - No profile can be `Approved` until D01 decisions land (OD-04 profile, ID-10 approver); both stay open in `docs/decisions.md`, with evidence added only. - Inventory facts were checked against code and `Cargo.lock`. Corrections found on the way: Postgres and SMTP use compiled-in `webpki-roots`, not the platform store; session digests use `sha2` while the profile named `ring` (the profile now names both). Not verified: negotiated TLS version and key-exchange group (marked unmeasured), and the "unless a root certificate is supplied in the URL" hedge. - Run `UPDATE_CRYPTO_INVENTORY=1 cargo test -p rag-crypto-config --test inventory_doc` after editing `INVENTORY`. ## Verification - `cargo test -p rag-crypto-config`: 32 unit + 1 boundary + 3 doc tests; `cargo test -p rag-api --test startup`: 7/7; `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --all --check` clean. - `scripts/coverage.sh rust` (real PostgreSQL): **91.36% workspace line coverage** (minimum 80%), 0 failed suites. Changed files: inventory.rs 99.5%, metadata.rs 100%, profile.rs 83.6%. - Dual-pass review (Ponytail complexity + opus correctness). Pass 2 found a broken Markdown table row (unescaped `||`) and the migrate-binary scope gap; both fixed, with the cell-count test failing first. Pass 1 re-check of the fixes was clean. ## Not in this PR - Wiring existing ring/rustls/webauthn-rs call sites to read the profile (K02/K03). - Gating `rag-migrate` and other binaries; any approved profile; KMS/HSM; audit event at boot. - Needs the user: ID-10 approver and cadence, OD-04 profile, whether to open a follow-up to move rustls to its aws-lc-rs provider (PQ-hybrid candidate), the KMS/HSM source for the three env-var keys (ID-11) and a key-label format to replace the `KeyRef` shape heuristic. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(crypto-config): escape table cells, scope the profile-set claim honestly, tighten tests (K01, #5)
Some checks failed
CI / Web checks (push) Successful in 46s
CI / Rust checks (push) Successful in 19m11s
CI / Web checks (pull_request) Successful in 2m4s
CI / Rust checks (pull_request) Failing after 40m44s
389ac1664d
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into feat/5-crypto-config
Some checks failed
CI / Web checks (pull_request) Failing after 3m3s
CI / Rust checks (pull_request) Successful in 46m28s
fa3234011b
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into feat/5-crypto-config
Some checks failed
CI / Web checks (pull_request) Has been cancelled
CI / Rust checks (pull_request) Has been cancelled
439e1b41e8
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
chore(security): ignore the cm1 metadata test vector in gitleaks (#5)
Some checks failed
CI / Web checks (pull_request) Successful in 2m48s
CI / Rust checks (pull_request) Has been cancelled
c4ea60e374
Two exact fingerprints; a profile id plus key label, not a secret.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into feat/5-crypto-config
All checks were successful
CI / Web checks (pull_request) Successful in 44s
CI / Rust checks (pull_request) Successful in 25m11s
13fb50e0b6
# Conflicts:
#	.gitattributes
#	README.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.