fix(wfctl): bootstrapSecrets returns rotation results for force-rotated keys (v0.27.3)#594
Merged
Merged
Conversation
…s bug
Adds two TDD-style tests pinning the rotation-result contract that
broke in core-dump rotate-spaces-key staging dispatch run 25616807427
(2026-05-09):
Step 1: rotating credential "coredump-deploy-key" (type infra.spaces_key)...
secret "SPACES_access_key": created
WFCTL_NEW_KEY_CREATED_AT=2026-05-10T01:41:58Z
rotate-and-prune: expected 1 rotation result, got 0
Root cause: `wfctl infra rotate-and-prune --name <RESOURCE_NAME>` builds
forceRotate keyed by the cloud-side resource name (per ADR 0023 +
docs/runbooks/spaces-key-prune.md), but bootstrapSecrets checks
forceRotate[gen.Key] keyed by the canonical generator key. Mismatch =>
force-rotate code path silently bypassed for that gen, "normal" first-
time-create path runs instead, prints "created" instead of "rotated",
and crucially never appends to the rotations slice. Side effects (DO
API mint + GH Secrets store + WFCTL_NEW_KEY_CREATED_AT sidecar) commit
under the disguise of a normal create; rotate-and-prune then errors
out before pruning, leaving the operator with a freshly-rotated
credential, the old credential still live, and no automated cleanup
path.
The first test exercises the full runInfraRotateAndPrune integration
with key="SPACES" + name="coredump-deploy-key" (the exact shape of
core-dump's infra.yaml on the failing run) and asserts code==0 with a
populated rotations result. Existing rotate-and-prune tests stub
bootstrapSecrets entirely, so they never hit the real keying contract.
The second test pins the bootstrapSecrets unit contract: when
forceRotate is properly keyed by gen.Key AND the underlying
generator+Set commits, rotations MUST contain a RotationResult. This
holds regardless of which architectural fix lands (CLI-side translation
or bootstrapSecrets-side multi-key tolerance).
Per workspace memories: feedback_proper_fixes_over_workarounds (no
soft fallbacks), feedback_force_strict_contracts_no_compat.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ed keys (v0.27.3) Closes the false-negative "expected 1 rotation result, got 0" surfaced in core-dump rotate-spaces-key staging dispatch run 25616807427 (2026-05-09). Two-layer architectural fix: 1. CLI translation (primary fix). runInfraRotateAndPrune now uses a new buildRotateAndPruneForceRotateSet helper that translates the cloud-side --name (per ADR 0023 + docs/runbooks/spaces-key-prune.md; matches secrets.generate[].name) into the canonical gen.Key values that bootstrapSecrets keys forceRotate by. Match precedence: .name first, fallback to .key for configs that omit .name. Rejects unknown names with a fast-fail error message — same UX shape as buildForceRotateSet's typo guard for `wfctl infra bootstrap --force-rotate`. The CLI surface is the architecturally correct place for this translation: the --name flag is documented to take the cloud-side name, and bootstrapSecrets rightly keys by the canonical generator identity. 2. Strict-contract guard (defense in depth). bootstrapSecrets now pre-validates that every forceRotate entry matches a known secrets.generate[].Key, returning an error before touching the store if not. This prevents future callers from silently bypassing the force-rotate code path when they pass mismatched keys — the exact shape of the staging-dispatch bug. Per workspace memory feedback_proper_fixes_over_workarounds and the user mandate "no soft fallback paths": the guard errors LOUD rather than tolerating the mismatch, ensuring callers get a structured error instead of a committed-side-effect-with-empty-result false-negative. Test fixture writeMinimalRotationConfig is extended with a second generate entry whose key != name so existing rotate-and-prune tests that pass --name canonical-name continue to work; previously those tests relied on stub-bootstrapSecrets to absorb the keying mismatch, which masked the bug. Per workspace memories: feedback_proper_fixes_over_workarounds, feedback_force_strict_contracts_no_compat, feedback_no_invented_interfaces. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes wfctl infra rotate-and-prune returning a false-negative rotation result when --name is a cloud-side resource name (secrets.generate[].name) but bootstrapSecrets keys force-rotate by canonical generator key (secrets.generate[].key). Adds a defense-in-depth contract check in bootstrapSecrets and regression tests covering the staging failure shape.
Changes:
- Add
buildRotateAndPruneForceRotateSetto translate--name(resource name) intosecrets.generate[].Keybefore callingbootstrapSecrets. - Add a strict-contract guard in
bootstrapSecretsto error if anyforceRotatekey doesn’t matchsecrets.generate[].Key. - Add/adjust tests and fixtures to reproduce and prevent the “expected 1 rotation result, got 0” false-negative.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cmd/wfctl/infra_rotate_and_prune.go |
Adds --name→gen.Key translation helper and uses it before rotation. |
cmd/wfctl/infra_rotate_and_prune_test.go |
Extends the minimal fixture to include a second secrets.generate entry for name→key translation coverage. |
cmd/wfctl/infra_bootstrap.go |
Adds strict validation that forceRotate keys must match secrets.generate[].Key. |
cmd/wfctl/infra_bootstrap_rotation_count_test.go |
Adds regression tests reproducing key/name mismatch and asserting rotation results are surfaced. |
Comment on lines
+128
to
+141
| // TestBootstrapSecrets_ForceRotate_NameOnlyMatch_StillRotatesAndAppends | ||
| // is the unit-level lock for the keying contract: when force-rotate | ||
| // contains an entry that matches secrets.generate[].name (NOT .key), | ||
| // rotation must still run and rotations must be appended. Without this, | ||
| // the rotate-and-prune integration is fragile to internal CLI changes. | ||
| // | ||
| // This test is the architecturally-correct contract for the bug. It can | ||
| // be satisfied by either: | ||
| // - bootstrapSecrets accepting forceRotate keyed by name OR key, OR | ||
| // - runInfraRotateAndPrune translating name→key before the call. | ||
| // | ||
| // Whichever fix lands, this test pins the invariant: a successful | ||
| // force-rotate where Set committed must produce a RotationResult. | ||
| func TestBootstrapSecrets_ForceRotate_AppendsRotationResultEvenWhenStoreEmpty(t *testing.T) { |
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
…view Addresses Copilot findings on PR 594: 1. buildRotateAndPruneForceRotateSet (cmd/wfctl/infra_rotate_and_prune.go:185) was permissive: multi-Name match returned multiple Keys, and non-provider_credential matches were accepted. Both classes reintroduced the false-negative-after-side-effects failure mode this PR was opened to fix: - multi-Name → multi-rotate → fails len(rotations)==1 after side effects - non-provider_credential → rotates without appending RotationResult Helper now enforces a strict contract: - exactly one matching gen entry (zero or two-plus reject with named keys) - matched gen MUST be type=provider_credential 2. TestBootstrapSecrets_ForceRotate doc comment claimed bootstrapSecrets accepted forceRotate keyed by either .name OR .key. Actual implementation strictly requires .Key. Comment updated to document strict contract. Adds TestBuildRotateAndPruneForceRotateSet covering 8 cases including multi-match + non-provider_credential rejection. Local tests PASS. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment on lines
+226
to
+229
| if matched[0].Type != "provider_credential" { | ||
| return nil, fmt.Errorf("--name %q matches secrets.generate entry of type %q; rotate-and-prune only operates on provider_credential entries (use `wfctl infra bootstrap --force-rotate` for other rotatable types)", name, matched[0].Type) | ||
| } | ||
| return map[string]bool{matched[0].Key: true}, nil |
…ilot Three Copilot findings on PR 594 round 2: 1. infra_rotate_and_prune.go: buildRotateAndPruneForceRotateSet caught multi-Name collisions but missed multi-Key-with-different-Names. Two gens with same .Key (different Names) → forceRotate[key]=true → bootstrapSecrets rotates BOTH → fails len(rotations)==1 after side effects committed (the same false-negative class via Key collision instead of Name collision). Added defense-in-depth Key-uniqueness check that rejects with named collision list. 2. infra_bootstrap_rotation_count_test.go: doc comment header listed a stale test name (TestBootstrapSecrets_ForceRotate_AppendsRotationResult_NameKeyMismatch) while the actual function is TestRotateAndPrune_KeyNameMismatch_ReturnsRotationResult. Synced. 3. infra_bootstrap_rotation_count_test.go: comment said the fix could be satisfied by "CLI translation OR bootstrapSecrets accepting both keying forms". Actual contract: bootstrapSecrets strictly requires forceRotate keyed by gen.Key (rejects unknown entries); CLI does the translation at buildRotateAndPruneForceRotateSet. Updated to match. Adds matched_key_shared_with_another_gen_rejected test case to TestBuildRotateAndPruneForceRotateSet covering the new defense-in-depth guard. All 9 cases PASS. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <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
Closes false-negative
rotate-and-prune: expected 1 rotation result, got 0from core-dump rotate-spaces-key staging dispatch run 25616807427 (2026-05-09). Rotation succeeded operationally — DO API minted a new key, GH SecretSPACES_access_keywas updated,WFCTL_NEW_KEY_CREATED_ATsidecar was emitted to stderr — butbootstrapSecretsreturned an empty rotations slice, sorotate-and-pruneerrored out after side effects already committed. Operator left with a freshly-rotated credential, the old credential still live, and no automated cleanup path.Root cause
wfctl infra rotate-and-prune --name <RESOURCE_NAME>buildsforceRotate := map[string]bool{name: true}keyed by the cloud-side resource name (per ADR 0023 +docs/runbooks/spaces-key-prune.md; matchessecrets.generate[].name). ButbootstrapSecretschecksforceRotate[gen.Key]keyed by the canonical generator key (e.g.SPACES).For core-dump's
infra.yaml(key: SPACES, name: coredump-deploy-key),forceRotate["coredump-deploy-key"]=truebutbootstrapSecretschecksforceRotate["SPACES"]=false→ force-rotate code path silently bypassed → "normal" first-time-create path runs (printingcreatedinstead ofrotated) → side effects commit → rotations slice never appended.Fix
Two-layer architectural fix:
runInfraRotateAndPrunenow uses a newbuildRotateAndPruneForceRotateSethelper that translates--name→gen.Keyviasecrets.generate[].namematch (fallback to.keyfor legacy configs), with a fast-fail typo guard mirroringbuildForceRotateSetininfra_bootstrap.go.bootstrapSecretsnow pre-validates that everyforceRotateentry matches a knownsecrets.generate[].Key, erroring loud if not. Per workspace memoryfeedback_proper_fixes_over_workaroundsand the user mandate "no soft fallback paths": never silently absorb the contract violation.Files
cmd/wfctl/infra_bootstrap.go— strict-contract guard at top ofbootstrapSecretscmd/wfctl/infra_rotate_and_prune.go—buildRotateAndPruneForceRotateSethelper + CLI call-site updatecmd/wfctl/infra_bootstrap_rotation_count_test.go(new) — failing-side test reproducing the staging-dispatch shape (key=SPACES, name=coredump-deploy-key) + bootstrapSecrets unit-level contract testcmd/wfctl/infra_rotate_and_prune_test.go— fixture extended with a second generate entry so existing tests'--name canonical-namecontinues working (previously masked by stub-bootstrapSecrets absorption)Test plan
origin/maincode (verified via stash)cmd/wfctl/tests pass:GOWORK=off go test ./cmd/wfctl/... -count=1=>okGOWORK=off go test ./...=> 0 failuresGOWORK=off golangci-lint run ./cmd/wfctl/...=>0 issuesGOWORK=off go test -race ./cmd/wfctl/ -count=1 -run "ForceRotate|RotateAndPrune|BootstrapSecrets"=>okrotate-spaces-keyworkflow againstwfctl@v0.27.3confirms the false-negative is closed (orchestrator validation post-merge)🤖 Generated with Claude Code