Fleet secrets key plan: Astra plan round 1 fixes (append-only fp list, lock ownership by entry point, separate replacement query, Sealer key accessor, remote sentinel, identity-based guard, STALE column, per-witness mutations); round 2 brief
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/plans/2026-10-29-fleet-secrets-key.md+20 −17docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R1.md+33 −0docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R2.md+38 −0
CI passed — run details
Intent
<task-notification> <task-id>bv32hs3ft</task-id> <tool-use-id>toolu_01PhXs3tcndFbFLYSzSaydFW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/bv32hs3ft.output</output-file> <status>completed</status> <summary>Background command "Run Astra plan review round 1" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 14.5 g CO₂e (1,617,543 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 a8dd75ae2..68b2af393 100644 |
| --- a/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md |
| +++ b/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md |
| @@ -35,6 +35,7 @@ |
| - R-1. Spec §5.2 step 2 asks for a placement backfill that finishes before the first seal. Under §2.1 an empty placement for a fleet app seals to the deployment key, which keeps I1 and is an I2 miss. So `sealKeyFor` uses `appPlacement` (store column, then routes) and the backfill runs in the existing startup goroutine beside `RunFleetOwnerBackfill` (`cmd/console/main.go:657-666`), not blocking. Cost if wrong: a fleet app placed before the column existed, with no routes, gets one deployment-key seal that its box refuses and `instances list` shows. |
| - R-2. The §5.2.1 lock is `s.lockAccount(acct.Sqid)`, already used for temporary-app caps. No new lock type. |
| +- R-4. Spec §5.1 puts one `secrets_key_fp` on the bucket owner record; the plan makes it an append-only list, `secrets_key_fps` (plan review R1 #1), so a failed or partial replacement never drops a still-registered key from direct mode's check. Cost if wrong: direct mode refuses a key that was once registered and is no longer used. |
| - R-3. `ConfigRefusal` names only a host (`snapshot.go:305`), so the §5.7 join shows a refusal only on an instance row the caller already sees, matched by host. A refusal for a host the caller does not own is never shown. |
| --- |
| @@ -68,6 +69,7 @@ |
| - `func (s Sealer) Fingerprint() string` (`KeyFingerprint(pub)`) |
| - `func (s Sealer) Binding() Binding` |
| - `func (s Sealer) Bound() bool` |
| + - `func (s Sealer) PublicKeyB64() string` (base64 of the public point, what the config GET serves as `secrets_pubkey`) |
| - `func (s Sealer) Seal(b Binding, plaintext []byte) (Var, error)`: refuses `ErrSealerBinding` when `b != s.Binding()`; seals with `SealBound` when bound, else `SealUnbound`; returns `Var{Kind: "secret", Envelope: env, SealedTo: s.Fingerprint()}`. |
| - `var ErrSealerBinding = errors.New(...)` |
| - `func SetSecret(ctx context.Context, s release.Store, acct, app string, sealed map[string]Var) error` (was `map[string]string`) |
| @@ -88,10 +90,10 @@ |
| - Produces: |
| - `Fleet` gains `SecretsPub string`, `SecretsKeyFP string`, `SecretsKeySetAt int64`, `SecretsKeySetBy string`. |
| - Columns `secrets_pubkey`, `secrets_key_fp`, `secrets_key_set_at`, `secrets_key_set_by` (ALTER ... ADD COLUMN with `"duplicate column"` ignored, as :128), and `CREATE UNIQUE INDEX IF NOT EXISTS fleets_secrets_key_fp ON fleets (secrets_key_fp) WHERE secrets_key_fp != ''` (pattern `registry.go:892`). |
| - - `func (r *Registry) SetFleetSecretsKey(name, pub, fp, by string, at int64) error`, returning `ErrFleetKeyInUse` on the unique index's constraint error; a remote case `"SetFleetSecretsKey"` in `dispatchRemote`. |
| + - `func (r *Registry) SetFleetSecretsKey(name, pub, fp, by string, at int64) error`, returning `ErrFleetKeyInUse` on the unique index's constraint error; a remote case `"SetFleetSecretsKey"` in `dispatchRemote`; `ErrFleetKeyInUse` appended to `remoteErrors` (`internal/registry/remote.go:17`) after the existing entries, keeping their numbers, so `errors.Is` holds through the remote transport. |
| - `consoleRegistry` gains `SetFleetSecretsKey(name, pub, fp, by string, at int64) error`. |
| -- [ ] **Step 1: Write failing tests** `TestFleetSecretsKeyRoundTrips` (set, `GetFleet` and `ListFleets` return all four fields), `TestFleetSecretsKeyIsUniqueAcrossFleets` (fleet `home` of `bab` and fleet `away` of another account: the second set of the same fp returns `ErrFleetKeyInUse`; the same fp on `home` again succeeds), `TestFleetSecretsKeyOverRemote` (the remote registry fixture used by the other fleet remote tests). |
| +- [ ] **Step 1: Write failing tests** `TestFleetSecretsKeyRoundTrips` (set, `GetFleet` and `ListFleets` return all four fields), `TestFleetSecretsKeyIsUniqueAcrossFleets` (fleet `home` of `bab` and fleet `away` of another account: the second set of the same fp returns `ErrFleetKeyInUse`; the same fp on `home` again succeeds), `TestFleetSecretsKeyOverRemote` (the remote registry fixture used by the other fleet remote tests; a duplicate fp through remote returns an error that `errors.Is(err, ErrFleetKeyInUse)`). |
| - [ ] **Step 2: Run** `nice -n 19 go test ./internal/registry/ -run 'TestFleetSecretsKey' -count=1`. Expected: FAIL. |
| - [ ] **Step 3: Implement** the columns, index, method, remote case and interface method. |
| - [ ] **Step 4: Run** the same, plus `-run 'Fleet'` over `./internal/registry/`. Expected: PASS. Show the mutation: drop the index, `TestFleetSecretsKeyIsUniqueAcrossFleets` fails. |
| @@ -106,15 +108,16 @@ |
| **Interfaces:** |
| - Consumes: Task 2's `SetFleetSecretsKey`, `ErrFleetKeyInUse`; Task 1's `Var.SealedTo`. |
| - Produces: |
| - - `FleetOwner` gains `SecretsKeyFP string \`json:"secrets_key_fp,omitempty"\``. |
| - - `func (s *Server) recordFleetKeyFP(ctx context.Context, f registry.Fleet, fp string) error`: creates the owner record if missing, else updates it with If-Match on its etag; the classifier admits exactly this update (same fleet and account, only `secrets_key_fp` changed) and the new field under its strict decode. |
| + - `FleetOwner` gains `SecretsKeyFPs []string \`json:"secrets_key_fps,omitempty"\``: every fingerprint ever registered for the fleet, APPEND-ONLY (plan review R1 #1: a replacement that overwrote the field, then failed in the registry, would drop the still-registered key from direct mode's exclusion list). |
| + - `func (s *Server) recordFleetKeyFP(ctx context.Context, f registry.Fleet, fp string) error`: creates the owner record if missing, else appends `fp` (if absent) with If-Match on its etag; nothing ever removes an entry. The classifier admits exactly this update (same fleet and account, `secrets_key_fps` a strict superset of the old list) and the new field under its strict decode. |
| - `func (s *Server) handleAPIFleetSecretsKey(w, r)` for `PUT /api/cli/fleets/{account}/{fleet}/secrets-key`, body `{"pubkey": "<base64>"}`, answer `{"fleet", "fingerprint", "stale": [{"app", "vars": [...], "minted": [...]}]}`. |
| - - `func (s *Server) fleetSealedValues(ctx context.Context, acct *Account, fleet, fp string) ([]staleApp, error)`: for every app placed on the fleet, the sealed vars (all bundles and environments) whose `SealedTo != fp`, split into user-set and console-minted (store, mail, relay names). |
| + - `func (s *Server) fleetStaleValues(ctx context.Context, acct *Account, fleet, fp string) ([]staleApp, error)`: for every app placed on the fleet, the sealed vars (all bundles and environments) whose `SealedTo != fp` (absent included), split into user-set and console-minted (store, mail, relay names). For the stale report only. |
| + - `func (s *Server) fleetHasSealedValues(ctx context.Context, acct *Account, fleet string) ([]string, error)`: the apps placed on the fleet holding ANY sealed var, whatever its `SealedTo`. For the §5.6 replacement refusal (plan review R1 #3). |
| - `fleetView` gains `SecretsKeyFP string \`json:"secrets_key_fp,omitempty"\`` and `StaleSecrets int \`json:"stale_secrets,omitempty"\``. |
| -Order inside the handler, every refusal before the first write: `apiOwnerAccountFor`; `apiFleet` (unknown or another account: 404); parse (`appconfig.ParsePublicKey`); fp equal to `s.expectedSecretsFP()`: refuse; fleet already has a different fp and `fleetSealedValues(..., oldFP)` lists any app with a value sealed to the old key: refuse naming the apps (§5.6); same fp as already set: 200 no-op; take `s.lockAccount(acct.Sqid)`; `recordFleetKeyFP`; `SetFleetSecretsKey` (`ErrFleetKeyInUse`: 409 with the copy row); compute `stale` against the new fp (§5.1 B2). |
| +Order inside the handler, every refusal before the first write: `apiOwnerAccountFor`; `apiFleet` (unknown or another account: 404); parse (`appconfig.ParsePublicKey`); fp equal to `s.expectedSecretsFP()`: refuse; fleet already has a different fp and `fleetHasSealedValues` lists any app: refuse naming the apps (§5.6); same fp as already set: 200 no-op; take `s.lockAccount(acct.Sqid)`; `recordFleetKeyFP`; `SetFleetSecretsKey` (`ErrFleetKeyInUse`: 409 with the copy row); compute `stale` with `fleetStaleValues` against the new fp (§5.1 B2). |
| -- [ ] **Step 1: Write failing tests** through the HTTP fixture: `TestFleetSecretsKeyOwnerOnly` (a non-owner member: 403; mutation: drop the owner check), `TestFleetSecretsKeyRefusals` (unknown fleet and another account's fleet answer the same 404; bad base64; the deployment's own key; a key registered on another account's fleet: 409), `TestFleetSecretsKeyIdempotent`, `TestFleetSecretsKeyWritesTheOwnerRecordFirst` (a store that fails the owner-record Put: the registry row has no key; a missing owner record is created), `TestFleetSecretsKeyListsStaleValues` (an app `shop` placed on `home` with a secret without `sealed_to`: listed), `TestFleetSecretsKeyReplacementRefusedWhileSealed`, `TestFleetListShowsKeyFingerprint`, `TestFleetOwnerClassifierAdmitsTheKeyUpdate` and `...RefusesOtherChanges` (in `internal/hostops`). |
| +- [ ] **Step 1: Write failing tests** through the HTTP fixture: `TestFleetSecretsKeyOwnerOnly` (a non-owner member: 403; mutation: drop the owner check), `TestFleetSecretsKeyRefusals` (unknown fleet and another account's fleet answer the same 404; bad base64; the deployment's own key; a key registered on another account's fleet: 409), `TestFleetSecretsKeyIdempotent`, `TestFleetSecretsKeyWritesTheOwnerRecordFirst` (a store that fails the owner-record Put: the registry row has no key; a missing owner record is created), `TestFleetSecretsKeyListsStaleValues` (an app `shop` placed on `home` with a secret without `sealed_to`: listed), `TestFleetSecretsKeyReplacementRefusedWhileSealed` (three arms: an app whose secret's `SealedTo` is the old fp, absent, and a third fp: all refuse), `TestFleetSecretsKeyFailedReplacementKeepsTheOldFingerprintListed` (inject a registry failure after the record write: the record lists both fps and the registry keeps the old one), `TestFleetListShowsKeyFingerprint`, `TestFleetOwnerClassifierAdmitsTheKeyUpdate` and `...RefusesOtherChanges` (in `internal/hostops`). |
| - [ ] **Step 2: Run** `nice -n 19 go test ./internal/console/ ./internal/hostops/ -run 'TestFleetSecretsKey|TestFleetListShowsKeyFingerprint|TestFleetOwnerClassifier' -count=1`. Expected: FAIL. |
| - [ ] **Step 3: Implement** the handler, the record write, the classifier change, the route (plus the three route-list tests), the list fields, and the BYO and fleet page lines (approved rows only, ids added to `fleetSecretsCopyBuilt`). |
| - [ ] **Step 4: Run** the same, plus `TestNoRoleReachesAMintFleetOrPolicyDoor` and the claim invariant tests by name, and `go test . -run 'TestFleetSecretsCopy'`. Expected: PASS. |
| @@ -131,10 +134,10 @@ Order inside the handler, every refusal before the first write: `apiOwnerAccount |
| - Produces: |
| - `carlos fleets secrets-key <fleet> <pubkey>` and `--file <path>` (accepts a `CARLOS_SECRETS_PUBKEY=` line or a bare key); parses locally first and prints the fingerprint, then the `stale` list. |
| - `func setFleetSecretsKey(ctx context.Context, a apiAcct, fleet, pub string) (fleetKeyAnswer, error)` |
| - - `fleets ls` header `FLEET\tBUCKET\tSECRETS KEY\tBOX\tSTATUS\tTAGS`, key shown as the first 12 hex characters after `sha256:` or `-`. |
| + - `fleets ls` header `FLEET\tBUCKET\tSECRETS KEY\tSTALE\tBOX\tSTATUS\tTAGS`, key shown as the first 12 hex characters after `sha256:` or `-`, STALE the count of stale sealed values (`-` when zero), from the list view's `stale_secrets`. |
| - `carlos secrets fingerprint [--file <path>]` (default `/etc/carlos/host.env`): reads `CARLOS_SECRETS_KEY`, prints `KeyFingerprint` of its public half, never the key; no console call. |
| -- [ ] **Step 1: Write failing tests** against a test console: `TestFleetsSecretsKeyCLI` (bare key and `--file` with genkey's output both register; fingerprint printed), `TestFleetsLsShowsSecretsKey`, `TestSecretsFingerprintReadsHostEnv` (a temp host.env; output equals `KeyFingerprint`; output never contains the private key). |
| +- [ ] **Step 1: Write failing tests** against a test console: `TestFleetsSecretsKeyCLI` (bare key and `--file` with genkey's output both register; fingerprint printed), `TestFleetsLsShowsSecretsKey` (and its STALE count goes from 2 to 0 after the two secrets are set again), `TestSecretsFingerprintReadsHostEnv` (a temp host.env; output equals `KeyFingerprint`; output never contains the private key). |
| - [ ] **Step 2: Run** `nice -n 19 go test . -run 'TestFleetsSecretsKeyCLI|TestFleetsLsShowsSecretsKey|TestSecretsFingerprint' -count=1`. Expected: FAIL. |
| - [ ] **Step 3: Implement.** |
| - [ ] **Step 4: Run** the same plus the copy gate. Expected: PASS. |
| @@ -172,12 +175,12 @@ 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`). |
| - - `storeSealKey` and `mailSealKey` become `func (s *Server) storeSealKey(w http.ResponseWriter, r *http.Request, acct *Account, app string) (appconfig.Sealer, bool)` (and the mail twin), answering the approved keyless-fleet refusal before any backend call. |
| + - 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. |
| - - Every seal-and-write runs under `s.lockAccount(sqid)`, taken before any app lock already held on that path. |
| -- Guard (`TestOnlySealKeyForBuildsSealers`): a go/ast walk of every non-test `.go` file in the module (pattern `internal/console/teamcreds_test.go`) collecting calls to `appconfig.Seal`, `appconfig.SealBound`, `appconfig.SealUnbound`, `appconfig.NewSealer` and `archive.Seal`. 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, a second seal inside `sealkey.go`, a sealer for `bab/shop` used on `bab/other` (fails at runtime with `ErrSealerBinding`). |
| + - 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`. A `Sealer` composite literal outside `internal/appconfig` cannot compile (unexported fields); the test also 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`, 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`. |
| +- [ ] **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`; 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. |
| @@ -190,7 +193,7 @@ Order inside the handler, every refusal before the first write: `apiOwnerAccount |
| - Test: `internal/console/fleetsecrets_moves_test.go` |
| **Interfaces:** |
| -- Consumes: Task 5's `sealKeyFor`; Task 3's `fleetSealedValues` logic, generalised as `func (s *Server) staleForTarget(ctx context.Context, acct *Account, app, target string) ([]string, error)` (sealed vars in any bundle or environment whose `SealedTo` is absent or not the target's key fingerprint; target `""` is the deployment key). |
| +- Consumes: Task 5's `sealKeyFor`; Task 3's `fleetStaleValues` logic, generalised as `func (s *Server) staleForTarget(ctx context.Context, acct *Account, app, target string) ([]string, error)` (sealed vars in any bundle or environment whose `SealedTo` is absent or not the target's key fingerprint; target `""` is the deployment key). |
| - Produces: `placeAppTarget` refuses with the approved row when `staleForTarget` is non-empty, after the rootfs/seed/HA refusals and before `SetAppPlacementContext`, under `s.lockAccount`; `claimAppWith` runs the same check before `createClaimAppRow` (:5107) when `adoptingExistingApp` and placement is non-empty; `handleAPIEnvironmentFork` takes `s.lockAccount(acct.Sqid)` before `s.lockApp`. |
| - [ ] **Step 1: Write failing tests**: `TestPlaceRefusesStaleSealedValues` (platform app `shop` with a deployment-key secret placed onto `home`: refused, names the var; placement unchanged), `TestPlaceAllowsAppWithNoSecrets`, `TestCreatePlaceAdoptingRefusesBeforeTheRow` (no app row written), `TestForkWaitsForTheAccountLock` (deterministic: fork holds; a replacement started after it blocks until it ends). |
| @@ -207,9 +210,9 @@ Order inside the handler, every refusal before the first write: `apiOwnerAccount |
| **Interfaces:** |
| - Consumes: Task 3's `FleetOwner.SecretsKeyFP`. |
| -- Produces: `func directSealRefusal(ctx context.Context, st release.Store, acct string, pub *ecdh.PublicKey) error`: lists `accounts/` (pattern `internal/provision/reconcile.go:2631`), keeps keys of shape `accounts/<a>/fleets/<f>.json`, refuses (approved rows) if any has `a == acct`, or if any record's `secrets_key_fp == KeyFingerprint(pub)`, or if the list or a read fails. Called before sealing; direct mode then seals with `NewSealer(pub, b, secretsEnvelopeV2Env())` and saves Vars with `SealedTo`. |
| +- Produces: `func directSealRefusal(ctx context.Context, st release.Store, acct string, pub *ecdh.PublicKey) error`: lists `accounts/` (pattern `internal/provision/reconcile.go:2631`), keeps keys of shape `accounts/<a>/fleets/<f>.json`, refuses (approved rows) if any has `a == acct`, or if any record's `secrets_key_fps` contains `KeyFingerprint(pub)`, or if the list or a read fails. Called before sealing; direct mode then seals with `NewSealer(pub, b, secretsEnvelopeV2Env())` and saves Vars with `SealedTo`. |
| -- [ ] **Step 1: Write failing tests** with a `DirStore`: `TestDirectSecretsSetRefusesAnAccountWithAFleet`, `TestDirectSecretsSetRefusesAnotherFleetsKey` (account B's fleet record carries the fp of the terminal key; target account A has no fleet: refused, I1), `TestDirectSecretsSetRefusesOnListError`, `TestDirectSecretsSetPlatformAppStillWorks`. |
| +- [ ] **Step 1: Write failing tests** with a `DirStore`: `TestDirectSecretsSetRefusesAnAccountWithAFleet`, `TestDirectSecretsSetRefusesAnotherFleetsKey` (account B's fleet record carries the fp of the terminal key; target account A has no fleet: refused, I1), `TestDirectSecretsSetRefusesOnListError`, `TestDirectSecretsSetRefusesAnyListedFingerprint` (a record listing an old and a new fp: both refused), `TestDirectSecretsSetPlatformAppStillWorks`. |
| - [ ] **Step 2: Run** `nice -n 19 go test . -run 'TestDirectSecretsSet' -count=1`. Expected: FAIL. |
| - [ ] **Step 3: Implement.** |
| - [ ] **Step 4: Run** the same plus Task 6's guard. Expected: PASS. Mutation: skip the fp comparison; `TestDirectSecretsSetRefusesAnotherFleetsKey` fails. |
| @@ -242,7 +245,7 @@ Order inside the handler, every refusal before the first write: `apiOwnerAccount |
| **Interfaces:** |
| - Consumes: Task 1's `Sealer`. |
| -- [ ] **Step 1: Write the witnesses** (no box code change): `TestFleetBoxRendersFleetKeyConfig` (agent in fleet mode over a store-door fixture, `CARLOS_REGION=fleet/home`, `CARLOS_SECRETS_KEY` = the fleet key: a v2 envelope sealed to the fleet key renders into `<host>.config.env`; `CanProvideConfig` is nil), `TestFleetBoxRefusesDeploymentKeyConfig` (same box, envelope sealed to another key: `ReasonCannotOpen`), `TestFleetBoxCannotRenderAnotherFleetsApp` (fleet `away`'s box, an app of `home`: refused). They are expected to pass at once; show each failing first by sealing to the wrong key in the fixture. Also `TestFleetBoxWritesNoEdgesFile` (§6: the platform candidate sets read only `control/edges/`; a fleet-mode agent's publisher loop exits, `edgesfile.go:1012-1014`), unless an existing test already pins it, in which case cite that test in the commit message. |
| +- [ ] **Step 1: Write the witnesses** (no box code change): `TestFleetBoxRendersFleetKeyConfig` (agent in fleet mode over a store-door fixture, `CARLOS_REGION=fleet/home`, `CARLOS_SECRETS_KEY` = the fleet key: a v2 envelope sealed to the fleet key renders into `<host>.config.env`; `CanProvideConfig` is nil), `TestFleetBoxRefusesDeploymentKeyConfig` (same box, envelope sealed to another key: `ReasonCannotOpen`), `TestFleetBoxCannotRenderAnotherFleetsApp` (fleet `away`'s box, an app of `home`: refused). They are expected to pass at once, so show each one can fail: for the rendering witness, seal to a wrong recipient (it must then fail); for the two refusal witnesses, give the box the matching key, or stub `CanProvideConfig` to nil (they must then fail). Also `TestFleetBoxWritesNoEdgesFile` (§6: the platform candidate sets read only `control/edges/`; a fleet-mode agent's publisher loop exits, `edgesfile.go:1012-1014`), unless an existing test already pins it, in which case cite that test in the commit message. |
| - [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/host/ -run 'TestFleetBox' -count=1` (sandbox off). Expected: PASS. |
| - [ ] **Step 3: Write the docs** from approved rows: registering a key (genkey on the first box, KEY in every box's host.env, restart the agent, `fleets secrets-key`), the stale list and how to clear it, `secrets fingerprint`, replacement (§5.6), and the rails guide's secrets step for a fleet app. |
| - [ ] **Step 4: Run** the copy gates (`go test . -run 'Copy|Applied|Built'`) and any docs drift test (`-run Rails`). Expected: PASS. |
diff --git a/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R1.md b/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R1.md| new file mode 100644 |
| index 000000000..552d2128d |
| --- /dev/null |
| +++ b/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R1.md |
| @@ -0,0 +1,33 @@ |
| +1. **P1 — Tasks 3 and 8: a failed replacement removes an active key from direct mode’s exclusion list. Invariant: I1, recipient authorization.** |
| + Task 3 overwrites the owner record before updating the registry ([plan:110](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:110), [plan:115](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:115)). Suppose fleet B has key K1 and attempts replacement with K2, already registered elsewhere. The bucket now records K2, but the uniqueness failure leaves K1 registered to B. Task 8 can then accept K1 when sealing another account’s secret because its listing contains no K1 ([plan:210](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:210)). |
| + **Fix:** preserve durable exclusion of the currently registered fingerprint throughout replacement, including failed or uncertain registry writes. Test direct sealing between the writes and after an injected registry failure; rollback alone does not close the intervening window. |
| + |
| +2. **P1 — Tasks 5–7: the account-lock instructions omit callers that already hold that lock. Invariant: lock acquisition must terminate and preserve account-before-app order.** |
| + `planLock` already acquires `lockAccount` when plans are enabled ([plancaps.go:227](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/plancaps.go:227)). App creation holds it before calling `claimAppWith` ([apicli.go:497](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/apicli.go:497)); instance creation holds it before private-store provisioning ([apiinstances.go:2009](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/apiinstances.go:2009), [apiinstances.go:2083](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/apiinstances.go:2083)). Adding acquisition inside those helpers deadlocks on the non-reentrant mutex. Separately, `teamApplyEnvironment` holds the app lock while invoking credential minting ([apiconfig.go:682](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/apiconfig.go:682), [apiconfig.go:715](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/apiconfig.go:715)). |
| + **Fix:** specify lock ownership at each entry point and helpers that require it already held. Include plans-enabled app adoption, private-store creation, and team environment creation in HTTP tests. |
| + |
| +3. **P1 — Task 3: the replacement check uses the inverse predicate. Invariant: §5.6 replacement refuses while any sealed value exists.** |
| + `fleetSealedValues(..., fp)` returns only values whose `SealedTo != fp`, but replacement calls it with `oldFP` to find values sealed to that old key ([plan:112](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:112), [plan:115](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:115)). An app containing only correctly marked old-key secrets produces an empty result, permitting replacement and failing `TestFleetSecretsKeyReplacementRefusedWhileSealed` without any race. |
| + **Fix:** use a separate “any sealed values” query for replacement; retain the mismatch predicate for stale-value reporting. Cover matching, missing, and different fingerprints. |
| + |
| +4. **P2 — Tasks 1, 5 and 6: the declared interfaces do not supply what their consumers need. Invariant: interface compatibility.** |
| + `Sealer` keeps its public key private and exposes no public-key encoding, although config GET must obtain `secrets_pubkey` from it ([plan:66](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:66), [plan:154](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:154)). The new `storeSealKey` requires `*http.Request`, while `instanceStorePreflight` has only a context and is also reached by detached seed work ([instanceprivatestore.go:371](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/instanceprivatestore.go:371), [apiinstanceseed.go:446](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/apiinstanceseed.go:446)). |
| + **Fix:** declare a public-key encoding accessor and a context-based selection/refusal interface usable by both HTTP handlers and detached callers; explicitly migrate the preflight return type to `Sealer`. |
| + |
| +5. **P2 — Task 2: the remote transport loses `ErrFleetKeyInUse`. Invariant: local and remote registry behavior agree.** |
| + Task 2 adds dispatch support but omits the sentinel’s remote encoding ([plan:84](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:84)). Unknown errors return as fresh `errors.New` values, so Task 3 cannot recognize the conflict with `errors.Is` ([remote.go:17](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/registry/remote.go:17)). |
| + **Fix:** append the sentinel to `remoteErrors`, preserving existing numeric assignments, and test duplicate registration through the remote transport and HTTP door. |
| + |
| +6. **P2 — Task 6: the guard’s inventory is narrower than the approved requirement. Invariant: I1 sealing-boundary coverage.** |
| + The specified scan enumerates free-function calls, but omits `Sealer.Seal` method calls and sealer constructions other than `NewSealer` ([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)); the spec explicitly requires those constructions and sealing methods ([spec:245](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md:245)). The suggested scanner pattern also matches the literal import identifier `appconfig`, missing aliases and unqualified same-package calls ([teamcreds_test.go:371](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/teamcreds_test.go:371)). |
| + **Fix:** specify identity-based detection covering aliases, constructors, literals and methods, with explicit allowances for package-internal crypto calls. Add negative fixtures for the omitted forms. |
| + |
| +7. **P2 — Tasks 3 and 4: `fleets ls` never displays the stale count. Invariant: G5, stale values remain visible until repaired.** |
| + The API gains `StaleSecrets`, but the CLI’s prescribed header and rendering contain only fleet, bucket, fingerprint, box, status and tags ([plan:113](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:113), [plan:134](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:134)). The spec requires repeating the stale count until zero ([spec:205](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md:205)). |
| + **Fix:** add approved CLI rendering and a test showing the count decrease after repair. |
| + |
| +8. **P2 — Task 10: the prescribed mutation cannot falsify the refusal witnesses. Invariant: tests demonstrate their claimed protection.** |
| + Task 10 says to make every witness fail by sealing to the wrong key, but two witnesses already expect wrong-key rejection ([plan:245](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:245)). Another wrong key leaves those tests passing. |
| + **Fix:** specify mutations per witness: use a wrong recipient for successful rendering, and the box’s matching key—or bypass the production refusal—for rejection witnesses. |
| + |
| +NOT READY |
| \ No newline at end of file |
diff --git a/docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R2.md b/docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R2.md| new file mode 100644 |
| index 000000000..90e21a6e6 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R2.md |
| @@ -0,0 +1,38 @@ |
| +# Review brief: fleet secrets key implementation plan, round 2 of 3 |
| + |
| +Repo carlos/platform, branch `design-fleet-secrets-key`, commit named in your prompt. |
| +Under review: `docs/superpowers/plans/2026-10-29-fleet-secrets-key.md`. |
| +Authorities: the APPROVED spec `docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md` (rev 5, Paul 2026-10-29; its §2.1 invariants bind), the code on this branch (main 0c39af30), `AGENTS.md`. Do not edit files. |
| + |
| +You are an independent reviewer. Read the plan and the spec, then the code each task names, and check every file:line, signature and name against the code. |
| + |
| +## Fixed: do not re-argue |
| + |
| +- The spec, approved after three Astra rounds (findings `docs/superpowers/specs/CODEX-FINDINGS-fleet-secrets-key-R1.md`, `-R2.md`, `-R3.md`). Review the plan against it, not the design itself. |
| +- Spec §2.1: I1 confidentiality is hard; I2 availability is best effort. Further direct-mode, copy-path or race findings against I2 alone are not findings. |
| +- The plan's rulings R-1 to R-3; challenge one only with an I1 failure or a would-not-work failure. |
| + |
| +## What to check |
| + |
| +1. Every spec requirement has a task, and no task builds something the spec does not ask for. |
| +2. I1 in the plan: does Task 6's guard (`TestOnlySealKeyForBuildsSealers`) and its allowlist really catch every seal path in the code today (list any `appconfig.Seal*`, `archive.Seal` or key-parsing site the plan misses), and can Task 5's `sealKeyFor` ever return a key for a fleet not owned by the app's account? |
| +3. Signatures and interfaces: do later tasks use exactly what earlier tasks produce? Would any changed signature (objstore, mail, `SetSecret`, `storeSealKey`, `convergeCallbackKey`, `rotateWebhookBudget`) break a caller the plan does not list? |
| +4. Task 3's bucket owner record update and the hostops classifier change: is it safe, and is the order (record before registry) right for direct mode (Task 8)? |
| +5. Lock order (account before app) on every path Tasks 5-7 put under `lockAccount`: any path that already holds an app or hostname lock first? |
| +6. Tests: does each named test prove what its task claims, through production wiring (AGENTS.md "Rules this repo has paid for")? |
| + |
| +## Round 2 |
| + |
| +Earlier round: `docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R1.md` (3 P1, 5 P2, all accepted). First give one line per round 1 finding: resolved, partly, or not. Carry unresolved ones forward at their severity, then add new findings, naming the invariant beside each (stopping rule 2). |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe (an I1 break), would not compile, a test fails, or it would not work. Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Follow-up list. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Name the invariant beside each finding. Do not raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3, each with task, problem, evidence (file:line) and fix. Then one verdict line: READY, READY AFTER FIXES (no P1), or NOT READY. A round with no P1 ends the review. This is round 2 of at most 3. |