Add crash-safe migration for legacy system secret keys#4346
Draft
amirejaz wants to merge 1 commit intophase3-wire-callersfrom
Draft
Add crash-safe migration for legacy system secret keys#4346amirejaz wants to merge 1 commit intophase3-wire-callersfrom
amirejaz wants to merge 1 commit intophase3-wire-callersfrom
Conversation
Existing users may have registry tokens and workload auth secrets stored under bare keys (BEARER_TOKEN_, OAUTH_CLIENT_SECRET_, REGISTRY_OAUTH_, etc.) that pre-date the scoped provider wrappers. This migration renames them into the __thv_<scope>_ namespace on first startup so they are accessible via the new scoped providers and hidden from user-facing secret commands. Key design properties: - Write-before-delete ordering: the new key is written before the old is deleted, so a crash mid-migration leaves the secret reachable. - Idempotent: a missing old key is silently skipped, making retries safe. - One-shot: guarded by the SecretScopeMigration config flag; once set, the migration is a cheap config read and returns immediately. - Discovery-based: DiscoverMigrations lists all secrets and matches known system prefixes, so no static registry of workload names is required. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
BEARER_TOKEN_,OAUTH_CLIENT_SECRET_,REGISTRY_OAUTH_, etc.) that pre-date the scoped provider wrappers. Without migration, those keys would be unreachable after Phase 3 wires callers to useScopeWorkloads/ScopeRegistryproviders.MigrateSystemKeysandDiscoverMigrationsinpkg/secrets/migration.go: discovers bare system keys by known prefix and renames them into the__thv_<scope>_namespace using write-before-delete ordering for crash safety.CheckAndPerformSecretScopeMigrationinpkg/migration/secret_scope.go: guards migration behind aSecretScopeMigrationconfig flag (same pattern as existing migrations) and is triggered fromcmd/thv/main.goalongside the other startup migrations.This is Phase 4 of the scoped secret store (part of #4192), tracking issue #4226. It is stacked on Phase 3 (#4343) and must be released at the same time.
Type of change
Test plan
go build ./...— clean buildgo test ./pkg/secrets/... ./pkg/migration/...— all pass, includingTestMigrateSystemKeysandTestDiscoverMigrationsgolangci-lint run— 0 issuesSpecial notes for reviewers
Key design properties of the migration:
GetSecretreturns a not-found error and the entry is silently skipped.DiscoverMigrationslists all secrets and matches againstSystemKeyPrefixMappings; no static workload registry is required.SecretScopeMigrationconfig flag prevents re-running on every startup after migration completes.CreateSecretProvider(bare, no wrapper) so it can enumerate and rename both old bare keys and already-scoped__thv_*keys without restriction.Generated with Claude Code