carlos / platform Public

fix: deny fleet-box writes to readiness authority

The console publishes fleets/<fleet>/boxes/<label>/ready.json through its
own release store as the word that a managed box may run workloads. The
store door's own-fleet write grant let any box of the fleet create, replace
or delete that object, its own or a sibling's.

aclWrite now refuses the exact five-segment shape (managedReadyObjectKey)
before the fleets/<fleet>/ prefix grant, for every label. Reads, the rest
of the boxes subtree, near names such as ready.jsonx, heartbeats and
bindings are unchanged. The key is matched after the existing canonicalKey
gate, so encoded, dotted and doubled-slash spellings are refused before
the ACL and never reach the bucket. Refusals keep the door's one 404.

Tests: TestStoreDoorManagedReady{ACL,Wire,Console,KeyMatchesConsole}; the
last pins the matcher to internal/console's managedReadyKey shape.

Plan 2b-1 Task 6 (#457 phase 2).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 39458f63a636a234716b97102593fae61f37f08b parent aedea9c
2 files changed, +265 −2
  • internal/edge/storedoor.go +29 −2
  • internal/edge/storedoor_test.go +236 −0
diff --git a/internal/edge/storedoor.go b/internal/edge/storedoor.go
index 85d1b22d9..c1af2003c 100644
--- a/internal/edge/storedoor.go
+++ b/internal/edge/storedoor.go
@@ -628,7 +628,9 @@ func canonicalPrefix(raw string) (string, bool) {
// every write on this wire is a CAS (read the etag, then Put with If-Match).
// A write scope you cannot read is a write scope you cannot use — the
// binding takeover guard and the heartbeat both read their own object first.
-// It grants access to nothing beyond what aclWrite already grants.
+// It grants access to nothing beyond what aclWrite already grants, with one
+// deliberate exception: a managed box's ready object, which the box reads
+// and only the console writes (managedReadyObjectKey).
//
// control/layout.json is not in F3's enumeration either, and is granted for
// the same reason control/serial is: every box needs the fleet's layout
@@ -761,9 +763,14 @@ func aclDir(sqid, fleet, dir string) bool {
// aclWrite is the write half of F3 — and DELETE's half too. Two scopes, and
// only two:
//
-// fleets/<fleet>/** its own corner
+// fleets/<fleet>/** its own corner, less its boxes' ready objects
// apps/<sqid>/<app>/<family>/** its own account's app logs, errors, analytics (applog.Prefix)
//
+// The one hole in the first scope is fleets/<fleet>/boxes/<label>/ready.json
+// (managedReadyObjectKey), refused before the prefix grant is consulted: it
+// is the console's word that a managed box may run workloads, published
+// through the console's own store handle, never this door.
+//
// It can never write a release artifact, a channel pointer, or an instance
// record, which is the tamper surface the whole spec exists to close (F6:
// retention does not arm on a fleet box either). It can never write a
@@ -793,12 +800,32 @@ func aclWrite(sqid, fleet, key string) bool {
if fleet == "" {
return false
}
+ if managedReadyObjectKey(fleet, key) {
+ return false
+ }
if strings.HasPrefix(key, "fleets/"+fleet+"/") {
return true
}
return aclWriteAppFamily(sqid, key)
}
+// managedReadyObjectKey reports whether key is a managed box's readiness
+// authority in fleet: exactly fleets/<fleet>/boxes/<label>/ready.json, five
+// segments, any non-empty label (internal/console's managedReadyKey). The
+// console publishes it create-only once the box passes its readiness checks,
+// and the box runs no workloads until it exists, so a box that could write
+// it would vouch for itself and one that could delete it could unseat a
+// sibling. Every label is matched, the caller's own included: aclWrite has
+// no authenticated label, and none is needed to refuse them all. Shape only,
+// no registry read. The key has already been through canonicalKey, so no
+// dot, empty or encoded segment reaches here, and a near name
+// ("ready.jsonx", a sixth segment) is an ordinary own-fleet object.
+func managedReadyObjectKey(fleet, key string) bool {
+ seg := strings.Split(key, "/")
+ return len(seg) == 5 && seg[0] == "fleets" && seg[1] == fleet &&
+ seg[2] == "boxes" && seg[3] != "" && seg[4] == "ready.json"
+}
+
// chunkFamilies is the allow-list of app subtrees a box may write: the
// chunk and day-file families it produces about its own tenant's apps
// (applog.Family). Exact segment names — "logs" is not "logsx".
diff --git a/internal/edge/storedoor_test.go b/internal/edge/storedoor_test.go
index 57cad7bb0..eea553adb 100644
--- a/internal/edge/storedoor_test.go
+++ b/internal/edge/storedoor_test.go
@@ -1199,3 +1199,239 @@ func TestStoreDoorListsOnlyItsOwnPolicyETags(t *testing.T) {
t.Errorf("empty etag listing = %d %q, want 200 []", w.Code, w.Body.String())
}
}
+
+// ---- managed readiness authority (#457 phase 2, plan 2b-1 Task 6) --------
+
+// The console's readiness authority for a managed box: the object it alone
+// publishes, and whose presence lets the box run workloads. The shape is
+// internal/console's managedReadyKey; TestStoreDoorManagedReadyKeyMatchesConsole
+// pins the two together.
+func readyKey(fleet, label string) string {
+ return "fleets/" + fleet + "/boxes/" + label + "/ready.json"
+}
+
+// TestStoreDoorManagedReadyACL: no fleet box may write or delete any box's
+// ready object in its own fleet, its own label included, while every read and
+// every other own-fleet write survives.
+func TestStoreDoorManagedReadyACL(t *testing.T) {
+ own, sibling := readyKey(testFleet, "box-a"), readyKey(testFleet, "box-b")
+ foreign := readyKey("other", "box-a")
+ rows := []struct {
+ key string
+ op aclOp
+ want bool
+ why string
+ }{
+ {own, opWrite, false, "a box never asserts its own readiness"},
+ {own, opDelete, false, "nor deletes the console's assertion"},
+ {sibling, opWrite, false, "nor a sibling's: aclWrite has no label and needs none"},
+ {sibling, opDelete, false, "nor deletes a sibling's"},
+ {own, opRead, true, "the box reads its own ready object"},
+ {sibling, opRead, true, "own-fleet reads are unchanged"},
+ {foreign, opRead, false, "another fleet's ready object"},
+ {foreign, opWrite, false, "is out of scope for writes"},
+ {foreign, opDelete, false, "and deletes"},
+ {ownFleetKey, opWrite, true, "own heartbeat still writes"},
+ {ownFleetKey, opDelete, true, "and deletes"},
+ {"fleets/pi/bindings/app.example.json", opWrite, true, "own bindings still write"},
+ {"fleets/pi/boxes/box-a/ready.jsonx", opWrite, true, "a near name is not the authority key"},
+ {"fleets/pi/boxes/box-a/ready.json/x", opWrite, true, "nor is a sixth segment"},
+ {"fleets/pi/boxes/ready.json", opWrite, true, "nor a key with no label"},
+ {"fleets/pi/boxes/box-a/status.json", opWrite, true, "the boxes subtree is not blanket-denied"},
+ {"fleets/pi/boxes/box-a/../box-a/ready.json", opWrite, false, "traversal is refused by canonicalKey"},
+ {"fleets/pi/boxes//ready.json", opWrite, false, "an empty label is refused by canonicalKey"},
+ }
+ for _, row := range rows {
+ if got := aclAllows(row.key, row.op); got != row.want {
+ t.Errorf("acl %s %q = %v, want %v (%s)", row.op, row.key, got, row.want, row.why)
+ }
+ }
+ for _, key := range []string{own, ownFleetKey, "fleets//boxes/box-a/ready.json"} {
+ if aclWrite(testSqid, "", key) {
+ t.Errorf("aclWrite with no fleet allowed %q", key)
+ }
+ if aclRead(testSqid, "", key) {
+ t.Errorf("aclRead with no fleet allowed %q", key)
+ }
+ }
+ matches := map[string]bool{
+ own: true,
+ sibling: true,
+ "fleets/pi/boxes/box-a/ready.jsonx": false,
+ "fleets/pi/boxes/box-a/xready.json": false,
+ "fleets/pi/boxes/box-a/ready.json/x": false,
+ "fleets/pi/boxes/ready.json": false,
+ "fleets/pi/box/box-a/ready.json": false,
+ "fleets/pix/boxes/box-a/ready.json": false,
+ "apps/pi/boxes/box-a/ready.json": false,
+ "x/fleets/pi/boxes/box-a/ready.json": false,
+ "fleets/pi/boxes/box-a/b/ready.json": false,
+ "fleets/pi/status/boxes/box-a.json": false,
+ "fleets/pi/boxes/box-a/Ready.json": false,
+ "fleets/pi/boxes/box-a/ready.json.tmp": false,
+ }
+ for key, want := range matches {
+ if got := managedReadyObjectKey(testFleet, key); got != want {
+ t.Errorf("managedReadyObjectKey(%q, %q) = %v, want %v", testFleet, key, got, want)
+ }
+ }
+}
+
+// TestStoreDoorManagedReadyWire drives the denial through the door: every
+// way of spelling a PUT or DELETE of a ready object reaches the bucket zero
+// times and answers the door's one refusal, while the box still reads the
+// exact object and its normal writes round-trip.
+func TestStoreDoorManagedReadyWire(t *testing.T) {
+ d, dir := newTestDoor(t)
+ refusal := missingInScopeShape(t, d)
+ ownBody, siblingBody := `{"label":"box-a"}`, `{"label":"box-b"}`
+ ownTag := seedObject(t, dir, readyKey(testFleet, "box-a"), ownBody)
+ siblingTag := seedObject(t, dir, readyKey(testFleet, "box-b"), siblingBody)
+ seedObject(t, dir, readyKey("other", "box-a"), `{"label":"foreign"}`)
+ counting := &doorOpCounter{Store: dir}
+ d.store = counting
+
+ targets := []string{
+ "/store/o/" + readyKey(testFleet, "box-a"),
+ "/store/o/" + readyKey(testFleet, "box-b"),
+ "/store/o/" + readyKey(testFleet, "box-c"),
+ "/store/o/fleets/pi/boxes/box-a%2Fready.json",
+ "/store/o/fleets%2Fpi%2Fboxes%2Fbox-a%2Fready.json",
+ "/store/o/fleets/pi/boxes/box-a/ready%2Ejson",
+ "/store/o/fleets/pi/boxes/box-a/%72%65ady.json",
+ "/store/o/fleets/pi/boxes/box-a/ready.json?x=1",
+ "/store/o/fleets/pi/boxes//box-a/ready.json",
+ "/store/o/fleets/pi//boxes/box-a/ready.json",
+ "/store/o/fleets/pi/boxes/box-a//ready.json",
+ "/store/o//fleets/pi/boxes/box-a/ready.json",
+ "/store/o/fleets/pi/boxes/box-a/ready.json/",
+ "/store/o/fleets/pi/boxes/x/../box-a/ready.json",
+ "/store/o/fleets/pi/boxes/x/%2e%2e/box-a/ready.json",
+ "/store/o/fleets/pi/boxes/box-a/./ready.json",
+ "/store/o/fleets/pi/boxes/box-a/%2E/ready.json",
+ "/store/o/./fleets/pi/boxes/box-a/ready.json",
+ "/store//o/fleets/pi/boxes/box-a/ready.json",
+ "/store/o/fleets/other/boxes/box-a/ready.json",
+ "/store/list?prefix=fleets/pi/boxes/box-a/ready.json",
+ "/store/dirs?prefix=fleets/pi/boxes/box-a/",
+ "/store/etags?prefix=fleets/pi/boxes/box-a/",
+ }
+ preconditions := []map[string]string{
+ {"If-None-Match": "*"},
+ {"If-Match": ownTag},
+ {"If-Match": siblingTag},
+ nil,
+ }
+ for _, target := range targets {
+ for _, method := range []string{"PUT", "DELETE", "POST", "PATCH"} {
+ for _, hdr := range preconditions {
+ h := map[string]string{"X-HTTP-Method-Override": "PUT"}
+ for k, v := range hdr {
+ h[k] = v
+ }
+ counting.ops = 0
+ w := doorDo(d, method, target, `{"label":"forged"}`, h)
+ if got := shapeOf(w); got != refusal {
+ t.Errorf("%s %s %v = %+v, want the bare refusal %+v", method, target, hdr, got, refusal)
+ }
+ if counting.ops != 0 {
+ t.Errorf("%s %s %v reached the bucket %d time(s), want 0", method, target, hdr, counting.ops)
+ }
+ }
+ }
+ }
+ for key, want := range map[string]string{readyKey(testFleet, "box-a"): ownBody, readyKey(testFleet, "box-b"): siblingBody} {
+ if body, _, err := dir.Get(context.Background(), key); err != nil || string(body) != want {
+ t.Errorf("%s after refused writes = %q, %v; want %q", key, body, err, want)
+ }
+ }
+ if _, _, err := dir.Get(context.Background(), readyKey(testFleet, "box-c")); !errors.Is(err, os.ErrNotExist) {
+ t.Errorf("a refused create-only PUT planted %s: %v", readyKey(testFleet, "box-c"), err)
+ }
+
+ // Reads keep the exact object.
+ for key, want := range map[string][2]string{
+ readyKey(testFleet, "box-a"): {ownBody, ownTag},
+ readyKey(testFleet, "box-b"): {siblingBody, siblingTag},
+ } {
+ w := doorDo(d, "GET", "/store/o/"+key, "", nil)
+ if w.Code != http.StatusOK || w.Body.String() != want[0] || w.Header().Get("ETag") != want[1] {
+ t.Errorf("GET %s = %d %q etag %q, want 200 %q etag %q", key, w.Code, w.Body.String(), w.Header().Get("ETag"), want[0], want[1])
+ }
+ }
+ if got := shapeOf(doorDo(d, "GET", "/store/o/"+readyKey("other", "box-a"), "", nil)); got != refusal {
+ t.Errorf("GET another fleet's ready object = %+v, want the bare refusal", got)
+ }
+ if got := shapeOf(doorDo(d, "GET", "/store/o/fleets/pi/boxes/box-a/../box-a/ready.json", "", nil)); got != refusal {
+ t.Errorf("GET a traversal-shaped ready key = %+v, want the bare refusal", got)
+ }
+
+ // Normal own-fleet writes round-trip, the near name and the rest of the
+ // boxes subtree included.
+ for _, key := range []string{ownFleetKey, "fleets/pi/bindings/app.example.json", "fleets/pi/boxes/box-a/ready.jsonx", "fleets/pi/boxes/box-a/status.json"} {
+ w := doorDo(d, "PUT", "/store/o/"+key, "one", map[string]string{"If-None-Match": "*"})
+ if w.Code != http.StatusOK {
+ t.Fatalf("create %s = %d, want 200", key, w.Code)
+ }
+ w = doorDo(d, "PUT", "/store/o/"+key, "two", map[string]string{"If-Match": w.Header().Get("ETag")})
+ if w.Code != http.StatusOK {
+ t.Fatalf("replace %s = %d, want 200", key, w.Code)
+ }
+ if w = doorDo(d, "GET", "/store/o/"+key, "", nil); w.Code != http.StatusOK || w.Body.String() != "two" {
+ t.Errorf("GET %s = %d %q, want 200 \"two\"", key, w.Code, w.Body.String())
+ }
+ if w = doorDo(d, "DELETE", "/store/o/"+key, "", nil); w.Code != http.StatusNoContent {
+ t.Errorf("DELETE %s = %d, want 204", key, w.Code)
+ }
+ }
+}
+
+// TestStoreDoorManagedReadyConsole: the console publishes through its own
+// direct store handle, create-only, and nothing the box can send forges the
+// object first or replaces or deletes it afterwards.
+func TestStoreDoorManagedReadyConsole(t *testing.T) {
+ d, console := newTestDoor(t)
+ key := readyKey(testFleet, "box-a")
+ path := "/store/o/" + key
+
+ if w := doorDo(d, "PUT", path, `{"forged":true}`, map[string]string{"If-None-Match": "*"}); w.Code != http.StatusNotFound {
+ t.Fatalf("box create-only PUT of its ready object = %d, want 404", w.Code)
+ }
+ body := `{"fleet":"pi","label":"box-a","ready_at":"2026-11-08T00:00:00Z","op":"op-1"}`
+ etag, err := console.Put(context.Background(), key, []byte(body), "")
+ if err != nil {
+ t.Fatalf("console create-only publication: %v", err)
+ }
+
+ w := doorDo(d, "GET", path, "", nil)
+ if w.Code != http.StatusOK || w.Body.String() != body || w.Header().Get("ETag") != etag {
+ t.Fatalf("box GET = %d %q etag %q, want the console's object", w.Code, w.Body.String(), w.Header().Get("ETag"))
+ }
+ if w := doorDo(d, "PUT", path, `{"forged":true}`, map[string]string{"If-Match": etag}); w.Code != http.StatusNotFound {
+ t.Errorf("box replace with the fresh etag = %d, want 404", w.Code)
+ }
+ if w := doorDo(d, "DELETE", path, "", nil); w.Code != http.StatusNotFound {
+ t.Errorf("box DELETE = %d, want 404", w.Code)
+ }
+ got, gotTag, err := console.Get(context.Background(), key)
+ if err != nil || string(got) != body || gotTag != etag {
+ t.Errorf("published object after box attempts = %q %q, %v; want the console's", got, gotTag, err)
+ }
+}
+
+// TestStoreDoorManagedReadyKeyMatchesConsole keeps the door's matcher and the
+// console's publisher on one key shape: if internal/console ever moves the
+// ready object, the door would otherwise stop protecting it silently.
+func TestStoreDoorManagedReadyKeyMatchesConsole(t *testing.T) {
+ src, err := os.ReadFile(filepath.Join("..", "console", "managedworker.go"))
+ if err != nil {
+ t.Fatalf("read console publisher: %v", err)
+ }
+ const want = `return "fleets/" + b.Fleet + "/boxes/" + b.Label + "/ready.json"`
+ if !strings.Contains(string(src), "func managedReadyKey(b managedBox) string {\n\t"+want+"\n}") {
+ t.Fatalf("internal/console managedReadyKey no longer reads %s; update managedReadyObjectKey to match", want)
+ }
+ if !managedReadyObjectKey(testFleet, readyKey(testFleet, "box-a")) {
+ t.Fatal("the door's matcher does not recognise the console's key")
+ }
+}