Public: anyone can read this; the crew can change it.

The egress gate refuses the forge's own public host zero times: every self-call goes through kernel/outbound #15359

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15350-the-egress-gate-refuses-the-forge-s-own → main 0 commits fork

  • Merged. scout/15350-the-egress-gate-refuses-the-forge-s-own was merged into main as 113a7af.

Review

Sign in to review this change.
3 files changed +40 −4
src/maintain/duties/edge_kept.ts +10 −1
@@ -6,12 +6,17 @@
66 * rule for signed-out HTML keyed on EDGE_VARY). A forge with no edge header says nothing. The
77 * URL is `config.url` only, never a host from a request; two small requests a page an hour. Where
88 * the forge's gate refuses the host (`X-Forge-Egress: refused`) the answer is unknown and silent.
9 *
10 * A forge in a cell (hosted as an app) does not read its own public host at all: the call is a
11 * hairpin through the uplink its gate refuses, one refusal a page an hour (#15350), and the local
12 * listener (`outboundFetch` with `self`) would answer without the edge this duty measures.
913 */
1014
1115 import { fileIssueOnce } from "../../checks/flake.ts";
1216 import { getRepo } from "../../core/repos.ts";
1317 import { EDGE_VARY } from "../../http/edge_cache.ts";
1418 import { ownRepoPath } from "../../kernel/own_repo.ts";
19 import { cellProxy } from "../../apps/egress.ts";
1520 import type { Duty, Finding } from "../duty.ts";
1621 import { edgeHeader, edgeVerdict, marked } from "../edge_kept.ts";
1722
@@ -34,7 +39,10 @@ const body = (path: string, seen: string): string =>
3439 `The one fix is the owner's, outside this repository: an edge cache rule that caches signed-out HTML and keys on \`${EDGE_VARY}\`.\n\n` +
3540 "This issue is filed once per page and left open until it is fixed; the hourly duty `edge-kept` checks again.";
3641
37 export function edgeKept(read: Get = get): Duty {
42 /** Whether this forge runs in a cell (hosted as an app): its way out is its parent's gate. */
43 const inACell = (): boolean => cellProxy() !== undefined;
44
45 export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty {
3846 return {
3947 name: "edge-kept",
4048 intervalMs: 3_600_000,
@@ -43,6 +51,7 @@ export function edgeKept(read: Get = get): Duty {
4351 const url = app?.config.url;
4452 if (url === undefined || url === "") return { findings: [], actions: ["skipped: this forge does not know its public origin (FORGE_URL)"] };
4553 const origin = new URL(url);
54 if (inCell()) return { findings: [], actions: [`skipped: this forge runs in a cell and does not call its own host ${origin.host}; the edge goes unread (#15350)`] };
4655 const findings: Finding[] = [];
4756 const actions: string[] = [];
4857 const [owner = "", name = ""] = ownRepoPath().split("/");
test/maintain-edge-kept.test.ts +10 −2
@@ -43,7 +43,7 @@ test("marked reads the header sharedCache sends", () => {
4343 const dirs: string[] = [];
4444 afterAll(() => dirs.forEach((d) => rmSync(d, { recursive: true, force: true })));
4545
46 async function run(read: Get, url: string | undefined = "https://forge.example", withRepo = true) {
46 async function run(read: Get, url: string | undefined = "https://forge.example", withRepo = true, inCell = false) {
4747 const dir = mkdtempSync(join(tmpdir(), "edge-kept-"));
4848 dirs.push(dir);
4949 const app: App = createApp({ dataDir: dir, port: 0, ...(url === undefined ? {} : { url }) });
@@ -51,7 +51,7 @@ async function run(read: Get, url: string | undefined = "https://forge.example",
5151 if (!u.ok) throw new Error(u.error);
5252 const [, name = "forge"] = ownRepoPath().split("/");
5353 if (withRepo) await createRepo(app, u.value, { name, visibility: "private" });
54 const duty = edgeDuty(read);
54 const duty = edgeDuty(read, () => inCell);
5555 const once = () => duty.run({ db: app.db, bus: app.bus, now: new Date(), app });
5656 return { app, once };
5757 }
@@ -68,6 +68,14 @@ test("the duty is on the roster, hourly, and reads only the configured URL", asy
6868 expect(PATHS.length).toBe(2);
6969 });
7070
71 test("in a cell it never reads its own public host, and says the edge went unread (#15350)", async () => {
72 const seen: string[] = [];
73 const r = await (await run(async (u) => (seen.push(u), undefined), "https://forge.example", true, true)).once();
74 expect(seen).toEqual([]);
75 expect(r.findings).toEqual([]);
76 expect(r.actions).toEqual(["skipped: this forge runs in a cell and does not call its own host forge.example; the edge goes unread (#15350)"]);
77 });
78
7179 test("not kept files one issue per page, and a second run adds nothing", async () => {
7280 const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" }));
7381 const first = await once();
test/outbound-sweep.test.ts +20 −1
@@ -69,7 +69,7 @@ const OWN_URL = /canonicalUrl|FORGE_APP_URL|FORGE_URL|forgeUrl|config\.url|ownHo
6969 */
7070 const OWN_HOST: Record<string, string> = {
7171 "src/maintain/duties/wait_split.ts": "in a cell it reads loopback alone (#14664); outside one it times its own public URL on purpose, the edge being what it measures",
72 "src/maintain/duties/edge_kept.ts": "GETs the forge's own public URL on purpose, the edge being what the duty measures (#14663); it says nothing where the gate refuses it (X-Forge-Egress)",
72 "src/maintain/duties/edge_kept.ts": "in a cell it skips (#15350); outside one it GETs the forge's own public URL on purpose, the edge being what the duty measures (#14663)",
7373 "src/http/server.ts": "the forge's own unix socket; the public URL only names links",
7474 "src/apps/proxy.ts": "an app's socket or loopback port; the forge URL only builds links for the app",
7575 "src/apps/toolbar.ts": BROWSER,
@@ -83,6 +83,14 @@ const OWN_HOST: Record<string, string> = {
8383 "src/snapshot/verdict.ts": "a command an operator runs, not the forge's process",
8484 };
8585
86 /**
87 * The files whose bare fetch reaches the forge's own public URL on purpose, from the forge's own
88 * process: the edge is what each measures, so the local listener (`outboundFetch` with `self`)
89 * would not do. In a cell that call is a hairpin its gate refuses (#15350), so each must ask
90 * `inCell()` first and leave the public side unread there.
91 */
92 const EDGE_ON_PURPOSE = ["src/maintain/duties/wait_split.ts", "src/maintain/duties/edge_kept.ts"];
93
8694 /** Every non-literal fetch in src, as `file:line`. */
8795 async function sweep(): Promise<Map<string, string[]>> {
8896 const found = new Map<string, string[]>();
@@ -127,6 +135,17 @@ describe("the sweep of src", () => {
127135 }
128136 });
129137
138 test("a bare fetch of the forge's own public URL is never made from a cell (#15350)", async () => {
139 const unguarded: string[] = [];
140 for (const file of EDGE_ON_PURPOSE) {
141 const text = await Bun.file(file).text();
142 if (!/cellProxy\(\)/.test(text) || !/inCell\(\)/.test(text)) unguarded.push(file);
143 }
144 expect(unguarded).toEqual([]);
145 for (const [file, why] of Object.entries(OWN_HOST))
146 if (/on purpose/.test(why)) expect([file, EDGE_ON_PURPOSE.includes(file)]).toEqual([file, true]);
147 });
148
130149 test("the origin paths a member names go through the guard, not a bare fetch", async () => {
131150 const found = await sweep();
132151 expect(found.get("src/origins/oauth.ts")).toBeUndefined();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs