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

Merged opened this in answer to

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

Merged

scout/forge:scout/13718-from-outside-claimed-child-forge-can-nev → main 6 commits fork 2 threads · 2 unresolved

  • Merged. scout/13718-from-outside-claimed-child-forge-can-nev was merged into main as d7a0c7f.

Review

Sign in to review this change.
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-
322322 - [A child forge's cores, held by pausing where the kernel cannot](child-cpu-pausing.md)
323323 - [A child forge's disk bandwidth is capped by its size](child-disk-bandwidth.md)
324324 - [A child forge's own filesystem](child-filesystem.md)
325 - [A claimed child receives the credential to propose back to its parent](child-proposal-credential.md)
325326 - [A client's monthly bill](forge-bill.md)
326327 - [A forge for a client, from one link](client-forge.md)
327328 - [The client list's three times: sent, opened, first tell](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 @@
55 * beside the heartbeat key (`storeProposal`), the way it already hands over the lent credit
66 * (`funding.ts`). The token lives `PROPOSAL_TTL_MS`; the parent's pass looks every few minutes and
77 * 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
910 * its code link is handed nothing, and its token is not renewed.
1011 */
1112
@@ -14,6 +15,7 @@ import { HANDOUT_EVERY_MINUTES } from "../actions/family_words.ts";
1415 import { childDirOf, listChildren, type Child } from "../actions/spawn.ts";
1516 import { mintProposalToken, parseOrigin, PROPOSAL_TTL_MS, revokeProposalTokens } from "../core/proposal_token.ts";
1617 import { getRepo } from "../core/repos.ts";
18 import { verifyToken } from "../core/tokens.ts";
1719 import { proposalUser, readDoc } from "./app_links.ts";
1820 import { storeProposal } from "./parent_credential.ts";
1921
@@ -24,6 +26,18 @@ export const HANDOUT_EVERY_MS = HANDOUT_EVERY_MINUTES * 60_000;
2426
2527 type Handed = "handed" | "kept" | "skipped";
2628
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
2741 /** Give one child a proposal credential when it has none or its own is nearly spent. Idempotent. */
2842 export function handProposalCredential(app: App, child: Child, now: number = Date.now()): Handed {
2943 const dir = childDirOf(app, child.bodyId);
@@ -37,7 +51,8 @@ export function handProposalCredential(app: App, child: Child, now: number = Dat
3751 if (parent === undefined) return "skipped";
3852 const have = doc["proposal"];
3953 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";
4156 // Only the spawner, and only while they may write to the parent; and only for an origin that
4257 // parses.
4358 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";
1414 import { FAMILY_WORDS, HANDOUT_EVERY_MINUTES } from "../src/actions/family_words.ts";
1515 import { PROPOSAL_TTL_MS } from "../src/core/proposal_token.ts";
1616 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";
1818 import { createUser, type User } from "../src/core/users.ts";
1919 import { hostedPlacement } from "../src/spawn/placement.ts";
2020 import { parentCredential } from "../src/spawn/parent_credential.ts";
@@ -126,6 +126,18 @@ describe("the proposal credential a parent hands each child", () => {
126126 expect(verifyToken(parent.db, now).ok).toBe(true);
127127 });
128128
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
129141 const tokens = () => parent.db.query<{ n: number }, []>("SELECT count(*) AS n FROM token").get()!.n;
130142
131143 test("the refusal's wait is the pass's own interval", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs