Public: anyone can read this; the crew can change it.
Access 4b: the 'Who may do what' page, linked from settings, by person and by resource #18131
Merged 6h 55m ago, live in production
scout/forge:scout/18105-access-4b-the-who-may-do-what-page-linke → main 0 commits fork 4 threads · 4 unresolved
8 files
changed +82
−13
docs/design/attention-budget.json +3 −3
| @@ -115,16 +115,16 @@ | ||
| 115 | 115 | }, |
| 116 | 116 | "settings": { |
| 117 | 117 | "390": { |
| 118 | "words": 149, | |
| 118 | "words": 153, | |
| 119 | 119 | "blocks": 32, |
| 120 | 120 | "colours": 1 |
| 121 | 121 | }, |
| 122 | 122 | "1280": { |
| 123 | "words": 149, | |
| 123 | "words": 153, | |
| 124 | 124 | "blocks": 32, |
| 125 | 125 | "colours": 1 |
| 126 | 126 | }, |
| 127 | "note": "146 words since #13308 (2026-11-15, Settings \u203a Connected agents): its side-nav entry added two words to the 144 main had; 147 since the forge dataset (Settings \u203a Dataset), one word; 148 since the Tables page (#6002), one word; 149 since Settings \u203a Infrastructure, one word: an admin looked for the cloud bill here and found no way to it." | |
| 127 | "note": "146 words since #13308 (2026-11-15, Settings \u203a Connected agents): its side-nav entry added two words to the 144 main had; 147 since the forge dataset (Settings \u203a Dataset), one word; 148 since the Tables page (#6002), one word; 149 since Settings \u203a Infrastructure, one word: an admin looked for the cloud bill here and found no way to it; 153 since Settings › Who may do what (#18105), four words: every account sees what it may do and through which grant, so the row is on every account's nav." | |
| 128 | 128 | }, |
| 129 | 129 | "search": { |
| 130 | 130 | "390": { |
docs/features/who-can.md +1 −1
| @@ -6,7 +6,7 @@ row: Who may do what | ||
| 6 | 6 | |
| 7 | 7 | One read over every table that holds a grant, in one shape: who, what they may do (an action or a role), on what, who granted it and when, and the page where it is changed. A table that does not record who granted it, or when, says "not recorded". It reads `member`, `team_member`, `app_member`, `game_grant`, `model_grant`, `subscription_grant`, `secret_grant`, `egress_grant`, `device_grant`, `child_reach_grant`, `origin_read_grant`, `pull_run_grant`, `telemetry_grant`, `client_cloud_member`, `crew_team_member` and `share` (`src/core/grants_view.ts`, the one reader). It changes no access: nothing here grants or revokes. |
| 8 | 8 | |
| 9 | - **Web:** Settings → Who may do what (`/settings/who-can`). A person sees their role, what the role alone lets them do, and every grant they hold. A forge admin sees every grant, and can look up a person (all they can reach, with their role) or a resource (everyone who reaches it; an app is `owner/name`, and what that app itself is granted is listed too). Each row links to where it is changed. | |
| 9 | - **Web:** Settings → Who may do what (`/settings/who-can`). A person sees their role, what the role alone lets them do, and every grant they hold. A forge admin sees every grant, and can look up a person (all they can reach, with their role) or a resource (everyone who reaches it; an app is `owner/name`, and what that app itself is granted is listed too). Each row links to where it is changed; in a person's own view, a grant only an admin changes (any page the route marks keep for admins: People, Crew, Cloud, Subscriptions, Secrets, Telemetry, Devices) says "an admin changes it" with that page named instead of linking to a page that would turn them away. The page is on every account's settings nav. | |
| 10 | 10 | - **MCP:** `whoami_can` with `kind: "grants"`, for anyone: your role and the grants you hold, or every grant for a forge admin (`{ scope, standing, grants }`). A forge admin's `access` tool with `action: "grants"` takes `person` or `resource` too. |
| 11 | 11 | - **Terminal:** `forge tui`, the palette entry "Who may do what": your own, or as an admin `p` a person, `r` a resource, `c` clear. |
| 12 | 12 | - Rules (`src/actions/grants_view.ts`): anyone else asking for another person's or a resource's answers `not_found`. |
src/actions/grants_view.ts +18 −1
| @@ -9,6 +9,7 @@ import type { App } from "../app.ts"; | ||
| 9 | 9 | import { everyGrant, type Grant } from "../core/grants_view.ts"; |
| 10 | 10 | import { ABILITIES, CAN, roleOf, type Role } from "../core/roles.ts"; |
| 11 | 11 | import { getUserByName, type User } from "../core/users.ts"; |
| 12 | import { isAdminRoute } from "../http/route_marks.ts"; | |
| 12 | 13 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 13 | 14 | |
| 14 | 15 | /** An account and what its role gives it before any grant. */ |
| @@ -40,11 +41,27 @@ function standingOf(app: App, user: { id: string; username: string; isAdmin: boo | ||
| 40 | 41 | |
| 41 | 42 | const isAdmin = (u: User): boolean => u.isAdmin && u.kind !== "agent"; |
| 42 | 43 | |
| 44 | /** A page's name as a row says it: `/settings/people` is "People". */ | |
| 45 | const pageName = (path: string): string => { | |
| 46 | const last = path.split("/").filter(Boolean).pop() ?? ""; | |
| 47 | return last.charAt(0).toUpperCase() + last.slice(1); | |
| 48 | }; | |
| 49 | ||
| 50 | /** | |
Incomplete: |
||
| 51 | * A grant as a person who is not an admin sees it (#18105). Where its page answers only a forge | |
| 52 | * admin, as the route marks say (`http/route_marks.ts`, the one list), `href` is "" and | |
| 53 | * `adminPage` names the page, so their view carries no link to a door that turns them away. | |
| 54 | */ | |
| 55 | const reachableBy = (g: Grant): Grant => { | |
| 56 | const path = g.href.split(/[?#]/)[0]!; | |
| 57 | return path !== "" && isAdminRoute(path) ? { ...g, href: "", adminPage: pageName(path) } : g; | |
| 58 | }; | |
| 59 | ||
| 43 | 60 | export function whoMayDoWhat(app: App, actor: User | undefined, query: GrantsQuery = {}): Result<GrantsView, "not_found"> { |
| 44 | 61 | if (actor === undefined) return err("not_found"); |
| 45 | 62 | const person = (query.person ?? "").trim().slice(0, MAX_NAME); |
| 46 | 63 | const resource = (query.resource ?? "").trim().slice(0, MAX_NAME); |
| 47 | const own = (): GrantsView => ({ scope: "self", standing: standingOf(app, actor), grants: everyGrant(app.db, actor.id) }); | |
| 64 | const own = (): GrantsView => ({ scope: "self", standing: standingOf(app, actor), grants: everyGrant(app.db, actor.id).map(reachableBy) }); | |
| 48 | 65 | if (person === "" && resource === "") return ok(isAdmin(actor) ? { scope: "all", standing: standingOf(app, actor), grants: everyGrant(app.db) } : own()); |
| 49 | 66 | if (!isAdmin(actor)) return person.toLowerCase() === actor.username.toLowerCase() && resource === "" ? ok(own()) : err("not_found"); |
| 50 | 67 | if (person !== "") { |
src/core/grants_view.ts +5
| @@ -40,6 +40,11 @@ export interface Grant { | ||
| 40 | 40 | byName: string | null | NotRecorded; |
| 41 | 41 | /** The page where the grant is changed: a path on this forge, never another host. */ |
| 42 | 42 | href: string; |
| 43 | /** | |
| 44 | * Set in a person's own view when `href` is "" because only an admin may open it: the page's | |
| 45 | * name. | |
| 46 | */ | |
| 47 | adminPage?: string; | |
| 43 | 48 | } |
| 44 | 49 | |
| 45 | 50 | /** |
src/tui/screens/whocan.ts +1 −1
| @@ -74,7 +74,7 @@ export function whoCanScreen(f: Session, ctx: Ctx): Screen { | ||
| 74 | 74 | const rows: ListRow[] = (v?.grants ?? []).map((g) => ({ |
| 75 | 75 | title: `${g.who} · ${g.action}`, |
| 76 | 76 | secondary: `${g.on} (${g.resource.kind})`, |
| 77 | meta: `${provenance(g)} · change at ${g.href}`, | |
| 77 | meta: `${provenance(g)} · ${g.href === "" ? `an admin changes it${g.adminPage === undefined ? "" : ` (${g.adminPage})`}` : `change at ${g.href}`}`, | |
| 78 | 78 | })); |
| 79 | 79 | drawList(s, list!, c, state, rows); |
| 80 | 80 | }, |
src/web/pages/origins.ts +2
| @@ -109,6 +109,7 @@ export type AccountSection = | ||
| 109 | 109 | | "password" |
| 110 | 110 | | "tokens" |
| 111 | 111 | | "grants" |
| 112 | | "who-can" | |
| 112 | 113 | | "shells" |
| 113 | 114 | | "keys" |
| 114 | 115 | | "model" |
| @@ -169,6 +170,7 @@ const SECTION_ROWS: readonly (readonly [ | ||
| 169 | 170 | ["Account", "Computer keys", "/settings/keys", "lock", (c) => c === "keys", false], |
| 170 | 171 | ["Account", "Access codes", "/settings/tokens", "key", (c) => c === "tokens", false], |
| 171 | 172 | ["Account", "Connected agents", "/settings/grants", "bot", (c) => c === "grants", false], |
| 173 | ["Account", "Who may do what", "/settings/who-can", "users", (c) => c === "who-can", false], | |
| 172 | 174 | ["Account", "Confirms", "/settings/confirms", "check", (c) => c === "confirms", false], |
| 173 | 175 | ["Crew and AI", "Model", "/settings/model", "key", (c) => c === "model", false], |
| 174 | 176 | ["Crew and AI", "Crew", "/settings/crew", "bot", (c) => c === "crew", true], |
src/web/pages/who-can.ts +12 −7
| @@ -16,12 +16,17 @@ import { btn, row as uiRow, rowList } from "../ui.ts"; | ||
| 16 | 16 | import { accountSections } from "./origins.ts"; |
| 17 | 17 | |
| 18 | 18 | const row = (g: Grant): Html => |
| 19 | uiRow({ | |
| 20 | nav: true, | |
| 21 | href: g.href, | |
| 22 | title: html`${g.who} · ${g.action}`, | |
| 23 | meta: html`${g.on} (${g.resource.kind}) · ${provenance(g)}`, | |
| 24 | }); | |
| 19 | g.href === "" | |
| 20 | ? uiRow({ | |
| 21 | title: html`${g.who} · ${g.action}`, | |
| 22 | meta: html`${g.on} (${g.resource.kind}) · ${provenance(g)} · an admin changes it${g.adminPage === undefined ? "" : ` (${g.adminPage})`}`, | |
| 23 | }) | |
| 24 | : uiRow({ | |
| 25 | nav: true, | |
| 26 | href: g.href, | |
| 27 | title: html`${g.who} · ${g.action}`, | |
| 28 | meta: html`${g.on} (${g.resource.kind}) · ${provenance(g)}`, | |
| 29 | }); | |
| 25 | 30 | |
| 26 | 31 | /** The one sentence the page opens with. */ |
| 27 | 32 | function said(view: GrantsView, resource: string): string { |
| @@ -60,7 +65,7 @@ export function whoCanPage(ctx: Ctx): Response { | ||
| 60 | 65 | ctx, |
| 61 | 66 | title: "Who may do what", |
| 62 | 67 | body: html`${pageHead("Who may do what")} |
| 63 | ${settingsLayout(accountSections("access", { admin, ssh: sshOn(ctx.app.db) }), body, "Account settings")}`, | |
| 68 | ${settingsLayout(accountSections("who-can", { admin, ssh: sshOn(ctx.app.db) }), body, "Account settings")}`, | |
| 64 | 69 | }); |
| 65 | 70 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 66 | 71 | return response; |
test/who-can.test.ts +40
| @@ -155,6 +155,46 @@ describe("who may do what", () => { | ||
| 155 | 155 | expect((await fetch(`${servers.url}/settings/who-can`, { redirect: "manual" })).status).not.toBe(200); |
| 156 | 156 | }); |
| 157 | 157 | |
| 158 | test("a person who is not an admin reaches the page from their account settings (#18105)", async () => { | |
| 159 | const settings = await (await fetch(`${servers.url}/settings`, { headers: { cookie: bobCookie } })).text(); | |
| 160 | expect(settings).toContain('href="/settings/who-can"'); | |
| 161 | const page = await (await fetch(`${servers.url}/settings/who-can`, { headers: { cookie: bobCookie } })).text(); | |
| 162 | expect(page).toMatch(/href="\/settings\/who-can"[^>]*aria-current="page"|aria-current="page"[^>]*href="\/settings\/who-can"/); | |
| 163 | }); | |
| 164 | ||
| 165 | test("a person's own grants never link to a page only an admin may open (#18105)", async () => { | |
| 166 | const dave = getUserByName(app.db, "dave")!; | |
| 167 | const own = whoMayDoWhat(app, dave, {}); | |
| 168 | const grants = own.ok ? own.value.grants : []; | |
| 169 | const member = grants.find((g) => g.table === "member")!; | |
| 170 | expect(member.href).toBe(""); | |
| 171 | const telemetry = grants.find((g) => g.table === "telemetry_grant")!; | |
| 172 | expect(telemetry.href).toBe(""); | |
| 173 | expect(telemetry.adminPage).toBe("Telemetry"); | |
| 174 | expect(member.adminPage).toBe("People"); | |
| 175 | // The admin still gets the link to change it. | |
| 176 | const asAdmin = whoMayDoWhat(app, alice(), { person: "dave" }); | |
| 177 | expect(asAdmin.ok && asAdmin.value.grants.find((g) => g.table === "member")!.href).toBe("/settings/people"); | |
| 178 | const cookie = `forge_session=${createSession(app.db, dave.id).token}`; | |
| 179 | const page = await (await fetch(`${servers.url}/settings/who-can`, { headers: { cookie } })).text(); | |
| 180 | for (const wall of ["/settings/people", "/settings/crew", "/settings/cloud", "/settings/subscriptions", "/settings/secrets", "/settings/telemetry", "/settings/devices"]) | |
| 181 | expect(page).not.toContain(`href="${wall}`); | |
| 182 | expect(page).toContain("an admin changes it (People)"); | |
| 183 | const terminal = headlessTerminal(200, 60); | |
| 184 | const { app: tui, session } = createForgeApp( | |
| 185 | app, | |
| 186 | { sshUsername: "dave", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: dave }, | |
| 187 | { terminal, exitHooks: false }, | |
| 188 | ); | |
| 189 | tui.start(); | |
| 190 | tui.ctx.push(whoCanScreen(session, tui.ctx)); | |
| 191 | await settleApp(tui); | |
| 192 | const shown = tui.screen.toText(); | |
| 193 | tui.stop?.(); | |
| 194 | expect(shown).toContain("an admin changes it (People)"); | |
| 195 | expect(shown).not.toContain("change at /settings/people"); | |
| 196 | }); | |
| 197 | ||
| 158 | 198 | test("a share's link is followed only when it is a path on this forge", () => { |
| 159 | 199 | for (const bad of ["//evil.example/x", "/\\evil.example", "/\t/evil.example", "https://evil.example", "", null]) |
| 160 | 200 | expect(forgePath(bad)).toBe("/settings"); |
new above
offline
Non-blocking:
/settings/connected-agentswould become "Connected-agents". Look the name up in the settings nav rows rather than deriving it from the path.