Skip to content

fix(config): recover stalled file LocalSecrets migrations #816

Closed as not planned

Description

@akrock

Context

A file-backed LocalSecrets user who encounters an unrecoverable exact-key migration needs to migrate other, unrelated keys without deleting or exposing either secret. This is a remaining review concern on PR #813. Normal secrets migrate-key behavior should remain simple; recovery is an explicit operator action.

Current State

Verified 2026-09-23. FileAppSurfaceLocalSecretStore.FileMigrationBackend uses one <store>.migration-journal.json slot (Config/ForgeTrust.AppSurface.Config.LocalSecrets/FileAppSurfaceLocalSecretStore.cs:1173). AppSurfaceLocalSecretMigrationCoordinator.Run commits Prepared before reading the source (Config/ForgeTrust.AppSurface.Config.LocalSecrets/AppSurfaceLocalSecretKeyMigration.cs:195-211). A missing source leaves that slot unfinished. A different migration then returns local-secret-migration-journal-conflict before reading values (same file:157-177). The Linux/Windows indexed and macOS v2 backends already derive journal paths from source/destination pairs (PlatformLocalSecretMigrationBackend.cs:120,183-188; MacOsV2MigrationBackend.cs:15-18); this issue addresses the file-store liveness gap.

Proposed Change

Keep the shared cross-process maintenance lease and the current copy/verify/index/delete ordering. Add an opt-in appsurface secrets migrate-key recover --migration-id <id> preview, --apply to quarantine an unfinished file-store journal, and --release --apply to record operator reconciliation. Preview and apply re-read the exact journal under the lease. Apply requires the current migration ID; a mismatch, malformed journal, unavailable exact read, unsafe file posture, or failed durable transition leaves the original protection in place. Quarantine durably retains metadata (ID, state, namespace, exact source and destination), frees the active journal slot, and never writes or deletes a secret. Before any new migration prepares a journal or reads a value, the file backend checks retained unresolved records under the same lease. An operation touching either unresolved identifier, including a case-only spelling, fails with a value-safe conflict; an unrelated operation proceeds. Release requires the retained ID and explicit --release --apply after operator reconciliation, changes only retained metadata, and lifts that overlap guard. A process crash at any transition must leave either the active journal or the retained guard effective.

appsurface secrets doctor reports the number of unresolved retained journals and bounded, escaped identifiers without printing values. An otherwise healthy store remains usable and doctor exits successfully with a warning. Ordinary config startup and secret lookup behavior do not change. Normal secrets migrate-key flags and preview remain unchanged. Document that source/destination reconciliation can require existing store or native tools; recovery does not promise to reconstruct a missing value.

API and documentation

Expose an optional, value-safe recovery capability from the LocalSecrets package for the CLI: inspect by namespace and migration ID, quarantine by ID, and release by ID. Results carry state, exact identifiers, and presence/diagnostic status but never value bytes or value hashes. Unsupported stores return a structured unsupported result. Document the capability, CLI preview/apply semantics, durable state, overlap rule, rollback constraint, and operator pitfalls in the package README and guides/config-key-migration.md.

Acceptance Criteria

  1. A file-store migration with a missing source before verification leaves a recoverable journal. Preview changes no store or journal bytes; --apply with the matching ID durably retains it and changes no secret value.
  2. A different source/destination pair can migrate after quarantine. A new request touching either protected identifier (including case-only spelling) fails before a new journal, value read, write, or delete.
  3. --release --apply requires the exact retained ID, lifts only that record's guard, and never changes secret values. Wrong ID or changed journal state leaves protection intact.
  4. Crashes or injected I/O failures before/after durable transitions cannot create a window in which a guarded identifier is unprotected. Cross-process writers continue to honor the shared lease.
  5. secrets doctor warns about retained unresolved records using bounded, display-safe identifiers; no value or value hash appears in journal, CLI output, or exception text. The warning alone does not fail app startup or an otherwise healthy doctor check.
  6. Existing successful migration, retry, collision, and source-deletion safety tests remain green; affected APIs and CLI flows have reference, decision, and pitfall documentation.

Testing Plan

Layer Cases
Coordinator/unit Missing source; ID mismatch; exact and case-folded overlap; unrelated pair; release; malformed retained metadata
File integration Fault injection at quarantine/slot transition; reopen after crash; independent-process writer under lease; no value mutation
CLI Preview; apply; release; doctor warning; safe output and unchanged normal command

Run scoped formatting, LocalSecrets and CLI tests, and meaningful changed-branch coverage; resolve introduced compiler, analyzer, and documentation warnings.

Rollback Plan

Do not roll back the overlap guard while unresolved retained journals exist. Pause new migrations and reconcile or restore their active protection under the maintenance lease before deploying an older binary. No rollback step deletes destination or source values.

Effort Estimate

Recovery capability and durable file state: ~1 day; CLI/doctor and docs: ~0.5-1 day; fault-injected and process tests: ~0.5-1 day. Total ~2-3 days.

Files Reference

File Change
Config/ForgeTrust.AppSurface.Config.LocalSecrets/AppSurfaceLocalSecretKeyMigration.cs:140 Recovery contract and coordinator guard
Config/ForgeTrust.AppSurface.Config.LocalSecrets/FileAppSurfaceLocalSecretStore.cs:1173 Durable quarantine and overlap checks
CLI/ForgeTrust.AppSurface.Cli/SecretsCommand.cs:206 Opt-in recovery and doctor output
Config/ForgeTrust.AppSurface.Config.LocalSecrets.Tests/LocalSecretFileMigrationPersistenceTests.cs Crash/reopen/cross-process regressions
Config/ForgeTrust.AppSurface.Config.LocalSecrets/README.md; guides/config-key-migration.md Operator and API guidance

Out of Scope

Automatic secret deletion, reconstructing absent values, changing the normal migration command, or replacing the existing lease and roll-forward protocol.

Related

PR #813: #813

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions