carlos / platform Public

edges files: a body is believed only when its box names the box its key names (hunt H3-M4)

The bucket's writer map lets a box write control/edges/<box>.json and
nothing else under the prefix, so the key is the publisher's identity and
the body's box field only its claim. Until now no reader compared them: a
file under any key could carry an entry for a host homed elsewhere at a
stamp no real claim reaches, dialBeats handed that host's backhaul dial to
the forged address, and KnownHost admitted every name in the body to the
ACME gate (deploymentHost).

edgesfile.BoxFromKey is the one derivation. internal/edge's parseEdgesFile
refuses a disagreeing body like one that will not parse, so refreshHosts
carries the key's last good parse forward: a forged body switches no live
dial target and clears no pairing (vouch, never revoke), and the fold
reflects no generation so the key is read again next poll. internal/host's
loadEdgesFileBodies (steering and moveTargets) fails the pass closed on a
mismatch, since skipping the file would withdraw the key's box's records;
an unparseable body still passes down verbatim. Steering is dormant without
CARLOS_STEERING_ZONE_ID, so that half is latent; the backhaul half is live.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude Fable (hunt fix) pushed by claude agent, operated by paul@keymail.dev a8ea8fdd5eae71af1382828ac78b2c09eec61c1d parent a4ade4d
7 files changed, +234 −6
  • internal/edge/homemap.go +25 −4
  • internal/edge/homemap_keybound_test.go +66 −0
  • internal/edge/hunt_H3-M4_test.go +36 −0
  • internal/edgesfile/edgesfile.go +25 −0
  • internal/edgesfile/edgesfile_test.go +23 −0
  • internal/host/steering_loop.go +33 −2
  • internal/host/steering_loop_test.go +26 −0
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go
index da513e36c..58bc68514 100644
--- a/internal/edge/homemap.go
+++ b/internal/edge/homemap.go
@@ -14,7 +14,10 @@ package edge
// last-good mirror certsync.go's certMirror is; that shape survived heavy
// review and is copied rather than reinvented. It NEVER writes: the
// writer map gives control/edges/<box>.json to that box's own loop, and
-// nothing in this package bumps control/serial.
+// nothing in this package bumps control/serial. That writer map is also
+// why a body is believed only when its box field names the box its KEY
+// names (parseEdgesFile, hunt H3-M4): the key is the authorised
+// identity, the body a claim.
//
// - the mesh keys ride the SAME refresh (loadMeshKeys, mesh.go), so a
// request path never reads the store: who homes a host and what key
@@ -440,8 +443,7 @@ func (m *homeMap) refreshHosts(ctx context.Context) error {
for _, key := range keys {
// The prefix is flat and every member is <box>.json. Anything else
// under it was not written by this deployment's edges loop.
- name, ok := strings.CutPrefix(key, edgesPrefix)
- if !ok || !strings.HasSuffix(name, ".json") || strings.Contains(name, "/") {
+ if _, ok := edgesfile.BoxFromKey(key); !ok {
continue
}
tried++
@@ -650,6 +652,21 @@ func (m *homeMap) setHostsWake(fn func()) {
// treatment an unreadable object gets — carry the last good parse forward —
// because a half-written body is no more usable than a body that never
// arrived, and the fix for both is the publisher's next pass.
+//
+// The body is bound to its key (hunt H3-M4). The writer map lets a box put
+// control/edges/<box>.json and nothing else under the prefix, so the key
+// names the publisher and the body's box field is the publisher's claim
+// about itself; the two must agree before any field of the body is acted
+// on. Were the body trusted on its own word, anyone who could write the
+// prefix could put a file under a key of their choosing carrying an entry
+// for a host homed elsewhere at a stamp no real claim will reach, and
+// dialBeats would hand that host's dial to the address in the forged body,
+// while KnownHost admitted every name in it to the ACME gate
+// (deploymentHost). A disagreeing body is refused like a body that will not
+// parse: refreshHosts carries this key's last good parse forward, so a
+// forged body switches no live dial target and clears no pairing (vouch,
+// never revoke), and the fold reflects no generation, so the key is read
+// again next poll.
func parseEdgesFile(key string, body []byte) (edgesFileView, error) {
var f edgesFileView
if err := json.Unmarshal(body, &f); err != nil {
@@ -663,6 +680,9 @@ func parseEdgesFile(key string, body []byte) (edgesFileView, error) {
// backhaul to every box that upgraded first.
return edgesFileView{}, fmt.Errorf("%s: unversioned edges file", key)
}
+ if box, ok := edgesfile.BoxFromKey(key); !ok || f.Box != box {
+ return edgesFileView{}, fmt.Errorf("%s: body names box %q, not the box its key names", key, f.Box)
+ }
return f, nil
}
@@ -686,7 +706,8 @@ func (m *homeMap) logPartialPoll(failed, tried int, err error) {
// - OWN BOX. A host homed here is SERVED here; offering it as a backhaul
// target would have the edge dial itself. Excluded by the file's own box
// field rather than by its object name, because the field is what the
-// publisher stamps and what self is derived to match.
+// publisher stamps and what self is derived to match (and parseEdgesFile
+// has already refused any file whose field and object name disagree).
// - NO DIAL ADDRESS. Task 1 publishes a box with no discoverable public IP
// as eip:"" so the DR runbook still gets its hosts list. There is
// nothing to dial, so it is not a target. The address is dialAddress's:
diff --git a/internal/edge/homemap_keybound_test.go b/internal/edge/homemap_keybound_test.go
new file mode 100644
index 000000000..1b84a9093
--- /dev/null
+++ b/internal/edge/homemap_keybound_test.go
@@ -0,0 +1,66 @@
+package edge
+
+import "testing"
+
+// A body is believed only when its box field names the box its KEY names
+// (parseEdgesFile, hunt H3-M4). hunt_H3-M4_test.go pins the dial; these pin
+// what else the binding protects: the ACME admission behind the same fold,
+// and the vouch-never-revoke posture when a LIVE key's body is replaced.
+
+// The ACME half. deploymentHost is the gate every certificate order passes
+// (edge.go), and its second half is KnownHost over the same fold. A file
+// under a key its body does not match admits none of its names: not the one
+// it contests (shop.example.com stays admitted on carol's word alone) and
+// not one nobody else publishes.
+func TestHomeMapKeyBoundForgedFileAdmitsNoHostToACME(t *testing.T) {
+ e, _, s := remoteHomedEdge(t, nil)
+ m := e.homes.Load()
+ putJSON(t, s, "control/edges/carol.json", `{"v":1,"box":"carol","eip":"198.51.100.10","hosts":{"shop.example.com":{"role":"home","platform":true,"account":"bab","app":"shop","stamp":7}}}`)
+ putJSON(t, s, "control/edges/zz.json", `{"v":1,"box":"mallory","eip":"203.0.113.66","hosts":{"shop.example.com":{"role":"home","platform":true,"account":"bab","app":"shop","stamp":9223372036854775807},"evil.example.com":{"role":"home","platform":true}}}`)
+ refreshHomeMap(t, m)
+ if !m.KnownHost("shop.example.com") || !e.deploymentHost("shop.example.com") {
+ t.Fatal("carol's own publication of shop.example.com must still be admitted")
+ }
+ if eip, box, ok := m.Home("shop.example.com"); !ok || box != "carol" || eip != "198.51.100.10" {
+ t.Fatalf("Home(shop.example.com) = %q %q %v, want carol's", eip, box, ok)
+ }
+ if m.KnownHost("evil.example.com") {
+ t.Fatal("KnownHost admitted a name published only by a body that does not match its key")
+ }
+ if e.deploymentHost("evil.example.com") {
+ t.Fatal("deploymentHost (the ACME gate) admitted a name published only by a body that does not match its key")
+ }
+}
+
+// Vouch, never revoke. annie's file is live and routes shop.example.com;
+// then the body at annie's key is replaced by one naming box mallory and
+// mallory's address. The refresh succeeds (one bad object is not a bad
+// poll), annie's last good parse is carried forward, and the dial and the
+// admission stay exactly as they were, while the forged body's new name is
+// admitted nowhere. When the key's publisher writes a matching body again,
+// it is believed again.
+func TestHomeMapKeyBoundReplacedBodyLeavesTheLiveTargetAlone(t *testing.T) {
+ s := meshTestStore(t)
+ putJSON(t, s, "control/edges/annie.json", `{"v":1,"box":"annie","eip":"198.51.100.10","hosts":{"shop.example.com":{"role":"home","platform":true,"account":"bab","app":"shop","stamp":7}}}`)
+ m := newHomeMap(s, "carol")
+ refreshHomeMap(t, m)
+ if eip, box, ok := m.Home("shop.example.com"); !ok || box != "annie" || eip != "198.51.100.10" {
+ t.Fatalf("precondition: Home(shop.example.com) = %q %q %v", eip, box, ok)
+ }
+ putJSON(t, s, "control/edges/annie.json", `{"v":1,"box":"mallory","eip":"203.0.113.66","hosts":{"shop.example.com":{"role":"home","platform":true,"account":"bab","app":"shop","stamp":9223372036854775807},"evil.example.com":{"role":"home","platform":true}}}`)
+ refreshHomeMap(t, m)
+ if eip, box, ok := m.Home("shop.example.com"); !ok || box != "annie" || eip != "198.51.100.10" {
+ t.Fatalf("after the forged body: Home(shop.example.com) = %q %q %v, want annie's last good parse carried forward", eip, box, ok)
+ }
+ if !m.KnownHost("shop.example.com") {
+ t.Fatal("the forged body cleared annie's live admission")
+ }
+ if m.KnownHost("evil.example.com") {
+ t.Fatal("the forged body's new name was admitted")
+ }
+ putJSON(t, s, "control/edges/annie.json", `{"v":1,"box":"annie","eip":"198.51.100.11","hosts":{"shop.example.com":{"role":"home","platform":true,"account":"bab","app":"shop","stamp":8}}}`)
+ refreshHomeMap(t, m)
+ if eip, box, ok := m.Home("shop.example.com"); !ok || box != "annie" || eip != "198.51.100.11" {
+ t.Fatalf("after the publisher's next matching body: Home(shop.example.com) = %q %q %v, want it believed again", eip, box, ok)
+ }
+}
diff --git a/internal/edge/hunt_H3-M4_test.go b/internal/edge/hunt_H3-M4_test.go
new file mode 100644
index 000000000..8e65fd2c5
--- /dev/null
+++ b/internal/edge/hunt_H3-M4_test.go
@@ -0,0 +1,36 @@
+package edge
+
+import "testing"
+
+// hunt H3-M4 (Opus verifier). annie really homes shop.example.com and
+// publishes control/edges/annie.json. Anyone who can write the deployment
+// bucket adds control/edges/zz.json naming a box that does not exist, an
+// address it controls and a stamp no real claim will reach. Every other edge
+// (carol here) folds it through the real Refresh -> refreshHosts ->
+// foldHomes, where dialBeats (homemap.go:834) lets the higher stamp take the
+// dial. SECURE: the dial target stays annie's.
+func TestHunt_H3_M4_ForgedEdgesFileTakesTheDial(t *testing.T) {
+ s := meshTestStore(t)
+ putJSON(t, s, "control/edges/annie.json", `{"v":1,"box":"annie","eip":"198.51.100.10","hosts":{"shop.example.com":{"role":"home","platform":true,"account":"bab","app":"shop","stamp":7}}}`)
+ putJSON(t, s, "control/edges/zz.json", `{"v":1,"box":"mallory","eip":"203.0.113.66","hosts":{"shop.example.com":{"role":"home","platform":true,"account":"bab","app":"shop","stamp":9223372036854775807}}}`)
+ m := newHomeMap(s, "carol")
+ refreshHomeMap(t, m)
+ eip, box, ok := m.Home("shop.example.com")
+ if !ok || box != "annie" || eip != "198.51.100.10" {
+ t.Fatalf("H3-M4: Home(shop.example.com) = %q %q %v; a file under control/edges/zz.json naming box %q took the dial from annie",
+ eip, box, ok, box)
+ }
+}
+
+// The object key and the body's box are never compared (parseEdgesFile,
+// homemap.go:653): a file under one box's key names another box. SECURE:
+// refused.
+func TestHunt_H3_M4_EdgesFileKeyAndBoxDisagree(t *testing.T) {
+ s := meshTestStore(t)
+ putJSON(t, s, "control/edges/annie.json", `{"v":1,"box":"mallory","eip":"203.0.113.66","hosts":{"blog.example.com":{"role":"home"}}}`)
+ m := newHomeMap(s, "carol")
+ refreshHomeMap(t, m)
+ if eip, box, ok := m.Home("blog.example.com"); ok {
+ t.Fatalf("H3-M4: control/edges/annie.json whose body says box %q was folded: Home = %q %q", box, eip, box)
+ }
+}
diff --git a/internal/edgesfile/edgesfile.go b/internal/edgesfile/edgesfile.go
index 10346696d..8c35b5e35 100644
--- a/internal/edgesfile/edgesfile.go
+++ b/internal/edgesfile/edgesfile.go
@@ -25,6 +25,7 @@ package edgesfile
import (
"encoding/json"
"fmt"
+ "strings"
)
// Prefix is the flat prefix every box's file lives under.
@@ -39,6 +40,30 @@ const RoleHome = "home"
// Key is the bucket key for box's file.
func Key(box string) string { return Prefix + box + ".json" }
+// BoxFromKey is Key's inverse: the box whose file lives at key, the <box>
+// of control/edges/<box>.json. ok is false for a key outside the prefix
+// and for every other shape under it (a nested key, one without the .json
+// suffix, an empty box), none of which this deployment's edges loop
+// writes.
+//
+// It is also the binding every reader checks a body against (hunt H3-M4).
+// The bucket's writer map lets a box write its own control/edges/<box>.json
+// and nothing else under the prefix, so the KEY is what names the publisher;
+// the body's box field is only the publisher's claim about itself. A body
+// whose box field disagrees with its key is not that box's publication,
+// whatever else it says, and nothing in it may be acted on.
+func BoxFromKey(key string) (box string, ok bool) {
+ name, ok := strings.CutPrefix(key, Prefix)
+ if !ok || strings.Contains(name, "/") {
+ return "", false
+ }
+ box, ok = strings.CutSuffix(name, ".json")
+ if !ok || box == "" {
+ return "", false
+ }
+ return box, true
+}
+
// Host is one per-host entry, decoded. Every mark is additive, and each
// defaults to false on a file written before that mark existed — but they
// fail in OPPOSITE directions, which is deliberate and load-bearing:
diff --git a/internal/edgesfile/edgesfile_test.go b/internal/edgesfile/edgesfile_test.go
index 2504b0ed1..438f39c12 100644
--- a/internal/edgesfile/edgesfile_test.go
+++ b/internal/edgesfile/edgesfile_test.go
@@ -47,3 +47,26 @@ func TestKeyIsThePrefixedBoxName(t *testing.T) {
t.Fatalf("Key = %q", got)
}
}
+
+// BoxFromKey is Key's inverse and the binding every reader checks a body
+// against (hunt H3-M4): only control/edges/<box>.json with a non-empty box
+// names a publisher. Every other shape is refused rather than guessed at.
+func TestBoxFromKeyIsKeysInverseAndRefusesEveryOtherShape(t *testing.T) {
+ if box, ok := BoxFromKey(Key("quiet-harbour")); !ok || box != "quiet-harbour" {
+ t.Fatalf("BoxFromKey(Key(quiet-harbour)) = %q %v, want quiet-harbour true", box, ok)
+ }
+ for _, key := range []string{
+ "control/edges/",
+ "control/edges/.json",
+ "control/edges/annie",
+ "control/edges/annie.json/",
+ "control/edges/nested/annie.json",
+ "control/certs/annie.json",
+ "annie.json",
+ "",
+ } {
+ if box, ok := BoxFromKey(key); ok {
+ t.Errorf("BoxFromKey(%q) = %q true, want refused", key, box)
+ }
+ }
+}
diff --git a/internal/host/steering_loop.go b/internal/host/steering_loop.go
index a13a55399..da761924b 100644
--- a/internal/host/steering_loop.go
+++ b/internal/host/steering_loop.go
@@ -7,6 +7,7 @@ package host
import (
"context"
+ "encoding/json"
"fmt"
"log"
"math/rand/v2"
@@ -15,6 +16,7 @@ import (
"strings"
"time"
+ "github.com/carlosframework/platform/internal/edgesfile"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
@@ -47,6 +49,19 @@ import (
// the same key-shape filter homeMap applies. A stray object under the prefix
// is not this deployment's edges file, and must not be able to fail the pass
// forever.
+//
+// A body that parses but whose box field names a box other than the one its
+// KEY names is refused, and it fails the pass (hunt H3-M4; the binding
+// internal/edge's parseEdgesFile applies, for the reason given there: the
+// writer map makes the key the publisher's identity and the body only its
+// claim). It is handled as a VISIBILITY fault rather than the fold's content
+// fault because of what each would do downstream: skipping the file would
+// leave the fold short of the box the key belongs to, and a short fold
+// withdraws that box's records, which is the revoke the forged body must
+// never be able to cause. Failing the pass leaves the zone, and every move
+// target moveTargets reads from the same bodies, exactly as they were. A
+// body that will not parse at all is still delivered verbatim (the fold's
+// business, as before).
func loadEdgesFileBodies(ctx context.Context, s release.Store) ([][]byte, error) {
keys, err := s.List(ctx, edgesFilePrefix)
if err != nil {
@@ -55,19 +70,35 @@ func loadEdgesFileBodies(ctx context.Context, s release.Store) ([][]byte, error)
sort.Strings(keys)
out := make([][]byte, 0, len(keys))
for _, key := range keys {
- name, ok := strings.CutPrefix(key, edgesFilePrefix)
- if !ok || !strings.HasSuffix(name, ".json") || strings.Contains(name, "/") {
+ box, ok := edgesfile.BoxFromKey(key)
+ if !ok {
continue
}
body, _, err := s.Get(ctx, key)
if err != nil {
return nil, fmt.Errorf("steering: read %s: %w", key, err)
}
+ if named, parsed := edgesBodyBox(body); parsed && named != box {
+ return nil, fmt.Errorf("steering: %s: body names box %q, not the box its key names", key, named)
+ }
out = append(out, body)
}
return out, nil
}
+// edgesBodyBox is the box field of an edges file body, and whether the body
+// was a JSON object at all. It reads nothing else: the rest of the body is
+// the fold's to judge.
+func edgesBodyBox(body []byte) (box string, parsed bool) {
+ var f struct {
+ Box string `json:"box"`
+ }
+ if err := json.Unmarshal(body, &f); err != nil {
+ return "", false
+ }
+ return f.Box, true
+}
+
// steeredRoutesFromRecords reads the deployment's steered hosts from the
// BUCKET RECORDS — provision.ListAllRecords — and never from this box's
// registry.
diff --git a/internal/host/steering_loop_test.go b/internal/host/steering_loop_test.go
index 6e2ba9add..a27f22a98 100644
--- a/internal/host/steering_loop_test.go
+++ b/internal/host/steering_loop_test.go
@@ -533,3 +533,29 @@ func TestSteeringLoopDormantWhenZoneMalformed(t *testing.T) {
t.Fatalf("log = %q, want the malformed id named loudly", buf.String())
}
}
+
+// A body whose box field names a box other than the one its key names (hunt
+// H3-M4) is a visibility fault: the pass fails closed, converge is never
+// called, and the error names the key and the body's box. Skipping the file
+// instead would have left the fold short of the key's box and withdrawn its
+// records on a forged body's word.
+func TestSteeringPassFailsClosedOnEdgesBodyNamingAnotherBox(t *testing.T) {
+ quietLog(t)
+ s := steeringTestStore(t, map[string][]byte{
+ "control/edges/dublin.json": []byte(`{"v":1,"box":"dublin"}`),
+ "control/edges/oregon.json": []byte(`{"v":1,"box":"mallory"}`),
+ })
+ seedAccount(t, s, 12, "Tito")
+ rec := &convergeRecorder{}
+
+ err := steeringPass(context.Background(), s, rec.converge)
+ if err == nil {
+ t.Fatal("steeringPass: nil error, want fail-closed on a body that does not match its key")
+ }
+ if !strings.Contains(err.Error(), "control/edges/oregon.json") || !strings.Contains(err.Error(), `"mallory"`) {
+ t.Fatalf("err = %v, want the key and the body's box named", err)
+ }
+ if rec.calls != 0 {
+ t.Fatalf("converge calls = %d, want 0 — a mismatched body must never reach the fold", rec.calls)
+ }
+}