Public: anyone can read this; the crew can change it.
Defect on the v1.0.0 path: the probe's keeper line answers 403 to a crew token on production, so the release tick's health is still unproven #15521
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15520-defect-on-the-v1-0-0-path-the-probe-s-ke → main 0 commits fork 1 thread · 1 unresolved
4 files
changed +79
−5
scripts/v1-probe.ts +24 −4
| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | * `--repo` (default `trevato/forge`). It never signs in, pays or writes. |
| 8 | 8 | * |
| 9 | 9 | * With `FORGE_TOKEN` set (the crew's token for the forge's repository is enough, #15449) it |
| 10 | * also GETs `/api/v1/keeper` with that token, and only there, and prints `keeper's last beat`: | |
| 11 | * the release tick's newest outcome and reason, so a stopped release is named from a shell. | |
| 10 | * also GETs `/api/v1/keeper` with that token and prints `keeper's last beat`: the release tick's | |
| 11 | * newest outcome and reason, so a stopped release is named from a shell. The token is sent to | |
| 12 | * `<base-url>` only, and to two endpoints only: `/api/v1/keeper`, and `/api/v1/here` when the | |
| 13 | * keeper answers 403, to word the refusal by its cause (#15520). | |
| 12 | 14 | * |
| 13 | 15 | * The schedules line reads `<base-url>/edition` (#15474), the morning paper's edition page; a 404 |
| 14 | 16 | * there is UNKNOWN, `this release predates /edition`. `--edition` is another public page a |
| @@ -336,12 +338,27 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch | ||
| 336 | 338 | else say(`security headers on ${path}`, "FAIL", path, `missing ${missing.join(", ")}`); |
| 337 | 339 | } |
| 338 | 340 | |
| 339 | // 8. The release keeper's newest beat (#15449), only for a caller holding a token. | |
| 341 | // 8. The release keeper's newest beat (#15449), only for a caller holding a token. A refusal is | |
| 342 | // worded by its cause (#15520), read from `/api/v1/here` with the same token: a 401 is a token | |
| 343 | // this forge knows no account for; "anonymous" means the header never reached the forge (a proxy | |
| 344 | // in front strips `authorization`, as the hosting forge's app proxy does for every app); a name | |
| 345 | // is an account without the right. | |
| 346 | const keeperRefusal = async (status: number): Promise<string> => { | |
| 347 | if (status === 401) return NOT_ACCEPTED(status, origin); | |
| 348 | if (status !== 403) return `${status}, the keeper did not answer`; | |
| 349 | const here = await get("/api/v1/here?path=/", { headers: { authorization: `Bearer ${token}` } }); | |
| 350 | if (typeof here === "string") return `403, and /api/v1/here did not answer: ${here}`; | |
| 351 | if (here.status === 401) return NOT_ACCEPTED(status, origin); | |
| 352 | const you = (json(here) as { you?: { as?: unknown } } | undefined)?.you; | |
| 353 | if (you?.as === "anonymous") return `403, the token did not reach ${origin}: a proxy in front strips the authorization header, so this forge saw no one`; | |
| 354 | const as = typeof you?.as === "string" ? you.as.replace(/[^\w-]/g, "") : "unknown"; | |
| 355 | return `403, this token's account (here a ${as}) may not read the release history: it must write the forge's repository or administer`; | |
| 356 | }; | |
| 340 | 357 | if (token) { |
| 341 | 358 | const keeper = await get("/api/v1/keeper", { headers: { authorization: `Bearer ${token}` } }); |
| 342 | 359 | const beat = keeperBeat(typeof keeper === "string" ? undefined : json(keeper)); |
| 343 | 360 | if (typeof keeper === "string") say(KEEPER_ITEM, "UNKNOWN", "/api/v1/keeper", keeper); |
| 344 | else if (keeper.status !== 200) say(KEEPER_ITEM, "UNKNOWN", "/api/v1/keeper", `${keeper.status}, this token may not read the release history`); | |
| 361 | else if (keeper.status !== 200) say(KEEPER_ITEM, "UNKNOWN", "/api/v1/keeper", await keeperRefusal(keeper.status)); | |
| 345 | 362 | else if (beat === undefined) say(KEEPER_ITEM, "UNKNOWN", "/api/v1/keeper", "200 without a heartbeat: the release tick has not reported yet"); |
| 346 | 363 | else { |
| 347 | 364 | const words = `${beat.outcome} at ${beat.at}${beat.silent ? " (silent for over an hour)" : ""}: ${beat.reason}`; |
| @@ -353,6 +370,9 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch | ||
| 353 | 370 | |
| 354 | 371 | export const KEEPER_ITEM = "keeper's last beat"; |
| 355 | 372 | |
| 373 | const NOT_ACCEPTED = (status: number, origin: string) => | |
| 374 | `${status}, token not accepted here: ${origin} knows no account for it (a token from another forge?)`; | |
| 375 | ||
| 356 | 376 | /** |
| 357 | 377 | * The keeper answer's `heartbeat`, its words stripped of control characters; undefined when it has |
| 358 | 378 | * none. |
src/http/api/keeper.ts +4
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * reason}`, for an administrator's admin token; anyone else is refused. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { INVALID_TOKEN_HINT, INVALID_TOKEN_WORDS } from "../../actions/here.ts"; | |
| 11 | 12 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 12 | 13 | import { isOutcome, REASON_MAX, recordBeat } from "../../keeper/beat.ts"; |
| 13 | 14 | import { keeperAnswer } from "../../keeper/landed.ts"; |
| @@ -23,6 +24,9 @@ const CONTROL = /[\u0000-\u001f\u007f-\u009f]/; | ||
| 23 | 24 | export function keeperRoutes(router: Router<Handler>): void { |
| 24 | 25 | router.add("GET", "/api/v1/keeper", (ctx) => { |
| 25 | 26 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 27 | // A credential this forge knows no account for is not a reader without the right (#15520): | |
| 28 | // 401 says "not accepted here", so a token from another forge is not mistaken for a role. | |
| 29 | if (ctx.auth.refused === true) return apiError("invalid_token", 401, INVALID_TOKEN_WORDS, INVALID_TOKEN_HINT); | |
| 26 | 30 | if (!mayReadKeeper(ctx.app, ctx.auth.user)) |
| 27 | 31 | return apiError("forbidden", 403, "the release history is for the forge's administrators and its repository's readers"); |
| 28 | 32 | // Tagged only after the access check, over the exact bytes sent: a recorded, promoted, held or |
test/keeper-writer-reads.test.ts +19
| @@ -10,6 +10,7 @@ import { tmpdir } from "node:os"; | ||
| 10 | 10 | import { join } from "node:path"; |
| 11 | 11 | import { createRepo } from "../src/actions/repos.ts"; |
| 12 | 12 | import { createApp, type App } from "../src/app.ts"; |
| 13 | import { stripForgeCredentials } from "../src/apps/proxy.ts"; | |
| 13 | 14 | import { addTeamMember, createOrg, createTeam } from "../src/core/orgs.ts"; |
| 14 | 15 | import { createToken } from "../src/core/tokens.ts"; |
| 15 | 16 | import { createUser, type User } from "../src/core/users.ts"; |
| @@ -96,6 +97,24 @@ describe("GET /api/v1/keeper for the forge repository's writers", () => { | ||
| 96 | 97 | expect(((await res.json()) as any).message).toBe(REFUSED); |
| 97 | 98 | }); |
| 98 | 99 | |
| 100 | test("a token this forge knows no account for answers 401 'not accepted here', not the release-history refusal (#15520)", async () => { | |
| 101 | const res = await get("forge_not-a-token-this-forge-minted"); | |
| 102 | expect(res.status).toBe(401); | |
| 103 | const body: any = await res.json(); | |
| 104 | expect(body.error).toBe("invalid_token"); | |
| 105 | expect(body.message).toBe("that token or password matches no account here"); | |
| 106 | }); | |
| 107 | ||
| 108 | test("behind the hosting forge's app proxy even a writer's token arrives as no one (#15520)", async () => { | |
| 109 | // Why production answers the crew's token 403: the proxy deletes `authorization` before the | |
| 110 | // app. | |
| 111 | const headers = new Headers({ authorization: `Bearer ${writer}` }); | |
| 112 | stripForgeCredentials(headers, "forge_grant_lab"); | |
| 113 | const res = await fetch(`${servers.url}/api/v1/keeper`, { headers }); | |
| 114 | expect(res.status).toBe(403); | |
| 115 | expect(((await res.json()) as any).message).toBe(REFUSED); | |
| 116 | }); | |
| 117 | ||
| 99 | 118 | test("over MCP, the writer reads the same body and the reader is refused", async () => { |
| 100 | 119 | const ok: any = await (await mcp(writer)).json(); |
| 101 | 120 | expect(ok.result.isError).toBeUndefined(); |
test/v1-probe.test.ts +32 −1
| @@ -24,6 +24,10 @@ interface World { | ||
| 24 | 24 | stated?: { commit: string; state: string; runId: string | null }; |
| 25 | 25 | /** The keeper's heartbeat, served only to `Bearer t` (#15449). */ |
| 26 | 26 | beat?: { at: string; outcome: string; reason: string; silent: boolean } | null; |
| 27 | /** Whether the keeper answers an unknown token 401 (#15520) rather than 403. */ | |
| 28 | keeper401?: boolean; | |
| 29 | /** A proxy in front strips `authorization`: the forge sees no one (#15520). */ | |
| 30 | stripped?: boolean; | |
| 27 | 31 | } |
| 28 | 32 | const green = (): World => ({ |
| 29 | 33 | version: "1.0.0", |
| @@ -68,8 +72,19 @@ const server = Bun.serve({ | ||
| 68 | 72 | case `/api/v1/repos/o/r/commits/${COMMIT}/check`: |
| 69 | 73 | return world.checkState === null ? html("Just a moment...", 403) : json({ state: world.checkState, runId: "run1" }); |
| 70 | 74 | case "/api/v1/keeper": |
| 75 | // `Bearer stranger` is a token this forge knows no account for: `keeper401` says whether | |
| 76 | // this release answers it 401, or 403 as releases before #15520 did. | |
| 77 | if (req.headers.get("authorization") === "Bearer stranger") return json({ error: "invalid_token" }, world.keeper401 ? 401 : 403); | |
| 71 | 78 | if (req.headers.get("authorization") !== "Bearer t") return json({ error: "forbidden" }, 403); |
| 72 | 79 | return json({ blocked: null, releases: [], holds: [], heartbeat: world.beat ?? null }); |
| 80 | case "/api/v1/here": { | |
| 81 | // What this forge saw: an unknown token 401, a stripped header anonymous, a known one a | |
| 82 | // role. | |
| 83 | const sent = req.headers.get("authorization"); | |
| 84 | if (sent === null || world.stripped) return json({ you: { as: "anonymous" } }); | |
| 85 | if (sent === "Bearer stranger") return json({ error: "invalid_token" }, 401); | |
| 86 | return json({ you: { as: "reader\u001b[2J" } }); | |
| 87 | } | |
| 73 | 88 | case "/edition": |
| 74 | 89 | return world.runs === null ? json({ error: "not_found" }, 404) : html(world.runs.map((r) => `<time datetime="${new Date(r.startedAt).toISOString()}"></time>`).join("")); |
| 75 | 90 | } |
| @@ -268,6 +283,22 @@ describe("v1 probe", () => { | ||
| 268 | 283 | expect((await keeperLine({ beat: { ...beat, silent: true } }, "t")).line!.verdict).toBe("FAIL"); |
| 269 | 284 | expect((await keeperLine({ beat: null }, "t")).line!.verdict).toBe("UNKNOWN"); |
| 270 | 285 | const refused = (await keeperLine({ beat }, "wrong")).line!; |
| 271 | expect([refused.verdict, refused.evidence]).toEqual(["UNKNOWN", "403, this token may not read the release history"]); | |
| 286 | expect([refused.verdict, refused.evidence]).toEqual(["UNKNOWN", "403, this token's account (here a reader2J) may not read the release history: it must write the forge's repository or administer"]); | |
| 287 | }); | |
| 288 | ||
| 289 | test("a token the forge knows no account for is worded 'not accepted here', on a 401 or an older 403 (#15520)", async () => { | |
| 290 | const line = async (w: Partial<World>) => { | |
| 291 | world = { ...green(), beat: null, ...w }; | |
| 292 | return (await probe(base, "o/r", fetch, NOW, undefined, "stranger")).find((l) => l.item === KEEPER_ITEM)!; | |
| 293 | }; | |
| 294 | const origin = new URL(base).origin; | |
| 295 | for (const [keeper401, status] of [[true, 401], [false, 403]] as const) { | |
| 296 | const l = await line({ keeper401 }); | |
| 297 | expect(l.verdict).toBe("UNKNOWN"); | |
| 298 | expect(l.evidence).toBe(`${status}, token not accepted here: ${origin} knows no account for it (a token from another forge?)`); | |
| 299 | } | |
| 300 | const stripped = await line({ stripped: true }); | |
| 301 | expect(stripped.evidence).toBe(`403, the token did not reach ${origin}: a proxy in front strips the authorization header, so this forge saw no one`); | |
| 302 | expect(seen.filter((s) => s.path.startsWith("/api/v1/here")).length).toBeGreaterThan(0); | |
| 272 | 303 | }); |
| 273 | 304 | }); |
new above
offline
On the preview, an unknown bearer still reaches the 403 below:
refusedis not true there. Make the 401 observable on the preview, or fix whererefusedis set for this route.