carlos / platform Public

store write credential: teardown releases a failed mint's claim

Astra code round 2's P2. Round 2's P1 (named-unit recovery bypasses the
console floor) is the rollback family's third round: held for Paul.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 04ddced3e4a585e3add245bed2b4b155a9c666be parent a246a44
4 files changed, +122 −18
  • docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-census-R1.md +28 −0
  • docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-code-R2.md +36 −0
  • internal/objstore/walk.go +20 −18
  • internal/objstore/writecred_test.go +38 −0
diff --git a/docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-census-R1.md b/docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-census-R1.md
new file mode 100644
index 000000000..8fcd3961e
--- /dev/null
+++ b/docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-census-R1.md
@@ -0,0 +1,28 @@
+Approved for commit `a246a44b68d375e37149f501c9ba670ca72a38e7`, against local `origin/main` at `d74dff114597775618926c0400842b5d728d1018`. I read the card, every changed file covered by its envelopes, and the relevant callees. No files changed, tests run, or network services called.
+
+The new root check cannot select another executable, path, or query target. It checks a fixed bucket key, then scans the staged executable D2 already reads. A forged floor can only restrict adoption; the existing proof check remains required.
+
+| Unit | Verdict and evidence |
+|---|---|
+| `infra/modules/deployment-buckets/main.tf:external` | **Approve.** Lines 247–264 add only two Deny statements, scoped to `control/console-floors/*`. Existing protections remain. The operator-only `legacy` disposition remains appropriate. [Source](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/deployment-buckets/main.tf:247) |
+| `infra/modules/region-host/main.tf:external` | **Approve.** Lines 160–163 refuse an empty prefix; lines 842–862 conditionally add the multipart pair and account-scoped federation names. No root runtime input or host-role grant changes. `legacy` retained. [Precondition](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/region-host/main.tf:160), [boundary](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/region-host/main.tf:842) |
+| `infra/modules/region-host/variables.tf:external` | **Approve.** Lines 315–319 introduce an operator-controlled boolean, default false. No box runtime read. `legacy` retained. [Source](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/region-host/variables.tf:315) |
+| `internal/release/adopt.go:adoptHost` | **Approve.** Lines 1630–1667 retain staging, runtime validation and D2’s existing file read. Lines 1734–1742 add a refusal before `bindProof`, without an alternative admission path. Existing `authority` disposition retained. [Staging](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/adopt.go:1630), [gate](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/adopt.go:1734) |
+| `infra/modules/deployment-buckets/tests/console_floors.tftest.hcl:external` | **Approve.** Lines 5–48 use a mock provider and assert both complete Deny statements. No runtime root reader; frozen `accepted-legacy` is appropriate. [Source](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/deployment-buckets/tests/console_floors.tftest.hcl:5) |
+| `infra/modules/region-host/tests/store_write_credentials.tftest.hcl:external` | **Approve.** Lines 4–99 are mock-provider plan tests covering default rendering, enabled grants, combined switches and missing-prefix refusal. Frozen `accepted-legacy` is appropriate. [Source](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/region-host/tests/store_write_credentials.tftest.hcl:4) |
+| `internal/objstore/aws_writecred.go:federatedName` | **Approve.** Lines 165–170 read eight bytes from `crypto/rand`; no caller-selected file or input. The console-side session-name helper fits `accepted-legacy`. [Source](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/aws_writecred.go:165) |
+| `internal/release/consolefloor.go:consoleFloorAdmits` | **Approve.** Lines 145–154 derive exactly the existing staged path and refuse errors. Lines 69–108 use a constant floor key, inspect existence only, and never interpret its body as authority or a target. The narrowly stated frozen `accepted-legacy` basis is supported. [Caller](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/consolefloor.go:145), [check](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/consolefloor.go:69) |
+| `internal/release/consolefloor.go:fileContains` | **Approve.** Lines 112–138 scan the existing staged file read-only with bounded buffering. Linux `safefile` rejects symlinks, nonregular files and multiple links. No expanded file target; frozen `accepted-legacy` is appropriate. [Scanner](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/consolefloor.go:112), [open checks](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/safefile/file_linux.go:52) |
+| `store_credential.go:runStoreCredential` | **Approve.** Lines 92–139 validate arguments and use the invoking user’s existing console API session. No root service dispatch or direct infrastructure fallback is introduced. Frozen `accepted-legacy` is appropriate. [Source](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/store_credential.go:92) |
+
+| Re-pinned envelope | Verdict and evidence |
+|---|---|
+| `.` | **Approve.** Command registration, request construction, validation and output remain within the CLI/API path; associated test changes add no runtime authority. [Registration](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/store.go:125), [implementation](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/store_credential.go:78) |
+| `infra/modules/deployment-buckets` | **Approve.** The only changed policy statements add the scoped floor protections assessed above. [Lines 247–264](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/deployment-buckets/main.tf:247) |
+| `infra/modules/deployment-buckets/tests` | **Approve.** Only mock plan assertions are added. [Lines 18–48](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/deployment-buckets/tests/console_floors.tftest.hcl:18) |
+| `infra/modules/region-host` | **Approve.** The new switch and conditional boundary statements preserve existing host-role restrictions, including boundary-conditioned user creation and policy writes. [Boundary](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/region-host/main.tf:842), [retained restrictions](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/region-host/main.tf:928) |
+| `infra/modules/region-host/tests` | **Approve.** The new tests exercise the exact policy changes and refusal; no production execution path. [Lines 43–99](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/infra/modules/region-host/tests/store_write_credentials.tftest.hcl:43) |
+| `internal/objstore` | **Approve.** New writer operations remain console-side. Prefix validation excludes policy wildcards; ownership checks precede writer mutation; teardown checks ownership; session minting uses bounded AWS configuration and deferred key cleanup. No added root execution path or weakened root input check. [Validation and policy](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/writecred.go:180), [ownership](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/writecred.go:353), [teardown](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/walk.go:825), [mint adapter](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/aws_writecred.go:79) |
+| `internal/release` | **Approve.** The floor writer is create-only; the reader uses a fixed key and the already-selected executable. Production S3 listing is bounded to one result. Existing adoption checks remain required. [Floor implementation](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/consolefloor.go:51), [bounded listing](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/store.go:1179), [adoption gate](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/adopt.go:1740) |
+
+CENSUS APPROVED
\ No newline at end of file
diff --git a/docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-code-R2.md b/docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-code-R2.md
new file mode 100644
index 000000000..d985975f5
--- /dev/null
+++ b/docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-code-R2.md
@@ -0,0 +1,36 @@
+R1 #1 — **Partly resolved, P1:** floor deletion is blocked, but named-unit recovery still bypasses the rollback gate.
+R1 #2 — **Resolved:** production checks existence through a bounded listing without reading the floor’s body.
+R1 #3 — **Resolved:** writer ownership now gates minting, policy changes and deletion.
+R1 #4 — **Resolved:** the census proposal and chain entry exist; the changed fingerprints and final seal match.
+R1 #5 — **Resolved:** the command projection and parity row are present.
+R1 #6 — **Resolved:** the comment states the lock requirements, and a test covers validation failure after a policy write.
+
+Reviewed `a246a44b68d375e37149f501c9ba670ca72a38e7` against local `origin/main` (`d74dff114597775618926c0400842b5d728d1018`). No network calls, edits, subagents or full suites. Targeted offline tests could not start because Go attempted to update the read-only `go.mod`.
+
+1. **P1 — A: Named-unit recovery can install a writer-unaware console despite the floor.**
+
+ **Evidence:** The new check exists in [adopt.go:1739](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/adopt.go:1739). However, `PassFilter` invokes recovery first and excludes handled routes from ordinary adoption at [adopt.go:588](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/adopt.go:588). Active named-unit recovery directly calls `PointLive`, then restarts the unit at [namedrecovery_active.go:191](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/host/namedrecovery_active.go:191). Stopped-unit recovery also calls `PointLive` directly at [namedrecovery.go:120](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/host/namedrecovery.go:120). Neither path checks the floor; their shared [StageSignedHead](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/release/signedhead.go:11) does not either.
+
+ **Failure scenario:** After phase 2 creates a writer and floor, promote a valid, signed console release predating writers. With nonlegacy named-unit recovery enabled, the root pass can install and restart that release before reaching `adoptHost`. The older console can then purge the store without retiring its writer or maintain storage denial without updating the writer.
+
+ **Concrete fix:** Enforce console-floor admission through one shared operation covering ordinary adoption and both named-unit recovery paths. Add witnesses with an existing floor and a signed pre-floor console for each path, including floor-read failure.
+
+ **Fault family:** Version changes must preserve credential retirement and storage enforcement. This carries forward R1 #1’s unresolved invariant and design round 3’s P1.
+
+2. **P2 — C: A failed first mint can leave a writer-name claim that teardown never releases.**
+
+ **Evidence:** Minting acquires the writer claim at [writecred.go:465](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/writecred.go:465), before either the floor write or state write can fail. Teardown releases that claim only inside `wc != nil` at [walk.go:825](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/walk.go:825). Its final name cleanup covers only the store user and bucket at [nameclaim.go:330](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/store-write-credential/internal/objstore/nameclaim.go:330).
+
+ **Failure scenario:** `bab/shop-eu` claims its writer name, then the floor or state write fails. Destroying the store succeeds but leaves the global writer claim. Subsequently, `bab/shop` with environment `eu` can provision its store yet cannot mint credentials because the deleted store still owns the colliding writer name. App-prefix purging cannot remove this global claim.
+
+ **Concrete fix:** Release this store’s owned writer claim during teardown even when no write-credentials state exists, preserving ownership checks and user-before-claim deletion ordering. Test failures at both writes followed by teardown and name reuse.
+
+ **Fault family:** Teardown must release names reserved by partially completed creation.
+
+No additional P1 or P2 found in part B.
+
+The census fingerprints match, but I withhold integration approval for `adoptHost` and the `internal/release` envelope because of finding 1, and for `internal/objstore` pending finding 2. The other proposed units and envelopes preserve their stated root-read boundaries. No verdict was posted externally.
+
+The rollback fault family has recurred. Under stopping rule 2, stop incremental fixes and choose between refusing unsupported recovery upfront, cutting the affected feature, or enforcing the invariant centrally with guard tests. I recommend the central invariant.
+
+**NOT READY**
\ No newline at end of file
diff --git a/internal/objstore/walk.go b/internal/objstore/walk.go
index 6a34262fe..6835b2e6c 100644
--- a/internal/objstore/walk.go
+++ b/internal/objstore/walk.go
@@ -819,27 +819,29 @@ func claimRawTeardownIn(ctx context.Context, s release.Store, p Provisioner, sc
return fmt.Errorf("objstore: delete user %s: %w", user, err)
}
// The store's writer (writecred.go), if it has one: the user (with its
- // policy and any key a crashed mint left), then the state object that
- // names it. Both are idempotent, so a re-run after a failure between
- // them converges, and the record, read first, still goes last.
+ // policy and any key a crashed mint left) and the name claim, when this
+ // store holds the claim, then the state object that names it. The claim
+ // is checked even with no state object: a first mint takes it before it
+ // writes anything else, and one that failed there leaves only the claim
+ // (Astra code round 2). Each step is idempotent, so a re-run after a
+ // failure between them converges, and the record, read first, still
+ // goes last. A colliding store's writer is that store's to tear down.
+ writer := WriterName(UserNameIn(acct, app, env))
+ held, err := holdsWriterName(ctx, s, acct, app, env)
+ if err != nil {
+ return fmt.Errorf("objstore: writer claim for %s/%s: %w", acct, app, err)
+ }
+ if held {
+ if err := p.DeleteUser(ctx, writer); err != nil {
+ return fmt.Errorf("objstore: delete writer %s: %w", writer, err)
+ }
+ if err := releaseName(ctx, s, userClaimKey(writer), acct, app, env); err != nil {
+ return fmt.Errorf("objstore: release writer claim %s: %w", writer, err)
+ }
+ }
if wc, _, err := GetWriteCredentialsIn(ctx, s, acct, app, env); err != nil {
return fmt.Errorf("objstore: read write credentials for %s/%s: %w", acct, app, err)
} else if wc != nil {
- // Only a writer this store holds the claim for (claimWriterName): a
- // colliding store's writer is that store's to tear down.
- writer := WriterName(UserNameIn(acct, app, env))
- held, err := holdsWriterName(ctx, s, acct, app, env)
- if err != nil {
- return fmt.Errorf("objstore: writer claim for %s/%s: %w", acct, app, err)
- }
- if held {
- if err := p.DeleteUser(ctx, writer); err != nil {
- return fmt.Errorf("objstore: delete writer %s: %w", writer, err)
- }
- if err := releaseName(ctx, s, userClaimKey(writer), acct, app, env); err != nil {
- return fmt.Errorf("objstore: release writer claim %s: %w", writer, err)
- }
- }
if err := s.Delete(ctx, WriteCredentialsKey(acct, app, env)); err != nil {
return fmt.Errorf("objstore: delete write credentials state for %s/%s: %w", acct, app, err)
}
diff --git a/internal/objstore/writecred_test.go b/internal/objstore/writecred_test.go
index 0aea37f74..e450e3af2 100644
--- a/internal/objstore/writecred_test.go
+++ b/internal/objstore/writecred_test.go
@@ -600,3 +600,41 @@ func (f *failAfterStore) Get(ctx context.Context, key string) ([]byte, string, e
}
return f.Store.Get(ctx, key)
}
+
+// A first mint that took the writer's claim and failed before its state
+// object leaves only the claim; teardown still gives it back, so a
+// colliding store can use the name afterwards (Astra code round 2).
+func TestTeardownReleasesAWriterClaimAFailedMintLeft(t *testing.T) {
+ ctx := context.Background()
+ s, p, _ := writeFixture(t)
+ writer := WriterName(UserNameIn("bab", "titogo", ""))
+ // The floor write fails, after the claim.
+ fs := &failPutStore{Store: s, key: release.ConsoleStoreWritersFloorKey}
+ if _, err := MintWriteCredentialIn(ctx, fs, p, "bab", "titogo", "", "m@example.com", "recordings/", time.Hour, time.Now().UTC()); err == nil {
+ t.Fatal("a mint whose floor write failed succeeded")
+ }
+ if held, _ := holdsWriterName(ctx, s, "bab", "titogo", ""); !held {
+ t.Fatal("fixture: the failed mint left no claim")
+ }
+ if wc, _, _ := GetWriteCredentialsIn(ctx, s, "bab", "titogo", ""); wc != nil {
+ t.Fatal("fixture: the failed mint wrote a state object")
+ }
+ if err := Teardown(ctx, s, p, nil, "bab", "titogo"); err != nil {
+ t.Fatal(err)
+ }
+ if c, err := getNameClaim(ctx, s, userClaimKey(writer)); err != nil || c != nil {
+ t.Fatalf("teardown left the writer claim: %+v, %v", c, err)
+ }
+}
+
+type failPutStore struct {
+ release.Store
+ key string
+}
+
+func (f *failPutStore) Put(ctx context.Context, key string, body []byte, etag string) (string, error) {
+ if key == f.key {
+ return "", errors.New("store unavailable")
+ }
+ return f.Store.Put(ctx, key, body, etag)
+}