carlos / platform Public

edge: a platform-alias path target is its instance (#186)

Task 9 fix round 1 (Astra R1 P1-1, P1-2; Paul's structural rule).
selectedEntry, in selection, resolves a matched platform-alias target to
its instance's own entry (same instance, not itself an alias) in case 1
and case 3 alike; each case then applies its own eligibility. No selected
Up carries platformAlias, so a box holding I's lease re-selects I for a
hop another box sent under I, and routeHAIngress judges a selected target
exactly as a request naming it. The routeName == host inference in
routeHAIngress is gone.

Front-forward log lines name wire host and route (hopName). Tests: the
alias-versus-instance dispatch guard over five placements, the catch-all
fallback test, and the blocked control's HA refusal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c33eebbc2ed0ca62f7cbc974ce1a78023bfff217 parent 3eb45b1
5 files changed, +261 −52
  • internal/edge/forwardha.go +12 −6
  • internal/edge/haingress.go +7 −9
  • internal/edge/path_across_ha_test.go +200 −26
  • internal/edge/pathselect.go +36 −6
  • internal/edge/pathselect_test.go +6 −5
diff --git a/internal/edge/forwardha.go b/internal/edge/forwardha.go
index d6b991e62..96d08804d 100644
--- a/internal/edge/forwardha.go
+++ b/internal/edge/forwardha.go
@@ -304,7 +304,7 @@ func (e *Edge) forwardHAFollow(w http.ResponseWriter, r *http.Request, host stri
if next.here {
return ForwardResult{Outcome: ForwardNotInView, Ref: next.ref, Gen: d.Gen, Kind: d.Kind, PeerGen: d.PeerGen}, true
}
- e.logThrottled("forward-handover "+next.ref, fmt.Sprintf("forward %s: %s handed the request over to %s; sending it there", host, d.Ref, next.ref))
+ e.logThrottled("forward-handover "+next.ref, fmt.Sprintf("forward %s: %s handed the request over to %s; sending it there", hopName(host, rt.Host), d.Ref, next.ref))
second := &forwardAttempt{rt: rt, orig: at.orig, whole: at.whole}
return e.forwardHANoted(w, r, host, rt, fw, ForwardDecision{Ref: next.ref, Kind: Holder}, second), false
}
@@ -352,6 +352,12 @@ func (e *Edge) forwardHA(w http.ResponseWriter, r *http.Request, host string, d
// included, is relayed as today, without the handover header.
func (e *Edge) forwardHAObserved(w http.ResponseWriter, r *http.Request, host string, d ForwardDecision, note func(ForwardResult), at *forwardAttempt) ForwardResult {
ref := d.Ref
+ // name is how the log lines below name what the forward carries: the
+ // wire host, and the route too when they differ (a path hop, hopName).
+ name := host
+ if at != nil {
+ name = hopName(host, at.rt.Host)
+ }
res := ForwardResult{Outcome: ForwardNotInView, Ref: ref, Gen: d.Gen, Kind: d.Kind, PeerGen: d.PeerGen}
m := e.homes.Load()
if m == nil || hopVerified(r.Context()) {
@@ -363,7 +369,7 @@ func (e *Edge) forwardHAObserved(w http.ResponseWriter, r *http.Request, host st
}
key := signingKey(m.meshKeys())
if len(key) == 0 {
- e.logThrottled("forward-no-mesh-key", fmt.Sprintf("%s is held on %s but no mesh key is mirrored; serving here", host, ref))
+ e.logThrottled("forward-no-mesh-key", fmt.Sprintf("%s is held on %s but no mesh key is mirrored; serving here", name, ref))
return res
}
res.Outcome = ForwardDone
@@ -389,7 +395,7 @@ func (e *Edge) forwardHAObserved(w http.ResponseWriter, r *http.Request, host st
if r.Context().Err() != nil {
res.Outcome = ForwardCanceled
}
- e.logThrottled("forward-error "+ref, fmt.Sprintf("forward %s → %s: reading the request body: %v", host, ref, err))
+ e.logThrottled("forward-error "+ref, fmt.Sprintf("forward %s → %s: reading the request body: %v", name, ref, err))
w.WriteHeader(http.StatusBadGateway)
return res
}
@@ -428,18 +434,18 @@ func (e *Edge) forwardHAObserved(w http.ResponseWriter, r *http.Request, host st
}
var connect *forwardConnectError
if errors.Is(err, errForwardDialQueued) && r.Context().Err() == nil {
- e.logThrottled("forward-queued "+ref, fmt.Sprintf("forward %s → %s (%s): %v; answering 503 + Retry-After: 10", host, ref, dial, err))
+ e.logThrottled("forward-queued "+ref, fmt.Sprintf("forward %s → %s (%s): %v; answering 503 + Retry-After: 10", name, ref, dial, err))
answerHolderUnreachable(w, r)
return
}
if errors.As(err, &connect) && r.Context().Err() == nil {
- e.logThrottled("forward-unreachable "+ref, fmt.Sprintf("forward %s → %s (%s): %v; answering 503 + Retry-After: 10", host, ref, dial, err))
+ e.logThrottled("forward-unreachable "+ref, fmt.Sprintf("forward %s → %s (%s): %v; answering 503 + Retry-After: 10", name, ref, dial, err))
res.Outcome = ForwardUnreachable
answerHolderUnreachable(w, r)
return
}
// After connecting, or the client left: backhaul's bad gateway.
- e.logThrottled("forward-error "+ref, fmt.Sprintf("forward %s → %s (%s): %v", host, ref, dial, err))
+ e.logThrottled("forward-error "+ref, fmt.Sprintf("forward %s → %s (%s): %v", name, ref, dial, err))
w.WriteHeader(http.StatusBadGateway)
}
// A body that is not copied streams as today, watched for its end
diff --git a/internal/edge/haingress.go b/internal/edge/haingress.go
index 95e97e52f..887b5ea1d 100644
--- a/internal/edge/haingress.go
+++ b/internal/edge/haingress.go
@@ -50,13 +50,11 @@ func (e *Edge) localPoolEligible(rt registry.Route) bool {
// §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 platform-alias target's is its instance's. A selected target is
-// judged as a request naming routeName is: claimed as its own route, and
-// without the platform alias's exemptions, which belong to a request naming
-// the alias (its entry is how the target was reached, not its identity).
+// 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.
func (e *Edge) routeHAIngress(w http.ResponseWriter, r *http.Request, host, routeName string, up upstream, local bool) bool {
- named := routeName == host
- viaPlatformAlias := up.platformAlias && named
rt, known := e.ingressRoute(routeName)
var claims []edgesfile.NameClaim
if local {
@@ -66,7 +64,7 @@ func (e *Edge) routeHAIngress(w http.ResponseWriter, r *http.Request, host, rout
}
class := edgesfile.NameRoute
target := ""
- if up.alias && named {
+ if up.alias {
class = edgesfile.NameAlias
target = up.route.Host
}
@@ -97,14 +95,14 @@ func (e *Edge) routeHAIngress(w http.ResponseWriter, r *http.Request, host, rout
}
rt, known = e.ingressRoute(primary)
}
- if local && (!up.hibernating || up.route.IsForward() || viaPlatformAlias || up.viaTunnel) && known && rt.Host == "" {
+ if local && (!up.hibernating || up.route.IsForward() || up.platformAlias || up.viaTunnel) && known && rt.Host == "" {
return false
}
if local && up.route.HA && e.localPoolEligible(up.route) && (!known || rt.Host == "" || !rt.HA) {
return false
}
if !known {
- if local && up.hibernating && !up.route.IsForward() && !viaPlatformAlias && !up.viaTunnel && !e.localPoolEligible(up.route) {
+ if local && up.hibernating && !up.route.IsForward() && !up.platformAlias && !up.viaTunnel && !e.localPoolEligible(up.route) {
HAUnavailableResponse(w, r)
return true
}
diff --git a/internal/edge/path_across_ha_test.go b/internal/edge/path_across_ha_test.go
index db565a270..2daebb5a8 100644
--- a/internal/edge/path_across_ha_test.go
+++ b/internal/edge/path_across_ha_test.go
@@ -28,6 +28,7 @@ import (
"net"
"net/http"
"net/http/httptest"
+ "reflect"
"slices"
"strings"
"sync"
@@ -184,6 +185,8 @@ type pathAcrossHAScene struct {
lookups map[*backhaulEdge]*acrossHALookup
// forwards counts front-forward dials per destination IP.
forwards sync.Map
+ // forwardDown fails every front-forward dial, as a refused connection.
+ forwardDown atomic.Bool
}
// acrossHARoute is a born-HA instance route of the across account.
@@ -220,6 +223,9 @@ func newPathAcrossHAScene(t *testing.T, o acrossHAOpts) *pathAcrossHAScene {
}
n, _ := s.forwards.LoadOrStore(ip, new(atomic.Int64))
n.(*atomic.Int64).Add(1)
+ if s.forwardDown.Load() {
+ return nil, errors.New("connection refused")
+ }
var d net.Dialer
return d.DialContext(ctx, network, byIP[ip])
}
@@ -484,7 +490,10 @@ func TestPathAcrossHAFrontLocalTargetSkipsFrontHA(t *testing.T) {
t.Fatalf("A sent %d requests elsewhere, want 0", n)
}
// Control: with no prefix, H's own dispatch refuses or forwards.
- s.get(t, s.hub, acrossHub, "/other")
+ res := s.get(t, s.hub, acrossHub, "/other")
+ if tc.blocked && (res.code != http.StatusServiceUnavailable || res.header.Get(holderHeader) != "none") {
+ t.Fatalf("blocked front, no prefix: %d %v %q, want the HA refusal", res.code, res.header, res.body)
+ }
s.hubApp.wantSeen(t)
nearApp.wantSeen(t, acrossSeen{acrossHub, "/near/x"})
if !tc.blocked {
@@ -594,36 +603,201 @@ func TestPathAcrossHAFrontPlatformAliasTarget(t *testing.T) {
}
}
-// A selected platform-alias target is judged as its instance I, as a request
-// naming I is: an unavailable (zero) projection for I refuses it, and so
-// does no projection on a box outside I's pool. The platform alias's own
-// exemptions (TestHAIngressZeroProjectionPreservesUnmanagedUpstream,
-// TestPoolGateCannotFallBackLocal) belong to a request naming the alias.
-func TestPathAcrossHASelectedAliasZeroProjection(t *testing.T) {
- for _, known := range []bool{true, false} {
- t.Run(fmt.Sprintf("projection known=%v", known), func(t *testing.T) {
- selectedAliasJudgedAsInstance(t, known)
- })
+// The catch-all fallback is the selected route's: a target whose exact name
+// has no projection is judged by its own parent's catch-all, never by the
+// front's. Only *.target.test is projected (born-HA), so the request is
+// HA-dispatched (here refused by the forwarder) and *.forward.test, the
+// front's parent, is never asked.
+func TestPathAcrossHACatchAllIsTheRoute(t *testing.T) {
+ const front, target = "front.forward.test", "app.target.test"
+ act := &fwAct{unavailable: true}
+ x := newFwScene(t, fwOpts{aAct: act})
+ l := &acrossHALookup{routes: map[string]registry.Route{
+ "*.target.test": {Host: "wild.target.test", Kind: "instance", Account: "abc", App: "shop", Pool: "ha", HA: true, Hibernate: true},
+ }}
+ x.a.edge.SetHAIngressLookup(l.lookup)
+ w := httptest.NewRecorder()
+ if !x.a.edge.routeHAIngress(w, httptest.NewRequest(http.MethodGet, "https://"+front+"/acme/", nil), front, target, upstream{}, false) {
+ t.Fatalf("not HA-dispatched (answered %d); names asked %v", w.Code, l.names())
+ }
+ if w.Code != http.StatusServiceUnavailable || act.asked.Load() != 1 {
+ t.Fatalf("answered %d, forwarder asked %d times; want 503 after one question", w.Code, act.asked.Load())
+ }
+ if got := l.names(); slices.Contains(got, "*.forward.test") || !slices.Contains(got, "*.target.test") {
+ t.Fatalf("names asked %v, want *.target.test and never *.forward.test", got)
}
}
-func selectedAliasJudgedAsInstance(t *testing.T, known bool) {
- const front, alias = "front.forward.test", "shop.forward.test"
- x := newFwScene(t, fwOpts{aAct: &ingressForwarder{&fwAct{}}})
- x.a.edge.SetHAIngressLookup(func(string) (registry.Route, bool) { return registry.Route{}, known })
- up := upstream{route: registry.Route{Host: fwHost, Kind: "instance", Hibernate: true, Provisioned: true}, hibernating: true, alias: true, platformAlias: true}
+// ---- a platform-alias target is its instance -------------------------------
- w := httptest.NewRecorder()
- if x.a.edge.routeHAIngress(w, httptest.NewRequest(http.MethodGet, "https://"+alias+"/", nil), alias, alias, up, true) {
- t.Fatalf("a request naming the platform alias was answered %d", w.Code)
+const (
+ guardInst = "i.bae.oncarlos.example" // the born-HA instance I
+ guardAlias = "shop.bae.oncarlos.example" // its platform alias P
+)
+
+// aliasInstance puts I (born-HA, pool "shop", on a unix socket whose backend
+// answers "inst-<box>") and its platform alias P on be, projects I on every
+// box and names holder as I's lease holder everywhere.
+func (s *pathAcrossHAScene) aliasInstance(t *testing.T, be *backhaulEdge, holder string) {
+ t.Helper()
+ backend := rgSocketBackend(t, shortSockDir(t), "inst-"+be.box)
+ irt := acrossHARoute(guardInst, "shop", "shop")
+ irt.Socket = backend.sock
+ for _, other := range s.boxes() {
+ s.lookups[other].set(guardInst, irt)
+ a := s.acts[other]
+ a.mu.Lock()
+ a.holders[guardInst] = holder
+ a.mu.Unlock()
+ }
+ s.haRoute(t, be, irt)
+ prt := acrossInstance(guardAlias, acrossAcct, "shop", "")
+ prt.Socket, prt.Platform = backend.sock, true
+ s.route(t, be, prt)
+ if up := be.edge.current()[guardAlias]; !up.platformAlias || up.route.Host != guardInst {
+ t.Fatalf("fixture: %s on %s is not a platform alias of %s: %+v", guardAlias, be.box, guardInst, up)
}
- w = httptest.NewRecorder()
- if !x.a.edge.routeHAIngress(w, httptest.NewRequest(http.MethodGet, "https://"+front+"/shop/", nil), front, fwHost, up, true) || w.Code != http.StatusServiceUnavailable {
- t.Fatalf("the alias selected for %s, judged as %s: answered %d, want the HA refusal", front, fwHost, w.Code)
+}
+
+// guardPaths gives front, on every box, the prefixes "shop" (the alias P)
+// and "inst" (the instance I itself), as a claim of account bae, app.
+func (s *pathAcrossHAScene) guardPaths(t *testing.T, front, app string) {
+ t.Helper()
+ for _, be := range s.boxes() {
+ s.path(t, be, front, "shop", guardAlias, acrossAcct, app)
+ s.path(t, be, front, "inst", guardInst, acrossAcct, app)
+ }
+}
+
+// haTrace is everything one request did across the scene: the answer, and
+// per box the requests received, the HA routes its forwarder and activator
+// were asked about and the backhaul holder it holds for I.
+type haTrace struct {
+ Code int
+ Body string
+ Holder string
+ Calls map[string]int64
+ Asked map[string][]string
+ Served map[string][]string
+ Holders map[string]string
+}
+
+func (s *pathAcrossHAScene) trace(t *testing.T, from *backhaulEdge, host, path string) haTrace {
+ t.Helper()
+ res := s.get(t, from, host, path)
+ tr := haTrace{Code: res.code, Body: res.body, Holder: res.header.Get(holderHeader),
+ Calls: map[string]int64{}, Asked: map[string][]string{}, Served: map[string][]string{}, Holders: map[string]string{}}
+ for _, be := range s.boxes() {
+ tr.Calls[be.box] = be.calls.Load()
+ asked, served, _ := s.acts[be].record()
+ tr.Asked[be.box], tr.Served[be.box] = asked, served
+ tr.Holders[be.box] = heldHolder(be, guardInst)
+ }
+ return tr
+}
+
+// The structural rule (fix round 1, Paul): a platform-alias target is its
+// instance, decided once in selection on every box. For each placement, a
+// request through the alias P and one through a prefix naming I directly are
+// dispatched identically: the same backend, the same HA questions on every
+// box, the same answer and the same holder learned. Each request runs on a
+// fresh scene.
+func TestPathAcrossHAPlatformAliasIsItsInstance(t *testing.T) {
+ type placement struct {
+ name string
+ front string
+ want string // the serving backend's body
+ build func(t *testing.T, s *pathAcrossHAScene) *backhaulEdge
+ }
+ for _, p := range []placement{
+ {"same box", acrossHub, "inst-annie", func(t *testing.T, s *pathAcrossHAScene) *backhaulEdge {
+ s.aliasInstance(t, s.hub, "annie")
+ s.guardPaths(t, acrossHub, "hub")
+ return s.hub
+ }},
+ {"case 3 on the target's box", acrossHub, "inst-betty", func(t *testing.T, s *pathAcrossHAScene) *backhaulEdge {
+ s.aliasInstance(t, s.tenant, "betty")
+ s.guardPaths(t, acrossHub, "hub")
+ return s.tenant
+ }},
+ // Astra R1 P1-1: H only on A; P and I on A and B; B holds I.
+ {"lease on another pool box", acrossHub, "inst-betty", func(t *testing.T, s *pathAcrossHAScene) *backhaulEdge {
+ s.aliasInstance(t, s.hub, "betty")
+ s.aliasInstance(t, s.tenant, "betty")
+ s.guardPaths(t, acrossHub, "hub")
+ return s.hub
+ }},
+ {"front is the instance, lease on another pool box", guardInst, "inst-betty", func(t *testing.T, s *pathAcrossHAScene) *backhaulEdge {
+ s.instanceFront(t)
+ s.aliasInstance(t, s.hub, "betty")
+ s.aliasInstance(t, s.tenant, "betty")
+ s.guardPaths(t, guardInst, "shop")
+ return s.hub
+ }},
+ // Astra R1 P1-2: H == I, and a peer that is not admitted publishes
+ // I in its own lifetime: I's local route claim serves it.
+ {"front is the instance, held peer claim", guardInst, "inst-annie", func(t *testing.T, s *pathAcrossHAScene) *backhaulEdge {
+ s.instanceFront(t)
+ s.aliasInstance(t, s.hub, "annie")
+ s.guardPaths(t, guardInst, "shop")
+ s.files["cindy"][guardInst] = fmt.Sprintf(`{"role":"home","account":%q,"app":"shop","stamp":7,"incarnation":1}`, acrossAcct)
+ putJSON(t, s.store, "control/edges/cindy.json", strings.Replace(s.fileBody(s.third), `"admitted":true`, `"admitted":false`, 1))
+ s.refresh(t)
+ return s.hub
+ }},
+ } {
+ t.Run(p.name, func(t *testing.T) {
+ run := func(prefix string) haTrace {
+ s := newPathAcrossHAScene(t, acrossHAOpts{})
+ from := p.build(t, s)
+ for _, be := range s.boxes() {
+ s.acts[be].record()
+ s.acts[be].reset()
+ be.calls.Store(0)
+ }
+ sel := from.edge.selectUpstream(httptest.NewRequest(http.MethodGet, "https://"+p.front+"/"+prefix+"/x", nil), p.front, "/"+prefix+"/x")
+ if !sel.OK || !sel.LocalTarget || sel.Up.alias || sel.Up.platformAlias || sel.Up.route.Host != guardInst {
+ t.Fatalf("/%s on %s: selection %s, want I's own entry as a local target", prefix, from.box, describeSel(sel))
+ }
+ return s.trace(t, from, p.front, "/"+prefix+"/x")
+ }
+ viaAlias, direct := run("shop"), run("inst")
+ if !reflect.DeepEqual(viaAlias, direct) {
+ t.Fatalf("through the alias:\n %+v\nthrough the instance:\n %+v", viaAlias, direct)
+ }
+ if viaAlias.Code != http.StatusOK || viaAlias.Body != p.want {
+ t.Fatalf("answer %d %q, want 200 %q", viaAlias.Code, viaAlias.Body, p.want)
+ }
+ })
}
- w = httptest.NewRecorder()
- up.alias, up.platformAlias = false, false
- if !x.a.edge.routeHAIngress(w, httptest.NewRequest(http.MethodGet, "https://"+fwHost+"/", nil), fwHost, fwHost, up, true) || w.Code != http.StatusServiceUnavailable {
- t.Fatalf("control: a request naming %s answered %d, want the HA refusal", fwHost, w.Code)
+}
+
+// instanceFront makes I a front: its certificate published and every box's
+// edges file naming A as I's front route (account bae, app shop).
+func (s *pathAcrossHAScene) instanceFront(t *testing.T) {
+ t.Helper()
+ s.ca.publish(t, s.store, guardInst)
+ s.publish(t, s.hub, guardInst, acrossRouteEntry(acrossAcct, "shop", 5))
+}
+
+func (a *acrossHAAct) reset() {
+ a.mu.Lock()
+ defer a.mu.Unlock()
+ a.asked, a.served, a.noted = nil, nil, nil
+}
+
+// A front forward's log lines name the wire host and the route it carries,
+// as a backhaul's do (hopName): C's forward of hub.example/acme to T's
+// holder B, which cannot be reached.
+func TestPathAcrossHAFrontForwardLogNamesRoute(t *testing.T) {
+ s := newPathAcrossHAScene(t, acrossHAOpts{target: true, tHolder: "betty"})
+ logs := captureLog(t)
+ s.forwardDown.Store(true)
+ res := s.get(t, s.third, acrossHub, "/acme/x")
+ if res.code != http.StatusServiceUnavailable || res.header.Get("Retry-After") != "10" {
+ t.Fatalf("unreachable holder: %d %v %q, want 503 with Retry-After: 10", res.code, res.header, res.body)
+ }
+ if want := "forward " + hopName(acrossHub, acrossTenant) + " → betty"; !strings.Contains(logs.String(), want) {
+ t.Fatalf("log lacks %q:\n%s", want, logs.String())
}
}
diff --git a/internal/edge/pathselect.go b/internal/edge/pathselect.go
index 675b17675..4fefacc1b 100644
--- a/internal/edge/pathselect.go
+++ b/internal/edge/pathselect.go
@@ -83,9 +83,9 @@ 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; for a
-// platform-alias target, its instance's, which is what its entry holds),
-// else host, the request's own name. A Remote selection never reaches HA
+// 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).
func (s requestSelection) haRouteName(host string) string {
if s.LocalTarget {
@@ -312,12 +312,16 @@ func (e *Edge) pathMatch(m map[string]upstream, host, urlPath string) (up upstre
// here too, and is never a target route on another box either
// (exactPathRoute is exact): the safe direction, deliberately.
tu, found := m[target]
+ if found {
+ // A platform-alias target is its instance (selectedEntry).
+ tu, found = selectedEntry(m, tu)
+ }
// The same-box guard, the one tenancy check case 1 adds to the 09-02
// answer: never an attached alias (whoever's route it names; a
- // platform alias is the instance's own entry and stays eligible), and
+ // platform alias resolved to its instance's own entry above), and
// never a route in another account than the front's. Every route kind
// stays eligible here, unlike across boxes.
- if !found || (tu.alias && !tu.platformAlias) || release.RouteAccount(tu.route) != release.RouteAccount(up.route) {
+ if !found || tu.alias || release.RouteAccount(tu.route) != release.RouteAccount(up.route) {
return up, true, prefix, target, false, front
}
// ONE HOP, deliberately: if tu itself carries a prefix map, it is NOT
@@ -329,6 +333,27 @@ func (e *Edge) pathMatch(m map[string]upstream, host, urlPath string) (up upstre
return tu, true, prefix, target, true, front
}
+// selectedEntry is the entry a target selected on m is dispatched under
+// (#186 fix round 1, Paul: a platform-alias target IS its instance, decided
+// once, here, on every box): tu itself, or, when tu is a platform alias
+// (an alias entry carrying its instance's route), the instance's own entry
+// m[tu.route.Host]. That entry must be the same instance and must not itself
+// be an alias; otherwise ok is false and the target is refused, as any
+// ineligible target is. So no selected Up carries platformAlias, and every
+// identity read downstream (region HA above all: routeHAIngress's claim
+// class and exemptions) sees the instance exactly as a request naming it
+// would. Each case still applies its own eligibility to the result.
+func selectedEntry(m map[string]upstream, tu upstream) (upstream, bool) {
+ if !tu.platformAlias {
+ return tu, true
+ }
+ inst, ok := m[tu.route.Host]
+ if !ok || inst.alias || inst.platformAlias || inst.route.Host != tu.route.Host || !sameInstance(inst.route, tu.route) {
+ return upstream{}, false
+ }
+ return inst, true
+}
+
// selectAcross runs cases 2 and 3 over one table; called only by selectUpstream.
// h is pathMatch's answer for host on t.hosts, which did not select a local
// target unless h.shadowed (a catch-all's answer for a host with a remote
@@ -411,7 +436,12 @@ func (e *Edge) selectForUnservedFront(t *routeTable, host, urlPath string, rm re
stay.Prefix, stay.Target = prefix, target
}
if tu, here := t.hosts[target]; here {
- if tu.alias || tu.platformAlias || tu.regional != regionalNone || tu.route.Host != target ||
+ // A platform-alias target is its instance (selectedEntry), so the
+ // box holding I's lease re-selects I for a hop another box sent
+ // under I (spec §5.7.3); every other entry must be target's own.
+ named := !tu.platformAlias
+ tu, ok := selectedEntry(t.hosts, tu)
+ if !ok || tu.alias || tu.regional != regionalNone || (named && tu.route.Host != target) ||
!registry.PathTarget(tu.route) || release.RouteAccount(tu.route) != rm.account {
e.pathSkip(host, fmt.Sprintf("prefix %q names %s, which this box serves but not as a ready instance or static route of account %s; sent to the host's home", prefix, target, rm.account))
return stay
diff --git a/internal/edge/pathselect_test.go b/internal/edge/pathselect_test.go
index 5afeb763c..9bb4ce3c8 100644
--- a/internal/edge/pathselect_test.go
+++ b/internal/edge/pathselect_test.go
@@ -192,9 +192,10 @@ func TestSelectCase1ServiceTarget(t *testing.T) {
wantLocal(t, s.sel(selFront, "/acme"), selTarget, "acme", selTarget)
}
-// Plan R2 P1-2: a same-account platform-minted target keeps working. Its
-// entry is its instance's (route.Host is the instance's), and LocalTarget
-// says a target was selected.
+// Plan R2 P1-2: a same-account platform-minted target keeps working.
+// Task 9 fix round 1: a platform-alias target IS its instance, so the
+// selected entry is the instance's own (never the alias's), Target keeps the
+// matched name, and LocalTarget says a target was selected.
func TestSelectCase1PlatformAliasTarget(t *testing.T) {
s := newSelScene(t)
const inst, alias = "a.bae.oncarlos.com", "shop.bae.oncarlos.com"
@@ -208,8 +209,8 @@ func TestSelectCase1PlatformAliasTarget(t *testing.T) {
}
got := s.sel(selFront, "/shop/x")
wantLocal(t, got, inst, "shop", alias)
- if !got.Up.platformAlias {
- t.Error("the selected entry is not the platform alias's")
+ if got.Up.alias || got.Up.platformAlias {
+ t.Error("the selected entry is the platform alias's, not its instance's own")
}
}