Fleet secrets key plan: Astra plan round 3 P2 (relay rotate and reconcile select per app); review complete
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/plans/2026-10-29-fleet-secrets-key.md+4 −2docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R3.md+8 −0
CI passed — run details
Intent
<task-notification> <task-id>bll3vua6l</task-id> <tool-use-id>toolu_01CzrizyRgQsQT5ykbGmUacE</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/bll3vua6l.output</output-file> <status>completed</status> <summary>Background command "Run Astra plan review round 3" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 85.5 g CO₂e (7,224,232 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-secrets-key, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md b/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md| index 003713639..a0fa1a319 100644 |
| --- a/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md |
| +++ b/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md |
| @@ -8,6 +8,8 @@ |
| **Tech Stack:** Go (console, CLI, registry SQLite, release.Store), ECDH-P256 envelopes (`internal/appconfig`). |
| +**Status:** reviewed, Astra plan rounds 1-3 (R3 READY AFTER FIXES, fixes applied). Awaiting Paul's look and execution method. |
| + |
| **Spec:** `docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md` (APPROVED rev 5). Read §2.1 first: I1 (confidentiality) is the hard invariant; I2 (a value sealed to a key the app's boxes hold) is best effort, and its misses surface through §5.7. |
| ## Global Constraints |
| @@ -175,13 +177,13 @@ Order inside the handler, every refusal before the first write: `apiOwnerAccount |
| - Consumes: Task 5's `sealKeyFor`; Task 1's `Sealer`. |
| - Produces: |
| - Every `sealPub *ecdh.PublicKey` parameter in `objstore` and `mail` becomes `seal appconfig.Sealer`; they call `seal.Seal(appconfig.Binding{acct, app}, ...)` and store the returned Var (with `SealedTo`). |
| - - Relay (plan review R2 #1): `relayReady()` (`relayops.go:477`) drops its `s.cfg.SecretsPub == ""` arm (`errRelayNoSealKey`); its callers `relayEnable` (`:979`), the rotate path (`:1347`) and owned-environment delivery (`relayenv.go:207`) call `sealKeyFor(ctx, sqid, app)` right after `relayReady` and before the first mutation, mapping `errNoDeploymentKey` to the existing `errRelayNoSealKey` answer and `errFleetNoSecretsKey` to the keyless-fleet row; `relayApplyConfig`/`relayApplyConfigIn` take the `appconfig.Sealer` instead of parsing the key. |
| + - Relay (plan review R2 #1): `relayReady()` (`relayops.go:477`) drops its `s.cfg.SecretsPub == ""` arm (`errRelayNoSealKey`); `relayEnable` (`:979`) and owned-environment delivery (`relayenv.go:207`) call `sealKeyFor(ctx, sqid, app)` right after `relayReady` and before the first mutation; `relayRotate` (`:1345`, context and region only) and the reconciliation paths (`relayops.go:1610`, `relayenv.go:158`) call it per app inside their record loops (in `relayReissue` and the reconcile body), before each app's mutation, and thread that sealer into the walks and environment delivery (plan review R3 #1). Each call maps `errNoDeploymentKey` to the existing `errRelayNoSealKey` answer and `errFleetNoSecretsKey` to the keyless-fleet row; `relayApplyConfig`/`relayApplyConfigIn` take the `appconfig.Sealer` instead of parsing the key. |
| - Selection is context-based: `sealKeyFor(ctx, sqid, app)` returns typed errors (`errFleetNoSecretsKey`, `errNoDeploymentKey`, `errUnknownApp`). HTTP doors wrap it: `func (s *Server) storeSealKey(w http.ResponseWriter, ctx context.Context, acct *Account, app string) (appconfig.Sealer, bool)` and the mail twin map each error to its approved refusal before any backend call. `instanceStorePreflight(ctx, w, acct, app)` returns `(appconfig.Sealer, bool)`; its detached seed caller (`apiinstanceseed.go:446`) calls `sealKeyFor` directly and records the error as the seed's failure. |
| - `rotateWebhookBudget(ctx)` and `convergeCallbackKey(ctx, acct *Account, app string)` take no key; each app's sealer comes from `sealKeyFor(ctx, target.acct, target.app)`. Background walks (plan storage, team credentials, webhook rotation) skip an app whose `sealKeyFor` fails, with a log line, and retry next pass. |
| - Lock ownership (plan review R1 #2). `lockAccount` is a non-reentrant keyed mutex, so it is taken only at entry points, never inside `sealKeyFor`, the package sealers or any helper. Entry points that take it (before any app lock): the config PUT (`handleAPIConfigPut`, before `teamApplyEnvironment`'s app lock, `apiconfig.go:682-715`), the key door, `handleAPIEnvironmentFork`, `placeAppTarget`'s callers, `handleAPIStoreGrant`/`Rotate`/`Provision`, `handleAPIEmailEnable`/`Rotate`, the scan doors, `handleAPISystemWebhookRotate` (per app inside `rotateWebhookBudget`), and each background walk per app. Entry points that ALREADY hold it and must not take it again: app creation (`apicli.go:497`, around `claimAppWith`), instance creation (`apiinstances.go:2009`, `:2083`, around private-store provisioning), and anything under `planLock` when plans are enabled (`plancaps.go:227`). Where an entry point holds it only when plans are enabled, the seal runs unlocked with plans off: an accepted I2 gap (§2.1), noted in a comment. The implementer lists every entry point in the commit message with which arm it is. |
| - Guard (`TestOnlySealKeyForBuildsSealers`): load every non-test package of the module with `golang.org/x/tools/go/packages` (types and syntax), and collect by OBJECT IDENTITY (`types.Info.Uses` resolving to the `*types.Func`, so import aliases and same-package calls count): calls to `appconfig.Seal`, `appconfig.SealBound`, `appconfig.SealUnbound`, `appconfig.NewSealer`, the method `(appconfig.Sealer).Seal`, and `archive.Seal`. Constructions too (plan review R2 #2): the guard also collects every composite literal whose type is `appconfig.Sealer` (via `types.Info.Types`), anywhere in the module, and allows exactly one, inside `NewSealer`; outside `internal/appconfig` a literal cannot compile (unexported fields), and the test asserts the struct has no exported field. Inside `internal/appconfig`, calls from `Sealer.Seal` to `SealBound`/`SealUnbound` and from `Seal` to them are allowed. Method calls `(Sealer).Seal` are allowed anywhere (a sealer can only come from an allowed constructor). If `x/tools` is not already a module dependency, use `go/types` with `go/importer.ForCompiler(fset, "source", nil)` instead; no new dependency. Allowlist, by enclosing function: `appconfig.(Sealer).Seal`; `console.(*Server).sealKeyFor`; `main.sealSecretAPI`; `main.runSecretsSet` (direct mode, after Task 8's checks); `archive.Seal` and its callers `buildArchive` and `offlineArchive` in `internal/host` (platform moves, deployment key; fleet instances are not moved). Any other call fails the test naming file:line. Negative fixtures as testdata packages: a new site with an arbitrary key, the same through an aliased import (`ac "…/internal/appconfig"`), a second `NewSealer` inside `sealkey.go` outside `sealKeyFor`, a second constructor inside `internal/appconfig` that returns `Sealer{...}`, and a sealer for `bab/shop` used on `bab/other` (fails at runtime with `ErrSealerBinding`). |
| -- [ ] **Step 1: Write failing tests**: `TestOnlySealKeyForBuildsSealers` with its three negative fixtures; `TestStoreGrantOnKeylessFleetRefusesBeforeBackend` (the fake provisioner records no call); `TestStoreGrantOnFleetSealsToTheFleetKey` (the delivered Var opens with the fleet private key and has `SealedTo`); `TestMailEnableOnFleetSealsToTheFleetKey`; `TestRelayApplyOnFleet`; `TestWebhookRotateUsesEachAppsKey` (two apps, one platform and one fleet, sqid-only targets); `TestPlanStorageSkipsKeylessFleet`; `TestRelayEnableOnFleetWithNoDeploymentKey` (console with empty `SecretsPub`, fleet key registered: enable succeeds and seals to the fleet key) and `TestRelayEnableOnKeylessFleetRefusesBeforeMutation` (no relay record written); lock tests through HTTP with plans enabled AND disabled: `TestAppCreateAdoptingFleetAppDoesNotDeadlock`, `TestInstanceCreatePrivateStoreOnFleetDoesNotDeadlock`, `TestTeamEnvironmentCreateOnFleetDoesNotDeadlock` (each with a 5 s deadline). |
| +- [ ] **Step 1: Write failing tests**: `TestOnlySealKeyForBuildsSealers` with its three negative fixtures; `TestStoreGrantOnKeylessFleetRefusesBeforeBackend` (the fake provisioner records no call); `TestStoreGrantOnFleetSealsToTheFleetKey` (the delivered Var opens with the fleet private key and has `SealedTo`); `TestMailEnableOnFleetSealsToTheFleetKey`; `TestRelayApplyOnFleet`; `TestWebhookRotateUsesEachAppsKey` (two apps, one platform and one fleet, sqid-only targets); `TestPlanStorageSkipsKeylessFleet`; `TestRelayEnableOnFleetWithNoDeploymentKey` (console with empty `SecretsPub`, fleet key registered: enable succeeds and seals to the fleet key) and `TestRelayEnableOnKeylessFleetRefusesBeforeMutation` (no relay record written), `TestRelayRotateUsesEachAppsKey` and `TestRelayReconcileUsesEachAppsKey` (a platform app and a fleet app in one pass: each envelope opens only with its own key); lock tests through HTTP with plans enabled AND disabled: `TestAppCreateAdoptingFleetAppDoesNotDeadlock`, `TestInstanceCreatePrivateStoreOnFleetDoesNotDeadlock`, `TestTeamEnvironmentCreateOnFleetDoesNotDeadlock` (each with a 5 s deadline). |
| - [ ] **Step 2: Run** `nice -n 19 go test ./internal/console/ ./internal/objstore/ ./internal/mail/ -run 'TestOnlySealKeyForBuildsSealers|TestStoreGrantOn|TestMailEnableOnFleet|TestRelayApplyOnFleet|TestWebhookRotateUsesEachAppsKey|TestPlanStorageSkipsKeylessFleet' -count=1`. Expected: FAIL. |
| - [ ] **Step 3: Implement**, approved rows only. |
| - [ ] **Step 4: Run** the same, plus `-run 'Store|Mail|Relay|Scan|Webhook|Plan|Team'` over the three packages. Expected: PASS. Mutation: add `appconfig.SealBound` to `apimail.go`; the guard fails naming it. |
diff --git a/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R3.md b/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R3.md| new file mode 100644 |
| index 000000000..b9bb4e428 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R3.md |
| @@ -0,0 +1,8 @@ |
| +- R2 #1: partly — deployment-key readiness is removed, but rotation and reconciliation need explicit per-app sealer wiring. |
| +- R2 #2: resolved — typed composite literals are checked, with a negative fixture for another constructor. |
| +- R2 #3: resolved — registration uses the authenticated `apiSession` receiver. |
| +- R2 #4: resolved — `pending` matches the reused parser. |
| + |
| +1. **P2 — Task 6. Invariant: per-app key selection and interface completeness.** [Plan:178](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:178) places `sealKeyFor(ctx, sqid, app)` immediately after rotation’s `relayReady()`. However, [`relayRotate`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/relayops.go:1345) receives only context and region; account/app become available in its record loop. Reconciliation also reaches the newly parameterized helpers without passing through `relayReady()` ([relayops.go:1610](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/relayops.go:1610), [relayenv.go:158](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/relayenv.go:158)). **Fix:** specify selection per app in `relayReissue` and the enabled reconciliation path, before their app mutations; thread that sealer through the walks and environment delivery. Include rotation and reconciliation witnesses using different apps’ keys. |
| + |
| +READY AFTER FIXES (no P1) |
| \ No newline at end of file |