--- story_id: "1.11" story_key: "1-11-master-key-identity-rotation" requirement: "FR-3" status: "done" baseline_commit: "767428436d3a54e60809a727044dfcec48e1f1dd + uncommitted Story 1.10 closure worktree" created: "2026-08-21T00:00:00+03:00" --- # Story 1.11: Согласовать master-key identity и безопасную rotation Status: done ## Story As an оператор Crank, I want все secret-using процессы использовать одну проверяемую master-key identity и безопасно менять ключ, so that сохранённые Secrets остаются доступными после restart, rotation и восстановления, а неправильный key не приводит к тихой порче или недоступности данных. ## Operational Brief Story 1.10 закрыла lifecycle Secrets/Auth Profiles/MCP keys/approval keys: raw values не читаются обратно, Secret versions шифруются, revoked credentials fail-closed. Но текущий `CRANK_MASTER_KEY` всё ещё является локальным значением процесса: Admin API и MCP отдельно создают `SecretCrypto::new(...)`, PostgreSQL не знает fingerprint/epoch, readiness не доказывает общий ключ, а смена key material без re-encryption ломает сохранённые Secrets. Story 1.11 делает master key явным durable security contract: - PostgreSQL хранит только non-secret fingerprint/epoch/cipher contract. - Каждый secret-using process до readiness сверяет свой `CRANK_MASTER_KEY` с active identity. - Ciphertext получает epoch-aware envelope/metadata. - Rotation выполняется operator-controlled, durable, resumable и не удаляет текущий ciphertext до verification/promotion. - Failure output, logs, traces, manifests и audit не содержат raw key material, plaintext Secret или decrypt error details. Это продолжение FR-3 и архитектурного AD-15. Backup/restore RPO/RTO и protected external key backup reference полностью квалифицируются позже в Epic 7, но 1.11 должна оставить совместимый key identity/rotation foundation. ## Requirement / Architecture Trace - **Direct requirement:** FR-3. - **Primary architecture:** AD-15 Shared master-key identity. - **Supporting architecture:** AD-16 migration authority, AD-17 typed config, AD-19 boundary errors, AD-22 admin identity/offline recovery guardrail, AD-24 backup/restore compatibility. - **Applicable NFR:** NFR-S2, NFR-S4, NFR-S7, NFR-S8, NFR-O1, NFR-O4, NFR-O5, NFR-C1, NFR-C3. ## Scope In scope: - Master-key identity registry in PostgreSQL: fingerprint, epoch, cipher contract, state, timestamps and safe operator metadata. - Startup/readiness preflight for Admin API and MCP Server before secret use and before serving product readiness. - Epoch-aware `SecretCrypto` envelope and decrypt path preserving support for existing `v1` legacy and current `v2` ciphertext. - Controlled operator rotation command/API surface sufficient for preflight, start/resume re-encryption, verify, promote and abort. - Durable rotation state/checkpoints and idempotent batch processing over existing `secret_versions`. - PostgreSQL migration through canonical migration authority only; expected next version is v7 after current v6. - Tests proving same-key, mismatch-key, corrupt ciphertext, interrupted rotation, resume, verify, promotion and old-key rejection semantics. - Safe diagnostics/audit/logging with request/trace IDs where boundary-originated; no key/plaintext/ciphertext leakage. Out of scope: - Full production backup manifest, WAL/PITR, RPO/RTO measurement and three restore runs — Epic 7. - Offline recovery UX and local operator bootstrap — Story 1.12/Epic 7. - Multi-instance rolling key reload — Community target remains single-instance restart/reload boundary. - Admin UI for master-key rotation unless a minimal status/readiness display is needed; CLI/operator command is sufficient. - Re-encryption of non-Secret future credential stores not yet implemented. - Changing credential lifecycle behavior from 1.10 except integrating master-key epoch metadata. ## Acceptance Criteria 1. **First identity registration is non-secret** - Given a fresh migrated database with no master-key identity - When controlled startup/preflight runs with valid `CRANK_MASTER_KEY` - Then PostgreSQL stores only non-secret fingerprint, active epoch and cipher-contract metadata - And raw master key bytes never enter PostgreSQL, logs, traces, diagnostics, manifests or test failure output. 2. **Secret-using processes verify identity before readiness** - Given Admin API, MCP Server or any process that can encrypt/decrypt Secrets - When startup/readiness executes - Then it computes the local non-secret fingerprint and compares it with PostgreSQL active identity - And mismatch, unknown epoch, missing identity after registration, unsupported cipher contract or storage error blocks safe readiness/startup with bounded typed diagnostics. 3. **Ciphertext is epoch-aware and backward compatible** - Given a newly written Secret version - When it is encrypted - Then its durable metadata identifies cipher version and master-key epoch without exposing key material - And existing legacy/current ciphertext remains readable under the registered compatible epoch - And corrupt/truncated/unknown-version ciphertext returns typed security error without plaintext or raw parser details. 4. **Rotation preflight is read-only** - Given current and target key material supplied by the operator - When preflight runs - Then it validates both keys, decryptability of all affected active Secret versions, target fingerprint uniqueness and absence of incompatible active rotation - And it does not change active epoch, Secret rows, ciphertext or readiness state. 5. **Rotation creates durable state and target ciphertext without deleting current ciphertext** - Given successful preflight - When rotation starts or resumes - Then a durable rotation record tracks ID, source epoch, target epoch, state, counts, checkpoint and safe metadata - And each processed Secret version gets verified target-epoch ciphertext while current ciphertext remains available until promotion. 6. **Crash/restart resume is idempotent** - Given a crash/interruption before all batches finish - When the operator reruns rotation - Then processing resumes from durable checkpoint without double-counting, skipping records incorrectly or losing Secrets - And current active epoch remains usable for reads until promotion. 7. **Concurrent Secret writes have a defined epoch contract** - Given rotation is in progress - When an Admin creates or rotates a Secret - Then the write is either rejected with a typed retryable rotation-in-progress error or written with a defined current/target handling that keeps it readable by all ready processes - And no write creates a Secret version inaccessible to the active deployment. 8. **Verification gates promotion** - Given all target ciphertext has been produced - When verification runs - Then every affected Secret version decrypts under the target key, counts match the source set and integrity failures block promotion - And evidence contains only IDs/counts/digests/safe error codes. 9. **Promotion is atomic and old key is no longer accepted after restart boundary** - Given verification succeeded - When target epoch is promoted - Then active epoch/fingerprint changes atomically - And Admin/MCP readiness with old key fails after the agreed restart/reload boundary - And readiness with target key succeeds and existing Auth Profile execution works. 10. **Abort/recovery preserves current epoch before promotion** - Given rotation fails or is aborted before promotion - When operator runs abort/recovery - Then current epoch remains active, target epoch is not used for new writes, partial target ciphertext is ignored or safely marked - And preflight can be rerun without disclosing stored Secrets. 11. **Backup key reference is opaque** - Given an operator records an external protected key-backup reference - When it is stored or shown - Then Crank stores only opaque reference plus fingerprint/epoch metadata - And key bytes are absent from product backup set, Evidence Manifest, logs and diagnostics. 12. **Final safety matrix** - Given Story 1.11 completion - When tests run - Then coverage includes matching/mismatching Admin+MCP processes, fresh identity registration, corrupt ciphertext, crash before/after checkpoint, resume, abort, successful rotation, promotion and old-key rejection - And `just verify`, relevant migration/config/boundary checks and explicit Community scope scan pass. ## Tasks / Subtasks - [x] Task 1 — Freeze master-key contract and RED tests (AC: 1–12) - [x] Add tests for non-secret fingerprint stability, raw-key redaction, unsupported/corrupt ciphertext and legacy ciphertext compatibility. - [x] Add Admin/MCP startup/readiness tests for same-key, mismatch-key, missing identity, storage failure and unsupported cipher contract. - [x] Add registry migration tests for fresh/current/corrupt v7 schema and append-only sequence. - [x] Add rotation state tests for preflight read-only, resume, verify, promote and abort. - [x] Task 2 — Domain and crypto model (AC: 1–3, 7–11) - [x] Extend `crank-runtime::SecretCrypto` with typed `MasterKeyIdentity`, fingerprint, epoch and cipher-contract metadata. - [x] Preserve decrypt compatibility for existing `v1` legacy and `v2` ciphertext; new writes must use epoch-aware metadata without changing raw Secret DTOs. - [x] Replace raw `RuntimeError::SecretCrypto` detail leakage with stable bounded safe diagnostics at product boundaries. - [x] Ensure Debug/Display/Serialize paths never expose raw key, derived key bytes, plaintext, ciphertext or parser internals. - [x] Task 3 — PostgreSQL schema and migration authority (AC: 1, 3–10) - [x] Add append-only v7 migration for master-key identity, rotation state/checkpoints and any target-ciphertext metadata required for re-encryption. - [x] Update migration descriptors, exact checksums, schema guard/fingerprint and `docs/schemas/migration-sequence.json`. - [x] Preserve v1–v6 immutable migration bytes and compatibility behavior. - [x] Add integration tests for fresh v7, v6→v7 upgrade, current v7, partial v7 rollback and corrupt ledger/constraint definitions. - [x] Task 4 — Registry key-authority API (AC: 1, 4–10) - [x] Add registry methods for identity registration/check, rotation creation, batch checkpointing, verification evidence, promotion and abort. - [x] Enforce single active rotation and transactional state transitions with row locks/CAS. - [x] Make preflight read-only and prove it does not mutate ciphertext/active epoch. - [x] Add bounded typed errors for mismatch, unknown epoch, rotation conflict, verification failure and storage unavailable. - [x] Task 5 — Process startup/readiness integration (AC: 1–2, 9) - [x] Wire Admin API and MCP Server to validate master-key identity after DB/migration compatibility and before SecretCrypto-dependent product readiness. - [x] Ensure mismatch blocks startup/readiness before serving Admin/MCP product routes and without raw driver/key output. - [x] Preserve config boundary: `CRANK_MASTER_KEY` remains parsed only by `crank-config`; reusable crates receive typed values. - [x] Add subprocess tests for safe diagnostics and no listener/product readiness on mismatch. - [x] Task 6 — Rotation operator command/surface (AC: 4–11) - [x] Implement minimal controlled operator path, preferably `crank-migrate` subcommand family or another explicit local operator command, not product runtime DDL. - [x] Support preflight, start/resume, verify, promote, abort and status with bounded JSON output. - [x] Accept target/current key material only via safe local operator input/env contract; never echo values. - [x] Record opaque external key-backup reference metadata without storing key bytes. - [x] Task 7 — Secret write/read integration during rotation (AC: 3, 5, 7–10) - [x] Update Admin Secret create/rotate and MCP/Admin Secret resolution to use epoch-aware crypto metadata. - [x] Define and implement concurrent write policy during rotation: fail-closed retryable rejection unless a fully verified dual-write path is implemented and tested. - [x] Ensure Auth Profile execution remains functional before promotion, after promotion with new key, and fails safely with old key. - [x] Keep Story 1.10 raw-secret/readback/redaction invariants unchanged. - [x] Task 8 — Documentation, inventory and evidence (AC: 1–12) - [x] Update docs for master-key identity, startup/readiness failure, rotation procedure, abort/recovery and opaque backup reference. - [x] Update Capability Inventory/baseline evidence for the FR-3 master-key slice only after checks pass. - [x] Record deferred Epic 7 backup/restore/RPO/RTO scope explicitly. - [x] Run explicit Community scope scan over every new/updated Story 1.11 path. - [x] Task 9 — Final verification (AC: 12) - [x] Run targeted crypto/registry/Admin/MCP/rotation tests. - [x] Run migration/config/boundary checks and SQLx checks if metadata changed. - [x] Run `cargo fmt --all --check`, `git diff --check`, `just verify`; run UI checks only if UI files change. - [x] Update Story File List, Dev Agent Record and Change Log with exact command results; set status to `review`. ### Review Findings - [x] [Review][Patch] Enforce strong master-key entropy before storing deterministic fingerprint — `SecretCrypto` accepts any non-empty key and stores a deterministic SHA-256 domain-separated fingerprint; weak `CRANK_MASTER_KEY` values would make the DB fingerprint an offline guessing oracle. Enforce a high-entropy/generated-key contract in config/crypto and operator key-file validation now. [crates/crank-runtime/src/secret_crypto.rs:43] - [x] [Review][Patch] Promoted target key cannot start Admin/MCP because startup always claims epoch 1 [apps/admin-api/src/main.rs:198] - [x] [Review][Patch] Stale old-key process can write inaccessible epoch-1 Secrets after promotion because Secret writes do not verify active master-key identity [crates/crank-registry/src/postgres/secret.rs:139] - [x] [Review][Patch] First identity registration on an upgraded populated DB can bless the wrong key without proving decryptability of existing Secret versions [crates/crank-registry/src/postgres/master_key.rs:31] - [x] [Review][Patch] Fresh DB first identity registration is racy: Admin and MCP with the same key can both observe no active row, then one fails on the unique active index instead of verifying the winner [crates/crank-registry/src/postgres/master_key.rs:9] - [x] [Review][Patch] Rotation begin and concurrent Secret writes are not serialized by a shared lock, so writes can commit outside the fixed rotation source count [crates/crank-registry/src/postgres/master_key.rs:273] - [x] [Review][Patch] `delete_secret` is allowed during active rotation and can cascade-delete source/target versions, making verification or promotion inconsistent [crates/crank-registry/src/postgres/secret.rs:313] - [x] [Review][Patch] Aborted rotation cannot be cleanly rerun for the same source epoch because rotation IDs are deterministic primary keys [crates/crank-registry/src/postgres/master_key.rs:279] - [x] [Review][Patch] v7 schema guard accepts same-named weakened constraints because it checks only constraint existence, not exact definitions [crates/crank-registry/src/migrations/schema_guard.rs:620] - [x] [Review][Patch] Preflight/rotation batch processing loads all Secret versions into memory before applying `--max-versions`, so large datasets are not bounded [apps/admin-api/src/bin/crank-migrate.rs:613] ## Dev Notes ### Current brownfield state - `crates/crank-runtime/src/secret_crypto.rs` owns `SecretCrypto`. It derives two AES-GCM ciphers from a raw master key: legacy SHA-256 `v1` and current HKDF `v2`. It exposes `key_version()` as `"v2"`, encrypts to a JSON envelope `{nonce_b64,ciphertext_b64}`, and decrypts by external `key_version`. - `SecretCrypto::new` is called separately in `apps/admin-api/src/main.rs` and `apps/mcp-server/src/main.rs` from `config.runtime.master_key.expose_secret()`. There is no PostgreSQL identity check before readiness. - `crates/crank-registry/src/postgres/secret.rs` persists `secret_versions(secret_id, version, ciphertext, key_version, created_at, created_by)`. There is no master-key epoch/fingerprint table or rotation state. - Admin Secret create/rotate encrypts payloads in `apps/admin-api/src/service/secrets.rs` and stores `self.secret_crypto.key_version()`. Admin/MCP execution decrypts current Secret versions before resolving Auth Profiles. - `crank-config` already treats `CRANK_MASTER_KEY` as required sensitive Shared runtime config and excludes raw value from debug/fingerprint. Do not introduce new direct env reads. - Current migration authority version is v6. Story 1.11 schema work must be v7 and must not edit immutable v1–v6 source bytes. ### Hard design decisions for implementation - Fingerprint must be deterministic and non-secret. It must not be raw key, derived encryption key, per-secret hash, or any value usable as an offline oracle beyond equality of configured deployment key. Use a domain-separated KDF/HMAC/fingerprint design and document why it is safe. - Epoch is deployment master-key epoch, not Secret version. Do not conflate `secret_versions.version`, `secret_versions.key_version` and master-key epoch. - New writes during rotation should default to fail-closed retryable rejection unless the story explicitly implements and proves dual-write/current+target handling. Simpler safe policy is acceptable and preferred for Community. - Promotion requires restart/reload boundary. Do not claim hot multi-process reload unless implemented and tested. - Preflight must be read-only. Any mutation during `preflight` is a story failure. - Abort before promotion must leave current epoch active. Do not delete source ciphertext or make target ciphertext authoritative before verification/promotion. - Raw target/current key material must only enter local operator command/process memory. Never place it in DB, manifest, logs, traces, command output or story evidence. ### File map Likely UPDATE: - `crates/crank-runtime/src/secret_crypto.rs` - `crates/crank-runtime/src/error.rs` - `crates/crank-runtime/src/execution_failure.rs` - `crates/crank-runtime/src/lib.rs` - `crates/crank-registry/src/model.rs` - `crates/crank-registry/src/error.rs` - `crates/crank-registry/src/postgres/secret.rs` - `crates/crank-registry/src/postgres/mod.rs` - `crates/crank-registry/src/migrations.rs` - `crates/crank-registry/src/migrations/authority.rs` - `crates/crank-registry/src/migrations/schema_guard.rs` - `crates/crank-registry/tests/integration/migrations.rs` - `crates/crank-registry/tests/integration/operations_artifacts.rs` - `apps/admin-api/src/main.rs` - `apps/admin-api/src/bin/crank-migrate.rs` - `apps/admin-api/src/service.rs` - `apps/admin-api/src/service/secrets.rs` - `apps/admin-api/tests/config_startup.rs` - `apps/admin-api/tests/migration_command.rs` - `apps/admin-api/tests/integration/credential_lifecycle.rs` - `apps/mcp-server/src/main.rs` - `apps/mcp-server/tests/config_startup.rs` - `apps/mcp-server/tests/integration/catalog_access.rs` - `apps/mcp-server/tests/integration/common.rs` - `docs/secrets-and-auth.md` - `docs/runtime-config.md` - `docs/migrations.md` - `docs/database-schema.md` - `docs/data-model.md` - `docs/production-checklist.md` - `docs/capability-inventory.json` - `docs/capability-baseline/manifest.json` - `docs/capability-baseline/results.json` - `docs/schemas/migration-sequence.json` - `.sqlx/query-*.json` only if SQLx offline metadata changes. Likely NEW: - `crates/crank-registry/src/migrations/master_key_identity_v7.sql` - `crates/crank-registry/src/migrations/master_key_identity_v7.rs` if Rust-side migration steps are required. - `crates/crank-registry/src/postgres/master_key.rs` or equivalent focused module. - `crates/crank-registry/tests/integration/master_key_identity.rs` or additional integration module. - `crates/crank-runtime/tests/secret_crypto.rs` if crypto tests outgrow inline module. - `apps/admin-api/tests/master_key_rotation_command.rs` if CLI coverage is clearer outside existing `migration_command.rs`. Do not modify: - Frozen migration v1–v6 source bytes/checksums except appending v7 metadata. - Story 1.10 raw Secret/key lifecycle semantics except adding epoch metadata. - Rust/npm toolchain or dependencies unless unavoidable and explicitly justified. - UI files unless adding an actual UI surface; a CLI/operator path is sufficient for this story. ### Testing requirements Required targeted tests: ```bash cargo test -p crank-runtime secret_crypto -- --test-threads=1 cargo test -p crank-registry --test integration migrations -- --test-threads=1 cargo test -p crank-registry --test integration master_key -- --test-threads=1 cargo test -p admin-api --test config_startup -- --test-threads=1 cargo test -p mcp-server --test config_startup -- --test-threads=1 cargo test -p admin-api --test master_key_rotation_command -- --test-threads=1 cargo test -p admin-api --test integration credential_lifecycle -- --test-threads=1 cargo test -p mcp-server --test integration catalog_access -- --test-threads=1 just migration-contract-check just config-contract-check just rust-boundaries just capability-inventory-check python3 scripts/check-community-scope.py --root . --files git diff --check just verify ``` Run `just sqlx-prepare ` and `just sqlx-check` if SQLx offline metadata changes. UI checks are required only if UI files change: ```bash just verify-ui ``` ### Review traps to avoid - Do not call config fingerprint the master-key fingerprint. Config fingerprint deliberately records only secret configured/unconfigured state and is not key identity. - Do not store a hash of raw key that could be used directly as an encryption key or leaked secret surrogate. - Do not silently auto-register a new identity on a populated database with existing encrypted Secrets unless the current key proves decryptability and the path is explicitly tested. - Do not allow Admin and MCP to each initialize different identities depending on startup order. - Do not claim backup/restore complete; only store opaque reference metadata and defer full restore proof. - Do not make rotation a runtime HTTP endpoint reachable remotely unless explicitly protected by local operator boundary and tests. Prefer controlled CLI. - Do not make readiness fail open when PostgreSQL key identity check is unavailable. - Do not include request/trace/master-key IDs in metric labels; metrics remain low-cardinality typed outcomes only. - Do not update Capability Inventory to implemented until targeted evidence and final gates pass. ### Previous story intelligence - Story 1.10 hardened credential lifecycle and added raw secret/key redaction, active Secret validation and immediate revocation. Preserve those invariants. - Story 1.10 closure updated `h2` to 0.4.16 for `RUSTSEC-2026-0258`; do not introduce unrelated dependency churn. - Story 1.4 established migration authority. All durable schema change must be v7 append-only with exact checksum and schema guard tests. - Story 1.3 established typed config. Reusable crates must not read environment variables directly. - Story 1.8 established typed execution errors. Secret crypto failures crossing product boundaries must normalize to safe typed outcomes. ### References - `_bmad-output/planning-artifacts/epics.md` — Story 1.11 and Epic 1 sequence. - `_bmad-output/planning-artifacts/prds/prd-crank-2026-08-03/prd.md` — FR-3 and FR-43 master-key/recovery consequences. - `_bmad-output/planning-artifacts/prds/prd-crank-2026-08-03/addendum.md` — protected master-key backup evidence contract. - `_bmad-output/planning-artifacts/architecture/architecture-crank-2026-08-03/ARCHITECTURE-SPINE.md` — AD-15, AD-16, AD-17, AD-22, AD-24. - `_bmad-output/project-context.md` — crypto/secrets/config/migration/process rules. - `_bmad-output/implementation-artifacts/1-10-lifecycle-auth-profiles-machine-keys.md` — previous FR-3 slice and review lessons. - `crates/crank-runtime/src/secret_crypto.rs` — current crypto implementation. - `crates/crank-registry/src/postgres/secret.rs` — current Secret version persistence. - `apps/admin-api/src/main.rs`, `apps/mcp-server/src/main.rs` — current independent `SecretCrypto::new` wiring. ## Dev Agent Record ### Agent Model Used GPT-5 Codex ### Debug Log References - 2026-08-21: Story context created by `bmad-create-story` during the next-story transition. - 2026-08-21: Implemented first Story 1.11 slice: crypto identity/epoch, v7 migration, registry identity verification and Admin/MCP startup wiring. - 2026-08-21: Verification passed for initial identity slice: targeted crypto/registry/migration tests, migration contract, explicit Community scope, diff check and full `just verify`. - 2026-08-21: Completed operator-controlled rotation workflow: preflight/status/rotate/resume/verify/promote/abort, active-rotation write rejection, target-ciphertext staging, atomic promotion and old-key rejection. - 2026-08-21: Initial final verification passed: targeted Story 1.11 tests, capability inventory/baseline, explicit Community scope, `git diff --check` and full `just verify`. - 2026-08-22: Closed code-review patches: strong config/crypto master-key minimum, target-epoch startup, populated DB decryptability proof before first identity registration, active-epoch write guards, active-rotation delete/write guards, rerunnable aborted rotations, bounded paginated rotation batches and exact v7 schema guard validation. ### Completion Notes List - Implemented durable master-key identity foundation: PostgreSQL stores active epoch/fingerprint/cipher contract only; Admin API and MCP verify it before readiness; mismatch fails closed with bounded diagnostics. - Implemented epoch-aware Secret encryption/decryption with backward-compatible legacy v1 support and strict epoch checks for current ciphertext. - Implemented controlled local `crank-migrate master-key` operator workflow: `status`, read-only `preflight`, resumable `rotate`, `verify`, atomic `promote`, and `abort`; key material is supplied via local files and never echoed. - Implemented fail-closed Secret create/rotate behavior during active rotation, durable target ciphertext staging, checkpointed resume, verification gate and old-key rejection after promotion. - Implemented review hardening: `CRANK_MASTER_KEY` requires at least 32 bytes in config and crypto, first identity registration proves existing decryptability on populated databases, Secret writes verify the active epoch under transaction, and master-key rotation/write coordination uses PostgreSQL transactional table locks without migration-boundary advisory locks. - Implemented bounded rotation iteration with paginated Secret-version reads, rerunnable aborted/failed deterministic rotations and exact v7 schema guard validation in a split module kept below code-health file limits. - Updated operator docs, data/schema docs, migration sequence contract, Capability Inventory and baseline evidence for the FR-3 master-key slice. Epic 7 backup/restore/RPO/RTO remains explicitly deferred. ### Final Verification - `cargo test -p crank-runtime secret_crypto -- --test-threads=1` — passed, 11 tests. - `cargo test -p crank-registry --test integration master_key_identity -- --test-threads=1` — passed, 7 tests. - `cargo test -p crank-registry --test integration migrations -- --test-threads=1` — passed, 23 tests. - `cargo test -p crank-registry --test integration operations_artifacts -- --test-threads=1` — passed, 10 tests. - `cargo test -p admin-api --test migration_command -- --test-threads=1` — passed, 5 tests. - `cargo test -p admin-api --test config_startup -- --test-threads=1` — passed, 5 tests. - `cargo test -p admin-api --test integration secrets_import_auth -- --test-threads=1` — passed, 6 tests. - `cargo test -p admin-api --test integration operations_agents -- --test-threads=1` — passed, 7 tests. - `cargo test -p mcp-server --test config_startup -- --test-threads=1` — passed, 4 tests. - `cargo test -p mcp-server --test integration catalog_access -- --test-threads=1` — passed, 20 tests. - `cargo test -p mcp-server --test integration transport_protocol -- --test-threads=1` — passed, 13 tests. - `cargo test -p crank-config --all-targets` — passed, 25 tests. - `cargo fmt --all --check` — passed. - `cargo check -p crank-registry -p crank-config -p admin-api --bin crank-migrate -p admin-api --test config_startup -p mcp-server --test config_startup` — passed. - `cargo clippy -p crank-runtime -p crank-config --all-targets --all-features -- -D warnings` — passed. - `cargo run -p crank-config --bin crank-config-contract -- --check` — passed. - `just rust-code-health` — passed. - `just rust-boundaries` — passed. - `just migration-contract-check` — passed with `{"status":"contract_current"}`. - `just capability-inventory-check` — passed with inventory `implemented=21` and baseline `flows=33`. - `python3 scripts/check-community-scope.py --root . --files <36 Story 1.11/review-patch paths>` — passed, 36 files scanned. - `git diff --check` — passed. - `just verify` — passed. ### File List - `_bmad-output/implementation-artifacts/1-11-master-key-identity-rotation.md` - `apps/admin-api/src/bin/crank-migrate.rs` - `apps/admin-api/src/error.rs` - `apps/admin-api/src/main.rs` - `apps/admin-api/src/service.rs` - `apps/admin-api/src/service/secrets.rs` - `apps/admin-api/tests/config_startup.rs` - `apps/admin-api/tests/integration/common.rs` - `apps/admin-api/tests/integration/auth_rate_limit.rs` - `apps/admin-api/tests/integration/community_access_usage.rs` - `apps/admin-api/tests/integration/operations_agents.rs` - `apps/admin-api/tests/integration/secrets_import_auth.rs` - `apps/admin-api/tests/migration_command.rs` - `apps/mcp-server/src/main.rs` - `apps/mcp-server/tests/config_startup.rs` - `apps/mcp-server/tests/integration/catalog_access.rs` - `apps/mcp-server/tests/integration/catalog_access/approval_access.rs` - `apps/mcp-server/tests/integration/common.rs` - `apps/mcp-server/tests/integration/transport_protocol.rs` - `crates/crank-community-mcp/src/app.rs` - `crates/crank-config/src/process.rs` - `crates/crank-config/src/render.rs` - `crates/crank-config/src/schema.rs` - `crates/crank-config/tests/contract.rs` - `crates/crank-config/tests/generation.rs` - `crates/crank-config/tests/redaction.rs` - `crates/crank-runtime/src/secret_crypto.rs` - `crates/crank-registry/src/error.rs` - `crates/crank-registry/src/lib.rs` - `crates/crank-registry/src/model.rs` - `crates/crank-registry/src/postgres/mod.rs` - `crates/crank-registry/src/postgres/secret.rs` - `crates/crank-registry/src/postgres/master_key.rs` - `crates/crank-registry/src/migrations.rs` - `crates/crank-registry/src/migrations/authority.rs` - `crates/crank-registry/src/migrations/authority_tests.rs` - `crates/crank-registry/src/migrations/schema_guard.rs` - `crates/crank-registry/src/migrations/schema_guard_v7.rs` - `crates/crank-registry/src/migrations/master_key_identity_v7.rs` - `crates/crank-registry/src/migrations/master_key_identity_v7.sql` - `crates/crank-registry/tests/integration.rs` - `crates/crank-registry/tests/integration/master_key_identity.rs` - `crates/crank-registry/tests/integration/migrations.rs` - `crates/crank-registry/tests/integration/operations_artifacts.rs` - `docs/capability-inventory.json` - `docs/capability-baseline/manifest.json` - `docs/capability-baseline/required-surfaces.json` - `docs/capability-baseline/outcome-taxonomy.json` - `docs/capability-baseline/manual-checklist.md` - `docs/capability-baseline/results.json` - `docs/data-model.md` - `docs/database-schema.md` - `docs/migrations.md` - `docs/production-checklist.md` - `docs/runtime-config.md` - `docs/secrets-and-auth.md` - `docs/schemas/runtime-config.schema.json` - `.env.example` - `deploy/community/.env.example` - `deploy/community/.env.images.example` - `docs/schemas/migration-sequence.json` ## Change Log - 2026-08-21: Created Story 1.11 from Epic 1 FR-3 with brownfield master-key, SecretCrypto, registry Secret version and migration authority context. - 2026-08-21: Added initial implementation for master-key identity registration/verification and epoch-aware Secret ciphertext. - 2026-08-21: Completed master-key rotation workflow, docs/evidence updates and final verification; story moved to `review`. - 2026-08-22: Applied and verified all Story 1.11 code-review patches; story moved to `done`.