host: link fixes: revocation first, visitor identity, state
Task 8 fix round 1 (Astra and Fable). - The link loop cancels a run the link row shows obsolete before it reads the published set, so a failing set read cannot hold a revoked connection open. - A linked request's visitor is the last X-Forwarded-For entry the hub appended: the app gets the hub's chain and the password gate keys its attempt limit on that visitor. Ordinary ingress is unchanged. - State writes come only from the current run (under the loop's lock); a stop without replacement records an empty state. - Witnesses for the activator and generation arm, the page cache and the asset catch under a pin; the one-site scan also covers lookupIn, lookupDemoAware and current() indexing. - Census overlay linked-deployments-slice1 re-proposed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+571
−63
docs/superpowers/notes/census-proposal-linked-deployments-slice1.md+3 −3internal/edge/edge.go+29 −0internal/edge/homemap.go+7 −2internal/edge/linkpin_test.go+228 −4internal/gate/gate.go+16 −1internal/host/link_client.go+94 −42internal/host/link_e2e_test.go+184 −2internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv+9 −8
diff --git a/docs/superpowers/notes/census-proposal-linked-deployments-slice1.md b/docs/superpowers/notes/census-proposal-linked-deployments-slice1.md| index 24404050b..bd28a0737 100644 |
| --- a/docs/superpowers/notes/census-proposal-linked-deployments-slice1.md |
| +++ b/docs/superpowers/notes/census-proposal-linked-deployments-slice1.md |
| @@ -28,7 +28,7 @@ Ruling `census-ruling-linked-deployments-slice1`. The independent reviewer appro |
| | `internal/registry/forward.go` `Registry.PutForward` | sites | +registry:Account, +registry:FleetLabel, +registry:Host, +registry:Region ×2 | linked deployments slice 1 Task 1: also accepts a Region that LinkPlacement parses (link/ + 12 hex), refusing a link row with a FleetLabel (ErrNotForward); the existing in-transaction SELECT also reads the held row's region and refuses a different placement class (ErrHostHeld); a link row additionally needs an active link_channels row of its account in the same transaction (linkAdmits, ErrLinkInactive). Same transaction and statement; the added reads are the argument and the box's own registry database, as carlos | |
| | `internal/registry/registry.go` `Registry.Fingerprint` | sites | +file:Query | linked deployments slice 1 Task 1: hashes link_channels (link_id, account, token_hash, status, generation; connected, seen_at, seq and created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no links digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; a digest, never a decision; linked deployments slice 1 Task 7: also folds home_link (id, serving_url, tunnel_url, the token's sha256 never the token, account, apps_domain, box_label, conn_gen; state and created_at not) and home_link_apps (name, home_account, home_app, home_host) through fingerprintHomeLink over the same fresh connection, each section marker written only when a row exists, so a registry with no link digests as before; no file path read; a digest, never a decision | |
| -Envelopes re-pinned: `internal/edge`, `internal/gate`, `internal/host`, `internal/provision`, `internal/regionlabel`, `internal/registry`, `internal/tunnelclient`. |
| +Envelopes re-pinned: `.`, `internal/edge`, `internal/gate`, `internal/host`, `internal/provision`, `internal/regionlabel`, `internal/registry`, `internal/tunnelclient`. |
| Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| @@ -63,7 +63,7 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - new `internal/edge/edge.go:Edge.pinnedUpstream`: reads +registry:Account, +registry:App, +registry:Host, +registry:Kind, +whole:Route; written legacy, accepted-legacy, frozen |
| - new `internal/edge/fleetforward.go:linkServeEligible`: reads +registry:Account ×3, +registry:FleetBox, +registry:FleetBoxes, +registry:FleetLabel; written legacy, accepted-legacy, frozen |
| - new `internal/host/link_client.go:linkLoopState.pass`: reads +registry:BoxLabel ×4, +registry:ConnGen, +registry:ID ×4, +registry:Name, +registry:Token, +registry:TunnelURL, +whole:HomeLink ×4, +whole:HomeLinkApp ×9; written legacy, accepted-legacy, frozen |
| -- new `internal/host/link_client.go:linkLoopState.start`: reads +registry:ConnGen, +registry:ID ×4, +registry:Token ×2, +registry:TunnelURL ×3, +whole:HomeLinkApp ×3; written legacy, accepted-legacy, frozen |
| +- new `internal/host/link_client.go:linkLoopState.start`: reads +registry:ConnGen, +registry:ID ×3, +registry:Token ×2, +registry:TunnelURL ×3, +whole:HomeLinkApp ×3; written legacy, accepted-legacy, frozen |
| - new `internal/host/link_client.go:linkSetNarrowed`: reads +whole:HomeLinkApp ×4; written legacy, accepted-legacy, frozen |
| - new `internal/host/link_handler.go:linkHandler.ServeHTTP`: reads +registry:HomeAccount ×2, +registry:HomeApp ×2, +registry:HomeHost ×2, +whole:HomeLinkApp; written legacy, accepted-legacy, frozen |
| - new `internal/registry/homelink.go:CheckCredentialFile`: reads +file:Lstat; written legacy, accepted-legacy, frozen |
| @@ -100,6 +100,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - reads `internal/provision/forward.go:forwardView.retirements`: +registry:Region; keeps legacy, task accepted-legacy |
| - reads `internal/registry/remote_dispatch.go:Registry.dispatchRemote`: +registry:Changed ×5, +registry:HomeLink ×2, +registry:HomeLinkApp ×2, +registry:HomeLinkApps, +registry:Host, +registry:Label, +registry:Link, +registry:LinkID ×5, +registry:LinkSeen, +registry:Name ×2, +registry:Number64, +registry:On ×2, +registry:Routes, +registry:SeenAt, +registry:Seq, +registry:Status, +registry:StringMap ×2, +whole:HomeLink ×2, +whole:HomeLinkApp ×3, +whole:LinkChannel, +whole:LinkSeen, +whole:Route; keeps hint, task E2 |
| -Seal: `6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a` → `8025c50a3e2dc1e51ed45b73a230dbf33aa09dd1672f92c425194d29bcc3e74a`. |
| +Seal: `6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a` → `0b8e44b7660274dbbd5d31545dc5704db2f3cfd2838fd982993a31c8436d15b9`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index fe3d47c43..f7bde5d78 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -2044,6 +2044,11 @@ func linkedRequest(ctx context.Context) bool { |
| // want.PublicHost (gate.WithPublicHost), and the app is sent |
| // Host and X-Forwarded-Host want.PublicHost with X-Forwarded-Proto |
| // https (linkedBackend, setForwarded). |
| +// - The visitor: the hub's X-Forwarded-For chain goes to the app as the |
| +// hub sent it (setForwarded), and the gate's attempt limiter keys on its |
| +// last entry, the client the hub observed (linkVisitor, |
| +// gate.WithClientAddr), not on the tunnel's address every visitor |
| +// shares. |
| // - No caching at home in either direction: the response LRU, the page |
| // cache and the asset catch are skipped, so an answer made for one |
| // origin is never replayed to the other. A Carlos-Purge-Host naming |
| @@ -2055,11 +2060,35 @@ func linkedRequest(ctx context.Context) bool { |
| // the request. |
| func (e *Edge) ServeLinked(w http.ResponseWriter, r *http.Request, want LinkedTarget) { |
| ctx := gate.WithPublicHost(withLinkPin(r.Context(), want), want.PublicHost) |
| + if visitor, ok := linkVisitor(r.Header); ok { |
| + ctx = gate.WithClientAddr(ctx, visitor) |
| + } |
| r = r.WithContext(ctx) |
| r.Host = want.Host |
| e.ServeHTTP(w, r) |
| } |
| +// linkVisitor is a linked request's visitor: the last X-Forwarded-For entry, |
| +// the client address the hub observed and appended (the hub never passes a |
| +// client's own X-Forwarded-For on). Only a linked request is read this way |
| +// (ServeLinked): on every other ingress the header is the client's to |
| +// forge. False when there is no entry or it is not an IP address. |
| +func linkVisitor(h http.Header) (string, bool) { |
| + chain := strings.Join(h.Values("X-Forwarded-For"), ",") |
| + if chain == "" { |
| + return "", false |
| + } |
| + last := chain |
| + if i := strings.LastIndexByte(chain, ','); i >= 0 { |
| + last = chain[i+1:] |
| + } |
| + ip := net.ParseIP(strings.TrimSpace(last)) |
| + if ip == nil { |
| + return "", false |
| + } |
| + return ip.String(), true |
| +} |
| + |
| // selectUpstream is where a request's upstream is chosen: the only |
| // request-path caller of lookupUpstream and lookupUpstreamPath |
| // (TestSelectUpstreamIsTheOnlySite). Without a link pin it is |
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go| index b22c513d6..23a091ee0 100644 |
| --- a/internal/edge/homemap.go |
| +++ b/internal/edge/homemap.go |
| @@ -1689,9 +1689,14 @@ func setForwarded(pr *httputil.ProxyRequest) { |
| defer signForwarded(pr) |
| // A linked request (ServeLinked) reaches its app as the visitor sent it |
| // to the serving side: the public host (linkedBackend has already made |
| - // it pr.In.Host, so Host and the proof agree) over https. It is never a |
| - // door call or a hop. |
| + // it pr.In.Host, so Host and the proof agree) over https, and the hub's |
| + // X-Forwarded-For chain, whose last entry is the client the hub |
| + // observed, rather than the tunnel's address SetXForwarded wrote. It |
| + // is never a door call or a hop. |
| if want, pinned := linkPinFrom(pr.In.Context()); pinned { |
| + if chain := pr.In.Header.Values("X-Forwarded-For"); len(chain) > 0 { |
| + pr.Out.Header.Set("X-Forwarded-For", strings.Join(chain, ", ")) |
| + } |
| pr.Out.Header.Set("X-Forwarded-Host", want.PublicHost) |
| pr.Out.Header.Set("X-Forwarded-Proto", "https") |
| return |
diff --git a/internal/edge/linkpin_test.go b/internal/edge/linkpin_test.go| index 4dddc4be9..6176ddc7f 100644 |
| --- a/internal/edge/linkpin_test.go |
| +++ b/internal/edge/linkpin_test.go |
| @@ -8,11 +8,20 @@ import ( |
| "go/ast" |
| "go/parser" |
| "go/token" |
| + "io" |
| + "net/http" |
| + "net/http/httptest" |
| "os" |
| "path/filepath" |
| "sort" |
| "strings" |
| + "sync" |
| + "sync/atomic" |
| "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/assetcache" |
| + "github.com/carlosframework/platform/internal/registry" |
| ) |
| // The functions besides selectUpstream allowed to call lookupUpstream or |
| @@ -24,13 +33,49 @@ var lookupNonRequestSites = map[string]string{ |
| "sweepUpgrades": "the reload sweep that closes tunnel upgrades whose host no longer maps to their tenancy", |
| } |
| +// The other ways to read the routing map by host, and where each may be |
| +// used. None of them is a request's upstream selection: a pinned request's |
| +// upstream comes only from selectUpstream. |
| +var mapReadSites = map[string]map[string]string{ |
| + // lookupIn(m, host): the host half of the lookup, wildcard fallback |
| + // included. |
| + "lookupIn": { |
| + "lookupDemoAware": "the lookup primitive itself, under lookupUpstream and lookupUpstreamPath", |
| + "importGateAdmit": "reads the request host's own row only to refuse an import-gated front host; it can only refuse, never pick an upstream", |
| + "instanceHostsIn": "the page cache's purge expansion over hosts an app's response named; a linked request never records a page", |
| + "pageRouteEligible": "the page cache's eligibility of the upstream already selected; never reached by a linked request", |
| + "pageHostsFor": "the pages a purge declaration clears, from the response's own route", |
| + "resolvePurgeOwnersIn": "validates the hosts a Carlos-Purge-Host names against the serving route's tenancy", |
| + "purgeOwns": "the owner check of a purge target host", |
| + }, |
| + // lookupDemoAware(m, host): the demo zone's exact-only lookup. |
| + "lookupDemoAware": { |
| + "lookupUpstream": "the lookup primitive", |
| + "lookupUpstreamPath": "the lookup primitive", |
| + }, |
| + // e.current()[host]: the exact map entry. |
| + "current()[]": { |
| + "Allowed": "autocert's host policy, not a request", |
| + "servesExactly": "an exact-key test for the alias and catch-all ownership block, which a linked request skips", |
| + "pinnedUpstream": "the pin's own exact entry, reached only from selectUpstream", |
| + "takeHost": "the HA take control path, an edge-owned handler a linked request never reaches", |
| + }, |
| +} |
| + |
| func TestSelectUpstreamIsTheOnlySite(t *testing.T) { |
| files, err := filepath.Glob("*.go") |
| if err != nil { |
| t.Fatal(err) |
| } |
| fset := token.NewFileSet() |
| - callers := map[string][]string{} // enclosing function -> positions |
| + callers := map[string][]string{} // enclosing function -> positions |
| + reads := map[string]map[string][]string{} // kind -> enclosing function -> positions |
| + note := func(kind, fn string, pos token.Pos) { |
| + if reads[kind] == nil { |
| + reads[kind] = map[string][]string{} |
| + } |
| + reads[kind][fn] = append(reads[kind][fn], fset.Position(pos).String()) |
| + } |
| for _, name := range files { |
| if strings.HasSuffix(name, "_test.go") { |
| continue |
| @@ -55,11 +100,21 @@ func TestSelectUpstreamIsTheOnlySite(t *testing.T) { |
| ident = x.Sel |
| case *ast.Ident: |
| ident = x |
| + case *ast.IndexExpr: |
| + if c, ok := x.X.(*ast.CallExpr); ok && len(c.Args) == 0 { |
| + if se, ok := c.Fun.(*ast.SelectorExpr); ok && se.Sel.Name == "current" { |
| + note("current()[]", fn.Name.Name, x.Pos()) |
| + } |
| + } |
| + return true |
| default: |
| return true |
| } |
| - if ident.Name == "lookupUpstream" || ident.Name == "lookupUpstreamPath" { |
| + switch ident.Name { |
| + case "lookupUpstream", "lookupUpstreamPath": |
| callers[fn.Name.Name] = append(callers[fn.Name.Name], fset.Position(ident.Pos()).String()) |
| + case "lookupIn", "lookupDemoAware": |
| + note(ident.Name, fn.Name.Name, ident.Pos()) |
| } |
| return true |
| }) |
| @@ -69,8 +124,11 @@ func TestSelectUpstreamIsTheOnlySite(t *testing.T) { |
| for _, decl := range f.Decls { |
| if gd, ok := decl.(*ast.GenDecl); ok { |
| ast.Inspect(gd, func(n ast.Node) bool { |
| - if id, ok := n.(*ast.Ident); ok && (id.Name == "lookupUpstream" || id.Name == "lookupUpstreamPath") { |
| - t.Errorf("%s: %s referenced outside a function", fset.Position(id.Pos()), id.Name) |
| + if id, ok := n.(*ast.Ident); ok { |
| + switch id.Name { |
| + case "lookupUpstream", "lookupUpstreamPath", "lookupIn", "lookupDemoAware": |
| + t.Errorf("%s: %s referenced outside a function", fset.Position(id.Pos()), id.Name) |
| + } |
| } |
| return true |
| }) |
| @@ -98,4 +156,170 @@ func TestSelectUpstreamIsTheOnlySite(t *testing.T) { |
| t.Errorf("lookupNonRequestSites lists %s, which no longer calls a lookup: drop it", fn) |
| } |
| } |
| + for kind, allowed := range mapReadSites { |
| + for fn, at := range reads[kind] { |
| + if _, ok := allowed[fn]; !ok { |
| + t.Errorf("%s reads the routing map by host (%s) at %v: select a request's upstream through selectUpstream, or add the function to mapReadSites with the reason it is not a selection", fn, kind, at) |
| + } |
| + } |
| + for fn := range allowed { |
| + if len(reads[kind][fn]) == 0 { |
| + t.Errorf("mapReadSites[%s] lists %s, which no longer reads that way: drop it", kind, fn) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// linkedGet serves GET path on e as a link channel would deliver it, pinned |
| +// to want. |
| +func linkedGet(e *Edge, want LinkedTarget, path string) *httptest.ResponseRecorder { |
| + rec := httptest.NewRecorder() |
| + e.ServeLinked(rec, httptest.NewRequest(http.MethodGet, "http://"+want.PublicHost+path, nil), want) |
| + return rec |
| +} |
| + |
| +// The production backend arm: an activator-owned, hibernating instance |
| +// reached through its current generation (appSocketProxy). A pin to it is |
| +// admitted, the activator is handed the pinned proxy and the app sees the |
| +// public host; a pin naming another app is refused before the activator. |
| +func TestLinkPinActivatorBackend(t *testing.T) { |
| + dir := genSockDir(t) |
| + var mu sync.Mutex |
| + var seen []string |
| + app := startGenApp(t, filepath.Join(dir, "a.sock"), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + mu.Lock() |
| + seen = append(seen, r.Host+" "+r.Header.Get("X-Forwarded-Host")+" "+r.Header.Get("X-Forwarded-Proto")) |
| + mu.Unlock() |
| + io.WriteString(w, "gen") |
| + })) |
| + reg := openReg(t) |
| + if err := reg.Upsert(registry.Route{Host: laHost, Kind: "instance", Hibernate: true, Socket: filepath.Join(dir, "canon.sock"), |
| + Status: "ready", Version: "v0", Account: "abc", App: "shop"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + act := &genActivator{fakeGens: newFakeGens(true)} |
| + act.switchTo(laHost, GenInfo{Socket: app.sock, N: 1, Build: laBuild}) |
| + e, err := New(reg, act) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(e.probers.Stop) |
| + if up := e.current()[laHost]; !up.hibernating || !up.genManaged || !up.localBackend { |
| + t.Fatalf("the entry is hibernating=%v genManaged=%v localBackend=%v; want the activator's generation arm", up.hibernating, up.genManaged, up.localBackend) |
| + } |
| + want := LinkedTarget{Host: laHost, Account: "abc", App: "shop", PublicHost: "shop.pub.example.com"} |
| + rec := linkedGet(e, want, "/p") |
| + if rec.Code != http.StatusOK || rec.Body.String() != "gen" { |
| + t.Fatalf("pinned GET = %d %q, want the generation's answer", rec.Code, rec.Body.String()) |
| + } |
| + if n := act.served.Load(); n != 1 { |
| + t.Fatalf("the activator was handed %d requests, want 1", n) |
| + } |
| + mu.Lock() |
| + got := strings.Join(seen, "|") |
| + mu.Unlock() |
| + if want := "shop.pub.example.com shop.pub.example.com https"; got != want { |
| + t.Fatalf("the app saw %q, want %q", got, want) |
| + } |
| + |
| + other := want |
| + other.App = "blog" |
| + rec = linkedGet(e, other, "/p") |
| + if rec.Code != http.StatusBadGateway || !strings.Contains(rec.Body.String(), copyLD51) { |
| + t.Fatalf("pin for another app = %d %q, want 502", rec.Code, rec.Body.String()) |
| + } |
| + if n := act.served.Load(); n != 1 { |
| + t.Fatalf("a refused pin reached the activator (%d)", n) |
| + } |
| +} |
| + |
| +// An instance opted into the page cache: a linked answer is never stored as |
| +// a page, and a page the tailnet stored is never replayed to a linked |
| +// request. |
| +func TestLinkPinNoPageCacheReplay(t *testing.T) { |
| + s := newPCScene(t, pageOK(pcBody), func(r *registry.Route) { r.Hibernate = true }) |
| + want := LinkedTarget{Host: pcHost, Account: "abc", App: "blog", PublicHost: "blog.pub.example.com"} |
| + linked := func(n int64) { |
| + t.Helper() |
| + rec := linkedGet(s.e, want, "/p") |
| + wantBody(t, rec, 200, pcBody) |
| + if c := rec.Header().Get("Carlos-Cache"); c == "hit" { |
| + t.Fatal("a linked request was answered from the page cache") |
| + } |
| + if got := s.b.n.Load(); got != n { |
| + t.Fatalf("the app saw %d requests, want %d", got, n) |
| + } |
| + } |
| + linked(1) |
| + if n := s.pages(); n != 0 { |
| + t.Fatalf("a linked answer stored %d pages", n) |
| + } |
| + wantCache(t, s.get("/p"), "miss") |
| + if !s.idx.OptedIn(s.scope()) { |
| + t.Fatal("the tailnet answer did not opt the instance in") |
| + } |
| + wantCache(t, s.get("/p"), "hit") |
| + if got := s.b.n.Load(); got != 2 { |
| + t.Fatalf("the app saw %d requests, want 2", got) |
| + } |
| + linked(3) |
| + linked(4) |
| + if n := s.lruLen(); n != 0 { |
| + t.Fatalf("the LRU holds %d entries", n) |
| + } |
| +} |
| + |
| +// The local asset catch: a linked request for a declared asset path is |
| +// never answered from the asset store or filled into it, and an entry the |
| +// tailnet filled is never replayed to a linked request. |
| +func TestLinkPinNoAssetCatchReplay(t *testing.T) { |
| + dir := genSockDir(t) |
| + var hits atomic.Int64 |
| + app := startGenApp(t, filepath.Join(dir, "a.sock"), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + hits.Add(1) |
| + assetOK(laBody)(w, r) |
| + })) |
| + reg := openReg(t) |
| + if err := reg.Upsert(registry.Route{Host: laHost, Kind: "instance", Hibernate: true, Socket: filepath.Join(dir, "canon.sock"), |
| + Status: "ready", Version: "v0", Account: "abc", App: "shop", AssetGen: laGen}); err != nil { |
| + t.Fatal(err) |
| + } |
| + act := &genActivator{fakeGens: newFakeGens(true)} |
| + act.switchTo(laHost, GenInfo{Socket: app.sock, N: 1, Build: laBuild}) |
| + e, err := New(reg, act) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(e.probers.Stop) |
| + local := &fakeLocalAssets{hosts: map[string]HostAssets{laHost: laAssets()}, builds: map[string]bool{laBuild: true}} |
| + store := openLAStore(t) |
| + e.assets.Store(&assetState{store: store, local: local, now: time.Now}) |
| + stored := func() int { |
| + n := 0 |
| + store.Retain(func(assetcache.Key) bool { n++; return true }) |
| + return n |
| + } |
| + want := LinkedTarget{Host: laHost, Account: "abc", App: "shop", PublicHost: "shop.pub.example.com"} |
| + linked := func(n int64) { |
| + t.Helper() |
| + rec := linkedGet(e, want, "/assets/app.js") |
| + if rec.Code != 200 || rec.Body.String() != laBody || rec.Header().Get("Carlos-Cache") == "hit" { |
| + t.Fatalf("linked asset = %d %q (Carlos-Cache %q)", rec.Code, rec.Body.String(), rec.Header().Get("Carlos-Cache")) |
| + } |
| + if got := hits.Load(); got != n { |
| + t.Fatalf("the app saw %d requests, want %d", got, n) |
| + } |
| + } |
| + linked(1) |
| + linked(2) |
| + if n := stored(); n != 0 { |
| + t.Fatalf("linked requests filled %d asset entries", n) |
| + } |
| + s := &laScene{e: e} |
| + wantCache(t, s.get(t, "/assets/app.js"), "miss") |
| + wantCache(t, s.get(t, "/assets/app.js"), "hit") |
| + if got := hits.Load(); got != 3 { |
| + t.Fatalf("the app saw %d requests, want 3", got) |
| + } |
| + linked(4) |
| } |
diff --git a/internal/gate/gate.go b/internal/gate/gate.go| index 18ea23e1d..5d9c9e474 100644 |
| --- a/internal/gate/gate.go |
| +++ b/internal/gate/gate.go |
| @@ -207,6 +207,17 @@ func WithPublicHost(ctx context.Context, host string) context.Context { |
| return context.WithValue(ctx, publicHostKey{}, host) |
| } |
| +type clientAddrKey struct{} |
| + |
| +// WithClientAddr marks ctx's request as one from the visitor at addr, |
| +// whatever its RemoteAddr says, for the attempt limiter. The edge sets it |
| +// only for a request a linked deployment's hub delivered (linked |
| +// deployments spec §6.2), whose RemoteAddr is the tunnel's, shared by every |
| +// visitor: addr is the client address the hub observed. |
| +func WithClientAddr(ctx context.Context, addr string) context.Context { |
| + return context.WithValue(ctx, clientAddrKey{}, addr) |
| +} |
| + |
| // hostOnly drops the port, if there is one, so :443 and an implicit 443 |
| // are the same origin here. |
| func hostOnly(h string) string { |
| @@ -244,8 +255,12 @@ func SafeNext(next string) string { |
| // clientKey is the remote address without its port. A backhauled request's |
| // address is the sibling edge's, which folds every hop from that edge into |
| -// one bucket — stricter, never looser, and named in the spec (§4.2). |
| +// one bucket — stricter, never looser, and named in the spec (§4.2). A |
| +// request carrying a visitor address (WithClientAddr) is keyed on that. |
| func clientKey(r *http.Request) string { |
| + if addr, ok := r.Context().Value(clientAddrKey{}).(string); ok && addr != "" { |
| + return addr |
| + } |
| if h, _, err := net.SplitHostPort(r.RemoteAddr); err == nil { |
| return h |
| } |
diff --git a/internal/host/link_client.go b/internal/host/link_client.go| index 66ea60452..4a2378e67 100644 |
| --- a/internal/host/link_client.go |
| +++ b/internal/host/link_client.go |
| @@ -35,6 +35,7 @@ import ( |
| "maps" |
| "net/http" |
| "os" |
| + "sync" |
| "time" |
| "github.com/carlosframework/platform/internal/edge" |
| @@ -93,7 +94,14 @@ func runLinkLoop(ctx context.Context, d linkLoopDeps) { |
| } |
| }) |
| l := &linkLoopState{d: d, ctx: ctx} |
| - defer l.stop("the agent is stopping", true) |
| + defer func() { |
| + if c := l.stop("the agent is stopping", linkStopIdle); c != nil { |
| + select { |
| + case <-c.done: |
| + case <-time.After(tunnelclient.HandshakeTimeout + time.Second): |
| + } |
| + } |
| + }() |
| for { |
| retry := l.pass() |
| if d.onPass != nil { |
| @@ -122,16 +130,34 @@ func runLinkLoop(ctx context.Context, d linkLoopDeps) { |
| type linkLoopState struct { |
| d linkLoopDeps |
| ctx context.Context |
| + // mu orders a run's state reports against the loop replacing or |
| + // stopping that run (reportState, stop, start). cur is written only by |
| + // the loop's goroutine, always under mu. |
| + mu sync.Mutex |
| cur *linkRun |
| } |
| +// What stop records as the link's state. |
| +type linkStopKind int |
| + |
| +const ( |
| + // linkStopReplace: a new run follows at once (or as soon as the |
| + // published set reads again): "reconnecting". |
| + linkStopReplace linkStopKind = iota |
| + // linkStopIdle: no run follows on this box (unlinked, a fleet box, the |
| + // agent stopping): "". |
| + linkStopIdle |
| + // linkStopLost: another box holds the link and owns its state: nothing. |
| + linkStopLost |
| +) |
| + |
| // pass brings the running tunnel in line with the registry. It reports |
| // whether to run again soon without a reload (a read or claim failed). |
| func (l *linkLoopState) pass() (retry bool) { |
| d := l.d |
| if tunnelEnvComplete(d.getenv) { |
| // A fleet box of another hub: never claims, never dials. |
| - l.stop("this box is a fleet box", false) |
| + l.stop("this box is a fleet box", linkStopIdle) |
| return false |
| } |
| link, err := d.reg.HomeLink() |
| @@ -140,7 +166,7 @@ func (l *linkLoopState) pass() (retry bool) { |
| return true |
| } |
| if link == nil { |
| - l.stop("the deployment is not linked", false) |
| + l.stop("the deployment is not linked", linkStopIdle) |
| return false |
| } |
| if link.BoxLabel == "" { |
| @@ -154,7 +180,7 @@ func (l *linkLoopState) pass() (retry bool) { |
| return true |
| } |
| if link == nil { |
| - l.stop("the deployment is not linked", false) |
| + l.stop("the deployment is not linked", linkStopIdle) |
| return false |
| } |
| if link.BoxLabel == d.label { |
| @@ -162,9 +188,23 @@ func (l *linkLoopState) pass() (retry bool) { |
| } |
| } |
| if link.BoxLabel != d.label { |
| - l.stop("box "+link.BoxLabel+" holds the link", false) |
| + l.stop("box "+link.BoxLabel+" holds the link", linkStopLost) |
| return false |
| } |
| + // What the link row alone says is obsolete is closed before anything |
| + // else is read: a revocation must not wait on the published set. |
| + if c := l.cur; c != nil { |
| + switch { |
| + case c.id != link.ID: |
| + l.stop("the link was replaced", linkStopReplace) |
| + case c.token != link.Token: |
| + l.stop("the link's key was rotated", linkStopReplace) |
| + case c.url != link.TunnelURL: |
| + l.stop("the link's tunnel address changed", linkStopReplace) |
| + case c.gen != link.ConnGen: |
| + l.stop("an app was unpublished or retargeted", linkStopReplace) |
| + } |
| + } |
| apps, err := d.reg.HomeLinkApps() |
| if err != nil { |
| d.logf("agent: link %s: reading the published set: %v", link.ID, err) |
| @@ -175,24 +215,14 @@ func (l *linkLoopState) pass() (retry bool) { |
| set[a.Name] = a |
| } |
| if c := l.cur; c != nil { |
| - switch { |
| - case c.id != link.ID: |
| - l.stop("the link was replaced", false) |
| - case c.token != link.Token: |
| - l.stop("the link's key was rotated", false) |
| - case c.url != link.TunnelURL: |
| - l.stop("the link's tunnel address changed", false) |
| - case c.gen != link.ConnGen: |
| - l.stop("an app was unpublished or retargeted", false) |
| - case linkSetNarrowed(c.apps, set): |
| - // conn_gen is bumped with every unpublish and retarget, so this |
| - // is the same fact read from the set itself. |
| - l.stop("an app was unpublished or retargeted", false) |
| - default: |
| + if !linkSetNarrowed(c.apps, set) { |
| // New names need nothing: the handler reads the set per request. |
| c.apps = set |
| return false |
| } |
| + // conn_gen is bumped with every unpublish and retarget, so this is |
| + // the same fact read from the set itself. |
| + l.stop("an app was unpublished or retargeted", linkStopReplace) |
| } |
| l.start(link, set) |
| return false |
| @@ -216,6 +246,9 @@ func (l *linkLoopState) start(link *registry.HomeLink, set map[string]registry.H |
| apps: maps.Clone(set), cancel: cancel, done: make(chan struct{})} |
| name := registry.LinkChannelName(link.ID) |
| d.logf("agent: link %s: dialing %s as box %s (%d app(s) published)", link.ID, link.TunnelURL, d.label, len(set)) |
| + l.mu.Lock() |
| + l.cur = run |
| + l.mu.Unlock() |
| go func() { |
| defer close(run.done) |
| tunnelclient.Loop(ctx, tunnelclient.Config{ |
| @@ -223,39 +256,58 @@ func (l *linkLoopState) start(link *registry.HomeLink, set map[string]registry.H |
| Name: name, |
| Token: link.Token, |
| Handler: linkHandler{reg: d.reg, serve: d.edge.ServeLinked}, |
| - // Only the running loop reports: a cancelled one must not write |
| - // over its replacement's state, or another box's. |
| - OnState: func(s string) { |
| - if ctx.Err() != nil { |
| - return |
| - } |
| - if err := d.reg.SetHomeLinkState(s); err != nil { |
| - d.logf("agent: link %s: recording state %s: %v", link.ID, s, err) |
| - } |
| - }, |
| - Logf: func(format string, args ...any) { d.logf("agent: link: "+format, args...) }, |
| + // Only the run the loop holds reports (reportState): a replaced |
| + // or stopped one must not write over its successor's state, or |
| + // another box's. |
| + OnState: func(s string) { l.reportState(run, s) }, |
| + Logf: func(format string, args ...any) { d.logf("agent: link: "+format, args...) }, |
| }) |
| }() |
| - l.cur = run |
| } |
| -// stop cancels the running tunnel, if any. It waits for the loop to return |
| -// only when wait is set (the agent is stopping): a replacement starts at |
| -// once, and the cancelled loop's own connection is closed by the cancel. |
| -func (l *linkLoopState) stop(why string, wait bool) { |
| +// reportState records s as the link's state if run is still the loop's |
| +// current run. It holds mu across the write, so a stop or a replacement |
| +// either comes before it (and the report is dropped) or after it (and its |
| +// own state is written last). |
| +func (l *linkLoopState) reportState(run *linkRun, s string) { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + if l.cur != run { |
| + return |
| + } |
| + if err := l.d.reg.SetHomeLinkState(s); err != nil { |
| + l.d.logf("agent: link %s: recording state %s: %v", run.id, s, err) |
| + } |
| +} |
| + |
| +// stop cancels the running tunnel, if any, records the state kind says, |
| +// and returns the stopped run (nil when none ran). Cancelling closes the |
| +// run's connection and every stream on it; the caller waits on its done |
| +// only when it must (the agent stopping): a replacement starts at once. |
| +func (l *linkLoopState) stop(why string, kind linkStopKind) *linkRun { |
| + l.mu.Lock() |
| c := l.cur |
| if c == nil { |
| - return |
| + l.mu.Unlock() |
| + return nil |
| } |
| l.cur = nil |
| - l.d.logf("agent: link %s: closing the connection: %s", c.id, why) |
| - c.cancel() |
| - if wait { |
| - select { |
| - case <-c.done: |
| - case <-time.After(tunnelclient.HandshakeTimeout + time.Second): |
| + var state string |
| + switch kind { |
| + case linkStopReplace: |
| + state = registry.HomeLinkReconnecting |
| + case linkStopIdle: |
| + state = "" |
| + } |
| + if kind != linkStopLost { |
| + if err := l.d.reg.SetHomeLinkState(state); err != nil { |
| + l.d.logf("agent: link %s: recording state %q: %v", c.id, state, err) |
| } |
| } |
| + l.mu.Unlock() |
| + l.d.logf("agent: link %s: closing the connection: %s", c.id, why) |
| + c.cancel() |
| + return c |
| } |
| // linkBoxLabel is the label this box claims a link under: the agent's box |
diff --git a/internal/host/link_e2e_test.go b/internal/host/link_e2e_test.go| index ce8be492c..3796dd343 100644 |
| --- a/internal/host/link_e2e_test.go |
| +++ b/internal/host/link_e2e_test.go |
| @@ -74,7 +74,7 @@ func linkPublicHost(name string) string { return name + "." + linkServingAcct + |
| // linkSeen is what a home app saw of one request. |
| type linkSeen struct { |
| - Method, Path, Host, XFH, XFP, LinkApp, ImportVerify, Purge, Cookie string |
| + Method, Path, Host, XFH, XFP, XFF, LinkApp, ImportVerify, Purge, Cookie string |
| } |
| // linkTestApp is a home app on a Unix socket. It records every request and |
| @@ -118,7 +118,7 @@ func startLinkApp(t *testing.T, name string) *linkTestApp { |
| func (a *linkTestApp) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| a.mu.Lock() |
| a.seen = append(a.seen, linkSeen{Method: r.Method, Path: r.URL.Path, Host: r.Host, |
| - XFH: r.Header.Get("X-Forwarded-Host"), XFP: r.Header.Get("X-Forwarded-Proto"), |
| + XFH: r.Header.Get("X-Forwarded-Host"), XFP: r.Header.Get("X-Forwarded-Proto"), XFF: strings.Join(r.Header.Values("X-Forwarded-For"), ", "), |
| LinkApp: strings.Join(r.Header.Values(tunnelclient.LinkAppHeader), ","), ImportVerify: r.Header.Get(edge.ImportVerifyHeader), |
| Purge: r.Header.Get(edge.PurgeHeader), Cookie: r.Header.Get("Cookie")}) |
| a.mu.Unlock() |
| @@ -968,3 +968,185 @@ func TestLinkBoxLabel(t *testing.T) { |
| t.Fatalf("with neither: %q, want %q", got, want) |
| } |
| } |
| + |
| +// linkFlakyReg fails HomeLinkApps on demand, on top of the real registry. |
| +type linkFlakyReg struct { |
| + *registry.Registry |
| + failApps atomic.Bool |
| +} |
| + |
| +func (f *linkFlakyReg) HomeLinkApps() ([]registry.HomeLinkApp, error) { |
| + if f.failApps.Load() { |
| + return nil, errors.New("published set unreadable") |
| + } |
| + return f.Registry.HomeLinkApps() |
| +} |
| + |
| +// A known revocation (conn_gen moved on the link row) closes the connection |
| +// even while the published set cannot be read. |
| +func TestLinkRevocationDoesNotWaitOnAppSetRead(t *testing.T) { |
| + w := newLinkWorld(t, true, map[string]string{"shop": "shop", "blog": "blog"}) |
| + flaky := &linkFlakyReg{Registry: w.homeReg} |
| + w.loopReg = flaky |
| + w.startLoop(t) |
| + w.waitConnected(t) |
| + sse := w.openSSE(t, "shop") |
| + |
| + flaky.failApps.Store(true) |
| + if ok, err := w.homeReg.DeleteHomeLinkApp("blog"); err != nil || !ok { |
| + t.Fatalf("DeleteHomeLinkApp = %v, %v", ok, err) |
| + } |
| + resumed := time.Now() |
| + w.reloadHome(t) |
| + linkEndsWithin(t, "shop's SSE response with the set unreadable", sse, resumed, linkWatch) |
| + |
| + flaky.failApps.Store(false) |
| + w.reloadHome(t) |
| + w.waitConnected(t) |
| + linkWait(t, "shop after the set reads again", func() bool { |
| + resp, body := w.via(t, "GET", "shop", "/", nil, "") |
| + return resp.StatusCode == http.StatusOK && body == "shop" |
| + }) |
| +} |
| + |
| +// linkStateRec records SetHomeLinkState calls and nothing else. |
| +type linkStateRec struct { |
| + *registry.Registry |
| + mu sync.Mutex |
| + states []string |
| +} |
| + |
| +func (r *linkStateRec) SetHomeLinkState(s string) error { |
| + r.mu.Lock() |
| + defer r.mu.Unlock() |
| + r.states = append(r.states, s) |
| + return nil |
| +} |
| + |
| +// Only the run the loop holds now may record the state: a replaced run's |
| +// late report is dropped. |
| +func TestLinkStateOnlyFromTheCurrentRun(t *testing.T) { |
| + rec := &linkStateRec{} |
| + l := &linkLoopState{d: linkLoopDeps{reg: rec, logf: t.Logf}} |
| + old, cur := &linkRun{id: "aaaaaaaaaaaa", cancel: func() {}}, &linkRun{id: "bbbbbbbbbbbb", cancel: func() {}} |
| + l.cur = cur |
| + l.reportState(old, registry.HomeLinkReconnecting) |
| + l.reportState(cur, registry.HomeLinkConnected) |
| + l.stop("test", linkStopIdle) |
| + l.reportState(cur, registry.HomeLinkReconnecting) |
| + rec.mu.Lock() |
| + defer rec.mu.Unlock() |
| + if got := strings.Join(rec.states, ","); got != "connected," { |
| + t.Fatalf("states written %q, want connected then the stop's empty state", got) |
| + } |
| +} |
| + |
| +// A loop that stops its run without a replacement records "". |
| +func TestLinkStopClearsState(t *testing.T) { |
| + w := newLinkedWorld(t, nil) |
| + linkWait(t, "state connected", func() bool { |
| + l, err := w.homeReg.HomeLink() |
| + return err == nil && l.State == registry.HomeLinkConnected |
| + }) |
| + w.stopLoop() |
| + if l, err := w.homeReg.HomeLink(); err != nil || l.State != "" { |
| + t.Fatalf("after the loop stopped: %+v, %v; want state empty", l, err) |
| + } |
| +} |
| + |
| +// linkVisitor is an HTTP client whose connections leave from local address |
| +// ip, so the hub observes that address as the visitor's. |
| +func linkVisitor(ip string) *http.Client { |
| + d := &net.Dialer{LocalAddr: &net.TCPAddr{IP: net.ParseIP(ip)}} |
| + return &http.Client{Timeout: 10 * time.Second, |
| + Transport: &http.Transport{DialContext: d.DialContext}, |
| + CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }} |
| +} |
| + |
| +func linkVisit(t *testing.T, c *http.Client, base, method, host, path string, hdr http.Header, body string) int { |
| + t.Helper() |
| + req, err := http.NewRequest(method, base+path, strings.NewReader(body)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Host = host |
| + for k, vs := range hdr { |
| + req.Header[k] = vs |
| + } |
| + resp, err := c.Do(req) |
| + if err != nil { |
| + t.Fatalf("%s %s%s: %v", method, host, path, err) |
| + } |
| + io.Copy(io.Discard, resp.Body) |
| + resp.Body.Close() |
| + return resp.StatusCode |
| +} |
| + |
| +// The app sees each linked visitor's own address, and the password gate |
| +// counts each visitor's attempts on its own. On ordinary ingress a forged |
| +// X-Forwarded-For changes nothing. |
| +func TestLinkVisitorIdentity(t *testing.T) { |
| + w := newLinkedWorld(t, nil) |
| + a, b := linkVisitor("127.0.0.2"), linkVisitor("127.0.0.3") |
| + public := linkPublicHost("shop") |
| + // A client's own X-Forwarded-For never survives the hub. |
| + forged := http.Header{"X-Forwarded-For": {"203.0.113.9"}} |
| + if code := linkVisit(t, a, w.hubURL, "GET", public, "/hello", forged, ""); code != http.StatusOK { |
| + t.Fatalf("visitor a: %d", code) |
| + } |
| + if code := linkVisit(t, b, w.hubURL, "GET", public, "/hello", nil, ""); code != http.StatusOK { |
| + t.Fatalf("visitor b: %d", code) |
| + } |
| + seen := w.apps["shop"].requests() |
| + if len(seen) != 2 || seen[0].XFF != "127.0.0.2" || seen[1].XFF != "127.0.0.3" { |
| + t.Fatalf("shop saw X-Forwarded-For %+v; want 127.0.0.2 then 127.0.0.3", seen) |
| + } |
| + |
| + hash, err := gate.Hash("shop-password") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := w.homeReg.SetGate(linkHomeHost("shop"), hash); err != nil { |
| + t.Fatal(err) |
| + } |
| + w.reloadHome(t) |
| + wrong := url.Values{"password": {"not-the-password"}, "next": {"/"}}.Encode() |
| + form := http.Header{"Content-Type": {"application/x-www-form-urlencoded"}} |
| + login := func(c *http.Client, base, host string, hdr http.Header) int { |
| + h := http.Header{} |
| + for k, v := range form { |
| + h[k] = v |
| + } |
| + for k, v := range hdr { |
| + h[k] = v |
| + } |
| + return linkVisit(t, c, base, "POST", host, gate.LoginPath, h, wrong) |
| + } |
| + for i := 0; i < 10; i++ { |
| + if code := login(a, w.hubURL, public, nil); code != http.StatusUnauthorized { |
| + t.Fatalf("visitor a attempt %d: %d, want 401", i+1, code) |
| + } |
| + } |
| + if code := login(a, w.hubURL, public, nil); code != http.StatusTooManyRequests { |
| + t.Fatalf("visitor a's 11th attempt: %d, want 429", code) |
| + } |
| + if code := login(a, w.hubURL, public, forged); code != http.StatusTooManyRequests { |
| + t.Fatalf("visitor a with a forged X-Forwarded-For: %d, want 429 still", code) |
| + } |
| + if code := login(b, w.hubURL, public, nil); code != http.StatusUnauthorized { |
| + t.Fatalf("visitor b after a was refused: %d, want its own 401", code) |
| + } |
| + |
| + // Ordinary ingress: one bucket for the connection's address, whatever |
| + // X-Forwarded-For says. |
| + tail := linkVisitor("127.0.0.4") |
| + for i := 0; i < 10; i++ { |
| + hdr := http.Header{"X-Forwarded-For": {fmt.Sprintf("198.51.100.%d", i+1)}} |
| + if code := login(tail, w.tailnet, linkHomeHost("shop"), hdr); code != http.StatusUnauthorized { |
| + t.Fatalf("tailnet attempt %d: %d, want 401", i+1, code) |
| + } |
| + } |
| + if code := login(tail, w.tailnet, linkHomeHost("shop"), http.Header{"X-Forwarded-For": {"198.51.100.99"}}); code != http.StatusTooManyRequests { |
| + t.Fatalf("tailnet 11th attempt with a new forged X-Forwarded-For: %d, want 429", code) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 22e679829..fad786bca 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -155,4 +155,4 @@ plan14-root-reads-gvisor-probe-diag.tsv a9ae6b238b6b2e177be1f9c7ae06ea0f24477e4e |
| plan14-root-reads-deploy-happy-path.tsv a9ae6b238b6b2e177be1f9c7ae06ea0f24477e4eb0e58abda63f4b7337dbe3ee |
| plan14-root-reads-held-move-speed.tsv 837f27a6b7b6ed272f8c68aca07650fa32cf3ec92ce28bf9d812a4282eeb0b58 |
| plan14-root-reads-litestream-quiet-802.tsv 6d3ea7fccce1a7f4bc507b6eb8d368ed0b62f83022504aa04c7684c72c93aa9a |
| -plan14-root-reads-linked-deployments-slice1.tsv 8025c50a3e2dc1e51ed45b73a230dbf33aa09dd1672f92c425194d29bcc3e74a |
| +plan14-root-reads-linked-deployments-slice1.tsv 0b8e44b7660274dbbd5d31545dc5704db2f3cfd2838fd982993a31c8436d15b9 |
diff --git a/internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv b/internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv| index d32fe57c6..a6029dbc9 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-linked-deployments-slice1.tsv |
| @@ -1,5 +1,5 @@ |
| # Census overlay linked-deployments-slice1, written by census-propose (#369). census-ruling-linked-deployments-slice1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-linked-deployments-slice1.md. |
| -# 15 body, 8 sites, 7 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 15 body, 8 sites, 8 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| # 39 new dispositions: 4 reads re-frozen at their disposition with the claim, 34 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 1 other. |
| @legacy 1cb1c2d61f2c9cac86a37ae03cbc610d0a6adb9862c436283aae7af1203081a2 internal/edge/demo.go Edge.handleDemoRequest legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-2;basis=demo.go:87-109 classifies request authority using the loaded refusal/upstream maps and checks the existing Route binding before protected dispatch. Five whole Route uses; malformed, unknown and expired names receive fixed policy-bearing refusals, never ordinary fallback. No new storage read.;rev3=census-ruling-agent-start-demo-3;basis=Check verified moved notices before route lookup so a purged source can still display its bounded notice. Census read-site delta: unchanged (5).;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: the upstream comes from selectUpstream(r, host, path), which is lookupUpstreamPath(host, path) unless the request carries a link pin; same reads whole:Route@446,whole:Route@513,whole:Route@554,whole:Route@770,whole:Route@812 a6d6ab6a73419e8fd1e9e38b2b3be8dab387a2fc119ced5eb35fa73ed9feb581 |
| @legacy 22be9ee0cf964afa8a4748c7c1ccfab5f0982a634e1905b6eef02024cf4f2bc6 internal/edge/demo.go Edge.redirectDemoRequest legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-2;basis=demo.go:87-102 answers a plain-HTTP demo request with a 308 to the same host and path over HTTPS, with demo policy headers, only after the loaded Route, alias and serving checks pass; reads only the already-loaded Route (whole value), never dispatches, counts or opens anything.;rev3=census-ruling-agent-start-demo-3;basis=Serve signed moved notices at the demo redirect entry before redirecting; retain exact-host validation. Census read-site delta: unchanged (3).;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: the upstream comes from selectUpstream(r, host, path), which is lookupUpstreamPath(host, path) unless the request carries a link pin (never on :80); same reads whole:Route@296,whole:Route@338,whole:Route@432 db1a9db900e5f41fd5f4696bd72bac7b7f038fcfce1beae6a2cd0c3465f431bb |
| @@ -16,8 +16,8 @@ |
| @legacy 016a166915f0e50879425a00398d783afebf2c3f2b138fe7303689dc5be0933a internal/registry/registry.go Registry.migrate legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user), on every registry open; a box CLI verb that opens the registry directly runs it as whoever runs the verb: census-ruling-seeded-instances's body with two more columns added to routes (incarnation and serving_seq, INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule); self-serve moves 1 Task 7;rev3=census-ruling-rootfs-apps-2;basis=one more ALTER TABLE, routes ADD COLUMN runtime TEXT NOT NULL DEFAULT '', beside main's rate_limit, assets_off, asset_gen, incarnation and serving_seq (the last four from the merges of origin/main 3c33f2eb and 953b9fda); the same sixteen sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328/#329 plan 1 Task 4: three more ALTER TABLE statements in the existing loop, routes ADD COLUMN egress_allow, size and policy_expires_at, each TEXT NOT NULL DEFAULT '' and idempotent through the duplicate-column rule; the same sixteen sites, no read added.;rev3=census-ruling-region-ha-p1a;basis=one more ALTER TABLE in the existing loop: routes ADD COLUMN ha INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule; the same sixteen sites, no read added;rev3=census-ruling-ha-p1a-433;basis=the registry's SQLite side as carlos (agent, registry child; a box CLI verb that opens the registry directly runs it as whoever runs it), on every registry open: the ALTER TABLE routes statements are now built from the one migration definition routeAddedColumns (addedColumn name, type, default; review r1 P2): for each entry without the Claim mark, "ALTER TABLE routes ADD COLUMN " + spec(), byte for byte the statements main runs, in main's order, under the same duplicate-column rule. +registry:Claim is that mark, +whole:addedColumn the struct. Every name, type and default is an in-binary literal; no statement added, removed or changed; no read added.;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: one more CREATE TABLE IF NOT EXISTS regional_domains (host TEXT PRIMARY KEY, target, account, app, region TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL DEFAULT 0), beside wildcard_domains; the added sites are that statement (+file:Exec, +registry:sql), an in-binary literal; additive, no existing statement changed;rev3=census-ruling-region-ha-p1b3b-t;basis=Create local HA duty/replay tables and revision triggers in the existing registry connection; no new database path.;rev3=census-ruling-agent-start-demo-3;basis=Create moved-notice storage as a single (id, wire) row; fingerprints include the stored wire bytes. Census read-site delta: +file:Exec, +registry:sql.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: calls migrateLinks after migrateHADuties (one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal); additive, no existing statement changed; linked deployments slice 1 Task 7: also runs migrateHomeLink (CREATE TABLE IF NOT EXISTS home_link and home_link_apps) after migrateLinks; additive, the box's own registry database, as carlos file:Exec@1124,file:Exec@1855,file:Exec@212,file:Exec@2409,file:Exec@3347,file:Exec@3626,file:Exec@4489,file:Exec@4665,file:Exec@51,file:Exec@761,registry:Claim@686,registry:sql@1124,registry:sql@1855,registry:sql@212,registry:sql@2409,registry:sql@3347,registry:sql@3626,registry:sql@4489,registry:sql@4665,registry:sql@51,registry:sql@761,whole:addedColumn@661 63fc63e2dd8bcd22c23e590d7e79f2996c31e0edc94aa1da2d48646f99c64ef2 |
| @legacy f859ac9ca9fc6e6e2f12190382770c2913ea39e0dd915557aa75b5396d3925f6 internal/edge/edge.go Edge.pinnedUpstream legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; a linked request's upstream: the exact in-memory routing-map entry for the pinned home host, admitted only when its route is that host's own row for the pinned account and app, an instance, not forward, demo or sidecar, served from this box; reads the route fields of the map entry the last Reload built, no registry, file or bucket read registry:Account@435,registry:App@466,registry:Host@156,registry:Kind@331,whole:Route@146 9e26e286bc9973a11697c46766f19587f791fb83cf4275d3ed6df2d638ec03a8 |
| @legacy a10d080a12c01e05c132febd9e72b6656c340866c1749be14ba9e1f142d8e1ea internal/edge/fleetforward.go linkServeEligible legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 3: new pure rule for a link-placed forward row: refused off the hub, when not inert, when it carries a fleet box, label or replica set, when its link is not in the active link owners, or when its raw Account is empty or not the link's owner; reads only the row and the owners map registry:Account@567,registry:Account@636,registry:Account@720,registry:FleetBox@277,registry:FleetBoxes@321,registry:FleetLabel@298 e15bfdfc2c2928ccd325b8844346be778eb5e186bd7898c2f21bf84c7574dde7 |
| -@legacy a7b32078a804f153f200f31c640781e83d6f39b8c3dc079aeb56cdf0870342fa internal/host/link_client.go linkLoopState.pass legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; the home link loop's pass: reads HomeLink and HomeLinkApps from the agent's own registry, claims an unclaimed link with ClaimHomeLink(label) unless this is a fleet box (tunnelEnvComplete), and starts, keeps or cancels the link's tunnel by link ID, token, tunnel URL, conn_gen and the published set; no file or bucket read, nothing executed registry:BoxLabel@415,registry:BoxLabel@837,registry:BoxLabel@940,registry:BoxLabel@983,registry:ConnGen@1569,registry:ID@1151,registry:ID@1339,registry:ID@547,registry:ID@911,registry:Name@1271,registry:Token@1408,registry:TunnelURL@1483,whole:HomeLink@1979,whole:HomeLink@331,whole:HomeLink@630,whole:HomeLink@749,whole:HomeLinkApp@1232,whole:HomeLinkApp@1258,whole:HomeLinkApp@1267,whole:HomeLinkApp@1281,whole:HomeLinkApp@1665,whole:HomeLinkApp@1671,whole:HomeLinkApp@1936,whole:HomeLinkApp@1943,whole:HomeLinkApp@1985 99b9ba1e43ba11fed0e208c5d9c113f061efe3e74de72d9bcaf81b619ea2086f |
| -@legacy 5629d34a3a55b4a39fe8274790c31a65c86963fad1802806b948a56f3d7989e4 internal/host/link_client.go linkLoopState.start legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; starts tunnelclient.Loop for the link (channel name from the link ID, the stored token and tunnel URL) serving linkHandler, and records its state with SetHomeLinkState while it is the running loop; no file or bucket read registry:ConnGen@221,registry:ID@167,registry:ID@337,registry:ID@416,registry:ID@980,registry:Token@183,registry:Token@601,registry:TunnelURL@200,registry:TunnelURL@425,registry:TunnelURL@555,whole:HomeLinkApp@237,whole:HomeLinkApp@254,whole:HomeLinkApp@454 c534438d025bf383de7271d58796590a5e5fb1b520a64261444b13873740de27 |
| +@legacy f860132d57fd2caeb25fa014f4623c9f134f49fb7035abbee16294698ec8c4a0 internal/host/link_client.go linkLoopState.pass legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; the home link loop's pass: reads HomeLink and HomeLinkApps from the agent's own registry, claims an unclaimed link with ClaimHomeLink(label) unless this is a fleet box (tunnelEnvComplete), and starts, keeps or cancels the link's tunnel by link ID, token, tunnel URL, conn_gen and the published set; no file or bucket read, nothing executed; fix round 1: a run the link row alone shows obsolete (link ID, token, tunnel URL or conn_gen changed) is cancelled before HomeLinkApps is read, so a failing set read cannot hold a revoked connection open; stops record the link state as reconnecting (replaced), empty (unlinked, fleet box) or nothing (another box holds the claim); same reads registry:BoxLabel@1004,registry:BoxLabel@429,registry:BoxLabel@858,registry:BoxLabel@961,registry:ConnGen@1520,registry:ID@1260,registry:ID@1718,registry:ID@561,registry:ID@932,registry:Name@1838,registry:Token@1339,registry:TunnelURL@1424,whole:HomeLink@2215,whole:HomeLink@338,whole:HomeLink@644,whole:HomeLink@763,whole:HomeLinkApp@1799,whole:HomeLinkApp@1825,whole:HomeLinkApp@1834,whole:HomeLinkApp@1848,whole:HomeLinkApp@1904,whole:HomeLinkApp@1910,whole:HomeLinkApp@1991,whole:HomeLinkApp@1998,whole:HomeLinkApp@2221 fa7441cf65bde320d4f58c08d43f927e9e8868960b303700fd26358e3668b29c |
| +@legacy 2a3a9d15fb722558e494553cb2b35373b688a0cacc948a8714c4531c8743d25e internal/host/link_client.go linkLoopState.start legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; starts tunnelclient.Loop for the link (channel name from the link ID, the stored token and tunnel URL) serving linkHandler, and records its state with SetHomeLinkState while it is the running loop; no file or bucket read; fix round 1: the run is made current under the loop's lock before its tunnel starts, and its OnState goes through reportState, which writes SetHomeLinkState only while that run is still current; one fewer read site (the link ID in the state callback's log line moved to reportState) registry:ConnGen@221,registry:ID@167,registry:ID@337,registry:ID@416,registry:Token@183,registry:Token@642,registry:TunnelURL@200,registry:TunnelURL@425,registry:TunnelURL@596,whole:HomeLinkApp@237,whole:HomeLinkApp@254,whole:HomeLinkApp@454 db8518154691958ef28b923401c208758c03925d23c2ff64ffb291effe6c013a |
| @legacy e14481c06286c23fa3ff9f20d51f906ae9fdfb69c56063c28b1a4d59d44e66ae internal/host/link_client.go linkSetNarrowed legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; compares two in-memory published sets by name; no read whole:HomeLinkApp@112,whole:HomeLinkApp@130,whole:HomeLinkApp@135,whole:HomeLinkApp@92 acf871a54433606a3d9a43fdc646108df576a8d6b25bdf6f8bbfa15f8e2dbcc6 |
| @legacy 6ddce06ad2bfd7fc901dc0f2e9de3aaac45f241045fc6dfe185af49d82960d8e internal/host/link_handler.go linkHandler.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; the link channel's handler: reads the one Carlos-Link-App value, looks it up with HomeLinkAppByName in the agent's own registry on every request, refuses a missing or unpublished name with 404, and hands a published one to edge.ServeLinked with the row's home account, app and host; the request's Host never selects; no file or bucket read registry:HomeAccount@1279,registry:HomeAccount@705,registry:HomeApp@1301,registry:HomeApp@730,registry:HomeHost@1256,registry:HomeHost@683,whole:HomeLinkApp@669 4a5cacac0f6fba9392d40246171f2dd4d38dcc99dd29f2bfccb8f19fe94c49a8 |
| @legacy fea79e228a063943572b0ca4d2abde20ebb96d9ea14678b6bff560828db248ed internal/registry/homelink.go CheckCredentialFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new (linked deployments slice 1 Task 7): Lstat of the registry path the Registry was opened with (never a caller-named path in production: PutHomeLink passes r.path, the console passes its configured registry); refuses a symbolic link, a non-regular file and a world-readable mode; reads only the mode, refuses more; fix round 1: also Lstats registry.db-wal, -shm and -journal beside the same path (the WAL holds the token first in WAL mode); a missing journal is skipped, an existing one must be a regular non-symlink file with no world-read bit, else refused naming it; reads only modes, refuses more file:Lstat@150 e721b4422cf333532c8e47d2c99553b6d71d7c8763c1ae4cbbbd29e72b6c3c69 |
| @@ -76,8 +76,8 @@ internal/registry/forward.go Registry.DeleteForward legacy accepted-legacy accep |
| internal/registry/registry.go Registry.migrate legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user), on every registry open; a box CLI verb that opens the registry directly runs it as whoever runs the verb: census-ruling-seeded-instances's body with two more columns added to routes (incarnation and serving_seq, INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule); self-serve moves 1 Task 7;rev3=census-ruling-rootfs-apps-2;basis=one more ALTER TABLE, routes ADD COLUMN runtime TEXT NOT NULL DEFAULT '', beside main's rate_limit, assets_off, asset_gen, incarnation and serving_seq (the last four from the merges of origin/main 3c33f2eb and 953b9fda); the same sixteen sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328/#329 plan 1 Task 4: three more ALTER TABLE statements in the existing loop, routes ADD COLUMN egress_allow, size and policy_expires_at, each TEXT NOT NULL DEFAULT '' and idempotent through the duplicate-column rule; the same sixteen sites, no read added.;rev3=census-ruling-region-ha-p1a;basis=one more ALTER TABLE in the existing loop: routes ADD COLUMN ha INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule; the same sixteen sites, no read added;rev3=census-ruling-ha-p1a-433;basis=the registry's SQLite side as carlos (agent, registry child; a box CLI verb that opens the registry directly runs it as whoever runs it), on every registry open: the ALTER TABLE routes statements are now built from the one migration definition routeAddedColumns (addedColumn name, type, default; review r1 P2): for each entry without the Claim mark, "ALTER TABLE routes ADD COLUMN " + spec(), byte for byte the statements main runs, in main's order, under the same duplicate-column rule. +registry:Claim is that mark, +whole:addedColumn the struct. Every name, type and default is an in-binary literal; no statement added, removed or changed; no read added.;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: one more CREATE TABLE IF NOT EXISTS regional_domains (host TEXT PRIMARY KEY, target, account, app, region TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL DEFAULT 0), beside wildcard_domains; the added sites are that statement (+file:Exec, +registry:sql), an in-binary literal; additive, no existing statement changed;rev3=census-ruling-region-ha-p1b3b-t;basis=Create local HA duty/replay tables and revision triggers in the existing registry connection; no new database path.;rev3=census-ruling-agent-start-demo-3;basis=Create moved-notice storage as a single (id, wire) row; fingerprints include the stored wire bytes. Census read-site delta: +file:Exec, +registry:sql.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: calls migrateLinks after migrateHADuties (one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal); additive, no existing statement changed; linked deployments slice 1 Task 7: also runs migrateHomeLink (CREATE TABLE IF NOT EXISTS home_link and home_link_apps) after migrateLinks; additive, the box's own registry database, as carlos file:Exec@1124,file:Exec@1855,file:Exec@212,file:Exec@2409,file:Exec@3347,file:Exec@3626,file:Exec@4489,file:Exec@4665,file:Exec@51,file:Exec@761,registry:Claim@686,registry:sql@1124,registry:sql@1855,registry:sql@212,registry:sql@2409,registry:sql@3347,registry:sql@3626,registry:sql@4489,registry:sql@4665,registry:sql@51,registry:sql@761,whole:addedColumn@661 63fc63e2dd8bcd22c23e590d7e79f2996c31e0edc94aa1da2d48646f99c64ef2 |
| internal/edge/edge.go Edge.pinnedUpstream legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; a linked request's upstream: the exact in-memory routing-map entry for the pinned home host, admitted only when its route is that host's own row for the pinned account and app, an instance, not forward, demo or sidecar, served from this box; reads the route fields of the map entry the last Reload built, no registry, file or bucket read registry:Account@435,registry:App@466,registry:Host@156,registry:Kind@331,whole:Route@146 9e26e286bc9973a11697c46766f19587f791fb83cf4275d3ed6df2d638ec03a8 |
| internal/edge/fleetforward.go linkServeEligible legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 3: new pure rule for a link-placed forward row: refused off the hub, when not inert, when it carries a fleet box, label or replica set, when its link is not in the active link owners, or when its raw Account is empty or not the link's owner; reads only the row and the owners map registry:Account@567,registry:Account@636,registry:Account@720,registry:FleetBox@277,registry:FleetBoxes@321,registry:FleetLabel@298 e15bfdfc2c2928ccd325b8844346be778eb5e186bd7898c2f21bf84c7574dde7 |
| -internal/host/link_client.go linkLoopState.pass legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; the home link loop's pass: reads HomeLink and HomeLinkApps from the agent's own registry, claims an unclaimed link with ClaimHomeLink(label) unless this is a fleet box (tunnelEnvComplete), and starts, keeps or cancels the link's tunnel by link ID, token, tunnel URL, conn_gen and the published set; no file or bucket read, nothing executed registry:BoxLabel@415,registry:BoxLabel@837,registry:BoxLabel@940,registry:BoxLabel@983,registry:ConnGen@1569,registry:ID@1151,registry:ID@1339,registry:ID@547,registry:ID@911,registry:Name@1271,registry:Token@1408,registry:TunnelURL@1483,whole:HomeLink@1979,whole:HomeLink@331,whole:HomeLink@630,whole:HomeLink@749,whole:HomeLinkApp@1232,whole:HomeLinkApp@1258,whole:HomeLinkApp@1267,whole:HomeLinkApp@1281,whole:HomeLinkApp@1665,whole:HomeLinkApp@1671,whole:HomeLinkApp@1936,whole:HomeLinkApp@1943,whole:HomeLinkApp@1985 99b9ba1e43ba11fed0e208c5d9c113f061efe3e74de72d9bcaf81b619ea2086f |
| -internal/host/link_client.go linkLoopState.start legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; starts tunnelclient.Loop for the link (channel name from the link ID, the stored token and tunnel URL) serving linkHandler, and records its state with SetHomeLinkState while it is the running loop; no file or bucket read registry:ConnGen@221,registry:ID@167,registry:ID@337,registry:ID@416,registry:ID@980,registry:Token@183,registry:Token@601,registry:TunnelURL@200,registry:TunnelURL@425,registry:TunnelURL@555,whole:HomeLinkApp@237,whole:HomeLinkApp@254,whole:HomeLinkApp@454 c534438d025bf383de7271d58796590a5e5fb1b520a64261444b13873740de27 |
| +internal/host/link_client.go linkLoopState.pass legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; the home link loop's pass: reads HomeLink and HomeLinkApps from the agent's own registry, claims an unclaimed link with ClaimHomeLink(label) unless this is a fleet box (tunnelEnvComplete), and starts, keeps or cancels the link's tunnel by link ID, token, tunnel URL, conn_gen and the published set; no file or bucket read, nothing executed; fix round 1: a run the link row alone shows obsolete (link ID, token, tunnel URL or conn_gen changed) is cancelled before HomeLinkApps is read, so a failing set read cannot hold a revoked connection open; stops record the link state as reconnecting (replaced), empty (unlinked, fleet box) or nothing (another box holds the claim); same reads registry:BoxLabel@1004,registry:BoxLabel@429,registry:BoxLabel@858,registry:BoxLabel@961,registry:ConnGen@1520,registry:ID@1260,registry:ID@1718,registry:ID@561,registry:ID@932,registry:Name@1838,registry:Token@1339,registry:TunnelURL@1424,whole:HomeLink@2215,whole:HomeLink@338,whole:HomeLink@644,whole:HomeLink@763,whole:HomeLinkApp@1799,whole:HomeLinkApp@1825,whole:HomeLinkApp@1834,whole:HomeLinkApp@1848,whole:HomeLinkApp@1904,whole:HomeLinkApp@1910,whole:HomeLinkApp@1991,whole:HomeLinkApp@1998,whole:HomeLinkApp@2221 fa7441cf65bde320d4f58c08d43f927e9e8868960b303700fd26358e3668b29c |
| +internal/host/link_client.go linkLoopState.start legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; starts tunnelclient.Loop for the link (channel name from the link ID, the stored token and tunnel URL) serving linkHandler, and records its state with SetHomeLinkState while it is the running loop; no file or bucket read; fix round 1: the run is made current under the loop's lock before its tunnel starts, and its OnState goes through reportState, which writes SetHomeLinkState only while that run is still current; one fewer read site (the link ID in the state callback's log line moved to reportState) registry:ConnGen@221,registry:ID@167,registry:ID@337,registry:ID@416,registry:Token@183,registry:Token@642,registry:TunnelURL@200,registry:TunnelURL@425,registry:TunnelURL@596,whole:HomeLinkApp@237,whole:HomeLinkApp@254,whole:HomeLinkApp@454 db8518154691958ef28b923401c208758c03925d23c2ff64ffb291effe6c013a |
| internal/host/link_client.go linkSetNarrowed legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; compares two in-memory published sets by name; no read whole:HomeLinkApp@112,whole:HomeLinkApp@130,whole:HomeLinkApp@135,whole:HomeLinkApp@92 acf871a54433606a3d9a43fdc646108df576a8d6b25bdf6f8bbfa15f8e2dbcc6 |
| internal/host/link_handler.go linkHandler.ServeHTTP legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 8: new; the link channel's handler: reads the one Carlos-Link-App value, looks it up with HomeLinkAppByName in the agent's own registry on every request, refuses a missing or unpublished name with 404, and hands a published one to edge.ServeLinked with the row's home account, app and host; the request's Host never selects; no file or bucket read registry:HomeAccount@1279,registry:HomeAccount@705,registry:HomeApp@1301,registry:HomeApp@730,registry:HomeHost@1256,registry:HomeHost@683,whole:HomeLinkApp@669 4a5cacac0f6fba9392d40246171f2dd4d38dcc99dd29f2bfccb8f19fe94c49a8 |
| internal/registry/homelink.go CheckCredentialFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-linked-deployments-slice1;basis=new (linked deployments slice 1 Task 7): Lstat of the registry path the Registry was opened with (never a caller-named path in production: PutHomeLink passes r.path, the console passes its configured registry); refuses a symbolic link, a non-regular file and a world-readable mode; reads only the mode, refuses more; fix round 1: also Lstats registry.db-wal, -shm and -journal beside the same path (the WAL holds the token first in WAL mode); a missing journal is skipped, an existing one must be a regular non-symlink file with no world-read bit, else refused naming it; reads only modes, refuses more file:Lstat@150 e721b4422cf333532c8e47d2c99553b6d71d7c8763c1ae4cbbbd29e72b6c3c69 |
| @@ -120,9 +120,10 @@ internal/provision/reconcile.go Reconcile legacy accepted-legacy accepted-legacy |
| internal/regionlabel/regionlabel.go ForRoute legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-labels;identity=the console and the carlos CLI (a pure package; no box unit links it for a decision);basis=new (region labels plan 1 task 2): labels a registry row already in hand from its Region and Pool columns and RouteServedEverywhere; pure: no file, no store, no registry open, nothing written;decision: Paul, as census owner, 2026-10-26: accepted as a new unit (#280);rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 6: a row placed on a linked deployment (registry.LinkPlacement over the row's own Region, "link/<id>") is labelled as linked (the new Label.Link, the link ID; Text empty) before the fleet and everywhere checks, instead of being labelled with "link/<id>" as a region code; pure, reads only the Route it is given, no read added registry:Pool@329,registry:Pool@394,registry:Region@100,registry:Region@138,registry:Region@199,registry:Region@233,registry:Region@318,registry:Region@364,whole:Route@292 f88391a298a8511fd1305ffcd046b84130d0fd1f756509802529f776679971ea |
| internal/registry/forward.go Registry.PutForward legacy accepted-legacy accepted-legacy;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 2: the only writer of a forward row's declared columns: refuses an argument whose kind is not forward; copies only the declared fields from its argument (Status ready, Provisioned true; no forbidden column is ever written); inside one IMMEDIATE transaction refuses a host a non-forward row holds (ErrHostHeld); keeps FleetBox while Region is unchanged; preserves the observational columns (+file:Exec, +file:QueryRow, +registry:Account, App, Channel, RateLimit, Region, Slug, +registry:Host x3, +registry:Kind, +registry:remote x2, +whole:Route x3, +whole:remoteClient x2).;rev3=census-ruling-fleet-routes-followups;basis=refuses up front, with the new sentinel ErrNotForward and before any read or write, an rt that is not a forward row (as before, now a sentinel), has an empty Host, or whose Region is not a fleet placement (registry.FleetPlacement); +registry:Host x2 and +registry:Region x2 read only the argument in those checks; the transaction and statement are unchanged;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5, rule 3), merged with main's ErrNotForward refusals (kept unchanged): the written row also carries FleetLabel = rt.FleetLabel and FleetBox = rt.FleetLabel; its conflict arm (forwardKept) writes fleet_label from the call and fleet_box as the call's label when set, else kept while the region is unchanged. The hub's forward phase in the agent, not root.;rev3=census-ruling-stateless-replicas-1;basis=Carry declarative Stateless into forward rows under existing transaction and shape guards; projection only.;rev3=census-ruling-agent-start-demo-1;basis=Reads and carries the four demo fields in the existing forward INSERT; the guarded conflict SQL refuses downgrade or identity change.;rev3=census-ruling-stateless-replicas-2;basis=Validates canonical set projection, writes explicit declarative columns and clears single-box binding; all forbidden columns zero. Same transaction/read source. merge of origin/main 6be08467: Retain main demo columns and immutable descriptor conflict guard alongside set validation/projection; merge-only existing route fields.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: also accepts a Region that LinkPlacement parses (link/ + 12 hex), refusing a link row with a FleetLabel (ErrNotForward); the existing in-transaction SELECT also reads the held row's region and refuses a different placement class (ErrHostHeld); a link row additionally needs an active link_channels row of its account in the same transaction (linkAdmits, ErrLinkInactive). Same transaction and statement; the added reads are the argument and the box's own registry database, as carlos file:Exec@2052,file:QueryRow@1631,registry:Account@1092,registry:Account@1989,registry:App@1069,registry:Channel@1145,registry:Copies@1392,registry:DemoExpiresAt@960,registry:DemoHost@901,registry:DemoID@880,registry:DemoLifetime@928,registry:FleetBox@1513,registry:FleetBoxes@1369,registry:FleetBoxes@1490,registry:FleetLabel@1280,registry:FleetLabel@1310,registry:FleetLabel@1525,registry:FleetLabel@540,registry:Host@1693,registry:Host@250,registry:Host@287,registry:Host@500,registry:Host@660,registry:Host@993,registry:Kind@259,registry:RateLimit@1172,registry:Region@1119,registry:Region@130,registry:Region@1898,registry:Region@509,registry:Region@82,registry:ReplicaIncarnation@1460,registry:ReplicaRevision@1420,registry:Slug@1045,registry:Stateless@1340,registry:remote@737,registry:remote@767,whole:Route@2085,whole:Route@822,whole:Route@830,whole:remoteClient@739,whole:remoteClient@769 92749de50752ac228f653180d60ea0b177331657a7062598c8b877b35c694106 |
| internal/registry/registry.go Registry.Fingerprint legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user); the remote arm, unchanged, in the process that holds a remote handle: census-ruling-seeded-instances's body with the row's lifetime pair (incarnation, serving_seq) folded into the edge's change poll, each only when non-zero, so a registry with no pair digests as before; self-serve moves 1 Task 7;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: hashes regional_domains (host, target, account, app, region; created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no regional rows digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; no file path read;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): review R1 finding 1: the routes SELECT also reads host, kind, account, app, platform and fingerprintForwardInert (one CASE over the ForwardForbidden columns), and every row folds host, kind, account and app (tagged, quoted), platform when set, and forward_inert=0 for a forward row that is not inert, so a rowid reused by another hostname, an in-place account or app rewrite, or a stray forbidden column moves the edge's change poll. Same one SELECT per table on the same fresh connection to the box's own registry database, as carlos; no table, file or bucket read added; a digest, never a decision.;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5): the SELECT also reads fleet_label and, only when it is set, hashes "fleet_label=<q>" into the digest, so labelling a row moves the edge's reload fingerprint. Read sites unchanged (33). Registry side, not root; an unlabelled registry's digest is byte-identical.;rev3=census-ruling-stateless-replicas-1;basis=Read the additive stateless projection in the existing registry SELECT and hash only when set; no new read source.;rev3=census-ruling-agent-start-demo-1;basis=Existing SELECT reads four more demo columns; only a marked row adds them to the hash, so ordinary hashes remain unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Four additive projection columns join the existing routes SELECT and hash only when nonzero; no new query or file read. merge of origin/main 6be08467: Union main demo identity and expiry with replica columns in the same SELECT and hash; merge-only body change.;rev3=census-ruling-agent-start-demo-3;basis=Hash moved-notice wire bytes so notice-only changes invalidate an edge route snapshot. Census read-site delta: +file:QueryRow.;rev3=census-ruling-edge-page-cache-1;basis=selects the new pages_off column with the rest and folds "pages_off=1" into the hash only when set, as assets_off, so a registry that never sets it fingerprints as before; same routes SELECT, no new table; read sites unchanged (34); no read added;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: hashes link_channels (link_id, account, token_hash, status, generation; connected, seen_at, seq and created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no links digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; a digest, never a decision; linked deployments slice 1 Task 7: also folds home_link (id, serving_url, tunnel_url, the token's sha256 never the token, account, apps_domain, box_label, conn_gen; state and created_at not) and home_link_apps (name, home_account, home_app, home_host) through fingerprintHomeLink over the same fresh connection, each section marker written only when a row exists, so a registry with no link digests as before; no file path read; a digest, never a decision file:Exec@284,file:Open@188,file:Query@10785,file:Query@11990,file:Query@368,file:Query@6655,file:Query@7134,file:Query@8120,file:Query@8816,file:Query@9728,file:QueryRow@12907,registry:ClaimIncarnation@1729,registry:ClaimIncarnation@5563,registry:ClaimIncarnation@5640,registry:ClaimOwner@1773,registry:ClaimOwner@5764,registry:ClaimOwner@5829,registry:ClaimRowID@1792,registry:ClaimRowID@5856,registry:ClaimRowID@5922,registry:ClaimStamp@1754,registry:ClaimStamp@5673,registry:ClaimStamp@5737,registry:Incarnation@1848,registry:Incarnation@6143,registry:Incarnation@6207,registry:ServingSeq@1867,registry:ServingSeq@6234,registry:ServingSeq@6297,registry:Text@158,registry:path@207,registry:remote@55,registry:remote@87,whole:remoteClient@57,whole:remoteClient@89 992e25925704805387f5c460a886c0ee9ba7eb57a06aa5ca384e94b677ea491f |
| -@coverage internal/edge f83d33ba41dc00b29dd6378c3f993c23e41e16d482920f1777e07488792ba93f |
| -@coverage internal/gate 9426f9796fb48245d339665197b32a418a9c1441a0c7c4dcd8be14279a54b331 |
| -@coverage internal/host 963de73935d7bd2c096124b0acf3477eedc8da278bcb615b548e36bd4a60db5b |
| +@coverage . 52c69727a1e337a47920a1c9f37d9808f1df8d14dbefd29db86f9892bdf10b7d |
| +@coverage internal/edge 9c0eb8a58548921c20de856c13fe990efd7902b15af404dcb6f57cd364f99182 |
| +@coverage internal/gate 17307a6623f6149db163fc8de9139f8d824b36d70d2da635c712aee3671e582a |
| +@coverage internal/host 18a1996c7aaeaddd6beaefb8197e80cb2c5818e92062ecb51c8943a1869b0e99 |
| @coverage internal/provision 6c3f9188cfe17a2f7f87d78cf5f60e9104f5bcd55941947129a5bcea3e4c586c |
| @coverage internal/regionlabel 8d831085b7e3ce7bb1ea1f20f443b4529c5b7177de18e7c4889e4ca330aa6a00 |
| @coverage internal/registry d160203302b7508294b6568f2a452e32c64921b5b1a1196ec358ee1128e335ba |