edge: judge HA by the selected target only under a front route (#186)
Whole-branch review R1 P1-2: haRouteName switched routeHAIngress to the target's identity for any local path selection. Under a catch-all or an attached alias inheriting a prefix map, the target's HA handling (a refusal, a front forward) then answered before the ownership block that sends another account's exact name to its own box. haRouteName now uses the target only when FrontAccount is set: the front passed the front-route test. Case 1 sets it through isFrontRoute (the same test selectFromServedFront now calls), case 3's local target sets it from the checked home-map row. Every other front passes host, as main. TestPathAcrossHATargetDoesNotBeatExactName: the catch-all and attached alias precedence scenes with an HA target that refuses (blocked) and one that front-forwards; neither intercepts the foreign exact name, and a front route's prefix still gets the target's dispatch. Task 9's HA tests stay green. Spec rev 5.3 §5.7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+170
−22
docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md+8 −3internal/edge/haingress.go+3 −3internal/edge/path_across_ha_precedence_test.go+105 −0internal/edge/pathselect.go+35 −16internal/edge/pathselect_test.go+19 −0
diff --git a/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md b/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md| index 11cd8ae77..da8263509 100644 |
| --- a/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md |
| +++ b/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md |
| @@ -1,6 +1,6 @@ |
| # Path routes across boxes: a prefix whose target lives on another box |
| -Rev 5.3, 2026-11-21 (§7.2 cut by Paul during the build; §7.3 clarified; §5.1 import-gated fronts). Rev 5 approved by Paul 2026-11-19. Discussion #186. Builds on the path-routing design |
| +Rev 5.3, 2026-11-21 (§7.2 cut by Paul during the build; §7.3 clarified; §5.1 import-gated fronts; §5.7 HA identity under a front route only). Rev 5 approved by Paul 2026-11-19. Discussion #186. Builds on the path-routing design |
| (`2026-09-02-path-based-routing-design.md`, "the 09-02 design" below) and |
| changes none of its rulings except the one it was written to lift: §6's |
| "a prefix's target route must be homed on the same box as the hostname's |
| @@ -387,13 +387,18 @@ everywhere a request is dispatched: |
| Concretely: |
| -1. **A prefix selects T on any box.** H's HA dispatch does not run for this |
| +1. **A front route's prefix selects T on any box.** H's HA dispatch does not run for this |
| request; T's does, exactly as it would for a request whose `Host` were T. |
| Today `routeHAIngress` resolves HA metadata from the request's `Host` and |
| compares it with the local upstream (`haingress.go`), which is round 1 |
| P1-5; it and `frontForwardHA` take the selected route instead of |
| re-deriving it from `Host`. |
| -2. **No prefix selects.** H's HA dispatch runs exactly as today. |
| +2. **No prefix selects, or H is not a front route.** H's HA dispatch runs |
| + exactly as today. A front that is not a front route (§5.3: a catch-all, |
| + an attached alias inheriting a prefix map) keeps H's identity even when |
| + its prefix selects a same-box T, because HA dispatch runs before the |
| + ownership block, which may send H to another account's exact owner |
| + (whole-branch review R1 P1-2). |
| 3. **Every hop a path-selected request makes** (the cross-box hop of §5.4, |
| an HA front forward to T's lease holder, a holder or handover follow) |
| carries wire `Host` H and is keyed on T on the sending side. The |
diff --git a/internal/edge/haingress.go b/internal/edge/haingress.go| index 887b5ea1d..bc76730eb 100644 |
| --- a/internal/edge/haingress.go |
| +++ b/internal/edge/haingress.go |
| @@ -48,9 +48,9 @@ func (e *Edge) localPoolEligible(rt registry.Route) bool { |
| // carries and signs (moveGate, frontForwardHAIngress). routeName is the name |
| // whose route every HA decision here is judged under (path routes, spec |
| // §5.7): the HA ingress projection, the name resolution and its local claim, |
| -// and the blocked set. It is host, except when a prefix on host selected a |
| -// local target (requestSelection.haRouteName), when it is the target's route |
| -// host. A selected up is always the target route's own entry, never an alias |
| +// and the blocked set. It is host, except when a front route's prefix on |
| +// host selected a local target (requestSelection.haRouteName), when it is |
| +// the target's route host. A selected up is always the target route's own entry, never an alias |
| // (selectedEntry resolves a platform-alias target to its instance), so its |
| // claim class and the platform-alias exemptions below are exactly those of a |
| // request naming routeName. |
diff --git a/internal/edge/path_across_ha_precedence_test.go b/internal/edge/path_across_ha_precedence_test.go| new file mode 100644 |
| index 000000000..5602cd994 |
| --- /dev/null |
| +++ b/internal/edge/path_across_ha_precedence_test.go |
| @@ -0,0 +1,105 @@ |
| +package edge |
| + |
| +// Whole-branch review R1 P1-2: a selected target's HA identity is used only |
| +// under a front route. A catch-all or an attached alias that inherits a |
| +// prefix map is not a front route (spec §5.3), so when its prefix selects a |
| +// local HA target T, region HA is judged under the request's own name, as on |
| +// main, and the ownership block still sends another account's exact name to |
| +// its own box: T's HA handling (a refusal, a front forward) never answers |
| +// for that name first. pathAcrossHAScene's boxes: B serves T (born-HA) and |
| +// the shared front; C serves another account's exact other.example. |
| + |
| +import ( |
| + "net/http" |
| + "net/http/httptest" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// sharedFrontOnTenant gives B a front for other.example that is not a front |
| +// route and whose prefix acme selects T here: a catch-all *.example of |
| +// wild.example (wildcard), or other.example as an attached alias of |
| +// prim.example (alias). Either way the front's own app is returned. |
| +func (s *pathAcrossHAScene) sharedFrontOnTenant(t *testing.T, kind, other string) *acrossApp { |
| + t.Helper() |
| + const primary = "prim.example" |
| + app := newAcrossApp(t, "prim-1") |
| + s.route(t, s.tenant, acrossInstance(primary, acrossAcct, "prim", app.addr())) |
| + alias := registry.RouteAlias{Alias: other, Host: primary, Account: acrossAcct, App: "prim"} |
| + if kind == "wildcard" { |
| + alias.Alias = "*.example" |
| + } |
| + if err := s.tenant.reg.UpsertAlias(alias); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.path(t, s.tenant, primary, acrossPrefix, acrossTenant, acrossAcct, "prim") |
| + sel := s.tenant.edge.selectUpstream(httptest.NewRequest(http.MethodGet, "https://"+other+"/acme/x", nil), other, "/acme/x") |
| + if !sel.OK || !sel.LocalTarget || sel.Up.route.Host != acrossTenant || sel.FrontAccount != "" { |
| + t.Fatalf("fixture: %s on B does not select the local HA target through a non-front name: %+v", other, sel) |
| + } |
| + return app |
| +} |
| + |
| +// The catch-all and attached-alias precedence tests (TestPathAcross |
| +// WildcardDoesNotBeatExactName, TestPathAcrossAttachedAliasDoesNotBeatExactName) |
| +// with T born-HA on B: once refusing (blocked) and once front-forwarding |
| +// (its lease on A, the projection's pool not B's row's). A front route's prefix to T gets |
| +// T's dispatch (the control); another account's exact name reaching B |
| +// through the catch-all or the alias goes to its own box C, and T's HA |
| +// handling never runs for it. |
| +func TestPathAcrossHATargetDoesNotBeatExactName(t *testing.T) { |
| + const other = "other.example" |
| + for _, kind := range []string{"wildcard", "alias"} { |
| + for _, mode := range []string{"refuses", "forwards"} { |
| + t.Run(kind+"/"+mode, func(t *testing.T) { |
| + // forwards: A holds T's lease and B's HA projection places T |
| + // in another pool than B's row, so T's dispatch on B would |
| + // front-forward to A; refuses: B holds it but T is in B's |
| + // blocked set, so T's dispatch would answer 503. |
| + holder := "betty" |
| + if mode == "forwards" { |
| + holder = "annie" |
| + } |
| + s := newPathAcrossHAScene(t, acrossHAOpts{target: true, tHolder: holder}) |
| + if mode == "forwards" { |
| + moved := acrossHARoute(acrossTenant, "tenant", "ha-moved") |
| + s.lookups[s.tenant].set(acrossTenant, moved) |
| + } |
| + s.ca.publish(t, s.store, other) |
| + otherApp := newAcrossApp(t, "other-1") |
| + s.route(t, s.third, acrossInstance(other, acrossOther, "other", otherApp.addr())) |
| + s.publish(t, s.third, other, acrossRouteEntry(acrossOther, "other", 5)) |
| + primApp := s.sharedFrontOnTenant(t, kind, other) |
| + if mode == "refuses" { |
| + block(s.tenant, acrossTenant) |
| + } |
| + // Control: T's own dispatch on B is armed. |
| + res := s.get(t, s.tenant, acrossHub, "/acme/control") |
| + if mode == "refuses" && res.code != http.StatusServiceUnavailable { |
| + t.Fatalf("control: a front route's prefix to blocked T answered %d %q, want T's HA refusal", res.code, res.body) |
| + } |
| + if mode == "forwards" && s.forwardsTo(acrossIPHub) != 1 { |
| + t.Fatalf("control: a front route's prefix to T made %d front forwards to A, want 1", s.forwardsTo(acrossIPHub)) |
| + } |
| + forwards := s.forwardsAny() |
| + s.acts[s.tenant].mu.Lock() |
| + s.acts[s.tenant].asked = nil |
| + s.acts[s.tenant].mu.Unlock() |
| + |
| + s.get(t, s.tenant, other, "/acme/x").want(t, http.StatusOK, "other-1|"+other+"|/acme/x") |
| + otherApp.wantSeen(t, acrossSeen{other, "/acme/x"}) |
| + primApp.wantSeen(t) |
| + s.tenantApp.wantSeen(t) |
| + asked, _, _ := s.acts[s.tenant].record() |
| + wantNames(t, "routes B's forwarder was asked about", asked) |
| + if n := s.forwardsAny() - forwards; n != 0 { |
| + t.Fatalf("%d front forwards for %s, want 0", n, other) |
| + } |
| + if n := s.dialsFrom(s.tenant, acrossIPThird); n < 1 { |
| + t.Fatalf("B dialled C %d times, want the backhaul to %s's owner", n, other) |
| + } |
| + }) |
| + } |
| + } |
| +} |
diff --git a/internal/edge/pathselect.go b/internal/edge/pathselect.go| index 8efd938ed..ca2563f50 100644 |
| --- a/internal/edge/pathselect.go |
| +++ b/internal/edge/pathselect.go |
| @@ -50,13 +50,13 @@ type requestSelection struct { |
| Prefix string // the matched prefix, whenever one matched |
| Target string // the matched target host, whenever one matched |
| // FrontAccount: set only when the front passed the front-route test |
| - // that lets its prefix select across boxes (case 2's in |
| - // selectFromServedFront, case 3's in selectForUnservedFront) and Prefix |
| - // is that front's match: the prefix map's account. Empty for every |
| - // front that may never send a prefix across (an alias, a platform |
| - // alias, a regional name, a catch-all, a non-PathFront route) and for a |
| - // door call. Kept on a verified hop's fallback. The login refusal reads |
| - // it (loginTargetAcross). |
| + // (isFrontRoute for case 1 and case 2, the home map's row in |
| + // selectForUnservedFront for case 3) and Prefix is that front's match: |
| + // the prefix map's account. Empty for every front that may never send |
| + // a prefix across (an alias, a platform alias, a regional name, a |
| + // catch-all, a non-PathFront route) and for a door call's cases 2 and 3 |
| + // (a door call never selects across boxes). Kept on a verified hop's |
| + // fallback. The login refusal and the HA identity (haRouteName) read it. |
| FrontAccount string |
| // LocalTarget: Up is the matched target's own entry, served here (case 1 |
| // or case 3). The ONLY signal downstream consumers (HA identity, login) |
| @@ -92,12 +92,18 @@ func (s requestSelection) sameBox() (upstream, bool) { |
| // haRouteName is the name whose route every region HA decision for this |
| // request is judged under (spec §5.7; routeHAIngress): the selected target's |
| -// route host when a prefix selected a local target (case 1 or case 3; a |
| -// platform-alias target was resolved to its instance's own entry by |
| -// selectedEntry), else host, the request's own name. A Remote selection never reaches HA |
| -// dispatch here (servePathRemote answers it first). |
| +// route host when a front route's prefix selected a local target (case 1 or |
| +// case 3, FrontAccount set; a platform-alias target was resolved to its |
| +// instance's own entry by selectedEntry), else host, the request's own name, |
| +// exactly as before path routes crossed boxes. A front that is not a front |
| +// route (a catch-all, an attached alias inheriting a prefix map) keeps |
| +// host: ServeHTTP runs HA dispatch before the ownership block, so judging |
| +// it under the target would let the target's HA answer (a refusal, a front |
| +// forward) for another account's exact name that the ownership block sends |
| +// to its own box (whole-branch review R1 P1-2). A Remote selection never |
| +// reaches HA dispatch here (servePathRemote answers it first). |
| func (s requestSelection) haRouteName(host string) string { |
| - if s.LocalTarget { |
| + if s.LocalTarget && s.FrontAccount != "" { |
| return s.Up.route.Host |
| } |
| return host |
| @@ -134,7 +140,11 @@ func (e *Edge) selectUpstream(r *http.Request, host, urlPath string) requestSele |
| _, mapped := t.remote[host] |
| shadowed := ok && !exact && mapped |
| if local && !shadowed { |
| - return requestSelection{Up: up, OK: true, Prefix: prefix, Target: target, LocalTarget: true, Front: front, FrontOK: true, sameBoxUp: up, sameBoxOK: true} |
| + sel := requestSelection{Up: up, OK: true, Prefix: prefix, Target: target, LocalTarget: true, Front: front, FrontOK: true, sameBoxUp: up, sameBoxOK: true} |
| + if isFrontRoute(t, host, front) { |
| + sel.FrontAccount = release.RouteAccount(front.route) |
| + } |
| + return sel |
| } |
| _, door := doorCallerFrom(ctx) |
| sel := e.selectAcross(t, host, urlPath, pathHit{up: up, ok: ok, prefix: prefix, target: target, local: local, shadowed: shadowed}, door, hopDoorFrom(ctx)) |
| @@ -402,8 +412,7 @@ func (e *Edge) selectAcross(t *routeTable, host, urlPath string, h pathHit, door |
| // route's own exact name satisfying PathFront and the home map's exact row |
| // for the target satisfies PathTarget in the front route's account. |
| func (e *Edge) selectFromServedFront(t *routeTable, host string, front upstream, prefix, target string, stay requestSelection) requestSelection { |
| - if _, exact := t.hosts[host]; !exact || front.alias || front.platformAlias || front.regional != regionalNone || |
| - front.route.Host != host || !registry.PathFront(front.route) { |
| + if !isFrontRoute(t, host, front) { |
| e.pathSkip(servedName(t, host), fmt.Sprintf("prefix %q names %s, which is not on this box, and only a route's own exact name (an instance or static route) sends a prefix to another box; the host's own route answers", |
| prefix, target)) |
| return stay |
| @@ -422,6 +431,16 @@ func (e *Edge) selectFromServedFront(t *routeTable, host string, front upstream, |
| return requestSelection{Remote: &remoteTarget{Target: target, Route: info}, Prefix: prefix, Target: target, FrontAccount: account} |
| } |
| +// isFrontRoute is the front-route test on a box that serves host (spec |
| +// §5.3), for cases 1 and 2: front, pathMatch's entry for host, is host's own |
| +// exact entry (never a catch-all, an alias, a platform alias or a regional |
| +// entry) and its route satisfies registry.PathFront. |
| +func isFrontRoute(t *routeTable, host string, front upstream) bool { |
| + _, exact := t.hosts[host] |
| + return exact && !front.alias && !front.platformAlias && front.regional == regionalNone && |
| + front.route.Host == host && registry.PathFront(front.route) |
| +} |
| + |
| // selectForUnservedFront is case 3: this box does not serve host exactly |
| // (nothing, or only a catch-all, answers it here), and holds its remote map. |
| // The home map's exact row for host must be a front route of the map's own |
| @@ -452,7 +471,7 @@ func (e *Edge) selectForUnservedFront(t *routeTable, host, urlPath string, rm re |
| return stay |
| } |
| tu.front = &frontMark{Host: host, Account: fi.Account, App: fi.App, Stamp: fi.Stamp, Incarnation: fi.Incarnation} |
| - return requestSelection{Up: tu, OK: true, Prefix: prefix, Target: target, LocalTarget: true} |
| + return requestSelection{Up: tu, OK: true, Prefix: prefix, Target: target, LocalTarget: true, FrontAccount: rm.account} |
| } |
| info, ok := homes.exactPathRoute(target) |
| if !ok || !info.Target || info.Account != rm.account { |
diff --git a/internal/edge/pathselect_test.go b/internal/edge/pathselect_test.go| index 9bb4ce3c8..5c47e188a 100644 |
| --- a/internal/edge/pathselect_test.go |
| +++ b/internal/edge/pathselect_test.go |
| @@ -174,6 +174,10 @@ func TestSelectCase1LocalTarget(t *testing.T) { |
| if got.Up.front != nil { |
| t.Errorf("a same-box target carries a front mark: %+v", got.Up.front) |
| } |
| + // A front route: its target's HA identity (spec §5.7). |
| + if got.FrontAccount != selAcct || got.haRouteName(selFront) != selTarget { |
| + t.Errorf("front account %q, HA name %q; want %q, %q", got.FrontAccount, got.haRouteName(selFront), selAcct, selTarget) |
| + } |
| got = s.sel(selFront, "/other") |
| wantFront(t, got, selFront) |
| if got.Prefix != "" || got.Target != "" { |
| @@ -362,6 +366,9 @@ func TestSelectCase3LocalTarget(t *testing.T) { |
| if got.Up.front == nil || *got.Up.front != want { |
| t.Errorf("front mark = %+v, want %+v", got.Up.front, want) |
| } |
| + if got.FrontAccount != selAcct || got.haRouteName(selFront) != selTarget { |
| + t.Errorf("front account %q, HA name %q; want %q, %q", got.FrontAccount, got.haRouteName(selFront), selAcct, selTarget) |
| + } |
| } |
| func TestSelectCase3LocalTargetOtherAccount(t *testing.T) { |
| @@ -543,6 +550,18 @@ func TestSelectAliasFrontNeverAcross(t *testing.T) { |
| if !got.Up.alias { |
| t.Error("the alias's own entry was not answered") |
| } |
| + // An alias's prefix selecting a same-box target is not a front route's: |
| + // HA is judged under the request's own name (review R1 P1-2). |
| + s.instance("near.example.com", selAcct, "near") |
| + s.path(selFront, "near", "near.example.com", selAcct, "hub") |
| + if err := s.e.Reload(); err != nil { |
| + t.Fatal(err) |
| + } |
| + got = s.sel("www.hub.example.com", "/near") |
| + wantLocal(t, got, "near.example.com", "near", "near.example.com") |
| + if got.FrontAccount != "" || got.haRouteName("www.hub.example.com") != "www.hub.example.com" { |
| + t.Errorf("an alias front: front account %q, HA name %q; want none and the alias", got.FrontAccount, got.haRouteName("www.hub.example.com")) |
| + } |
| } |
| // A forward route is never a target: published (its marks are false) or |