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

opened this

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

  • Merged. scout/18105-access-4b-the-who-may-do-what-page-linke was merged into main as 3ecccb5.

Review

Sign in to review this change.
8 files changed +82 −13
docs/design/attention-budget.json +3 −3
@@ -115,16 +115,16 @@
115115 },
116116 "settings": {
117117 "390": {
118 "words": 149,
118 "words": 153,
119119 "blocks": 32,
120120 "colours": 1
121121 },
122122 "1280": {
123 "words": 149,
123 "words": 153,
124124 "blocks": 32,
125125 "colours": 1
126126 },
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."
128128 },
129129 "search": {
130130 "390": {
docs/features/who-can.md +1 −1
@@ -6,7 +6,7 @@ row: Who may do what
66
77 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.
88
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.
1010 - **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.
1111 - **Terminal:** `forge tui`, the palette entry "Who may do what": your own, or as an admin `p` a person, `r` a resource, `c` clear.
1212 - 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";
99 import { everyGrant, type Grant } from "../core/grants_view.ts";
1010 import { ABILITIES, CAN, roleOf, type Role } from "../core/roles.ts";
1111 import { getUserByName, type User } from "../core/users.ts";
12 import { isAdminRoute } from "../http/route_marks.ts";
1213 import { err, ok, type Result } from "../kernel/result.ts";
1314
1415 /** 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
4041
4142 const isAdmin = (u: User): boolean => u.isAdmin && u.kind !== "agent";
4243
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);

Non-blocking: /settings/connected-agents would become "Connected-agents". Look the name up in the settings nav rows rather than deriving it from the path.

48 };
49
50 /**
outdated

Incomplete: /settings/telemetry and /settings/devices are admin-only in src/http/marks/settings.json but are missing here, so a person's own telemetry or device grant still links to a page that turns them away. Read the admin-only set from the route marks instead of a copy, so a page that becomes admin-only cannot be forgotten.

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
4360 export function whoMayDoWhat(app: App, actor: User | undefined, query: GrantsQuery = {}): Result<GrantsView, "not_found"> {
4461 if (actor === undefined) return err("not_found");
4562 const person = (query.person ?? "").trim().slice(0, MAX_NAME);
4663 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) });
4865 if (person === "" && resource === "") return ok(isAdmin(actor) ? { scope: "all", standing: standingOf(app, actor), grants: everyGrant(app.db) } : own());
4966 if (!isAdmin(actor)) return person.toLowerCase() === actor.username.toLowerCase() && resource === "" ? ok(own()) : err("not_found");
5067 if (person !== "") {
src/core/grants_view.ts +5
@@ -40,6 +40,11 @@ export interface Grant {
4040 byName: string | null | NotRecorded;
4141 /** The page where the grant is changed: a path on this forge, never another host. */
4242 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;
4348 }
4449
4550 /**
src/tui/screens/whocan.ts +1 −1
@@ -74,7 +74,7 @@ export function whoCanScreen(f: Session, ctx: Ctx): Screen {
7474 const rows: ListRow[] = (v?.grants ?? []).map((g) => ({
7575 title: `${g.who} · ${g.action}`,
7676 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}`}`,
7878 }));
7979 drawList(s, list!, c, state, rows);
8080 },
src/web/pages/origins.ts +2
@@ -109,6 +109,7 @@ export type AccountSection =
109109 | "password"
110110 | "tokens"
111111 | "grants"
112 | "who-can"
112113 | "shells"
113114 | "keys"
114115 | "model"
@@ -169,6 +170,7 @@ const SECTION_ROWS: readonly (readonly [
169170 ["Account", "Computer keys", "/settings/keys", "lock", (c) => c === "keys", false],
170171 ["Account", "Access codes", "/settings/tokens", "key", (c) => c === "tokens", false],
171172 ["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],
172174 ["Account", "Confirms", "/settings/confirms", "check", (c) => c === "confirms", false],
173175 ["Crew and AI", "Model", "/settings/model", "key", (c) => c === "model", false],
174176 ["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";
1616 import { accountSections } from "./origins.ts";
1717
1818 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})`}`,

Non-blocking: this wording is repeated in src/tui/screens/whocan.ts. Share one helper beside provenance.

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 });
2530
2631 /** The one sentence the page opens with. */
2732 function said(view: GrantsView, resource: string): string {
@@ -60,7 +65,7 @@ export function whoCanPage(ctx: Ctx): Response {
6065 ctx,
6166 title: "Who may do what",
6267 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")}`,
6469 });
6570 notePhase(ctx.request, "render", performance.now() - rendering);
6671 return response;
test/who-can.test.ts +40
@@ -155,6 +155,46 @@ describe("who may do what", () => {
155155 expect((await fetch(`${servers.url}/settings/who-can`, { redirect: "manual" })).status).not.toBe(200);
156156 });
157157
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");
outdated

This asserts the telemetry link stays, but /settings/telemetry is admin-only. Assert it is blank like the others, and add telemetry and devices to the wall list below.

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
158198 test("a share's link is followed only when it is a path on this forge", () => {
159199 for (const bad of ["//evil.example/x", "/\\evil.example", "/\t/evil.example", "https://evil.example", "", null])
160200 expect(forgePath(bad)).toBe("/settings");

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs