carlos / platform Public

Fleet box witnesses and docs for the fleet secrets key (Task 10)

Box tests over a real store door, no box code change: a fleet box renders a
v2 envelope sealed to its fleet key, refuses one sealed to the deployment key
or to another fleet's key (cannot_open), and a fleet-mode agent's edges loop
exits and writes no control/edges/. Each witness has a mutation that fails it.
TestFleetBoxWritesNoEdgesFile runs the loop itself: the existing
TestShouldSkipPublisherElection pins only the predicate.

Docs from approved rows FSK-C56..C70 (cli.md, rails.md, rootfs.md, README),
each id in fleetSecretsCopyBuilt.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 8c5193d2100e762ad0897ec734a6696ad7c0db57 parent 6553646
6 files changed, +361 −1
  • README.md +8 −0
  • approved_fleet_secrets_copy_test.go +4 −1
  • docs/site/cli.md +24 −0
  • docs/site/rails.md +4 −0
  • docs/site/rootfs.md +2 −0
  • internal/host/fleet_secrets_key_test.go +319 −0

Intent

Human

<task-notification> <task-id>a01da7d8d7c4b02d7</task-id> <tool-use-id>toolu_01PfonMxai2vHiqJDKxxahJj</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/a01da7d8d7c4b02d7.output</output-file> <status>completed</status> <summary>Agent "Implement Task 9: refusals on instances list" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE (fix round 1 applied) **Commit:** 6553646f. A `packed-refs.lock` error printed, but `git log -1` confirms the commit exists. **Tests:** Both new tests failed first and now pass. - `TestInstanceListCappedReasonSkipsAwakeRows`: an awake row carried `capped=true` before the fix. - `TestInstanceListCappedReasonNeverOnPlatformBoxes`: a platform box with 101 refusals put `capped=true` on the caller's row before the fix. - `TestInstanceListCappedReportIsTheRowsBoxs` now pins the new rule. - The Task 9 tests plus the InstanceList/Rollout/Workers/reasonCell runs pass (console 25.0s, root package ok). Vet, gofmt and the darwin, windows and linux/arm64 builds are clean. **What changed:** In `apiinstances.go`, only a fleet box of a fleet the caller owns can mark a row as capped. A row a box reports is marked only when that box is capped and has the row asleep. A row no box reports is marked when its fleet has a capped box. Platform boxes never produce it. `capped` is now keyed by fleet and label, which also closes review Minor 2 (a platform and a fleet box sharing a label). **Concerns:** None new. I left review Minors 1 (server-side reason sanitising), 3 and 4 untouched. **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/.superpowers/sdd/2026-10-29-fleet-secrets-key/task-9-report.md (fix round appended)</result> <usage><subagent_tokens>143168</subagent_tokens><tool_uses>8</tool_uses><duration_ms>160006</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>af8a99bfb9014bcd6</task-id> <tool-use-id>toolu_01YcLJtFiVLtgogQvg1JHyui</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/af8a99bfb9014bcd6.output</output-file> <status>completed</status> <summary>Agent "Re-review Task 9 fix round 1" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Finding (capped REASON on awake rows and platform boxes): ADDRESSED Fix round: all findings addressed, no new Critical/Important breakage. There are two Minor notes, in the report. Path: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/.superpowers/sdd/2026-10-29-fleet-secrets-key/task-9-rereview-1.md</result> <usage><subagent_tokens>54954</subagent_tokens><tool_uses>4</tool_uses><duration_ms>33572</duration_ms></usage> </task-notification>

diff --git a/README.md b/README.md
index 48d50a9f5..8a2c51d27 100644
--- a/README.md
+++ b/README.md
@@ -624,6 +624,14 @@ The keypair is the mirror image of the release signing pair:
exactly two places, your secret manager and every host's
`/etc/carlos/host.env`.
+An app on a fleet cannot hold a secret until the fleet has its own secrets key. The key is a pair. The private half stays on your fleet's boxes and the platform never sees it. The public half goes to the console, which seals every secret and credential for the fleet's apps to it.
+
+Make the pair with \`carlos secrets genkey\`. Put the private half in \`/etc/carlos/host.env\` on every box as \`CARLOS_SECRETS_KEY\`, then restart the agent with \`systemctl restart carlos-edge\`. Register the public half with \`carlos fleets secrets-key <name> <pubkey>\`. Only an account owner can do that.
+
+Register it with `carlos fleets secrets-key home <pubkey>`, or pass `--file` with a file that holds a `CARLOS_SECRETS_PUBKEY=` line or the bare key. The command prints the key's fingerprint.
+
+`carlos secrets fingerprint` prints the fingerprint of the `CARLOS_SECRETS_KEY` in `/etc/carlos/host.env`, or in the file you name with `--file`. It runs on your machine, calls no console and never prints the key.
+
Hosts converge during the hourly root `carlos adopt` pass: with
`CARLOS_SECRETS_KEY` set, each pass materializes the manifest into
`/etc/carlos/apps/<route.Host>.env` (the file `carlos-app@.service`
diff --git a/approved_fleet_secrets_copy_test.go b/approved_fleet_secrets_copy_test.go
index 08113b2ec..313fe1708 100644
--- a/approved_fleet_secrets_copy_test.go
+++ b/approved_fleet_secrets_copy_test.go
@@ -56,7 +56,7 @@ var fleetSecretsCopyStatuses = []string{"pending", "approved", "struck"}
// task that writes a row's text adds its id here in the same commit, once the
// row is approved. Task 3 built the door, BYO page and fleet page rows; Task 4 the CLI rows;
// Task 5 sealKeyFor's refusals and the config door's; Task 6a the store and
-// email doors' keyless-fleet refusals; Task 6b the relay's; Task 7 the move refusal; Task 9 the REASON cells.
+// email doors' keyless-fleet refusals; Task 6b the relay's; Task 7 the move refusal; Task 9 the REASON cells; Task 10 the docs.
var fleetSecretsCopyBuilt = []string{
"FSK-C01", "FSK-C02", "FSK-C03", "FSK-C04",
"FSK-C05", "FSK-C06", "FSK-C07", "FSK-C08",
@@ -71,6 +71,9 @@ var fleetSecretsCopyBuilt = []string{
"FSK-C41", "FSK-C42", "FSK-C43", "FSK-C44",
"FSK-C45", "FSK-C46", "FSK-C47", "FSK-C48", "FSK-C49", "FSK-C50",
"FSK-C51", "FSK-C52", "FSK-C53", "FSK-C54", "FSK-C55",
+ "FSK-C56", "FSK-C57", "FSK-C58", "FSK-C59", "FSK-C60",
+ "FSK-C61", "FSK-C62", "FSK-C63", "FSK-C64", "FSK-C65",
+ "FSK-C66", "FSK-C67", "FSK-C68", "FSK-C69", "FSK-C70",
}
func mustParseFleetSecretsRecord(t *testing.T) []copyRow {
diff --git a/docs/site/cli.md b/docs/site/cli.md
index 16c7d6dc8..5fca803a6 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -154,6 +154,8 @@ later, puts the app's routes and instances on a fleet your account owns.
in that empty spelling: leaving it off is a usage error, never a silent
clear.
+`carlos apps place` refuses an app whose sealed values were sealed to a different key from the target's, and `carlos apps create --place` does the same for an app that already has config. The message lists the values. Unset them, place the app, then set them again and rotate any credential the console minted.
+
carlos apps place refuses a rootfs app, whatever the target, because a rootfs app's instances do not move. Give a rootfs app its fleet with --place fleet/<name> when you create it, before its first ship. [Rootfs apps](/docs/rootfs) says why.
Two more flags are stamped at claim time. `--control-plane` marks the app as
@@ -886,6 +888,12 @@ Sealing uses a public key; the private half lives on the box that decrypts
them and never leaves it, in either mode. `carlos secrets genkey` mints the
pair, and it is always local to your terminal.
+An app placed on a fleet is sealed to the fleet's key, which `carlos secrets set` takes from the console. Leave `CARLOS_SECRETS_PUBKEY` unset in your terminal for it, and use a `carlos` CLI that knows about fleet keys, because the console refuses a secret from an older one.
+
+In direct-bucket mode, \`carlos secrets set\` refuses for any account that owns a fleet, because it cannot tell which key an app needs. Unset \`CARLOS_DEPLOYMENT_BUCKET\` and \`CARLOS_DEPLOYMENT_DIR\`, sign in with \`carlos auth login\`, and run \`carlos secrets set\` through the console.
+
+`carlos secrets fingerprint` prints the fingerprint of the `CARLOS_SECRETS_KEY` in `/etc/carlos/host.env`, or in the file you name with `--file`. It runs on your machine, calls no console and never prints the key.
+
An empty value is refused rather than stored. A command substitution that
produced nothing looks exactly like a real value at the point you type it, and
a stored empty secret usually surfaces much later as a feature quietly not
@@ -942,6 +950,8 @@ build that failed there is tried again, as a canary:
carlos instances retry --app hello shop-1.hello.example.com
```
+When a box refuses an instance's config, REASON in \`carlos instances list\` says why and what to do. A box without a secrets key needs \`CARLOS_SECRETS_KEY\` in its \`host.env\` and a restart with \`systemctl restart carlos-edge\`. A box that cannot open a secret needs its key compared with the fleet's using \`carlos secrets fingerprint\` and \`carlos fleets ls\`. If the keys match, run \`carlos secrets set\` for the listed values and rotate any credential the console minted.
+
For a rootfs app, RUNTIME says `rootfs`, or `rootfs, hibernates` for an instance that sleeps when idle. WORKERS counts the instance's running workers out of the ones it declares, and names a worker that keeps crashing. A binary instance shows `binary` and a dash.
`--environment <e>` on `create`, and `set-environment` on a route that
@@ -2061,6 +2071,20 @@ the old one, but it does not evict a channel the box is already holding. If a
credential may be compromised, `detach-box` is the command that actually
stops it.
+An app on a fleet cannot hold a secret until the fleet has its own secrets key. The key is a pair. The private half stays on your fleet's boxes and the platform never sees it. The public half goes to the console, which seals every secret and credential for the fleet's apps to it.
+
+Make the pair with \`carlos secrets genkey\`. Put the private half in \`/etc/carlos/host.env\` on every box as \`CARLOS_SECRETS_KEY\`, then restart the agent with \`systemctl restart carlos-edge\`. Register the public half with \`carlos fleets secrets-key <name> <pubkey>\`. Only an account owner can do that.
+
+Register it with `carlos fleets secrets-key home <pubkey>`, or pass `--file` with a file that holds a `CARLOS_SECRETS_PUBKEY=` line or the bare key. The command prints the key's fingerprint.
+
+A key belongs to one fleet only, and it cannot be the platform's own. Registering the same key on the same fleet again changes nothing.
+
+If apps on the fleet already hold sealed values, the command lists them. They were sealed to another key, so the fleet's boxes cannot open them. Set each secret again with `carlos secrets set`, and run `carlos store rotate` or `carlos email rotate` for a credential the console minted. The STALE column of `carlos fleets ls` counts what is left.
+
+To check that a box holds the registered key, run `carlos secrets fingerprint` on the box. Its answer should start with the characters in the SECRETS KEY column of `carlos fleets ls`, which shows the first 12 after `sha256:`.
+
+You can replace a fleet's key only while none of its apps holds a sealed value. Unset those apps' secrets, register the new key, set the secrets again and rotate the credentials the console minted. If a key may have leaked, first run \`carlos fleets detach-box <fleet> <label>\`. A detached box stops reading the platform's store.
+
### carlos services
Credentials a server holds rather than a person: a CI job that ships, a
diff --git a/docs/site/rails.md b/docs/site/rails.md
index a1d3ec3ad..524131958 100644
--- a/docs/site/rails.md
+++ b/docs/site/rails.md
@@ -175,6 +175,8 @@ carlos promote --app shop v1
carlos instances create --app shop --host shop.k3x.example.com
```
+A fleet needs its own secrets key before an app on it can hold a secret. \`carlos store create\` needs it too, because the console seals the store's credential to that key. If the fleet has none, register it with \`carlos fleets secrets-key <fleet> <pubkey>\`. [carlos fleets](/docs/cli#carlos-fleets) shows how.
+
Ship before you create the instance. An app's first release makes it a rootfs app, and an instance takes that, and whether it hibernates, from the release when it is created.
The first start runs release, which migrates the empty database, then starts web, then the worker once web answers. carlos instances list shows the instance's runtime and its workers, and carlos logs shows all three processes.
@@ -184,6 +186,8 @@ carlos instances list --app shop
carlos logs --app shop -f
```
+If \`carlos secrets set\` or \`carlos store create\` says the fleet has no secrets key, register it with \`carlos fleets secrets-key <fleet> <pubkey>\` and run the command again. If \`carlos instances list\` shows a config refusal, its REASON column says what to do.
+
carlos run does not reach rootfs instances yet.
## Deploys and migrations
diff --git a/docs/site/rootfs.md b/docs/site/rootfs.md
index 5276a9bb0..abc521ba4 100644
--- a/docs/site/rootfs.md
+++ b/docs/site/rootfs.md
@@ -4,6 +4,8 @@ A rootfs app is an app shipped as a read-only Linux image instead of a single bi
A rootfs app runs only on boxes your account owns: a fleet of yours on a deployment that runs apps for other people, or any box of a deployment run for one customer. The box must be on the nested layout, must run overlap deploys and must have passed its rootfs check. The console refuses anywhere else, and so does the box.
+A fleet app's secrets and its store credential are sealed to the fleet's own secrets key, so register one before the app needs a secret. [carlos fleets](/docs/cli#carlos-fleets) explains how.
+
## What fixes an app's kind
An app's first release makes it a binary app or a rootfs app, and it stays that kind. A release of the other kind is refused when you ship it. To change kinds, create a new app.
diff --git a/internal/host/fleet_secrets_key_test.go b/internal/host/fleet_secrets_key_test.go
new file mode 100644
index 000000000..adec34b66
--- /dev/null
+++ b/internal/host/fleet_secrets_key_test.go
@@ -0,0 +1,319 @@
+package host
+
+import (
+ "context"
+ "crypto/ecdh"
+ "crypto/rand"
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "net/http/httptest"
+ "net/url"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/appconfig"
+ "github.com/carlosframework/platform/internal/domains"
+ "github.com/carlosframework/platform/internal/edge"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Fleet secrets key, Task 10 (spec 2026-10-29-fleet-secrets-key-design.md §6):
+// no box code changes, so the box side is proved here. A fleet box with
+// CARLOS_SECRETS_KEY set runs the config guard and the sync pass over the
+// store door, and the console seals a fleet app's values to the fleet's own
+// key. These tests stand up the real door (a real edge, the registry-backed
+// credential table, the real ACL, a DirStore behind it) and drive a box that
+// is built from its environment the way runAgent builds it: the guard and the
+// sync pass over openDeployStoreEnv's store, CARLOS_REGION=fleet/<name>,
+// CARLOS_SECRETS_KEY the fleet's key.
+//
+// Neutral names: account "bab" is the sqid of id 7, app "shop", fleets "home"
+// and "away", one box "box-1" in each.
+
+const (
+ fskApp = "shop"
+ fskHost = "shop.home.example.com"
+ fskLabel = "box-1"
+)
+
+// fskWorld is one platform and two fleets of one account. The bucket (store)
+// is the console's side: the tests write config to it the way the console
+// does, and no box code path touches it. A box sees only the door.
+type fskWorld struct {
+ t *testing.T
+ srvURL string
+ store *release.DirStore
+ account string
+ tokens map[string]string // fleet -> that fleet's box token
+ // The three keys of the world: each fleet's own, and the deployment's.
+ keys map[string]*ecdh.PrivateKey // "home", "away", "deployment"
+}
+
+func newFSKWorld(t *testing.T) *fskWorld {
+ t.Helper()
+ w := &fskWorld{
+ t: t,
+ account: domains.Sqid(7),
+ tokens: map[string]string{"home": "home-token", "away": "away-token"},
+ keys: map[string]*ecdh.PrivateKey{},
+ store: release.NewDirStore(t.TempDir()),
+ }
+ for _, name := range []string{"home", "away", "deployment"} {
+ k, err := ecdh.P256().GenerateKey(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+ w.keys[name] = k
+ }
+
+ reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db"))
+ if err != nil {
+ t.Fatalf("open registry: %v", err)
+ }
+ t.Cleanup(func() { _ = reg.Close() })
+ for fleet, token := range w.tokens {
+ if err := reg.UpsertFleet(registry.Fleet{Name: fleet, Account: w.account, Bucket: fleet + "-data"}); err != nil {
+ t.Fatalf("UpsertFleet(%s): %v", fleet, err)
+ }
+ sum := sha256.Sum256([]byte(token))
+ if err := reg.AddFleetBox(registry.FleetBox{
+ Fleet: fleet, Label: fskLabel, TokenHash: hex.EncodeToString(sum[:]), Status: "active",
+ }); err != nil {
+ t.Fatalf("AddFleetBox(%s): %v", fleet, err)
+ }
+ }
+
+ _, pubB64, err := release.GenerateKey()
+ if err != nil {
+ t.Fatal(err)
+ }
+ pub, err := release.ParsePublicKey(pubB64, "test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ e, err := edge.New(reg, nil)
+ if err != nil {
+ t.Fatalf("edge.New: %v", err)
+ }
+ srv := httptest.NewServer(e)
+ t.Cleanup(srv.Close)
+ w.srvURL = srv.URL
+ u, err := url.Parse(srv.URL)
+ if err != nil {
+ t.Fatal(err)
+ }
+ e.EnableStatic(w.store, pub, filepath.Join(t.TempDir(), "cache"))
+ e.EnableTunnels(edge.NewTunnelHub(u.Hostname(), nil))
+ if err := e.Reload(); err != nil {
+ t.Fatalf("Reload: %v", err)
+ }
+ return w
+}
+
+// putConfig writes the app's default config the way the console does: one
+// secret sealed with a v2 envelope bound to (account, app) to the key named
+// by sealedTo, plus one plain variable.
+func (w *fskWorld) putConfig(sealedTo, plaintext string) {
+ w.t.Helper()
+ s := appconfig.NewSealer(w.keys[sealedTo].PublicKey(), appconfig.Binding{Account: w.account, App: fskApp}, true)
+ v, err := s.Seal(appconfig.Binding{Account: w.account, App: fskApp}, []byte(plaintext))
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ body, err := json.Marshal(appconfig.Manifest{Schema: 1, App: fskApp, Vars: map[string]appconfig.Var{
+ "STRIPE_KEY": v,
+ "LOG_LEVEL": {Kind: "env", Value: "info"},
+ }})
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ if _, err := w.store.Put(context.Background(), appconfig.Key(w.account, fskApp), body, ""); err != nil {
+ w.t.Fatal(err)
+ }
+}
+
+// fskBox is one fleet box: its environment, the store its loops open from it,
+// the config guard built from it, and the data directory its sync writes to.
+type fskBox struct {
+ getenv func(string) string
+ store release.Store
+ guard *configGuard
+ reg *registry.Registry
+ dd string
+ route registry.Route
+}
+
+// box builds the box of fleet, holding the key named holds (the box's own
+// CARLOS_SECRETS_KEY), with no deployment bucket or dir so that its store is
+// the door.
+func (w *fskWorld) box(fleet, holds string) *fskBox {
+ w.t.Helper()
+ env := map[string]string{
+ "CARLOS_FLEET": fleet,
+ "CARLOS_FLEET_BOX": fskLabel,
+ "CARLOS_REGION": "fleet/" + fleet,
+ "CARLOS_TUNNEL_URL": w.srvURL,
+ "CARLOS_TUNNEL_TOKEN": w.tokens[fleet],
+ "CARLOS_SECRETS_KEY": keyB64(w.keys[holds]),
+ }
+ getenv := func(k string) string { return env[k] }
+ store, err := openDeployStoreEnv(context.Background(), getenv)
+ if err != nil {
+ w.t.Fatalf("open the box's store: %v", err)
+ }
+ if _, ok := store.(*release.DirStore); ok {
+ w.t.Fatal("the box's store is the bucket itself, not the door")
+ }
+ g := newConfigGuard(getenv, func(ctx context.Context) (release.Store, error) {
+ return openDeployStoreEnv(ctx, getenv)
+ })
+ reg := restartTestRegistry(w.t)
+ rt := registry.Route{Host: fskHost, Kind: "instance", App: fskApp, Account: w.account,
+ Hibernate: true, Status: "ready", Socket: "/run/carlos/" + fskHost + ".sock"}
+ if err := reg.Upsert(rt); err != nil {
+ w.t.Fatal(err)
+ }
+ return &fskBox{getenv: getenv, store: store, guard: g, reg: reg, dd: w.t.TempDir(), route: rt}
+}
+
+// admit is the guard's answer for the instance: the admission the activator
+// asks before it takes the lease.
+func (b *fskBox) admit() error {
+ return b.guard.Gate(context.Background(), b.route)
+}
+
+// sync runs the box's config pass (the one configSyncLoop runs) and returns
+// the rendered <host>.config.env, or "" when the pass wrote none.
+func (b *fskBox) sync(t *testing.T) string {
+ t.Helper()
+ priv, err := appconfig.ParsePrivateKey(b.getenv("CARLOS_SECRETS_KEY"), "CARLOS_SECRETS_KEY")
+ if err != nil {
+ t.Fatal(err)
+ }
+ // The pass may refuse a host it cannot render; what matters is the file.
+ _ = syncExecSerialized(context.Background(), b.reg, b.store, priv, b.dd, nil)
+ raw, err := os.ReadFile(filepath.Join(b.dd, fskHost+".config.env"))
+ if os.IsNotExist(err) {
+ return ""
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(raw)
+}
+
+// A v2 envelope sealed to the fleet key renders into <host>.config.env on a
+// fleet box that holds that key, and the admission question answers nil.
+func TestFleetBoxRendersFleetKeyConfig(t *testing.T) {
+ w := newFSKWorld(t)
+ w.putConfig("home", "sk_live_example")
+ b := w.box("home", "home")
+
+ if err := b.admit(); err != nil {
+ t.Fatalf("CanProvideConfig through the guard = %v, want nil", err)
+ }
+ if got := b.sync(t); got != "LOG_LEVEL=info\nSTRIPE_KEY=sk_live_example\n" {
+ t.Errorf("%s.config.env = %q, want the fleet-sealed secret rendered", fskHost, got)
+ }
+}
+
+// The same box refuses an envelope sealed to the deployment key: it renders
+// nothing and the guard says cannot_open.
+func TestFleetBoxRefusesDeploymentKeyConfig(t *testing.T) {
+ w := newFSKWorld(t)
+ w.putConfig("deployment", "sk_live_example")
+ b := w.box("home", "home")
+
+ if got := reasonOfGate(t, b.admit()); got != appconfig.ReasonCannotOpen {
+ t.Errorf("reason = %q, want %q", got, appconfig.ReasonCannotOpen)
+ }
+ if got := b.sync(t); got != "" {
+ t.Errorf("%s.config.env = %q, want none written", fskHost, got)
+ }
+}
+
+// Fleet away's box, holding away's key, cannot render an app of fleet home:
+// the door lets it read the account's config (one account), and its key
+// does not open what the console sealed to home's.
+func TestFleetBoxCannotRenderAnotherFleetsApp(t *testing.T) {
+ w := newFSKWorld(t)
+ w.putConfig("home", "sk_live_example")
+ b := w.box("away", "away")
+
+ if got := reasonOfGate(t, b.admit()); got != appconfig.ReasonCannotOpen {
+ t.Errorf("reason = %q, want %q", got, appconfig.ReasonCannotOpen)
+ }
+ if got := b.sync(t); got != "" {
+ t.Errorf("%s.config.env = %q, want none written", fskHost, got)
+ }
+}
+
+// The witnesses above are expected to pass at once, so this is the proof that
+// each can fail: the same fixtures with one thing changed give the opposite
+// answer on every line. Sealing to the wrong recipient fails the rendering
+// witness; handing a refusing box the matching key fails the refusal ones.
+func TestFleetBoxWitnessesCanFail(t *testing.T) {
+ t.Run("a wrong recipient does not render", func(t *testing.T) {
+ w := newFSKWorld(t)
+ w.putConfig("away", "sk_live_example") // sealed to a key home's box does not hold
+ b := w.box("home", "home")
+ if err := b.admit(); err == nil {
+ t.Error("admitted a config sealed to another key")
+ }
+ if got := b.sync(t); got != "" {
+ t.Errorf("rendered %q for an envelope sealed to another key", got)
+ }
+ })
+ t.Run("the deployment key's holder renders what was sealed to it", func(t *testing.T) {
+ w := newFSKWorld(t)
+ w.putConfig("deployment", "sk_live_example")
+ b := w.box("home", "deployment")
+ if err := b.admit(); err != nil {
+ t.Errorf("a box holding the key it was sealed to refused: %v", err)
+ }
+ if got := b.sync(t); !strings.Contains(got, "STRIPE_KEY=sk_live_example") {
+ t.Errorf("a box holding the key it was sealed to rendered %q", got)
+ }
+ })
+ t.Run("the matching key opens another fleet's app", func(t *testing.T) {
+ w := newFSKWorld(t)
+ w.putConfig("home", "sk_live_example")
+ b := w.box("away", "home") // away's box holding home's key
+ if err := b.admit(); err != nil {
+ t.Errorf("a box holding the matching key refused: %v", err)
+ }
+ if got := b.sync(t); !strings.Contains(got, "STRIPE_KEY=sk_live_example") {
+ t.Errorf("a box holding the matching key rendered %q", got)
+ }
+ })
+}
+
+// §6: the platform's candidate sets read only control/edges/, which fleet
+// boxes never write. A fleet-mode agent's edges publisher loop exits at once,
+// before it opens a store or writes a key. (TestShouldSkipPublisherElection
+// pins the predicate; this runs the loop itself.)
+func TestFleetBoxWritesNoEdgesFile(t *testing.T) {
+ dir := t.TempDir()
+ t.Setenv("CARLOS_DEPLOYMENT_DIR", dir)
+ t.Setenv("CARLOS_FLEET", "home")
+ t.Setenv("CARLOS_REGION", "fleet/home")
+
+ done := make(chan struct{})
+ go func() {
+ defer close(done)
+ edgesFileLoop(nil, false, nil)
+ }()
+ select {
+ case <-done:
+ case <-time.After(5 * time.Second):
+ t.Fatal("edgesFileLoop did not return on a fleet box")
+ }
+ if _, err := os.Stat(filepath.Join(dir, "control", "edges")); !os.IsNotExist(err) {
+ t.Errorf("a fleet box wrote under control/edges/ (stat err %v)", err)
+ }
+}