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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13001-security-shows-a-status-word-and-glyph-p → main 8 commits fork 2 threads · 2 unresolved
7 files
changed +75
−32
docs/features/security-controls.md +5 −4
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | # Security controls |
| 2 | 2 | |
| 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 | |
| 4 | 4 | admin sees it at `/settings/security/controls` (linked from Security) and in |
| 5 | 5 | the terminal as the palette command "Security controls". Anyone else gets a 404 |
| 6 | 6 | 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: | ||
| 20 | 20 | 3. Otherwise "No check recorded". Pod security is kept in the cluster's source, |
| 21 | 21 | so only a `controls` entry written by whatever checks the cluster gives it a time. |
| 22 | 22 | |
| 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. | |
| 26 | 27 | |
| 27 | 28 | ## Code |
| 28 | 29 |
forge.json +2 −2
| @@ -4,8 +4,8 @@ | ||
| 4 | 4 | "api.github.com" |
| 5 | 5 | ], |
| 6 | 6 | "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"], | |
| 9 | 9 | "run": "bun run src/main.ts", |
| 10 | 10 | "install": "", |
| 11 | 11 | "health": "/healthz", |
src/tui/screens/controls.ts +11 −8
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * 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 | |
| 5 | 5 | * directive (the security page's "Blocked by the page policy" line), absent |
| 6 | 6 | * when nothing was, then the uncaught script errors pages reported (#11447). Read-only. |
| 7 | 7 | */ |
| @@ -18,14 +18,17 @@ import type { PaletteEntry } from "./entries.ts"; | ||
| 18 | 18 | |
| 19 | 19 | const isAdmin = (f: Session): boolean => f.user?.isAdmin === true && f.user.kind !== "agent"; |
| 20 | 20 | |
| 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 | ||
| 21 | 27 | export function controlRows(dataDir: string, nowMs: number): ListRow[] { |
| 22 | 28 | return controlStandings(dataDir, nowMs).map(({ control, check, attention }) => ({ |
| 23 | 29 | title: control.name, |
| 24 | 30 | 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)}`, | |
| 29 | 32 | })); |
| 30 | 33 | } |
| 31 | 34 | |
| @@ -63,11 +66,11 @@ export function controlsScreen(f: Session, ctx: Ctx): Screen { | ||
| 63 | 66 | }; |
| 64 | 67 | } |
| 65 | 68 | |
| 66 | /** Each safeguard, and when it was last tested. */ | |
| 69 | /** Each safeguard, its state, and when it was last checked. */ | |
| 67 | 70 | export const entry: PaletteEntry = { |
| 68 | 71 | id: "security-controls", |
| 69 | 72 | 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", | |
| 71 | 74 | offered: isAdmin, |
| 72 | 75 | run: (session, ctx) => ctx.push(controlsScreen(session, ctx)), |
| 73 | 76 | }; |
src/web/pages/security_controls.ts +26 −16
| @@ -6,18 +6,33 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 6 | 6 | import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts"; |
| 7 | 7 | import { html, type Html } from "../html.ts"; |
| 8 | 8 | 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"; | |
| 10 | 11 | import { accountSections } from "./origins.ts"; |
| 11 | 12 | |
| 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 { | |
| 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 | }); | |
| 21 | 36 | } |
| 22 | 37 | |
| 23 | 38 | export function securityControlsPage(ctx: Ctx): Response { |
| @@ -26,12 +41,7 @@ export function securityControlsPage(ctx: Ctx): Response { | ||
| 26 | 41 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 27 | 42 | const rendering = performance.now(); |
| 28 | 43 | 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)); | |
| 35 | 45 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 36 | 46 | return page({ |
| 37 | 47 | ctx, |
test/forge-looks.test.ts +2 −1
| @@ -24,6 +24,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 24 | 24 | "/home": "the home's old address: a redirect to /, which is pictured", |
| 25 | 25 | "/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", |
| 26 | 26 | "/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", | |
| 27 | 28 | "/pricing": "no picture: the cap of 24 looks is spent; the page is covered by test/pricing-order.test.ts", |
| 28 | 29 | "/audit": "no picture: its slot went to /pinned; /audit.csv is its download, covered by test/audit.test.ts", |
| 29 | 30 | "/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 | ||
| 171 | 172 | test("a look below the top level is the preview seed's, taken as the owner", () => { |
| 172 | 173 | const { looks, looksAsOwner } = manifest(); |
| 173 | 174 | 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); | |
| 175 | 176 | expect(looksAsOwner).toContain(p); |
| 176 | 177 | } |
| 177 | 178 | }); |
test/palette-roster.test.ts +1 −1
| @@ -188,7 +188,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 188 | 188 | ["traffic-sources", "Traffic sources", "where people come from and where they go, for the forge"], |
| 189 | 189 | ["from-visit-to-paid", "From visit to paid", "the last 7 days: home visits, plans seen, plan clicks, forges made, paid"], |
| 190 | 190 | ["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"], | |
| 192 | 192 | ["billing", "Billing", "each forge's plan, and grant one by hand"], |
| 193 | 193 | ["lapsed", "Lapsed forges", "forges asleep until paid, when their data goes, pay again"], |
| 194 | 194 | ["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", | ||
| 40 | 40 | const text = await res.text(); |
| 41 | 41 | for (const c of CONTROLS) expect(text).toContain(c.name); |
| 42 | 42 | 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")); | |
| 43 | 56 | }); |
| 44 | 57 | |
| 45 | 58 | test("the page is an admin's", async () => { |
| @@ -103,6 +116,21 @@ test("the terminal rows match the page", () => { | ||
| 103 | 116 | expect(rows.find((r) => r.title === "Pod security")?.meta).toBe("No check recorded"); |
| 104 | 117 | }); |
| 105 | 118 | |
| 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 | ||
| 106 | 134 | test("the terminal lists script errors, for an admin only", () => { |
| 107 | 135 | expect(scriptErrorRows(app.db, Date.now())).toEqual([]); |
| 108 | 136 | recordScriptError(app.db, { page: "/", src: "/a.js", line: 3, msg: "boom" }); |
new above
offline
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.