Public: anyone can read this; the crew can change it.

/security shows a status word and glyph per control and drops its explanatory paragraphs #13015

Merged opened this

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

Merged

mason/forge:mason/13001-security-shows-a-status-word-and-glyph-p → main 8 commits fork 2 threads · 2 unresolved

  • Merged. mason/13001-security-shows-a-status-word-and-glyph-p was merged into main as 0d80ccd.

Review

Sign in to review this change.
7 files changed +75 −32
docs/features/security-controls.md +5 −4
@@ -1,6 +1,6 @@
11 # Security controls
22
3 Each safeguard of `docs/ops/RED-TEAM.md`, and when it was last tested. A site
3 Each safeguard of `docs/ops/RED-TEAM.md`, and its state with when it was last checked. A site
44 admin sees it at `/settings/security/controls` (linked from Security) and in
55 the terminal as the palette command "Security controls". Anyone else gets a 404
66 on the page and is offered nothing in the terminal. Read-only.
@@ -20,9 +20,10 @@ whole by the timer outside the forge. Per control, first match wins:
2020 3. Otherwise "No check recorded". Pod security is kept in the cluster's source,
2121 so only a `controls` entry written by whatever checks the cluster gives it a time.
2222
23 A line says "Failed" when `ok` is false and "Out of date" when the check is
24 more than 8 days old; both use one badge. Hover a name for what it holds and
25 what keeps it.
23 Each control is one row with a word and glyph, never colour alone: "Passing",
24 "Failed" (`ok` is false), "Out of date" (the check is more than 8 days old) or
25 "No check recorded". The terminal says the same four words. Open a row's fold
26 (a native `details`, no script) for what the control holds and what keeps it.
2627
2728 ## Code
2829
forge.json +2 −2
@@ -4,8 +4,8 @@
44 "api.github.com"
55 ],
66 "app": {
7 "looks": ["/", "/front", "/docs", "/explore", "/board", "/notes", "/review", "/releases", "/apps", "/map", "/system", "/maintenance", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"],
8 "looksAsOwner": ["/", "/board", "/flow", "/boards?help", "/settings/crew", "/settings/crew?help", "/talk", "/system", "/maintenance", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"],
7 "looks": ["/", "/docs", "/explore", "/board", "/notes", "/review", "/releases", "/apps", "/map", "/system", "/maintenance", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/security/controls", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"],
8 "looksAsOwner": ["/", "/board", "/flow", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/security/controls", "/talk", "/system", "/maintenance", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"],
99 "run": "bun run src/main.ts",
1010 "install": "",
1111 "health": "/healthz",
src/tui/screens/controls.ts +11 −8
@@ -1,7 +1,7 @@
11 /**
22 * Security controls in the terminal, a forge admin's: the same lines as
3 * /settings/security/controls (`checks/controls.ts`), each safeguard and when
4 * it was last tested, then what the page policy blocked this week by
3 * /settings/security/controls (`checks/controls.ts`), each safeguard with its state
4 * (Passing, Failed, Out of date or No check recorded) and when it was last checked, then what the page policy blocked this week by
55 * directive (the security page's "Blocked by the page policy" line), absent
66 * when nothing was, then the uncaught script errors pages reported (#11447). Read-only.
77 */
@@ -18,14 +18,17 @@ import type { PaletteEntry } from "./entries.ts";
1818
1919 const isAdmin = (f: Session): boolean => f.user?.isAdmin === true && f.user.kind !== "agent";
2020
21 /** The same four words as the page's badge. */
22 function stateWord(ok: boolean, attention: boolean): string {
23 if (!ok) return "Failed";
24 return attention ? "Out of date" : "Passing";
25 }
26
2127 export function controlRows(dataDir: string, nowMs: number): ListRow[] {
2228 return controlStandings(dataDir, nowMs).map(({ control, check, attention }) => ({
2329 title: control.name,
2430 secondary: "",
25 meta:
26 check === null
27 ? "No check recorded"
28 : `${attention ? (check.ok ? "Out of date, " : "Failed, ") : ""}checked ${check.at.slice(0, 10)}`,
31 meta: check === null ? "No check recorded" : `${stateWord(check.ok, attention)}, checked ${check.at.slice(0, 10)}`,
2932 }));
3033 }
3134
@@ -63,11 +66,11 @@ export function controlsScreen(f: Session, ctx: Ctx): Screen {
6366 };
6467 }
6568
66 /** Each safeguard, and when it was last tested. */
69 /** Each safeguard, its state, and when it was last checked. */
6770 export const entry: PaletteEntry = {
6871 id: "security-controls",
6972 title: "Security controls",
70 hint: "each safeguard, and when it was last tested",
73 hint: "each safeguard, its state, and when it was last checked",
7174 offered: isAdmin,
7275 run: (session, ctx) => ctx.push(controlsScreen(session, ctx)),
7376 };
src/web/pages/security_controls.ts +26 −16
@@ -6,18 +6,33 @@ import type { Ctx } from "../../http/context.ts";
66 import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts";
77 import { html, type Html } from "../html.ts";
88 import { page } from "../layout.ts";
9 import { badge, time } from "../ui.ts";
9 import { icon } from "../icons.ts";
10 import { badge, listCard, row, time } from "../ui.ts";
1011 import { accountSections } from "./origins.ts";
1112
12 function line({ control: c, check, attention }: Standing): Html {
13 const state =
14 check === null
15 ? html`<span class="muted">No check recorded</span>`
16 : html`${attention ? html`${badge(check.ok ? "Out of date" : "Failed", { tone: "attn" })} ` : null}<span class="muted">Checked ${time(check.at)}</span>`;
17 return html`<div class="status-row" id="${c.id}">
18 <dt title="${c.holds} Kept by ${c.keptBy}.">${c.name}</dt>
19 <dd>${state}</dd>
20 </div>`;
13 /** One control, one word and glyph: the state is never colour alone. */
14 function stateBadge({ check, attention }: Standing): Html {

Both doors: the terminal's controlRows must say the same four words as this badge; today a passing control shows no state there. Add a test.

15 if (check === null) return badge("No check recorded", { tone: "default", variant: "outline", icon: "dot" });
16 if (!check.ok) return badge("Failed", { tone: "danger", icon: "x" });
17 if (attention) return badge("Out of date", { tone: "attn", icon: "alert" });
18 return badge("Passing", { tone: "success", icon: "check" });
19 }
20
21 /** A control is one row: state, name, last checked; what it holds and its test fold open. */
22 function line(s: Standing): Html {

Docs: docs/features/security-controls.md still describes the hover title and a single badge; update to match this row and fold.

23 const { control: c, check } = s;
24 return row({
25 id: c.id,
26 lead: icon("chevronRight"),
27 title: c.name,
28 meta: stateBadge(s),
29 ...(check === null ? {} : { trail: html`<span class="muted">Checked ${time(check.at)}</span>` }),
30 fold: {
31 id: `${c.id}-evidence`,
32 open: false,
33 body: html`<div class="card-body"><p>${c.holds}</p><p class="small muted">Kept by <span class="mono">${c.keptBy}</span>.</p></div>`,
34 },
35 });
2136 }
2237
2338 export function securityControlsPage(ctx: Ctx): Response {
@@ -26,12 +41,7 @@ export function securityControlsPage(ctx: Ctx): Response {
2641 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
2742 const rendering = performance.now();
2843 const standings = controlStandings(ctx.app.config.dataDir, Date.now());
29 const body = html`<p class="small muted mb">
30 Each safeguard, and when it was last tested. <a href="/settings/security">Back to Security</a>.
31 </p>
32 <dl class="status-rows">
33 ${standings.map(line)}
34 </dl>`;
44 const body = listCard(standings.map(line));
3545 notePhase(ctx.request, "render", performance.now() - rendering);
3646 return page({
3747 ctx,
test/forge-looks.test.ts +2 −1
@@ -24,6 +24,7 @@ const NOT_A_PAGE: Record<string, string> = {
2424 "/home": "the home's old address: a redirect to /, which is pictured",
2525 "/desk": "a POST that leaves a note on the desk; the desk is read on the home (/), which is pictured; covered by test/desk.test.ts",
2626 "/feed": "no picture: its slot went to /docs; the page is covered by its own tests",
27 "/front": "no picture: its slot went to /settings/security/controls, the security controls (#13001); covered by its own tests",
2728 "/pricing": "no picture: the cap of 24 looks is spent; the page is covered by test/pricing-order.test.ts",
2829 "/audit": "no picture: its slot went to /pinned; /audit.csv is its download, covered by test/audit.test.ts",
2930 "/deploy-to": "a form for a forge admin that fills from its link; covered by test/pinned-page.test.ts",
@@ -171,7 +172,7 @@ test("`/` signed out is its own look at phone and desktop, taken with no session
171172 test("a look below the top level is the preview seed's, taken as the owner", () => {
172173 const { looks, looksAsOwner } = manifest();
173174 for (const p of looks.filter((p) => !isTopLevel(p))) {
174 expect(p.startsWith("/preview-admin/sample") || p === "/settings/crew" || isHelpLook(p)).toBe(true);
175 expect(p.startsWith("/preview-admin/sample") || p === "/settings/crew" || p === "/settings/security/controls" || isHelpLook(p)).toBe(true);
175176 expect(looksAsOwner).toContain(p);
176177 }
177178 });
test/palette-roster.test.ts +1 −1
@@ -188,7 +188,7 @@ test("a site-admin person is offered the whole roster", () => {
188188 ["traffic-sources", "Traffic sources", "where people come from and where they go, for the forge"],
189189 ["from-visit-to-paid", "From visit to paid", "the last 7 days: home visits, plans seen, plan clicks, forges made, paid"],
190190 ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"],
191 ["security-controls", "Security controls", "each safeguard, and when it was last tested"],
191 ["security-controls", "Security controls", "each safeguard, its state, and when it was last checked"],
192192 ["billing", "Billing", "each forge's plan, and grant one by hand"],
193193 ["lapsed", "Lapsed forges", "forges asleep until paid, when their data goes, pay again"],
194194 ["codes", "Gift codes", "make a code that gives a plan for free, and revoke one"],
test/security-controls.test.ts +28
@@ -40,6 +40,19 @@ test("an admin sees every control; with no report each says no check recorded",
4040 const text = await res.text();
4141 for (const c of CONTROLS) expect(text).toContain(c.name);
4242 expect(text.match(/No check recorded/g)?.length).toBe(CONTROLS.length);
43 // One row and one fold per control; none dropped, and the explanatory prose is gone.
44 expect(text.match(/<details id="[a-z-]+-evidence"/g)?.length).toBe(CONTROLS.length);
45 for (const c of CONTROLS) expect(text).toContain(`id="${c.id}"`);
46 expect(text).not.toContain("Each safeguard, and when it was last tested");
47 });
48
49 test("a passing control says Passing with its checked time", async () => {
50 const at = new Date().toISOString();
51 await writeFile(join(dir, "security-report.json"), JSON.stringify({ controls: [{ id: "app-env", at, ok: true }] }));
52 const text = await (await get(admin)).text();
53 expect(text.match(/Passing/g)?.length).toBe(1);
54 expect(text).toContain("Checked");
55 await rm(join(dir, "security-report.json"));
4356 });
4457
4558 test("the page is an admin's", async () => {
@@ -103,6 +116,21 @@ test("the terminal rows match the page", () => {
103116 expect(rows.find((r) => r.title === "Pod security")?.meta).toBe("No check recorded");
104117 });
105118
119 test("the terminal says Passing, Failed and Out of date as the page does", async () => {
120 const now = Date.now();
121 const old = new Date(now - 20 * 86400000).toISOString();
122 const at = new Date(now).toISOString();
123 await writeFile(
124 join(dir, "security-report.json"),
125 JSON.stringify({ controls: [{ id: "app-env", at, ok: true }, { id: "edge-secret", at, ok: false }, { id: "crew-sandbox", at: old, ok: true }] }),
126 );
127 const meta = (name: string) => controlRows(dir, now).find((r) => r.title === name)?.meta;
128 expect(meta(CONTROLS.find((c) => c.id === "app-env")!.name)).toStartWith("Passing, checked ");
129 expect(meta(CONTROLS.find((c) => c.id === "edge-secret")!.name)).toStartWith("Failed, checked ");
130 expect(meta(CONTROLS.find((c) => c.id === "crew-sandbox")!.name)).toStartWith("Out of date, checked ");
131 await rm(join(dir, "security-report.json"));
132 });
133
106134 test("the terminal lists script errors, for an admin only", () => {
107135 expect(scriptErrorRows(app.db, Date.now())).toEqual([]);
108136 recordScriptError(app.db, { page: "/", src: "/a.js", line: 3, msg: "boom" });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs