Public: anyone can read this; the crew can change it.
Revert "A child's parent.json cannot name an upstream or a minting identity the child was not given" #15138
Check · Review · Land · Live — Changes were asked on this head.
revert-14942 → main 1 commit 2 threads · 2 unresolved
2 files
changed +8
−64
src/spawn/app_links.ts +8 −13
| @@ -40,7 +40,7 @@ import { | ||
| 40 | 40 | renewFollowTokens, |
| 41 | 41 | revokeFollowTokens, |
| 42 | 42 | } from "../core/proposal_token.ts"; |
| 43 | import { canRead, canWrite, getRepo, getRepoById, listReposOwnedBy, type Repo } from "../core/repos.ts"; | |
| 43 | import { canWrite, getRepo, getRepoById, listReposOwnedBy, type Repo } from "../core/repos.ts"; | |
| 44 | 44 | import { |
| 45 | 45 | followAad, |
| 46 | 46 | getFollow, |
| @@ -244,9 +244,8 @@ export async function anchorsOf(app: App, parent: Repo): Promise<string[]> { | ||
| 244 | 244 | const ANCHORS_MAX = 8; |
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | * The person a follow token for `repo` is minted as: the spawner, and only while they may read it. | |
| 248 | * The repository's owner is never stood in: a child whose spawner left, or lost the repository, | |
| 249 | * stops being able to read it, and the fork page says so (`notOffered`). | |
| 247 | * The person a follow token for `repo` is minted as: the spawner, when they may read it, else the | |
| 248 | * repository's owner when that is a person. | |
| 250 | 249 | */ |
| 251 | 250 | function mintingUser( |
| 252 | 251 | app: App, |
| @@ -255,9 +254,9 @@ function mintingUser( | ||
| 255 | 254 | ): User | undefined { |
| 256 | 255 | const spawner = |
| 257 | 256 | ownerId === undefined ? undefined : getUserById(app.db, ownerId); |
| 258 | return spawner !== undefined && spawner.kind === "user" && canRead(app.db, parent, spawner) | |
| 259 | ? spawner | |
| 260 | : undefined; | |
| 257 | if (spawner !== undefined && spawner.kind === "user") return spawner; | |
| 258 | const owner = getUserById(app.db, parent.ownerId); | |
| 259 | return owner?.kind === "user" ? owner : undefined; | |
| 261 | 260 | } |
| 262 | 261 | |
| 263 | 262 | /** |
| @@ -371,7 +370,7 @@ export async function offerAppLinks(app: App, child: Child): Promise<Offered> { | ||
| 371 | 370 | } |
| 372 | 371 | const token = followToken(app, parent, { name: child.name, url: child.url, ownerId: child.ownerId }); |
| 373 | 372 | if (parent.visibility !== "public" && token === undefined) { |
| 374 | skip(ref, `${ref} is private and the person who spawned this child is gone or can no longer read it, so no read credential is minted`); | |
| 373 | skip(ref, `${ref} is private and no person here can mint it a read credential`); | |
| 375 | 374 | continue; |
| 376 | 375 | } |
| 377 | 376 | const entry: AppEntry = { |
| @@ -872,8 +871,7 @@ export function reportLines(app: App, forge: string, lines: readonly AppLinkLine | ||
| 872 | 871 | /** |
| 873 | 872 | * For the heartbeat's answer: the tip of each followed app on this forge's default branch, by the |
| 874 | 873 | * child's own repository, so a child in a cell of its own learns an app landed without waiting |
| 875 | * for its clock. Only apps the ledger says it was given, that it applied and did not sever; | |
| 876 | * bounded. | |
| 874 | * for its clock. Only apps it applied and did not sever; bounded. | |
| 877 | 875 | */ |
| 878 | 876 | export async function appTipsFor( |
| 879 | 877 | app: App, |
| @@ -882,14 +880,11 @@ export async function appTipsFor( | ||
| 882 | 880 | const child = await childNamed(app, name); |
| 883 | 881 | if (child === undefined) return {}; |
| 884 | 882 | const tips: Record<string, string> = {}; |
| 885 | // parent.json is the child's to write: only the apps the ledger says it was given are looked up. | |
| 886 | const given = new Set(child.apps); | |
| 887 | 883 | for (const e of entriesOf(await readDoc(childDirOf(app, child.bodyId))).slice( |
| 888 | 884 | 0, |
| 889 | 885 | 50, |
| 890 | 886 | )) { |
| 891 | 887 | if (e.appliedAt === undefined || e.severedAt !== undefined) continue; |
| 892 | if (!given.has(e.upstream)) continue; | |
| 893 | 888 | const [o, n] = e.upstream.split("/") as [string, string]; |
| 894 | 889 | const parent = getRepo(app.db, o, n); |
| 895 | 890 | if (parent === undefined) continue; |
test/spawn-app-links.test.ts −51
| @@ -847,56 +847,5 @@ describe("apps sent down by a spawn follow their parent", () => { | ||
| 847 | 847 | ); |
| 848 | 848 | expect(getFollow(own.child.db, repo.id)!.via).toBe(""); |
| 849 | 849 | }, 240_000); |
| 850 | ||
These two tests are the only coverage for the spawner-only minting and the ledger-bound heartbeat tips. Deleting them leaves the behaviour unguarded. Keep them. |
||
| 851 | /** Rewrite a child's ledger entry for who spawned it; undefined drops the field. */ | |
| 852 | async function setSpawner(name: string, ownerId: string | undefined) { | |
| 853 | const at = join(parent.config.dataDir, "spawn", `${name}.json`); | |
| 854 | const ledger = (await Bun.file(at).json()) as Record<string, unknown>; | |
| 855 | if (ownerId === undefined) delete ledger["ownerId"]; | |
| 856 | else ledger["ownerId"] = ownerId; | |
| 857 | await Bun.write(at, JSON.stringify(ledger)); | |
| 858 | } | |
| 859 | ||
| 860 | test("a follow token is minted only as the spawner, while they can read the parent: never as the owner in their place", async () => { | |
| 861 | await bare("orphan"); | |
| 862 | await setSpawner("orphan", undefined); | |
| 863 | const bob = await createUser(parent.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]" }); | |
| 864 | if (!bob.ok) throw new Error("user"); | |
| 865 | await bare("stranger"); | |
| 866 | await setSpawner("stranger", bob.value.id); | |
| 867 | const done = await reconcileAppLinks(parent, true); | |
| 868 | // The public app is still offered; the private one has no one to read it as. | |
| 869 | expect(done["orphan"]?.offered).toEqual(["alice/notes"]); | |
| 870 | expect(done["stranger"]?.offered).toEqual(["alice/notes"]); | |
| 871 | expect(followTokenCount(parent.db, vault.id, "orphan")).toBe(0); | |
| 872 | expect(followTokenCount(parent.db, vault.id, "stranger")).toBe(0); | |
| 873 | const { listChildren } = await import("../src/actions/spawn.ts"); | |
| 874 | const orphan = (await listChildren(parent)).find((c) => c.name === "orphan")!; | |
| 875 | const line = (await appLinkLines(parent, orphan)).find((l) => l.upstream === "alice/vault")!; | |
| 876 | expect(line.state).toBe("not-offered"); | |
| 877 | expect(line.why).toContain("spawned this child is gone or can no longer read it"); | |
| 878 | }, 240_000); | |
| 879 | ||
| 880 | test("the heartbeat's tips name only apps the ledger gave the child, whatever parent.json claims", async () => { | |
| 881 | const liar = await bare("liar"); | |
| 882 | await reconcileAppLinks(parent, true); | |
| 883 | await applyAppLinks(liar.child); | |
| 884 | const at = join(liar.dataDir, "parent.json"); | |
| 885 | const doc = (await Bun.file(at).json()) as Record<string, unknown>; | |
| 886 | const now = new Date().toISOString(); | |
| 887 | await Bun.write( | |
| 888 | at, | |
| 889 | JSON.stringify({ | |
| 890 | ...doc, | |
| 891 | apps: [ | |
| 892 | ...(doc["apps"] as unknown[]), | |
| 893 | { repo: "liar/other", upstream: "alice/other", url: "x", branch: "main", mode: "take-updates", anchor: "0".repeat(40), offeredAt: now, appliedAt: now }, | |
| 894 | ], | |
| 895 | }), | |
| 896 | ); | |
| 897 | const tips = await appTipsFor(parent, "liar"); | |
| 898 | expect(Object.keys(tips).sort()).toEqual(["liar/notes", "liar/vault"]); | |
| 899 | expect(Object.values(tips)).not.toContain(await tip(parentDir(other))); | |
| 900 | }, 240_000); | |
| 901 | 850 | }); |
| 902 | 851 | }); |
new above
offline
This falls back to the repository owner and drops the
canReadcheck, so a private repository's read credential is minted for someone who never asked. Keep the spawner-only, can-read rule.