carlos / platform Public

Fleet secrets key design, rev 1 (#366): a per-fleet key so apps on a customer's fleet get their secrets and store credentials without the deployment key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev bb2d9e348811fc36da3a57c7ee82a80849d0c60c parent 0c39af3
1 file changed, +289 −0
  • docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md +289 −0

CI passed — run details

Intent

Attributed to this commit: 137 g CO₂e (14,729,214 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/specs/2026-10-29-fleet-secrets-key-design.md b/docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md
new file mode 100644
index 000000000..8d36df816
--- /dev/null
+++ b/docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md
@@ -0,0 +1,289 @@
+# Fleet secrets key: secrets for apps on a customer's own boxes
+
+Status: draft rev 1, 2026-10-29. Discussion: amadan carlos/platform #366
+(found by rootfs Plan 4 Task 11). Branch `design-fleet-secrets-key`.
+
+## 1. Why
+
+An app placed on a customer's fleet (`carlos apps create --place fleet/<f>`)
+cannot have a secret today. Every sealed value (a `carlos secrets set`
+value, a store credential, a mail credential, a relay credential) is sealed
+to the deployment's one `CARLOS_SECRETS_PUBKEY` and opens only with
+`CARLOS_SECRETS_KEY` (`internal/appconfig/crypto.go:17-21`). A fleet box
+belongs to one customer and must never hold that key, because it opens
+every tenant's secrets. The box's config guard does the right thing and
+refuses the instance (`internal/appconfig/canprovide.go`, reason `no_key`).
+
+Found on dev, 2026-10-29: the rootfs sample (`examples/rails-shop`) on
+fleet `r10r` needs `SECRET_KEY_BASE`; with it set, box-1 logs
+`config guard: refusing shop.bab.dev.oncarlos.com: cannot provide this
+instance's config: no_key`, and without it `db:migrate` aborts. The same
+applies to every fleet app with a secret, binary apps included, and to the
+Rails tenant's move that rootfs apps exist for (#366).
+
+Paul's ruling (2026-10-29, recorded on #366): each fleet gets its own
+secrets key. Its private half lives only on that fleet's boxes; its public
+half is on the fleet record; the CLI and the console seal a fleet-placed
+app's secrets and store credential to it. Not taken: giving a fleet box the
+deployment key, or carrying the sample's secrets as plain config.
+
+## 2. Goals, non-goals, anti-goals
+
+Goals:
+- G1. A fleet owner registers a public key for their fleet; the platform
+ never sees the private half.
+- G2. Everything sealed for an app placed on a fleet is sealed to that
+ fleet's key: `carlos secrets set` values, and every credential the
+ console mints and seals (store, mail, relay, scan callback, plan-storage
+ deny).
+- G3. Nothing sealed for a fleet-placed app is ever sealed to the
+ deployment key, and nothing for any other app is ever sealed to a fleet
+ key. Enforced in one place, checked by a guard test.
+- G4. The owner can see, per fleet, whether a key is registered and which
+ boxes hold it.
+- G5. A mismatch is refused when it is written, not found when an instance
+ starts.
+
+Non-goals (v1):
+- Key rotation with both keys live. v1 allows replacing a fleet's key only
+ while no app placed on it has a sealed value (§5.6).
+- Re-sealing on a move. `carlos apps place` refuses an app whose sealed
+ values were sealed to a different key (§5.5).
+- Managed fleets (#457) provisioning the key for the owner. That design
+ can call the same door; §8 names the seam.
+- Any change to platform (non-fleet) boxes or the deployment key.
+
+Anti-goals (a failure even if it works):
+- The console, the deployment bucket or any platform box ever holding a
+ fleet's private key.
+- A fleet box able to open a value sealed for another account's app.
+- A secret silently missing at start: the box guard stays the last line,
+ never the first.
+
+## 3. What exists (main 0c39af30)
+
+- Fleet enrollment is by hand. `fleets create` writes a registry `Fleet`
+ row (`internal/registry/fleets.go:29-46`) and the bucket owner record
+ `accounts/<acct>/fleets/<f>.json` (`release.FleetOwner`,
+ `internal/release/release.go:174-185`). `fleets add-box` mints a tunnel
+ token, shown once (`internal/console/fleets.go:315`). The owner writes
+ the box's `host.env` from the BYO page
+ (`internal/console/templates/fleet_byo.html`); it has no
+ `CARLOS_SECRETS_KEY` line.
+- A box opens config with whatever `CARLOS_SECRETS_KEY` its host.env holds
+ (`internal/host/agent.go:1532`, `configguard.go:110`) and publishes that
+ key's fingerprint as `secrets_key_fp` (`internal/host/edgesfile.go:329-336,946`).
+ A fleet box reads its apps' manifests from the deployment store through
+ the store door (`internal/edge/storedoor.go:530-544`, `apps/<sqid>/**`).
+ So a fleet box with a fleet key in host.env opens envelopes sealed to it
+ with **no box code change**.
+- `carlos secrets genkey` already mints a P-256 pair
+ (`appconfig_cli.go:1117`, `appconfig.GenerateKey`).
+- The CLI seals to the `secrets_pubkey` the console's config GET returns
+ (`internal/console/apiconfig.go:264`; `secretsPubKeyAPI`,
+ `appconfig_cli.go:855`), unless `CARLOS_SECRETS_PUBKEY` is set in the
+ terminal, which wins. Only `secrets set` seals (`runSecretsSet`, :903).
+ The console's PUT checks envelope shape only (`apiconfig.go:392`,
+ `appconfig.CheckEnvelope`): sealing records no recipient, so the console
+ cannot tell which key an envelope was sealed to.
+- Console seal sites all parse `s.cfg.SecretsPub`: `storeSealKey`
+ (`apistore.go:687`, used by store grant/rotate/provision, scan, system,
+ instance private store), `mailSealKey` (`apimail.go:151`), relay
+ (`relayops.go:591`, `relayenv.go:73`), scan callback (`scankeysync.go:41`),
+ plan-storage deny (`planstorage.go:85`), team credentials
+ (`teamcreds.go:60`). Each has `(acct, app)` in hand.
+- Placement: `apps.placement` in the console store (`store.go:527`), read
+ by `appPlacement` (`fleets.go:543`), written by `apps create --place` and
+ `placeAppTarget` (`fleets.go:623,755`). Only the fleet's own account can
+ place onto it (`fleets.go:569`). `placeAppTarget` writes no config.
+- Envelopes: v1 unbound, v2 bound to `(account, app)` as GCM associated
+ data (`crypto.go`, `Binding`). v2 is a deployment switch
+ (`CONSOLE_SECRETS_ENVELOPE_V2`, advertised as `secrets_account`).
+ `KeyFingerprint` is `sha256:<hex>` of the public point (`fingerprint.go:16`).
+
+## 4. The idea in one paragraph
+
+The owner mints a keypair with the existing `carlos secrets genkey`, puts
+the private half in each fleet box's host.env as `CARLOS_SECRETS_KEY`, and
+registers the public half with `carlos fleets secrets-key <fleet>
+<pubkey>`. The console stores the public key and its fingerprint on the
+fleet's registry row. One console function, `sealKeyFor(acct, app)`, answers
+"which public key does this app's sealed config go to": the fleet's key if
+the app is placed on a fleet, the deployment key otherwise. Every seal site
+and the config GET call it. The CLI writes the fingerprint it sealed to
+beside each envelope (`sealed_to`), and the console's PUT refuses an
+envelope whose `sealed_to` is not `sealKeyFor`'s answer. Boxes do not
+change.
+
+## 5. Design
+
+### 5.1 Registering a key (the first thing Paul can see)
+
+- `carlos fleets secrets-key <fleet> <base64 pubkey>` (and `--file <path>`
+ reading a `CARLOS_SECRETS_PUBKEY=` line or a bare key, so the owner can
+ pipe `carlos secrets genkey` output through a file). The CLI parses the
+ key locally (`appconfig.ParsePublicKey`) and prints its fingerprint.
+- Console door: `PUT /api/cli/fleets/{fleet}/secrets-key` with
+ `{"pubkey": "<base64>"}`. Authority: the same as `fleets add-box` (an
+ owner of the fleet's account), because whoever sets the key decides who
+ can read the fleet's future secrets, which is no less than minting a box
+ token. Refuses: an unknown fleet or one of another account (same answer,
+ as `fleets.go:1107`); a key that does not parse; the deployment's own
+ public key (fingerprint equal to `expectedSecretsFP()`), because that
+ would mean the owner holds the deployment key or is about to be asked
+ for it; a replacement while sealed values exist (§5.6).
+- Storage: three columns on the registry `fleets` table,
+ `secrets_pubkey`, `secrets_key_fp`, `secrets_key_set_at` (plus who set
+ it, as the other fleet writes record). Builder's call whether it also
+ goes on the bucket `FleetOwner` record; nothing on a box needs it.
+- Shown: `carlos fleets ls` gains the key's short fingerprint per fleet
+ (`-` when none), and per box whether the box's published
+ `secrets_key_fp` matches (`holds key`, `no key`, `other key`, `unknown`
+ for a box that has published nothing yet). The fleet's console page
+ shows the same. The BYO page's host.env block gains the
+ `CARLOS_SECRETS_KEY=` line with one sentence on where it comes from.
+
+### 5.2 One answer for "which key": `sealKeyFor`
+
+`func (s *Server) sealKeyFor(ctx, acct *Account, app string) (pub *ecdh.PublicKey, fp string, err error)`:
+
+1. `placement := appPlacement(reg, acct, app)`.
+2. `fleet/<f>`: load the fleet row; it must belong to `acct` (defence in
+ depth; placement already guarantees it). No key registered: a typed
+ refusal, `errFleetNoSecretsKey{fleet}`, whose message tells the owner to
+ run `carlos fleets secrets-key <f>`.
+3. Not placed: the deployment key, with today's refusals when the console
+ has none or it does not parse.
+
+Every site in §3's seal-site list calls it instead of parsing
+`s.cfg.SecretsPub`, and so does the config GET's `secrets_pubkey`. A guard
+test (go/ast, like the rootfs Plan 2 guard) fails if any file in
+`internal/console` other than the one holding `sealKeyFor` reads
+`cfg.SecretsPub` to seal; `expectedSecretsFP` stays for the platform
+regions' box checks. Background walks (store, mail, plan storage, scan
+callback) call it per app, so an app placed on a keyless fleet is skipped
+with a log line and retried on the next pass, never sealed to the
+deployment key as a fallback.
+
+Fleet-key envelopes are always v2 (bound), whatever the deployment switch
+says, so a fleet box opens an envelope only while rendering the app it was
+sealed for. The config GET therefore always sends `secrets_account` for a
+fleet-placed app.
+
+### 5.3 What the CLI sends, and what the console refuses
+
+- Each sealed `Var` gains `sealed_to` (the fingerprint, omitted for plain
+ vars): `Var{Kind, Value, Envelope, SealedTo}` (`appconfig.go:160`). The
+ CLI fills it from the key it sealed with; console seal sites fill it too.
+- The console's PUT, for each sealed var in the request:
+ - app placed on a fleet: `sealed_to` must equal `sealKeyFor`'s fp.
+ Absent (an older CLI) or different: refused, naming the var, the
+ fleet, and the fix (upgrade the CLI; unset `CARLOS_SECRETS_PUBKEY` in
+ the terminal if set). The envelope must be v2.
+ - app not placed: `sealed_to` absent is accepted (older CLIs, today's
+ behaviour); present and not the deployment fp is refused.
+- The terminal's `CARLOS_SECRETS_PUBKEY` override keeps winning in the
+ CLI; the PUT check is what stops it sealing a fleet app's secret to the
+ wrong key.
+- Refusals run before the first store call, as the PUT's existing ones do.
+
+### 5.4 Store, mail and relay credentials
+
+They go through `sealKeyFor` (§5.2) with no other change: the console
+mints, seals to the fleet key, writes `sealed_to`. `carlos store create`
+(and grant) for an app on a keyless fleet refuses before the first backend
+call, as `storeSealKey` does today for a keyless console (a minted key that
+cannot be delivered is the state that code exists to prevent).
+
+### 5.5 Moves
+
+`carlos apps place` (and `apps create --place` onto an app name that has
+config) refuses when the app has any sealed value, in any bundle or
+environment, whose `sealed_to` differs from the target's key or is absent.
+The message lists the vars and the order that works: `carlos secrets unset`
+the listed names, place, set them again; `carlos store rotate` (or `mail` /
+`relay rotate`) after placing re-seals what the console minted. Rootfs,
+seeded and HA apps are already refused by `placeAppTarget` (`fleets.go:627-722`),
+so v1 never re-seals.
+
+### 5.6 Replacing a fleet's key
+
+Allowed only while no app placed on the fleet has a sealed value. Otherwise
+refused, naming the apps. This keeps v1 free of a two-key window on the
+box. A lost or exposed key is handled by unsetting those apps' secrets,
+replacing the key, setting them again and rotating minted credentials; the
+docs say so. Detaching a box (`fleets detach-box`) already stops it reading
+the deployment store, which is what an exposed box needs first.
+
+### 5.7 Instance create and ship
+
+No new refusal at `instances create` beyond §5.3 and §5.4: an app with no
+sealed values on a keyless fleet works today and keeps working. An app
+whose sealed values a fleet box cannot open is still refused by the box's
+config guard, and its reason (`no_key`, `cannot_open`) reaches `carlos
+instances list` through the box's status snapshot, as now. Builder to
+confirm that path shows the reason for a fleet box; if it does not, that
+is in scope.
+
+## 6. Boxes
+
+No box change. A fleet box with `CARLOS_SECRETS_KEY` set runs the config
+sync loop over the store door for the first time in production, so the
+plan carries a production-wired witness: a fleet-mode box test (store door,
+`CARLOS_REGION=fleet/<f>`) that renders a v2 envelope sealed to a fleet key
+into `<host>.config.env`, and one that refuses (`cannot_open`) a v2
+envelope sealed to the deployment key. The rootfs path reads
+`<host>.config.env` like the binary path; Task 11 proves it live.
+
+The platform-region box checks that compare a box's `secrets_key_fp` with
+`expectedSecretsFP()` (`boxchoice.go:141`, `regioncandidates.go:197`,
+`apiinstancemove_offline.go:435`, `apiinstances.go:1735`) must not count a
+fleet box as a keyless or wrong-key platform box. Builder to confirm fleet
+boxes never enter those candidate sets; if one can, exclude it there.
+
+## 7. Copy, docs, census, cost
+
+- Copy: new CLI and console strings (the command's help and output, the
+ refusals in §5.1-5.6, the `fleets ls` column, the BYO line, the fleet
+ page) go through copy review as a deck before they are written.
+- Docs: the fleets page (registering a key, the BYO step), the rootfs and
+ Rails guides (a fleet app's secrets need the fleet key first), `carlos
+ secrets` reference.
+- Census: the registry schema change and the console seal sites are in
+ scope; `make census-card` decides. Boxes unchanged.
+- Cost and requests: none new. `sealKeyFor` reads the console's own store
+ and registry; no new bucket reads or polling.
+- Provider boundary: no cloud API. The fleet key is ECDH-P256 like the
+ deployment key; nothing here is AWS-specific.
+
+## 8. Seams for later
+
+- Managed fleets (#457): the provisioner can mint the key on the box and
+ call the same door, so the owner never handles it.
+- Two-key rotation: a `CARLOS_SECRETS_KEY_PREVIOUS` on boxes plus a
+ re-seal pass, if owners ask.
+
+## 9. Rollout and Task 11
+
+Console only. Roll order as usual (dev console, then flagship). On dev:
+register r10r's key (`carlos secrets genkey` on DOCS-T1 into a 0600 file,
+the private half into box-1's host.env by one SSM command reading it from
+a presigned URL, never in command parameters), check `fleets ls` says
+`holds key`, set shop's secrets, and resume rootfs Plan 4 Task 11. The dev
+store backend (approved by Paul, 2026-10-29) is configured beside it.
+
+## 10. Calls made without Paul (check these)
+
+- C1. The owner mints the key with `carlos secrets genkey` on their own
+ machine; the platform never generates it. (Alternative: the box mints it
+ and registers the public half itself over its tunnel.)
+- C2. Setting the key needs the same authority as `fleets add-box`.
+- C3. Moves refuse instead of re-sealing (§5.5); key replacement refuses
+ while sealed values exist (§5.6).
+- C4. Fleet-key envelopes are always v2, independent of the deployment
+ switch.
+- C5. `sealed_to` is plaintext metadata beside the envelope, not a new
+ envelope version: boxes need no change, and it only affects the
+ writer's own app if a client lies about it.
+- C6. Keyless fleet in a background walk: skip and retry, never fall back
+ to the deployment key.