Public: anyone can read this; the crew can change it.
From outside: Claimed child forge can never propose upstream: its proposal credential is never handed over (no_parent_forge forever) #13727
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13718-from-outside-claimed-child-forge-can-nev → main 6 commits fork 2 threads · 2 unresolved
4 files
changed +44
−3
docs/features/README.md +1
| @@ -322,6 +322,7 @@ Read with the guide page [Hosting forges for others, and getting paid](../guide- | ||
| 322 | 322 | - [](child-cpu-pausing.md) |
| 323 | 323 | - [](child-disk-bandwidth.md) |
| 324 | 324 | - [](child-filesystem.md) |
| 325 | - [](child-proposal-credential.md) | |
| 325 | 326 | - [](forge-bill.md) |
| 326 | 327 | - [](client-forge.md) |
| 327 | 328 | - [](client-link-times.md) |
docs/features/child-proposal-credential.md added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | # A child receives its proposal credential | |
| 2 | ||
| 3 | A child forge that carries a fork of its parent's code can propose back to it, but only with a | |
| 4 | credential the parent hands over. The parent's background pass (`spawn/proposal_handout.ts`, run from | |
| 5 | the follow pass) gives each finished child one by writing `proposal` into the child's `parent.json`; | |
| 6 | the child reads it (`spawn/parent_credential.ts`). No screen: nothing to do by hand. | |
| 7 | ||
| 8 | - **What it is:** a proposal token minted as the person who spawned the child, and only while they | |
| 9 | may write to the parent repository, gated to push `child/<name>/…` branches and open pulls there. | |
| 10 | - **How long:** `PROPOSAL_TTL_MS`. Near its end the next pass mints a fresh one and revokes the one | |
| 11 | it replaces once the child holds the new one. A token a person revoked is replaced on the next pass. | |
| 12 | - **When it is not handed:** the child has no `forgeCode`, severed its link, its upstream is not on | |
| 13 | this forge, the spawner cannot write there, or its address is not an https origin. |
src/spawn/proposal_handout.ts +17 −2
| @@ -5,7 +5,8 @@ | ||
| 5 | 5 | * beside the heartbeat key (`storeProposal`), the way it already hands over the lent credit |
| 6 | 6 | * (`funding.ts`). The token lives `PROPOSAL_TTL_MS`; the parent's pass looks every few minutes and |
| 7 | 7 | * mints a fresh one when the child has none or its token is within `RENEW_BEFORE_MS` of its end, so |
| 8 | * a child that keeps reporting never lapses and one that stops ends by itself. A child that severed | |
| 8 | * a child that keeps reporting never lapses and one that stops ends by itself. A held token that no | |
| 9 | * longer verifies (a person revoked it) is replaced on the next pass. A child that severed | |
| 9 | 10 | * its code link is handed nothing, and its token is not renewed. |
| 10 | 11 | */ |
| 11 | 12 | |
| @@ -14,6 +15,7 @@ import { HANDOUT_EVERY_MINUTES } from "../actions/family_words.ts"; | ||
| 14 | 15 | import { childDirOf, listChildren, type Child } from "../actions/spawn.ts"; |
| 15 | 16 | import { mintProposalToken, parseOrigin, PROPOSAL_TTL_MS, revokeProposalTokens } from "../core/proposal_token.ts"; |
| 16 | 17 | import { getRepo } from "../core/repos.ts"; |
| 18 | import { verifyToken } from "../core/tokens.ts"; | |
| 17 | 19 | import { proposalUser, readDoc } from "./app_links.ts"; |
| 18 | 20 | import { storeProposal } from "./parent_credential.ts"; |
| 19 | 21 | |
| @@ -24,6 +26,18 @@ export const HANDOUT_EVERY_MS = HANDOUT_EVERY_MINUTES * 60_000; | ||
| 24 | 26 | |
| 25 | 27 | type Handed = "handed" | "kept" | "skipped"; |
| 26 | 28 | |
| 29 | /** | |
| 30 | * Whether the held credential still verifies as this child's proposal token for `repoId`; one a | |
| 31 | * person revoked does not. | |
| 32 | */ | |
| 33 | function stillWorks(app: App, have: unknown, repoId: string, child: string): boolean { | |
| 34 | const token = typeof have === "object" && have !== null ? (have as Record<string, unknown>)["token"] : undefined; | |
| 35 | if (typeof token !== "string") return false; | |
| 36 | const v = verifyToken(app.db, token); | |
| 37 | const p = v.ok ? v.value.proposal : undefined; | |
| 38 | return p !== undefined && p.repoId === repoId && p.child === child && p.readOnly !== true; | |
| 39 | } | |
| 40 | ||
| 27 | 41 | /** Give one child a proposal credential when it has none or its own is nearly spent. Idempotent. */ |
| 28 | 42 | export function handProposalCredential(app: App, child: Child, now: number = Date.now()): Handed { |
| 29 | 43 | const dir = childDirOf(app, child.bodyId); |
| @@ -37,7 +51,8 @@ export function handProposalCredential(app: App, child: Child, now: number = Dat | ||
| 37 | 51 | if (parent === undefined) return "skipped"; |
| 38 | 52 | const have = doc["proposal"]; |
| 39 | 53 | const expiresAt = typeof have === "object" && have !== null ? (have as Record<string, unknown>)["expiresAt"] : undefined; |
| 40 | if (typeof expiresAt === "number" && expiresAt - now > RENEW_BEFORE_MS) return "kept"; | |
| 54 | if (typeof expiresAt === "number" && expiresAt - now > RENEW_BEFORE_MS && stillWorks(app, have, parent.id, child.name)) | |
| 55 | return "kept"; | |
| 41 | 56 | // Only the spawner, and only while they may write to the parent; and only for an origin that |
| 42 | 57 | // parses. |
| 43 | 58 | const as = proposalUser(app, parent, child.ownerId); |
test/proposal-handout.test.ts +13 −1
| @@ -14,7 +14,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 14 | 14 | import { FAMILY_WORDS, HANDOUT_EVERY_MINUTES } from "../src/actions/family_words.ts"; |
| 15 | 15 | import { PROPOSAL_TTL_MS } from "../src/core/proposal_token.ts"; |
| 16 | 16 | import { getRepo, type Repo } from "../src/core/repos.ts"; |
| 17 | import { verifyToken } from "../src/core/tokens.ts"; | |
| 17 | import { revokeToken, verifyToken } from "../src/core/tokens.ts"; | |
| 18 | 18 | import { createUser, type User } from "../src/core/users.ts"; |
| 19 | 19 | import { hostedPlacement } from "../src/spawn/placement.ts"; |
| 20 | 20 | import { parentCredential } from "../src/spawn/parent_credential.ts"; |
| @@ -126,6 +126,18 @@ describe("the proposal credential a parent hands each child", () => { | ||
| 126 | 126 | expect(verifyToken(parent.db, now).ok).toBe(true); |
| 127 | 127 | }); |
| 128 | 128 | |
| 129 | test("a credential a person revoked is replaced on the next pass, though it has time left", async () => { | |
| 130 | const old = docOf().proposal.token; | |
| 131 | const known = verifyToken(parent.db, old); | |
| 132 | if (!known.ok || known.value.proposal === undefined) throw new Error("no proposal token held"); | |
| 133 | revokeToken(parent.db, known.value.proposal.tokenId); | |
| 134 | expect(handProposalCredential(parent, await kid())).toBe("handed"); | |
| 135 | const now = docOf().proposal.token; | |
| 136 | expect(now).not.toBe(old); | |
| 137 | expect(verifyToken(parent.db, now).ok).toBe(true); | |
| 138 | expect(handProposalCredential(parent, await kid())).toBe("kept"); | |
| 139 | }); | |
| 140 | ||
| 129 | 141 | const tokens = () => parent.db.query<{ n: number }, []>("SELECT count(*) AS n FROM token").get()!.n; |
| 130 | 142 | |
| 131 | 143 | test("the refusal's wait is the pass's own interval", () => { |
new above
offline