Fleet public routes Task 6: the edges file publishes what the edge serves
The writer asks edge.FleetServeEligible about the rows Reload asks it about (every forward row; any other row where edge.TunnelsArmed), in Reload's order, reading edge.HubArmed and the fleets table inside each write. A withheld name stays out under every alias, instance catch-all and wildcard entry, a platform alias of a withheld source goes with it, a forward host's path rows do not count toward its owner, and a forward host publishes no assets block (an unsettled pass's republish included). The alias loop takes its primary from the served rows, closing a latent nil-owner panic on an alias that chains through an alias. Reload's alias fold skips an alias of a refused row, so a refused row's attached names are not served through an alias carrying the refused name. enableTunnelsFromEnv calls the new edge.TunnelsArmed. Golden edges file for the separate-issuer test; spec §4.4 and §7 reconciled with the census card.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md+35 −2internal/edge/edge.go+9 −2internal/edge/fleetforward.go+11 −0internal/edge/issuer_forward_test.go+49 −0internal/edge/testdata/edges-forward-hub.json+1 −0internal/host/edgesfile.go+106 −7internal/host/edgesfile_forward_test.go+516 −0
Intent
<task-notification> <task-id>aed772157eb013f6f</task-id> <tool-use-id>toolu_01HfhKiFN8Jo2JtKk51BA1vb</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/aed772157eb013f6f.output</output-file> <status>completed</status> <summary>Agent "Implement Task 5: request policy" 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_WITH_CONCERNS.** Concern 1 below is a gap that was already there before this task, not a defect in the change. **Commit:** `768dcb25` on top of 1eb0ec0c. Not pushed. **What changed:** `rateAdmit`, `planThrottleOf`, `trackUpgrade` and `planThrottleFor` now act on forward rows as well as instances, so the hub enforces once. The `fromTunnel` exemptions are untouched, so the fleet edge still skips tunneled requests. **Tests:** RED shown first for all four new tests, then GREEN. The Step 4 `RateLimit|PlanThrottle` run passes over both packages, and `-race -count=3` on the new tests is clean. Five mutations each made a test fail: dropping the box's `fromTunnel` exemption, and reverting each of the four selectors. Build, vet, gofmt and the darwin, windows and linux/arm64 cross-builds pass. **Census:** the card shows exactly the four units, and spec §7 already lists all four. I added a note to §7 recording Task 5's card, in the same commit. **Concerns:** 1. **WebSockets do not cross the fleet tunnel at all.** This is true today for every fleet-placed row, not only forward rows. The hub's tunnel client is HTTP/2, which rejects any request with an `Upgrade` header (`http2: invalid Upgrade request header`), so an admitted handshake gets a 502 at the hub. As a result: - **Open-upgrade close:** spec §8 test 7's "an open upgrade is closed by `CloseAccountUpgrades`" can't be shown on a real open socket. The test shows it instead while the forward handshake is still in flight at the hub (it closes exactly 1). - **Box exemption:** "the fleet edge never limits a tunneled request" is proven for HTTP requests only, because no upgrade ever reaches the box. - **Users:** forward-routed apps that use WebSockets won't work through the hub. The spec doesn't mention this; it needs a ruling as a non-goal or its own task. 2. The brief uses `bab`. Per your ruling I used `bah` everywhere, with `fwdOwner` from Task 4's fixture. 3. The `fromTunnel` exemption in `planThrottleOf` isn't mutation-tested, because the box has no throttle hook in these tests. The brief didn't ask for it. Full report, with the RED/GREEN output, mutation table and census card: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/.superpowers/sdd/2026-10-30-fleet-public-routes/task-5-report.md` Files changed: - `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/internal/edge/ratelimit.go` - `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/internal/edge/planthrottle.go` - `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/internal/host/plans_pass.go` - `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/internal/edge/fleetforward_policy_test.go` (new) - `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/internal/host/plans_pass_test.go` - `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md` (§7)</result> <usage><subagent_tokens>137554</subagent_tokens><tool_uses>46</tool_uses><duration_ms>673498</duration_ms></usage> </task-notification>
<task-notification> <task-id>a56237a04e4029d8b</task-id> <tool-use-id>toolu_012FG7mMS1RR1asH9gkA2feR</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a56237a04e4029d8b.output</output-file> <status>completed</status> <summary>Agent "Review Task 5: request policy" 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>**Spec compliance:** ✅ Spec compliant. All four selectors, at `ratelimit.go:127`, `planthrottle.go:57` and `:104`, and `plans_pass.go:210`, read `Kind != "instance" && !IsForward()`, and the `fromTunnel` exemptions are unchanged. The three targeted edge tests I ran pass. - ⚠️ I could not verify a throttled upgrade crossing the tunnel, or an open WebSocket being closed. The controller ruling covers this. Forward-routed apps that use WebSockets still will not work through the hub, and that should be recorded somewhere visible. **Task quality:** Approved. The tests show hub-only enforcement for HTTP requests. For upgrades they show admission, refusal and tracking at the hub, within the controller's ruling. Each has a mutation that breaks it. Findings: - Critical: none. - Important: none. - Minor: `TestForwardPlanThrottleAndUpgradeClose` in `fleetforward_policy_test.go` only checks that `CloseAccountUpgrades` returns 1. It never checks that the tracked request's context was cancelled. - Minor: `TestForwardUpgradeIsLimitedAtTheHub` has a vacuous `ups > 2` assertion, because the app sees 0 upgrades. The 101-or-502 acceptance cannot tell "admitted" from any other non-429 answer. Box-side exemption of upgrades is untested, as the report admits. - Minor: no edge-level test covers the plain HTTP plan-throttle path for a forward row, so its shared bucket keying is unexercised. The selector itself is covered through the upgrade test. - Minor: the `fromTunnel` exemption in `planThrottleOf` and `trackUpgrade` on the box is not mutation-tested (report concern 3). - Minor: `ratelimit.go:119-121` has one overlong line in the reflowed doc comment (cosmetic). The review is written to `.superpowers/sdd/2026-10-30-fleet-public-routes/task-5-review.md`.</result> <usage><subagent_tokens>69336</subagent_tokens><tool_uses>8</tool_uses><duration_ms>65143</duration_ms></usage> </task-notification>
<cross-session-message from="uds:/run/user/1001/cc-socks/276368.sock" from-name="platform-61" from-mode="bypass"> box-1 (r10r) is on v0.31.1 (box 7021a2f2), current by 10:56:42Z. It updated itself on stable; its host.env and apps were not touched. v0.31.1 is the bfc668c8 tag (region HA P1b-2 forwarding, dormant; static _headers; rootfs exit and process reporting). It is live on dev only: boxes plus the dev console (dc849550). Flagship stays on v0.31.0. I read shop's logs only, and they show process=web and process=worker since the update. Next on dev, from platform-61: the HA forwarding drill on hapair-a1 (leo and sophie only, kills leo's carlos-edge once). It does not touch box-1. </cross-session-message>
diff --git a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md| index 2786fd7d5..88f5744f4 100644 |
| --- a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md |
| +++ b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md |
| @@ -457,7 +457,19 @@ Callers: |
| wildcard entry whose primary is left out. A forward row publishes no |
| `assets` block. So a refused row is in no edges file, `KnownHost` never |
| names it, and no issuer anywhere orders for it (`deploymentHost`, |
| - `edge.go:1363`; `certsync.go:207`). |
| + `edge.go:1363`; `certsync.go:207`). Task 6, as built: the writer asks |
| + the predicate about exactly the rows `Reload` asks it about (every |
| + forward row; any other row only where `edge.TunnelsArmed`, `Reload`'s |
| + fleet arm, holds; elsewhere a fleet-placed row keeps its old path), in |
| + `Reload`'s order (sidecar, readiness, then the fleet arm). A withheld |
| + name is also taken out where another row's alias carries it, a platform |
| + alias whose source is withheld goes with it, a forward host's path rows |
| + do not count toward its published owner, and a wildcard entry (both |
| + halves) whose catch-all primary is withheld is left out. The one thing |
| + the file cannot say is `refusedUnder`: a refused name under another |
| + row's served `*.<parent>` is not in the file (`KnownHost` is exact), and |
| + a far edge that dials it through that catch-all reaches the hub, which |
| + refuses it. |
| The source of the owner is the hub's local `fleets` table, written only by |
| the console and already the authority for tunnel credentials and the store |
| @@ -971,6 +983,26 @@ Units, by file (N = new, R = removed, otherwise a changed body or sites): |
| `SetFleetBoxIf`). |
| - `internal/host/edgesfile.go`: `edgesFileWriteClaims` (eligibility, |
| fleets read, no `assets` for forward rows). |
| + |
| + Task 6's card, reconciled with this list. `edgesFileWriteClaims`: |
| + `reads` (`+registry:Account`, `+registry:Host` x7, `+registry:Name`, |
| + `+whole:Fleet` x2, `+whole:Route`, `+whole:RoutePath` x7; keeps |
| + authority, task F,J1): the `ListFleets` read and the owner map |
| + (`Fleet.Name`, `Fleet.Account`), the predicate call, the `withheld` and |
| + `forwards` marks, the platform-alias source check, the path rows of a |
| + forward host left out of its owner, the catch-all whose primary was |
| + withheld, and the alias loop now taking its primary from the served |
| + rows (`owners`) rather than from the growing map. `Edge.Reload` moves |
| + from `+registry:Host` x9 to x10: the alias fold skips an alias whose |
| + primary is a refused row (`fleetRefused[a.Host]`), so a refused row's |
| + attached names are not served through an alias that carries the |
| + refused name. `edge.TunnelsArmed` (new, `fleetforward.go`: Reload's |
| + fleet arm, `CARLOS_TUNNEL_HOST` set) and `enableTunnelsFromEnv`, which |
| + now calls it, are not on the card: the env read goes through the |
| + `getenv` parameter, as `HubArmed`'s does, and both move only the |
| + `internal/edge` envelope. Envelopes re-pinned: `internal/edge`, |
| + `internal/host`. No unit on the card for Task 6 is missing from this |
| + list. |
| - `internal/host/egress_source.go`: `boxWhollyNested`, **runs as root**. |
| The new case reads `Kind` and the forbidden columns of an |
| agent-written row only to SKIP that row; every other refusal and the |
| @@ -981,7 +1013,8 @@ Units, by file (N = new, R = removed, otherwise a changed body or sites): |
| - `internal/host/plans_pass.go`: `planThrottleFor` (admit). |
| - `internal/edge/edge.go`: `Edge.Reload` (forward case, eligibility, fleets |
| read moved before the routes loop, path rows of forward hosts not |
| - folded, refused hosts held through every fold); `Edge.ServeHTTP` |
| + folded, refused hosts held through every fold, no alias folded onto a |
| + refused row (Task 6)); `Edge.ServeHTTP` |
| (`loginPost`, `cacheable`). |
| - `internal/edge/fleetforward.go` (a new file): `FleetServeEligible` (N). |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index 4d5a4cd70..cd23a961c 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -1179,6 +1179,13 @@ func (e *Edge) Reload() error { |
| log.Printf("edge: alias %s shadowed by a real route — skipped", a.Alias) |
| continue |
| } |
| + // An alias of a refused row is not served, even where the refused |
| + // name is itself attached to another route earlier in this loop: m |
| + // holds that alias by now, and resolving through it would serve the |
| + // refused row's own attached names with another row's entry. |
| + if fleetRefused[a.Host] { |
| + continue |
| + } |
| up, ok := m[a.Host] |
| if !ok { |
| continue |
| @@ -4184,10 +4191,10 @@ func enableStaticFromEnv(e *Edge, dataDir string) error { |
| // channel names are validated separately, at the registry writer |
| // (AddFleetBox) — they are never parsed from this env var. |
| func enableTunnelsFromEnv(e *Edge) error { |
| - host := os.Getenv("CARLOS_TUNNEL_HOST") |
| - if host == "" { |
| + if !TunnelsArmed(os.Getenv) { |
| return nil |
| } |
| + host := os.Getenv("CARLOS_TUNNEL_HOST") |
| clients, err := parseTunnelClients(os.Getenv("CARLOS_TUNNEL_CLIENTS")) |
| if err != nil { |
| return err |
diff --git a/internal/edge/fleetforward.go b/internal/edge/fleetforward.go| index dc67b361f..4a9c1eaa3 100644 |
| --- a/internal/edge/fleetforward.go |
| +++ b/internal/edge/fleetforward.go |
| @@ -18,6 +18,17 @@ func HubArmed(getenv func(string) string) bool { |
| return strings.TrimSpace(getenv("CARLOS_TUNNEL_HOST")) != "" && getenv("CARLOS_FLEET") == "" |
| } |
| +// TunnelsArmed reports whether this box's edge enables its tunnel hub |
| +// (enableTunnelsFromEnv): CARLOS_TUNNEL_HOST set, read as it stands. It is |
| +// the edge's dispatch, not the hub test: on every box where it holds, Reload |
| +// sends a fleet-placed row with no Tunnel through the fleet arm and asks |
| +// FleetServeEligible about it, so the edges-file writer asks about the same |
| +// rows. HubArmed is narrower (trimmed, and CARLOS_FLEET unset) and gates |
| +// forward rows. |
| +func TunnelsArmed(getenv func(string) string) bool { |
| + return getenv("CARLOS_TUNNEL_HOST") != "" |
| +} |
| + |
| // FleetServeEligible decides whether rt may take the fleet arm: be served |
| // through a fleet's tunnel (spec §4.4, with the controller's ruling on |
| // invalid accounts). It is the one place the rule is written; Reload asks it |
diff --git a/internal/edge/issuer_forward_test.go b/internal/edge/issuer_forward_test.go| new file mode 100644 |
| index 000000000..c80ee7eff |
| --- /dev/null |
| +++ b/internal/edge/issuer_forward_test.go |
| @@ -0,0 +1,49 @@ |
| +package edge |
| + |
| +import ( |
| + "context" |
| + "os" |
| + "path/filepath" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// Fleet public routes, Task 6 (spec §4.4): a separate issuer, an edge with no |
| +// local rows that reads the hub's edges file, may order a certificate for |
| +// every name the hub serves for a forward row and for none of a refused |
| +// row's. The file is the one internal/host's TestEdgesFileForwardGolden |
| +// writes (the writer's own output, checked in), so this test reads exactly |
| +// what the hub publishes. |
| +func TestSeparateIssuerAdmitsOnlyPublishedForwardNames(t *testing.T) { |
| + golden, err := os.ReadFile(filepath.Join("testdata", "edges-forward-hub.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + s := release.NewDirStore(t.TempDir()) |
| + if _, err := s.Put(context.Background(), "control/edges/hub.json", golden, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + issuer, err := New(openReg(t), nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(issuer.probers.Stop) |
| + m := newHomeMap(s, "issuer") |
| + refreshHomeMap(t, m) |
| + issuer.homes.Store(m) |
| + |
| + for _, h := range []string{"shop.bah.example.com", "tickets.example.com", "shop.bah-custom.example.com"} { |
| + if issuer.Allowed(h) { |
| + t.Fatalf("%s is in the issuer's own table; the test needs an edge with no local rows", h) |
| + } |
| + if !issuer.deploymentHost(h) { |
| + t.Errorf("%s: the issuer refuses a name the hub publishes", h) |
| + } |
| + } |
| + for _, h := range []string{"shop.baj.example.com", "store.example.com", "shop.baj-custom.example.com"} { |
| + if issuer.deploymentHost(h) { |
| + t.Errorf("%s: the issuer admits a refused forward row's name", h) |
| + } |
| + } |
| +} |
diff --git a/internal/edge/testdata/edges-forward-hub.json b/internal/edge/testdata/edges-forward-hub.json| new file mode 100644 |
| index 000000000..00967b69c |
| --- /dev/null |
| +++ b/internal/edge/testdata/edges-forward-hub.json |
| @@ -0,0 +1 @@ |
| +{"v":1,"box":"hub","eip":"198.51.100.7","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"addrs":null,"generation":"2026-10-30T00:00:00Z","hosts":{"*.bah-wild.example.com":{"role":"home","platform":false,"alias":true,"wildcard":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"shop.bah-custom.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"shop.bah.example.com":{"role":"home","platform":true,"account":"bah","app":"shop"},"tickets.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"}}} |
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go| index 8b5fb1f8b..80a104cc0 100644 |
| --- a/internal/host/edgesfile.go |
| +++ b/internal/host/edgesfile.go |
| @@ -520,6 +520,14 @@ var errBoxAddressesUnknown = errors.New("edges file: the box's addresses could n |
| // |
| // localAddrs is read on every pass for Addrs (boxAddrs); the loop passes |
| // instancectl.LocalAddresses, and tests their own. |
| +// |
| +// Fleet public routes (spec §4.4): a row edge.FleetServeEligible refuses, as |
| +// Reload asks it, is not published, nor is any alias, instance catch-all or |
| +// wildcard entry served with it, nor its name under another row's alias. The |
| +// hub test and the tunnels switch are read from the environment inside each |
| +// write (edge.HubArmed, edge.TunnelsArmed), and the fleet owners from this |
| +// box's fleets table. A forward row and every name served with it publish no |
| +// assets block. |
| func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Registry, ident edgesFile, eip string, last *[]byte, refresh bool, addrs AddressSource, lifetimes bool, assets *assetPolicy, localAddrs func() ([]netip.Prefix, error)) error { |
| // A policy whose box has not opened its asset store publishes nothing. |
| assets = assets.active() |
| @@ -539,11 +547,33 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| // A platform alias the edge refuses to serve (edge.PlatformAliasFold: |
| // another tenant's socket, or an owner that is not ready) is not |
| // advertised either, nor anything attached to it (#338 follow-up). |
| - _, refusedAliases := edge.PlatformAliasFold(routes) |
| - for _, r := range routes { |
| - if refusedAliases[r.Host] { |
| - continue |
| + platformSources, refusedAliases := edge.PlatformAliasFold(routes) |
| + // Fleet public routes (spec §4.4): the file names exactly what the edge |
| + // serves, so the writer asks edge.FleetServeEligible what Reload asks, of |
| + // the rows Reload asks it about: every forward row, and, on a box whose |
| + // tunnels are on (edge.TunnelsArmed, Reload's fleet arm), every other row. |
| + // hub is the one hub test, read inside each write from the environment |
| + // the edge reads (no parameter: the writer has some thirty callers), and |
| + // the owners are this box's own fleets table, read once per write, and |
| + // only where Reload reads it. withheld collects every name the rule left |
| + // out, and a forward row that is not ready, as Reload's fleetRefused does; |
| + // after every fold below each is taken out again, so no alias, instance |
| + // catch-all or catch-all of another row names it. |
| + tunnels, hub := edge.TunnelsArmed(os.Getenv), edge.HubArmed(os.Getenv) |
| + var fleetOwners map[string]string |
| + if tunnels { |
| + fleets, err := reg.ListFleets() |
| + if err != nil { |
| + return fmt.Errorf("edges: list fleets: %w", err) |
| + } |
| + fleetOwners = make(map[string]string, len(fleets)) |
| + for _, f := range fleets { |
| + fleetOwners[f.Name] = f.Account |
| } |
| + } |
| + withheld := map[string]bool{} |
| + forwards := map[string]bool{} |
| + for _, r := range routes { |
| // edge.Reload (internal/edge/edge.go) is the deployment's own |
| // definition of "serves": it skips any row whose Status != "ready" |
| // because a pending/creating/failed row has no working backend and |
| @@ -551,8 +581,13 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| // here means this file never claims role:"home" for a host nothing |
| // actually serves. Hibernating routes stay Status "ready" (that is |
| // what makes wake-on-request possible), so nothing reachable is |
| - // excluded by this filter. |
| + // excluded by this filter. A forward row that is not ready is |
| + // refused as well (Reload's fleetRefused), so its name stays out |
| + // under every alias and catch-all too. |
| if r.Status != "ready" { |
| + if r.IsForward() { |
| + withheld[r.Host] = true |
| + } |
| continue |
| } |
| // A sidecar is NEVER advertised as served — by this box or any |
| @@ -576,6 +611,23 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| if r.IsSidecar() { |
| continue |
| } |
| + // The fleet arm, in Reload's order: a forward row always, any other |
| + // row only where the tunnels are on (FleetServeEligible passes a row |
| + // that is not fleet-placed, or that carries its own Tunnel). Before |
| + // the platform-alias refusal, as in Reload, so a refused platform |
| + // alias the fleet rule also refuses is withheld under every name. |
| + if r.IsForward() || tunnels { |
| + if ok, _ := edge.FleetServeEligible(r, hub, fleetOwners); !ok { |
| + withheld[r.Host] = true |
| + continue |
| + } |
| + } |
| + if refusedAliases[r.Host] { |
| + continue |
| + } |
| + if r.IsForward() { |
| + forwards[r.Host] = true |
| + } |
| // Keys are registry row Host values verbatim, INCLUDING *.parent |
| // catch-all wildcard rows (Task 3's reconcile pass derives these |
| // from a claim's catch-all row, same as edge.go's upstream map) — |
| @@ -597,6 +649,14 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| } |
| hosts[r.Host] = h |
| } |
| + // A platform alias is served with its source's own entry, so one whose |
| + // source was withheld above is not served either (Reload drops it when |
| + // the source has no entry). |
| + for host, src := range platformSources { |
| + if _, served := hosts[src]; !served { |
| + delete(hosts, host) |
| + } |
| + } |
| // Owners (#175 P7): computed over the served rows alone, before any alias |
| // or catch-all joins the map, so an alias can only ever inherit a route's. |
| paths, err := reg.ListPaths() |
| @@ -606,7 +666,18 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| if assets != nil && assets.betweenReads != nil { |
| assets.betweenReads() |
| } |
| - owners := servedOwners(routes, hosts, paths) |
| + // A forward host has no path map at the edge (spec §4.4): its paths are |
| + // the fleet edge's business, so none of them counts toward its owner. |
| + ownerPaths := paths |
| + if len(forwards) > 0 { |
| + ownerPaths = make([]registry.RoutePath, 0, len(paths)) |
| + for _, p := range paths { |
| + if !forwards[p.Host] { |
| + ownerPaths = append(ownerPaths, p) |
| + } |
| + } |
| + } |
| + owners := servedOwners(routes, hosts, ownerPaths) |
| for host, h := range hosts { |
| h.Account, h.App = owners[host].owner() |
| hosts[host] = h |
| @@ -642,7 +713,11 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| if a.Alias == "" || strings.HasPrefix(a.Alias, "*.") { |
| continue |
| } |
| - if _, served := hosts[a.Host]; !served { |
| + // The primary must be a served row (owners holds exactly those), not |
| + // an alias this loop added: a name that is attached here while its |
| + // own row is withheld or not ready lends nothing to the aliases of |
| + // that row. |
| + if _, served := owners[a.Host]; !served { |
| continue |
| } |
| if a.DNSStatus != "pointing" { |
| @@ -709,10 +784,15 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| // catchallServed maps each served parent to the primary its "*.<parent>" |
| // alias row points at, the route the edge serves the catch-all with. |
| catchallServed := map[string]string{} |
| + // catchallWithheld names each parent whose catch-all is served by a row |
| + // the fleet rule withheld: its wildcard entry goes with its primary. |
| + catchallWithheld := map[string]bool{} |
| for _, a := range aliases { |
| if parent, ok := strings.CutPrefix(a.Alias, "*."); ok { |
| if _, served := owners[a.Host]; served { |
| catchallServed[parent] = a.Host |
| + } else if withheld[a.Host] { |
| + catchallWithheld[parent] = true |
| } |
| } |
| } |
| @@ -731,6 +811,9 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| hosts[key] = prev |
| continue |
| } |
| + if _, served := catchallServed[wd.Host]; !served && catchallWithheld[wd.Host] { |
| + continue |
| + } |
| // Marked alias whenever the DIAL half is on, and the mark is |
| // load-bearing rather than cosmetic. The catch-all key never reaches |
| // the alias loop above (it skips "*." rows on purpose), so this is |
| @@ -765,6 +848,14 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| hosts[key] = edgeHost{Role: role, Wildcard: true, Alias: alias, Account: acct, App: app, Stamp: stamp, |
| Incarnation: inc, ServingSeq: seq, TargetHost: target} |
| } |
| + // Refusals hold through every fold above (Reload's refusedHosts): a |
| + // withheld name is published under no alias of another row, and a remote |
| + // reader dialing it through another row's "*.<parent>" reaches this box, |
| + // whose edge refuses it under that catch-all; KnownHost is exact, so no |
| + // issuer orders for it. |
| + for host := range withheld { |
| + delete(hosts, host) |
| + } |
| // Asset-cache blocks (edge asset cache design §3.3, §4.1), last, over the |
| // finished map: an alias not yet pointing and |
| @@ -783,6 +874,14 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| settled = assets.auth.settled(clocks) |
| in := newAssetInputs(routes, hosts, paths, aliases, owners) |
| for host, h := range hosts { |
| + // A forward row publishes no assets block, nor does any name |
| + // served with it (spec §4.4): the fleet edge serves its assets. |
| + // Checked before an unsettled pass's republish (assets.withheld) |
| + // too, which would otherwise hand on the block that a row the |
| + // forward row replaced at the same host last wrote. |
| + if forwards[host] || forwards[h.TargetHost] { |
| + continue |
| + } |
| if !settled { |
| if b, ok := assets.withheld(host, h); ok { |
| h.Assets = b |
diff --git a/internal/host/edgesfile_forward_test.go b/internal/host/edgesfile_forward_test.go| new file mode 100644 |
| index 000000000..7d00267d3 |
| --- /dev/null |
| +++ b/internal/host/edgesfile_forward_test.go |
| @@ -0,0 +1,516 @@ |
| +package host |
| + |
| +// Fleet public routes, Task 6 (spec §4.4, §4.11): the hub's edges file |
| +// publishes exactly what its edge serves. The writer asks |
| +// edge.FleetServeEligible the question Reload asks, about the rows Reload |
| +// asks it about (every forward row; every other row only on a box whose |
| +// tunnels are on), and leaves a refused name out under every alias, instance |
| +// catch-all and wildcard entry too. |
| +// |
| +// Accounts: the fleet's owner is domains.Sqid(7) ("bah") and the second |
| +// account domains.Sqid(8) ("baj"), valid non-ops sqids. Neither "bab" |
| +// (OpsAccount) nor an invalid name owns a fleet here. |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "database/sql" |
| + "encoding/json" |
| + "os" |
| + "path/filepath" |
| + "reflect" |
| + "regexp" |
| + "strings" |
| + "sync" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/edge" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +var ( |
| + fpOwner = domains.Sqid(7) // owns fleet home |
| + fpOther = domains.Sqid(8) // owns no fleet |
| +) |
| + |
| +const ( |
| + fpEligible = "shop.bah.example.com" |
| + fpRefused = "shop.baj.example.com" |
| + fpTunnel = "tunnel.example.com" |
| +) |
| + |
| +// fpGolden is the hub's file for the first test's world, checked in for the |
| +// edge package's issuer test (internal/edge cannot import this package). |
| +var fpGolden = filepath.Join("..", "edge", "testdata", "edges-forward-hub.json") |
| + |
| +// setHubEnv sets the two variables edge.HubArmed and edge.TunnelsArmed read. |
| +func setHubEnv(t *testing.T, tunnelHost, fleet string) { |
| + t.Helper() |
| + t.Setenv("CARLOS_TUNNEL_HOST", tunnelHost) |
| + t.Setenv("CARLOS_FLEET", fleet) |
| +} |
| + |
| +// fpForward is an eligible-shaped forward row on fleet for account. |
| +func fpForward(host, fleet, account string) registry.Route { |
| + return registry.Route{Host: host, Kind: registry.KindForward, Slug: "shop", App: "shop", |
| + Account: account, Region: registry.PlacementTarget(fleet), Channel: "production"} |
| +} |
| + |
| +// fpRegistry is a registry holding fleet home, owned by fpOwner. |
| +func fpRegistry(t *testing.T) *registry.Registry { |
| + t.Helper() |
| + reg := edgesTestRegistry(t) |
| + if err := reg.UpsertFleet(registry.Fleet{Name: "home", Account: fpOwner, Bucket: "home-data"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + return reg |
| +} |
| + |
| +func fpPutForward(t *testing.T, reg *registry.Registry, rt registry.Route) { |
| + t.Helper() |
| + if err := reg.PutForward(rt); err != nil { |
| + t.Fatalf("PutForward(%s): %v", rt.Host, err) |
| + } |
| +} |
| + |
| +func fpAlias(t *testing.T, reg *registry.Registry, alias, primary, account string) { |
| + t.Helper() |
| + if err := reg.UpsertAlias(registry.RouteAlias{Alias: alias, Host: primary, Account: account, App: "shop", DNSStatus: "pointing"}); err != nil { |
| + t.Fatalf("UpsertAlias(%s): %v", alias, err) |
| + } |
| +} |
| + |
| +// fpWildcard attaches a served catch-all: the "*.<parent>" alias on primary |
| +// and the parent's wildcard_domains row. |
| +func fpWildcard(t *testing.T, reg *registry.Registry, parent, primary, account string) { |
| + t.Helper() |
| + if err := reg.UpsertAlias(registry.RouteAlias{Alias: "*." + parent, Host: primary, Account: account, App: "shop"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.UpsertWildcardDomain(registry.WildcardDomain{Host: parent, Account: account, App: "shop"}); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// fpWorld is the first test's world: two forward rows on fleet home, one of |
| +// the owner's (eligible) and one of the second account's (refused), each with |
| +// an attached custom domain, an instance catch-all name (<slug>.<parent>, |
| +// what deriveInstanceAliases writes) and a served wildcard catch-all. |
| +func fpWorld(t *testing.T) *registry.Registry { |
| + t.Helper() |
| + reg := fpRegistry(t) |
| + fpPutForward(t, reg, fpForward(fpEligible, "home", fpOwner)) |
| + fpPutForward(t, reg, fpForward(fpRefused, "home", fpOther)) |
| + fpAlias(t, reg, "tickets.example.com", fpEligible, fpOwner) |
| + fpAlias(t, reg, "shop.bah-custom.example.com", fpEligible, fpOwner) |
| + fpWildcard(t, reg, "bah-wild.example.com", fpEligible, fpOwner) |
| + fpAlias(t, reg, "store.example.com", fpRefused, fpOther) |
| + fpAlias(t, reg, "shop.baj-custom.example.com", fpRefused, fpOther) |
| + fpWildcard(t, reg, "baj-wild.example.com", fpRefused, fpOther) |
| + return reg |
| +} |
| + |
| +var fpEligibleNames = []string{fpEligible, "tickets.example.com", "shop.bah-custom.example.com", "*.bah-wild.example.com"} |
| +var fpRefusedNames = []string{fpRefused, "store.example.com", "shop.baj-custom.example.com", "*.baj-wild.example.com"} |
| + |
| +// fpWrite runs one writer pass on box "hub" into a fresh store and returns the |
| +// written body. |
| +func fpWrite(t *testing.T, reg *registry.Registry) []byte { |
| + t.Helper() |
| + withheldAliasSaid = sync.Map{} |
| + s := release.NewDirStore(t.TempDir()) |
| + var last []byte |
| + if err := edgesFileWriteClaims(context.Background(), s, reg, edgesFile{Box: "hub"}, "198.51.100.7", &last, false, nil, false, nil, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + body, _, err := s.Get(context.Background(), edgesFileKey("hub")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return body |
| +} |
| + |
| +// fpHosts parses body's hosts, each entry raw and parsed. |
| +func fpHosts(t *testing.T, body []byte) (map[string]edgeHost, map[string]map[string]json.RawMessage) { |
| + t.Helper() |
| + var f edgesFile |
| + if err := json.Unmarshal(body, &f); err != nil { |
| + t.Fatal(err) |
| + } |
| + var raw struct { |
| + Hosts map[string]map[string]json.RawMessage `json:"hosts"` |
| + } |
| + if err := json.Unmarshal(body, &raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + return f.Hosts, raw.Hosts |
| +} |
| + |
| +func TestEdgesFilePublishesOnlyEligibleForwardRows(t *testing.T) { |
| + setHubEnv(t, fpTunnel, "") |
| + body := fpWrite(t, fpWorld(t)) |
| + hosts, raw := fpHosts(t, body) |
| + for _, n := range fpEligibleNames { |
| + h, ok := hosts[n] |
| + if !ok { |
| + t.Fatalf("%s not published:\n%s", n, body) |
| + } |
| + if h.Role != "home" || h.Account != fpOwner || h.App != "shop" { |
| + t.Errorf("%s = %+v, want role home, account %s, app shop", n, h, fpOwner) |
| + } |
| + if _, ok := raw[n]["assets"]; ok { |
| + t.Errorf("%s carries an assets block: %s", n, body) |
| + } |
| + } |
| + if h := hosts[fpEligible]; !h.Platform || h.Alias { |
| + t.Errorf("the forward row's own entry = %+v, want platform, not alias", h) |
| + } |
| + for _, n := range []string{"tickets.example.com", "shop.bah-custom.example.com", "*.bah-wild.example.com"} { |
| + if h := hosts[n]; !h.Alias || h.TargetHost != fpEligible { |
| + t.Errorf("%s = %+v, want an alias served by %s", n, h, fpEligible) |
| + } |
| + } |
| + for _, n := range fpRefusedNames { |
| + if _, ok := hosts[n]; ok { |
| + t.Errorf("refused name %s published:\n%s", n, body) |
| + } |
| + } |
| + for _, s := range []string{fpOther, "baj-"} { |
| + if bytes.Contains(body, []byte(s)) { |
| + t.Errorf("the file names %q, something of the refused row's:\n%s", s, body) |
| + } |
| + } |
| +} |
| + |
| +func TestEdgesFileOmitsForwardRowsOffTheHub(t *testing.T) { |
| + for _, c := range []struct{ name, tunnel, fleet string }{ |
| + {"no tunnel host", "", ""}, |
| + {"a fleet box with a tunnel host", fpTunnel, "home"}, |
| + {"a blank tunnel host", " ", ""}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + setHubEnv(t, c.tunnel, c.fleet) |
| + reg := fpWorld(t) |
| + seedRoute(t, reg, "plain.example.com") |
| + hosts, _ := fpHosts(t, fpWrite(t, reg)) |
| + if _, ok := hosts["plain.example.com"]; !ok { |
| + t.Fatalf("the positive control is not published: %+v", hosts) |
| + } |
| + for _, n := range append(append([]string{}, fpEligibleNames...), fpRefusedNames...) { |
| + if _, ok := hosts[n]; ok { |
| + t.Errorf("%s published off the hub", n) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// corruptRow writes value into host's routes column by raw SQL, behind every |
| +// registry writer, asserts it hit exactly one row, and reads the row back |
| +// through a fresh registry.Open(...).Get to prove the value persisted: the |
| +// field the column maps to (registry.ForwardForbidden) is no longer zero. |
| +func corruptRow(t *testing.T, regPath, host string, c registry.ForwardColumn) { |
| + t.Helper() |
| + var value any = "x" |
| + if c.Type == "INTEGER" { |
| + value = 1 |
| + } |
| + db, err := sql.Open("sqlite", regPath) |
| + if err != nil { |
| + t.Fatalf("corruptRow: open: %v", err) |
| + } |
| + res, err := db.Exec(`UPDATE routes SET `+c.Column+` = ? WHERE host = ?`, value, host) |
| + if err != nil { |
| + db.Close() |
| + t.Fatalf("corruptRow(%s, %s): %v", host, c.Column, err) |
| + } |
| + n, err := res.RowsAffected() |
| + db.Close() |
| + if err != nil || n != 1 { |
| + t.Fatalf("corruptRow(%s, %s): %d rows affected (%v), want 1", host, c.Column, n, err) |
| + } |
| + reg, err := registry.Open(regPath) |
| + if err != nil { |
| + t.Fatalf("corruptRow: reopen: %v", err) |
| + } |
| + defer reg.Close() |
| + rt, err := reg.Get(host) |
| + if err != nil || rt == nil { |
| + t.Fatalf("corruptRow: Get(%s) = %v, %v", host, rt, err) |
| + } |
| + if reflect.ValueOf(*rt).FieldByName(c.Field).IsZero() { |
| + t.Fatalf("corruptRow: %s.%s (%s) reads back zero after the write", host, c.Field, c.Column) |
| + } |
| +} |
| + |
| +func TestEdgesFileOmitsEachCorruptForwardRow(t *testing.T) { |
| + setHubEnv(t, fpTunnel, "") |
| + if len(registry.ForwardForbidden) == 0 { |
| + t.Fatal("ForwardForbidden is empty") |
| + } |
| + for _, c := range registry.ForwardForbidden { |
| + t.Run(c.Column, func(t *testing.T) { |
| + reg := fpRegistry(t) |
| + fpPutForward(t, reg, fpForward(fpEligible, "home", fpOwner)) |
| + fpAlias(t, reg, "tickets.example.com", fpEligible, fpOwner) |
| + // Positive control: the inert row and its alias publish. |
| + hosts, _ := fpHosts(t, fpWrite(t, reg)) |
| + for _, n := range []string{fpEligible, "tickets.example.com"} { |
| + if _, ok := hosts[n]; !ok { |
| + t.Fatalf("%s not published before the corruption", n) |
| + } |
| + } |
| + corruptRow(t, reg.Path(), fpEligible, c) |
| + hosts, _ = fpHosts(t, fpWrite(t, reg)) |
| + for _, n := range []string{fpEligible, "tickets.example.com"} { |
| + if h, ok := hosts[n]; ok { |
| + t.Errorf("%s published with %s corrupted: %+v", n, c.Column, h) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// fpGenerationRe matches the pass's own clock reading, the one field that |
| +// differs between two writes of the same world. |
| +var fpGenerationRe = regexp.MustCompile(`"generation":"[^"]*"`) |
| + |
| +func TestEdgesFileForwardGolden(t *testing.T) { |
| + setHubEnv(t, fpTunnel, "") |
| + body := fpWrite(t, fpWorld(t)) |
| + got := fpGenerationRe.ReplaceAll(body, []byte(`"generation":"2026-10-30T00:00:00Z"`)) |
| + want, err := os.ReadFile(fpGolden) |
| + if err != nil { |
| + t.Fatalf("read golden: %v\nthe written file is:\n%s", err, got) |
| + } |
| + if !bytes.Equal(got, bytes.TrimSuffix(want, []byte("\n"))) { |
| + t.Fatalf("the written file differs from %s. If the change is intended, update the file by hand to:\n%s", fpGolden, got) |
| + } |
| +} |
| + |
| +// A fleet-placed row that is not a forward row is judged where the edge |
| +// judges it: on a box whose tunnels are on, the account rule; elsewhere its |
| +// existing path (a hub-less edge serves it from its socket). |
| +func TestEdgesFileFleetPlacedRowsFollowTheEdgesDispatch(t *testing.T) { |
| + hand := func(host, account string) registry.Route { |
| + return registry.Route{Host: host, Kind: "instance", Socket: "/run/carlos/" + host + ".sock", Status: "ready", |
| + Region: registry.PlacementTarget("home"), Account: account, App: "shop"} |
| + } |
| + world := func(t *testing.T) *registry.Registry { |
| + reg := fpRegistry(t) |
| + for _, rt := range []registry.Route{ |
| + hand("owner.example.com", fpOwner), |
| + hand("accountless.example.com", ""), |
| + hand("other.example.com", fpOther), |
| + hand("invalid.example.com", "B!"), |
| + hand("elsewhere.example.com", fpOwner), |
| + } { |
| + if rt.Host == "elsewhere.example.com" { |
| + rt.Region = registry.PlacementTarget("away") // a fleet this box does not hold |
| + } |
| + if err := reg.Upsert(rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + fpAlias(t, reg, "www.other.example.com", "other.example.com", fpOther) |
| + return reg |
| + } |
| + refusedOnTunnel := []string{"other.example.com", "www.other.example.com", "invalid.example.com", "elsewhere.example.com"} |
| + for _, c := range []struct { |
| + name, tunnel, fleet string |
| + refused []string |
| + }{ |
| + {"hub", fpTunnel, "", refusedOnTunnel}, |
| + {"tunnels on, not the hub", fpTunnel, "home", refusedOnTunnel}, |
| + {"no tunnels", "", "", nil}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + setHubEnv(t, c.tunnel, c.fleet) |
| + hosts, _ := fpHosts(t, fpWrite(t, world(t))) |
| + for _, n := range []string{"owner.example.com", "accountless.example.com", "other.example.com", |
| + "www.other.example.com", "invalid.example.com", "elsewhere.example.com"} { |
| + _, published := hosts[n] |
| + refused := false |
| + for _, r := range c.refused { |
| + refused = refused || r == n |
| + } |
| + if published == refused { |
| + t.Errorf("%s published = %v, want %v", n, published, !refused) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// fpServedBy is the edge's own answer for the same registry and environment: |
| +// edge.New, the tunnels armed as enableTunnelsFromEnv arms them, one Reload. |
| +func fpServedBy(t *testing.T, reg *registry.Registry) *edge.Edge { |
| + t.Helper() |
| + e, err := edge.New(reg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if h := os.Getenv("CARLOS_TUNNEL_HOST"); h != "" { |
| + e.EnableTunnels(edge.NewTunnelHub(h, nil)) |
| + } |
| + if err := e.Reload(); err != nil { |
| + t.Fatal(err) |
| + } |
| + return e |
| +} |
| + |
| +// The edge and the file agree, name by name: every exact name the file |
| +// publishes as served is Allowed by the hub's edge and every name it leaves |
| +// out is not, including a refused host under another row's alias, a platform |
| +// alias of a refused row, and a refused host under a served catch-all. |
| +func TestEdgesFilePublishesWhatTheHubServes(t *testing.T) { |
| + world := func(t *testing.T) *registry.Registry { |
| + reg := fpWorld(t) |
| + // The refused host's own name attached to the eligible row: the edge's |
| + // alias fold would serve it, and refusedHosts takes it out again. |
| + fpAlias(t, reg, fpRefused, fpEligible, fpOwner) |
| + // A hand row of the second account on the owner's fleet, and a |
| + // platform alias sharing its socket (PlatformAliasFold's source). |
| + for _, rt := range []registry.Route{ |
| + {Host: "hand.baj.example.com", Kind: "instance", Socket: "/run/carlos/hand.sock", Status: "ready", |
| + Region: registry.PlacementTarget("home"), Account: fpOther, App: "shop"}, |
| + {Host: "apex.baj.example.com", Kind: "instance", Socket: "/run/carlos/hand.sock", Status: "ready", |
| + Platform: true, Account: fpOther, App: "shop"}, |
| + // A served catch-all row over the refused host's parent. |
| + {Host: "*.example.com", Kind: "service", Addr: "10.0.0.1:3000", Status: "ready"}, |
| + {Host: "plain.example.com", Kind: "service", Addr: "10.0.0.1:3001", Status: "ready"}, |
| + } { |
| + if err := reg.Upsert(rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + // A forward row that is not ready (no writer leaves one so; a hand |
| + // edit can), its name attached to the plain row: refused all the same. |
| + fpPutForward(t, reg, fpForward("idle.bah.example.com", "home", fpOwner)) |
| + db, err := sql.Open("sqlite", reg.Path()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err = db.Exec(`UPDATE routes SET status = 'creating' WHERE host = ?`, "idle.bah.example.com") |
| + db.Close() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + fpAlias(t, reg, "idle.bah.example.com", "plain.example.com", "") |
| + return reg |
| + } |
| + names := append(append([]string{"hand.baj.example.com", "apex.baj.example.com", "plain.example.com", "idle.bah.example.com"}, |
| + fpEligibleNames...), fpRefusedNames...) |
| + for _, c := range []struct{ name, tunnel, fleet string }{ |
| + {"hub", fpTunnel, ""}, |
| + {"tunnels on, not the hub", fpTunnel, "home"}, |
| + {"no tunnels", "", ""}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + setHubEnv(t, c.tunnel, c.fleet) |
| + reg := world(t) |
| + hosts, _ := fpHosts(t, fpWrite(t, reg)) |
| + e := fpServedBy(t, reg) |
| + for _, n := range names { |
| + if strings.HasPrefix(n, "*.") { |
| + continue // never Allowed; the catch-all keys are checked by name in the tests above |
| + } |
| + h, published := hosts[n] |
| + published = published && h.Role == "home" |
| + if served := e.Allowed(n); served != published { |
| + t.Errorf("%s: edge serves %v, file publishes %v (%+v)", n, served, published, h) |
| + } |
| + } |
| + if c.name == "hub" { |
| + if _, ok := hosts[fpEligible]; !ok { |
| + t.Fatalf("positive control: %s not published on the hub", fpEligible) |
| + } |
| + if _, ok := hosts["apex.baj.example.com"]; ok { |
| + t.Error("the platform alias of a refused row is published") |
| + } |
| + // The refused row's own attached names stay refused although |
| + // its name is attached to the eligible row: neither side |
| + // resolves them through that alias. |
| + for _, n := range []string{"store.example.com", "shop.baj-custom.example.com"} { |
| + if _, ok := hosts[n]; ok || e.Allowed(n) { |
| + t.Errorf("%s: published %v, served %v; want neither", n, ok, e.Allowed(n)) |
| + } |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A forward host publishes no asset block, even on a pass that republishes |
| +// the blocks it last wrote: the instance row the forward row replaced at the |
| +// same host (spec §4.6, a hub-homed app placed onto a fleet) had one, with |
| +// the same owner, and an unsettled pass would otherwise hand it on. |
| +func TestEdgesFileForwardHostPublishesNoAssetBlock(t *testing.T) { |
| + setHubEnv(t, fpTunnel, "") |
| + w := newAssetWorld(t) |
| + if err := w.reg.UpsertFleet(registry.Fleet{Name: "home", Account: fpOwner, Bucket: "home-data"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + assetShip(t, w.store.Store, fpOwner, "v1", "/assets/") |
| + if err := w.reg.Upsert(registry.Route{Host: fpEligible, Kind: "instance", Socket: "/run/carlos/shop.sock", Status: "ready", |
| + Account: fpOwner, App: "shop", AssetGen: assetGen1, Version: "v1"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + now := w.clock.now() |
| + w.auth.recordsPass(now, provision.ReconcileReport{Complete: map[string]bool{fpOwner + "/shop": true}}) |
| + w.auth.aliasPass(now, domains.AliasReport{Complete: true}) |
| + w.pass() |
| + if h := w.written()[fpEligible]; h.Assets == nil { |
| + t.Fatalf("positive control: the instance row published no asset block: %+v", h) |
| + } |
| + |
| + if err := w.reg.Delete(fpEligible); err != nil { |
| + t.Fatal(err) |
| + } |
| + fpPutForward(t, w.reg, fpForward(fpEligible, "home", fpOwner)) |
| + // A records pass runs between the writer's reads: the pass is unsettled |
| + // and republishes what it last wrote for each host it still names. |
| + w.policy.betweenReads = func() { w.auth.passBegin(); w.auth.passEnd() } |
| + w.pass() |
| + h, ok := w.written()[fpEligible] |
| + if !ok || !h.Platform { |
| + t.Fatalf("the forward row is not published: %+v %v", h, ok) |
| + } |
| + if h.Assets != nil { |
| + t.Fatalf("the forward host republished the instance's asset block: %+v", h.Assets) |
| + } |
| + w.policy.betweenReads = nil |
| + w.pass() |
| + if h := w.written()[fpEligible]; h.Assets != nil { |
| + t.Fatalf("a settled pass published an asset block for the forward host: %+v", h.Assets) |
| + } |
| +} |
| + |
| +// A forward host has no path map at the hub (spec §4.4): Reload folds none of |
| +// its path rows, so every path of it reaches the forward row and the fleet |
| +// edge routes inside it. Its published owner is the forward row's alone, |
| +// whatever a path row on it targets here; a non-forward host keeps the |
| +// mixed-owner rule. |
| +func TestEdgesFileForwardHostOwnerIgnoresItsPathRows(t *testing.T) { |
| + setHubEnv(t, fpTunnel, "") |
| + reg := fpRegistry(t) |
| + fpPutForward(t, reg, fpForward(fpEligible, "home", fpOwner)) |
| + fpAlias(t, reg, "tickets.example.com", fpEligible, fpOwner) |
| + ownedRoute(t, reg, "blog.example.com", fpOwner, "blog") |
| + ownedRoute(t, reg, "plain.example.com", fpOwner, "shop") |
| + for _, p := range []registry.RoutePath{ |
| + {Host: fpEligible, Prefix: "blog", Target: "blog.example.com", Account: fpOwner, App: "shop"}, |
| + {Host: "plain.example.com", Prefix: "blog", Target: "blog.example.com", Account: fpOwner, App: "shop"}, |
| + } { |
| + if err := reg.UpsertPath(p); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + hosts, _ := fpHosts(t, fpWrite(t, reg)) |
| + wantOwner(t, hosts, fpEligible, fpOwner, "shop") |
| + wantOwner(t, hosts, "tickets.example.com", fpOwner, "shop") |
| + wantOwner(t, hosts, "plain.example.com", "", "") // the positive control: mixed |
| +} |