Public: anyone can read this; the crew can change it.
A cloud account can be a sealed, expiring, read-only view for a client #17942
Merged 20h ago, live in production
torque/forge:torque/17937-a-cloud-account-can-be-a-sealed-expiring → main 0 commits fork 3 threads · 3 unresolved
22 files
changed +1440
−220
- docs/design/audit.md
- docs/features/client-clouds.md
- src/actions/client_cloud.ts
- src/cloud/client_read.ts
- src/core/client_cloud.ts
- src/core/reserved.ts
- src/generated/duties.ts
- src/generated/marks.ts
- src/generated/screens.ts
- src/http/lazy_lists.ts
- src/http/marks/client-clouds.json
- src/http/routes/operations.ts
- src/maintain/duties/client_keys.ts
- src/tui/screens/client_clouds.ts
- src/web/pages/client_cloud.ts
- test/budgets/unfixtured/client-clouds-id.json
- test/client-cloud.test.ts
- test/forge-looks.test.ts
- test/no-polling.test.ts
- test/palette-roster.test.ts
- test/security-floor-routes.test.ts
- test/tui-client-clouds.test.ts
docs/design/audit.md +1
| @@ -104,6 +104,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 104 | 104 | - `/apps/new` — `pages/apps.ts` (`newAppPage`) · make an app from the template · `/new` · colour 1. |
| 105 | 105 | - `/apps/open` — `pages/apps.ts` (`appsOpen`) · a door from a name to a running app · `/apps` · colour 1. |
| 106 | 106 | - `/archive` — `pages/archive.ts` · everything put away, who archived it and why, Unarchive with Undo · `/apps` (its old `?archived=1` view), the terminal's Archive · none seen. |
| 107 | - `/client-clouds` — `pages/client_cloud.ts` · sealed, expiring, read-only views of a client's cloud, for the people named on them · the terminal's Clients' clouds · none seen. | |
| 107 | 108 | - `/organizations/new` — `pages/org.ts` · make an organization · none · none seen. |
| 108 | 109 | - `/migrate` — `pages/migrate.ts` · bring a repository in from elsewhere · `/settings/origins` (mirror jobs) · none seen. |
| 109 | 110 | - `/migrate/inventory` — `pages/inventory.ts` · what is left to bring over from connected origins · `/migrate` · none seen. |
docs/features/client-clouds.md added +21
| @@ -0,0 +1,21 @@ | ||
| 1 | --- | |
| 2 | topic: Hosting forges for others, and getting paid | |
| 3 | row: Clients' clouds | |
| 4 | --- | |
| 5 | # Clients' clouds | |
| 6 | ||
| 7 | Look at a client's cloud without the key, or what it shows, leaking (#17937). An admin attaches the client's Azure Reader service principal (`TENANT_ID:CLIENT_ID:CLIENT_SECRET`) for 1 to 90 days; the named people read the cloud live, read-only. The page and the terminal say the same thing about the one switch that matters: **the client's own expiring Reader principal is the real off switch.** Deleting the key here stops this forge looking; only the client ending, or letting expire, its principal stops everyone who holds the key. | |
| 8 | ||
| 9 | - **Page** (`src/web/pages/client_cloud.ts`): `/client-clouds` lists the views you are named on (an admin also sees the attach form); `/client-clouds/:id` reads the cloud now (subscriptions, then each resource's kind, region, size, state), with who is named and every look so far. Anyone not named, signed in or not, finds no such page. Every response is `no-store` and `noindex`. | |
| 10 | - **Terminal**: the "Clients' clouds" screen (`src/tui/screens/client_clouds.ts`), offered to an admin and to anyone named. `enter` reads one, `n` names another person, `x` deletes the key now (the page's button asks first on `/-/confirm`), `a` attaches (key typed masked, never drawn). Both doors go through `src/actions/client_cloud.ts`. | |
| 11 | - **Not offered**: no API route and no MCP tool, on purpose. A token is not a person named, so the crew, which acts only through tokens, has no way to ask. | |
| 12 | ||
| 13 | ## What holds | |
| 14 | ||
| 15 | - **Sealed to named people.** The creator is the first name; any named person may name another (a signed-up person, never a crew member or an organization). Only an admin or whoever attached the key deletes it early. | |
| 16 | - **The key is deleted at its expiry.** It is sealed under the view's id (`kernel/secret.ts`) and set to null when its time is up: by whichever door asks first, and by the `client-keys` duty every ten minutes. The view and its audit stay and say the key is deleted. | |
| 17 | - **No write verbs.** The reader's network (`readOnly`, `src/cloud/client_read.ts`) sends a GET, Azure's sign-in, and the two read queries (Resource Graph, Cost Management); any other verb or path throws before it leaves. A principal with more than Reader still can only be read with. | |
| 18 | - **Every read audited.** Each look writes a row (who, when, what, refused or not) before the read; the attach is the first. The rows are on the view's page. They are the view's own table, not the owner's vendor-call log. | |
| 19 | - **Kept out of the owner's cloud.** No row of `cloud_account`, `cloud_resource`, `cloud_project` or `secret`, so not in the cloud tree, costs, the ceiling or the hourly watch. No event is appended, so nothing reaches the feed, Talk, a webhook or a crew run; no public page links it (`test/client-cloud.test.ts`). | |
| 20 | ||
| 21 | Not done: only Azure (the one reader that needs no write verb at all); no cost of the client's cloud is shown; a key that a person types into the terminal is as private as that terminal. |
src/actions/client_cloud.ts added +166
| @@ -0,0 +1,166 @@ | ||
| 1 | /** | |
| 2 | * A client's cloud, as people reach it (#17937): an admin attaches the client's Reader key for a | |
| 3 | * number of days, the named people look, any of them may name one more, and an admin or whoever | |
| 4 | * attached it deletes the key early. Every way in asks `sweepKeys` first, so a key past its time is | |
| 5 | * gone before anything is decided. Only a person is ever named or let in: an agent, an org and a | |
| 6 | * token acting for one are refused, and no mutation appends an event, so nothing here reaches the | |
| 7 | * feed, Talk, a webhook or the crew. Anyone not named is told `not_found`, as of anything unseen. | |
| 8 | */ | |
| 9 | ||
| 10 | import type { App } from "../app.ts"; | |
| 11 | import { CLIENT_PROVIDERS, isClientProvider, readClient } from "../cloud/client_read.ts"; | |
| 12 | import type { Inventory } from "../cloud/inventory.ts"; | |
| 13 | import { | |
| 14 | KEEP_DAYS, | |
| 15 | LABEL_MAX, | |
| 16 | addMember, | |
| 17 | allClientClouds, | |
| 18 | clientCloudsOf, | |
| 19 | createClientCloud, | |
| 20 | endClientCloud, | |
| 21 | getClientCloud, | |
| 22 | isMember, | |
| 23 | membersOf, | |
| 24 | openKey, | |
| 25 | readsOf, | |
| 26 | recordRead, | |
| 27 | sweepKeys, | |
| 28 | type ClientCloud, | |
| 29 | type ClientRead, | |
| 30 | lookedWithin, | |
| 31 | } from "../core/client_cloud.ts"; | |
| 32 | import { getUserById, getUserByName, isActive, type User } from "../core/users.ts"; | |
| 33 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 34 | import { net } from "./cloud.ts"; | |
| 35 | ||
| 36 | export const NOT_FOUND = "not_found"; | |
| 37 | ||
| 38 | /** | |
| 39 | * One person's live reads of one view are this far apart: a reload does not become a flood on the | |
| 40 | * client's cloud. | |
| 41 | */ | |
| 42 | const LOOK_PAUSE_SECONDS = 5; | |
| 43 | ||
| 44 | /** Said on every surface that shows a view: the key's real off switch is the client's own. */ | |
| 45 | export const OFF_SWITCH = | |
| 46 | "The client's own Reader principal, with its expiry, is the real off switch: deleting the key here stops this forge looking, but only the client ending or letting its principal expire stops everyone who holds it. Until then, the key reads."; | |
| 47 | ||
| 48 | /** A person the forge may let in: a signed-in everyday account, never an agent or an org. */ | |
| 49 | const person = (u: User | undefined): u is User => u !== undefined && u.kind === "user" && isActive(u); | |
| 50 | ||
| 51 | export interface ClientCloudRow extends ClientCloud { | |
| 52 | readonly state: "held" | "ended"; | |
| 53 | /** | |
| 54 | * Whether the person is named on it: only the named read it; an admin sees the rest only to | |
| 55 | * delete their keys. | |
| 56 | */ | |
| 57 | readonly named: boolean; | |
| 58 | } | |
| 59 | ||
| 60 | /** The views this person is named on; empty for anyone else, an agent included. */ | |
| 61 | export function myClientClouds(app: App, actor: User | undefined, now = new Date()): ClientCloudRow[] { | |
| 62 | if (!person(actor)) return []; | |
| 63 | sweepKeys(app.db, now); | |
| 64 | const named = new Set(clientCloudsOf(app.db, actor.id).map((c) => c.id)); | |
| 65 | const shown = actor.isAdmin ? allClientClouds(app.db) : clientCloudsOf(app.db, actor.id); | |
| 66 | return shown.map((c) => ({ ...c, state: c.endedAt === null ? "held" : "ended", named: named.has(c.id) })); | |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * Attach a client's key: an admin's. The key is read once, with reads only, before it is sealed, so | |
| 71 | * a bad paste is never kept, and that look is the first of the view's audit. | |
| 72 | */ | |
| 73 | export async function attachClientCloud( | |
| 74 | app: App, | |
| 75 | actor: User | undefined, | |
| 76 | o: { provider: string; label: string; key: string; days: number }, | |
| 77 | now = new Date(), | |
| 78 | ): Promise<Result<ClientCloud, string>> { | |
| 79 | if (!person(actor) || !actor.isAdmin) return err(NOT_FOUND); | |
| 80 | if (!isClientProvider(o.provider)) return err(`A client's cloud can be one of: ${CLIENT_PROVIDERS.join(", ")}.`); | |
| 81 | const label = o.label.trim(); | |
| 82 | if (label === "" || label.length > LABEL_MAX) return err(`Name the client's cloud in 1 to ${LABEL_MAX} characters.`); | |
| 83 | if (!Number.isInteger(o.days) || o.days < KEEP_DAYS.min || o.days > KEEP_DAYS.max) return err(`Keep the key for ${KEEP_DAYS.min} to ${KEEP_DAYS.max} whole days.`); | |
| 84 | const key = o.key.trim(); | |
| 85 | if (key === "") return err("Paste the client's key first."); | |
| 86 | let seen: Inventory; | |
| 87 | try { | |
| 88 | seen = await readClient(o.provider, key, net.fetch); | |
| 89 | } catch (e) { | |
| 90 | return err(e instanceof Error ? e.message : "the key could not be used"); | |
| 91 | } | |
| 92 | const made = createClientCloud(app.db, app.config.dataDir, { provider: o.provider, label, key, days: o.days, by: actor.id, now }); | |
| 93 | recordRead(app.db, made.id, actor.id, `attached: ${seen.projects.length} subscriptions, ${seen.things.length} resources`, true, now); | |
| 94 | return ok(made); | |
| 95 | } | |
| 96 | ||
| 97 | export interface ClientCloudView { | |
| 98 | readonly cloud: ClientCloud; | |
| 99 | /** What the key sees, read now; absent once the key is deleted. */ | |
| 100 | readonly seen?: Inventory; | |
| 101 | /** Why it could not be read, when it could not. */ | |
| 102 | readonly why?: string; | |
| 103 | readonly members: readonly { readonly username: string; readonly grantedBy: string; readonly grantedAt: string }[]; | |
| 104 | readonly reads: readonly (ClientRead & { readonly username: string })[]; | |
| 105 | readonly offSwitch: string; | |
| 106 | } | |
| 107 | ||
| 108 | const nameOf = (app: App, id: string): string => getUserById(app.db, id)?.username ?? "(gone)"; | |
| 109 | ||
| 110 | /** Open one view for a named person: audited before the read, and the read is live, never kept. */ | |
| 111 | export async function lookAtClientCloud(app: App, actor: User | undefined, id: string, now = new Date()): Promise<Result<ClientCloudView, string>> { | |
| 112 | if (!person(actor)) return err(NOT_FOUND); | |
| 113 | sweepKeys(app.db, now); | |
| 114 | if (!isMember(app.db, id, actor.id)) return err(NOT_FOUND); | |
| 115 | const cloud = getClientCloud(app.db, id); | |
| 116 | if (cloud === undefined) return err(NOT_FOUND); | |
| 117 | let seen: Inventory | undefined; | |
| 118 | let why: string | undefined; | |
| 119 | if (cloud.endedAt === null) { | |
| 120 | const key = openKey(app.db, app.config.dataDir, id); | |
| 121 | if (key === undefined || !isClientProvider(cloud.provider)) why = "the key cannot be opened"; | |
| 122 | else if (lookedWithin(app.db, id, actor.id, now, LOOK_PAUSE_SECONDS)) why = `you looked a moment ago: wait ${LOOK_PAUSE_SECONDS} seconds between looks`; | |
| 123 | else { | |
| 124 | recordRead(app.db, id, actor.id, "looked", true, now); | |
| 125 | try { | |
| 126 | seen = await readClient(cloud.provider, key, net.fetch); | |
| 127 | } catch (e) { | |
| 128 | why = e instanceof Error ? e.message : "the cloud could not be read"; | |
| 129 | recordRead(app.db, id, actor.id, `looked, refused: ${why}`, false, now); | |
| 130 | } | |
| 131 | } | |
| 132 | } | |
| 133 | return ok({ | |
| 134 | cloud, | |
| 135 | ...(seen === undefined ? {} : { seen }), | |
| 136 | ...(why === undefined ? {} : { why }), | |
| 137 | members: membersOf(app.db, id).map((m) => ({ username: nameOf(app, m.userId), grantedBy: nameOf(app, m.grantedBy), grantedAt: m.grantedAt })), | |
| 138 | reads: readsOf(app.db, id).map((r) => ({ ...r, username: nameOf(app, r.userId) })), | |
| 139 | offSwitch: OFF_SWITCH, | |
| 140 | }); | |
| 141 | } | |
| 142 | ||
| 143 | /** A named person names one more. The one named is told nothing the page does not show them. */ | |
| 144 | export function grantClientCloud(app: App, actor: User | undefined, id: string, username: string, now = new Date()): Result<string, string> { | |
| 145 | if (!person(actor)) return err(NOT_FOUND); | |
| 146 | sweepKeys(app.db, now); | |
| 147 | if (!isMember(app.db, id, actor.id)) return err(NOT_FOUND); | |
| 148 | const cloud = getClientCloud(app.db, id); | |
| 149 | if (cloud === undefined || cloud.endedAt !== null) return err("That view has ended: its key is deleted."); | |
| 150 | const who = getUserByName(app.db, username.trim()); | |
| 151 | if (!person(who)) return err("No such person: only a signed-up person can be named, never a crew member or an organization."); | |
| 152 | return addMember(app.db, id, who.id, actor.id, now) ? ok(who.username) : err(`${who.username} is named already.`); | |
| 153 | } | |
| 154 | ||
| 155 | /** Delete the key now: an admin, or whoever attached it. The view and its audit stay. */ | |
| 156 | export function endClientCloudKey(app: App, actor: User | undefined, id: string, now = new Date()): Result<void, string> { | |
| 157 | if (!person(actor)) return err(NOT_FOUND); | |
| 158 | sweepKeys(app.db, now); | |
| 159 | const cloud = getClientCloud(app.db, id); | |
| 160 | // The off switch does not depend on being named: an admin ends any key, whoever attached one ends | |
| 161 | // their own. | |
| 162 | if (cloud === undefined) return err(NOT_FOUND); | |
| 163 | if (!actor.isAdmin && !isMember(app.db, id, actor.id)) return err(NOT_FOUND); | |
| 164 | if (!actor.isAdmin && cloud.createdBy !== actor.id) return err("Only an admin, or whoever attached it, deletes the key."); | |
| 165 | return endClientCloud(app.db, id, now) ? ok() : err("The key is already deleted."); | |
| 166 | } |
src/cloud/client_read.ts added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | /** | |
| 2 | * Reading a client's cloud with the client's own key (#17937). The key is an Azure service | |
| 3 | * principal with the Reader role, and the forge only ever reads with it: `readOnly` wraps the | |
| 4 | * network so that a request that is not a read never leaves, whatever the reader asks for. The | |
| 5 | * sign-in is the one POST that is not a read of the cloud (it asks for a token); the two other | |
| 6 | * POSTs are Azure's queries, as `azure_read.ts` already holds them to. | |
| 7 | */ | |
| 8 | ||
| 9 | import { Reasoned, type Inventory } from "./inventory.ts"; | |
| 10 | import { readAzure } from "./azure_read.ts"; | |
| 11 | import type { Fetch } from "./providers.ts"; | |
| 12 | ||
| 13 | /** What a client's key may be: the clouds the forge reads a Reader of. */ | |
| 14 | export const CLIENT_PROVIDERS = ["azure"] as const; | |
| 15 | export type ClientProvider = (typeof CLIENT_PROVIDERS)[number]; | |
| 16 | export const isClientProvider = (v: string): v is ClientProvider => (CLIENT_PROVIDERS as readonly string[]).includes(v); | |
| 17 | ||
| 18 | /** Sign-in, and Azure's two read queries: the only requests that are not a GET. */ | |
| 19 | const MAY_POST: readonly RegExp[] = [ | |
| 20 | /^https:\/\/login\.microsoftonline\.com\/[0-9a-zA-Z.-]+\/oauth2\/v2\.0\/token$/, | |
| 21 | /^https:\/\/management\.azure\.com\/providers\/Microsoft\.ResourceGraph\/resources$/, | |
| 22 | /^https:\/\/management\.azure\.com\/subscriptions\/[0-9a-fA-F-]{36}\/providers\/Microsoft\.CostManagement\/query$/, | |
| 23 | ]; | |
| 24 | ||
| 25 | /** | |
| 26 | * The only hosts a request may reach, so a redirect or a link in an answer never carries the token | |
| 27 | * elsewhere. | |
| 28 | */ | |
| 29 | const HOSTS: readonly string[] = ["login.microsoftonline.com", "management.azure.com"]; | |
| 30 | ||
| 31 | /** A request that is no read: refused before the network sees it. */ | |
| 32 | export class NotARead extends Error {} | |
| 33 | ||
| 34 | /** The network, but for reads: any other verb or path is refused and never sent. */ | |
| 35 | export function readOnly(f: Fetch): Fetch { | |
| 36 | return (url, init) => { | |
| 37 | const method = (init?.method ?? "GET").toUpperCase(); | |
| 38 | const at = new URL(url); | |
| 39 | const bare = `${at.origin}${at.pathname}`; | |
| 40 | if (at.protocol !== "https:" || !HOSTS.includes(at.hostname)) throw new NotARead(`${at.host} is not a host the forge reads a client's cloud from`); | |
| 41 | if (method !== "GET" && !(method === "POST" && MAY_POST.some((r) => r.test(bare)))) throw new NotARead(`${method} ${at.host}${at.pathname} is not a read the forge makes with a client's key`); | |
| 42 | return f(url, init); | |
| 43 | }; | |
| 44 | } | |
| 45 | ||
| 46 | /** What the key sees, read through `readOnly`; a refusal is words, never the key. */ | |
| 47 | export async function readClient(provider: ClientProvider, key: string, f: Fetch): Promise<Inventory> { | |
| 48 | try { | |
| 49 | return await readAzure(readOnly(f), key); | |
| 50 | } catch (e) { | |
| 51 | if (e instanceof Reasoned) throw e; | |
| 52 | throw new Reasoned("the cloud could not be read just now"); | |
| 53 | } | |
| 54 | } |
src/core/client_cloud.ts added +209
| @@ -0,0 +1,209 @@ | ||
| 1 | /** | |
| 2 | * A client's cloud, sealed (#17937): a Reader key a client gave the forge to look with, for a | |
| 3 | * while. It is its own concept and shares nothing with the owner's cloud accounts: no row of | |
| 4 | * `cloud_account`, `cloud_resource` or `secret`, so it is in none of the owner's tree, costs or | |
| 5 | * cost watch, and no event, so no feed, Talk, webhook or crew run reads of it. The key is sealed | |
| 6 | * (`kernel/secret.ts`) under the view's id and set to null at its expiry (`sweepKeys`), which every | |
| 7 | * way in asks first. Who may look is the named people (`client_cloud_member`), never an agent, and | |
| 8 | * every look is a row of `client_cloud_read`. Pure data and no authz: `actions/client_cloud.ts`. | |
| 9 | */ | |
| 10 | ||
| 11 | import type { Database } from "bun:sqlite"; | |
| 12 | import { open, seal } from "../kernel/secret.ts"; | |
| 13 | import { id as newId } from "../kernel/id.ts"; | |
| 14 | ||
| 15 | const made = new WeakSet<Database>(); | |
| 16 | function tables(db: Database): void { | |
| 17 | if (made.has(db)) return; | |
| 18 | db.run(`CREATE TABLE IF NOT EXISTS client_cloud ( | |
| 19 | id TEXT PRIMARY KEY, | |
| 20 | provider TEXT NOT NULL, | |
| 21 | label TEXT NOT NULL, | |
| 22 | sealed TEXT, | |
| 23 | expires_at TEXT NOT NULL, | |
| 24 | created_by TEXT NOT NULL, | |
| 25 | created_at TEXT NOT NULL, | |
| 26 | ended_at TEXT | |
| 27 | )`); | |
| 28 | db.run(`CREATE TABLE IF NOT EXISTS client_cloud_member ( | |
| 29 | cloud_id TEXT NOT NULL, | |
| 30 | user_id TEXT NOT NULL, | |
| 31 | granted_by TEXT NOT NULL, | |
| 32 | granted_at TEXT NOT NULL, | |
| 33 | PRIMARY KEY (cloud_id, user_id) | |
| 34 | )`); | |
| 35 | db.run(`CREATE TABLE IF NOT EXISTS client_cloud_read ( | |
| 36 | seq INTEGER PRIMARY KEY AUTOINCREMENT, | |
| 37 | cloud_id TEXT NOT NULL, | |
| 38 | user_id TEXT NOT NULL, | |
| 39 | at TEXT NOT NULL, | |
| 40 | what TEXT NOT NULL, | |
| 41 | ok INTEGER NOT NULL | |
| 42 | )`); | |
| 43 | made.add(db); | |
| 44 | } | |
| 45 | ||
| 46 | /** The shortest and longest a client's key may be kept, in days. */ | |
| 47 | export const KEEP_DAYS = { min: 1, max: 90 } as const; | |
| 48 | export const LABEL_MAX = 60; | |
| 49 | ||
| 50 | export interface ClientCloud { | |
| 51 | readonly id: string; | |
| 52 | readonly provider: string; | |
| 53 | readonly label: string; | |
| 54 | readonly expiresAt: string; | |
| 55 | readonly createdBy: string; | |
| 56 | readonly createdAt: string; | |
| 57 | /** When the key was deleted, at its expiry or by a person; null while it is held. */ | |
| 58 | readonly endedAt: string | null; | |
| 59 | } | |
| 60 | ||
| 61 | interface Row { | |
| 62 | id: string; | |
| 63 | provider: string; | |
| 64 | label: string; | |
| 65 | expires_at: string; | |
| 66 | created_by: string; | |
| 67 | created_at: string; | |
| 68 | ended_at: string | null; | |
| 69 | } | |
| 70 | ||
| 71 | const toCloud = (r: Row): ClientCloud => ({ | |
| 72 | id: r.id, | |
| 73 | provider: r.provider, | |
| 74 | label: r.label, | |
| 75 | expiresAt: r.expires_at, | |
| 76 | createdBy: r.created_by, | |
| 77 | createdAt: r.created_at, | |
| 78 | endedAt: r.ended_at, | |
| 79 | }); | |
| 80 | ||
| 81 | const aad = (cloudId: string): string => `client-cloud:${cloudId}`; | |
| 82 | ||
| 83 | /** | |
| 84 | * Delete the key of every view whose time is up. Asked first by every way in, and by the | |
| 85 | * `client-keys` duty, so a key outlives its expiry by no more than the duty's interval when nobody | |
| 86 | * looks. Returns how many keys it deleted. | |
| 87 | */ | |
| 88 | export function sweepKeys(db: Database, now: Date): number { | |
| 89 | tables(db); | |
| 90 | return db | |
| 91 | .query("UPDATE client_cloud SET sealed = NULL, ended_at = ?1 WHERE ended_at IS NULL AND expires_at <= ?1") | |
| 92 | .run(now.toISOString()).changes; | |
| 93 | } | |
| 94 | ||
| 95 | /** Seal a key for a view that ends `days` from `now`; the creator is its first member. */ | |
| 96 | export function createClientCloud( | |
| 97 | db: Database, | |
| 98 | dataDir: string, | |
| 99 | o: { provider: string; label: string; key: string; days: number; by: string; now: Date }, | |
| 100 | ): ClientCloud { | |
| 101 | tables(db); | |
| 102 | const id = newId(); | |
| 103 | const expires = new Date(o.now.getTime() + o.days * 86_400_000).toISOString(); | |
| 104 | db.transaction(() => { | |
| 105 | db.query("INSERT INTO client_cloud (id, provider, label, sealed, expires_at, created_by, created_at) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)").run( | |
| 106 | id, o.provider, o.label, seal(dataDir, o.key, aad(id)), expires, o.by, o.now.toISOString(), | |
| 107 | ); | |
| 108 | db.query("INSERT INTO client_cloud_member (cloud_id, user_id, granted_by, granted_at) VALUES (?1, ?2, ?2, ?3)").run(id, o.by, o.now.toISOString()); | |
| 109 | })(); | |
| 110 | return getClientCloud(db, id)!; | |
| 111 | } | |
| 112 | ||
| 113 | export function getClientCloud(db: Database, id: string): ClientCloud | undefined { | |
| 114 | tables(db); | |
| 115 | const r = db.query<Row, [string]>("SELECT id, provider, label, expires_at, created_by, created_at, ended_at FROM client_cloud WHERE id = ?1").get(id); | |
| 116 | return r ? toCloud(r) : undefined; | |
| 117 | } | |
| 118 | ||
| 119 | /** The views a person is named on, newest first (ended ones too: they say so). */ | |
| 120 | export function clientCloudsOf(db: Database, userId: string): ClientCloud[] { | |
| 121 | tables(db); | |
| 122 | return db | |
| 123 | .query<Row, [string]>( | |
| 124 | `SELECT c.id, c.provider, c.label, c.expires_at, c.created_by, c.created_at, c.ended_at FROM client_cloud c | |
| 125 | JOIN client_cloud_member m ON m.cloud_id = c.id WHERE m.user_id = ?1 ORDER BY c.created_at DESC, c.id DESC`, | |
| 126 | ) | |
| 127 | .all(userId) | |
| 128 | .map(toCloud); | |
| 129 | } | |
| 130 | ||
| 131 | export function isMember(db: Database, cloudId: string, userId: string): boolean { | |
| 132 | tables(db); | |
| 133 | return db.query("SELECT 1 FROM client_cloud_member WHERE cloud_id = ?1 AND user_id = ?2").get(cloudId, userId) !== null; | |
| 134 | } | |
| 135 | ||
| 136 | export interface Member { | |
| 137 | readonly userId: string; | |
| 138 | readonly grantedBy: string; | |
| 139 | readonly grantedAt: string; | |
| 140 | } | |
| 141 | ||
| 142 | export function membersOf(db: Database, cloudId: string): Member[] { | |
| 143 | tables(db); | |
| 144 | return db | |
| 145 | .query<{ user_id: string; granted_by: string; granted_at: string }, [string]>("SELECT user_id, granted_by, granted_at FROM client_cloud_member WHERE cloud_id = ?1 ORDER BY granted_at, user_id") | |
| 146 | .all(cloudId) | |
| 147 | .map((r) => ({ userId: r.user_id, grantedBy: r.granted_by, grantedAt: r.granted_at })); | |
| 148 | } | |
| 149 | ||
| 150 | /** Name one more person; false when they were named already. */ | |
| 151 | export function addMember(db: Database, cloudId: string, userId: string, by: string, now: Date): boolean { | |
| 152 | tables(db); | |
| 153 | return db.query("INSERT OR IGNORE INTO client_cloud_member (cloud_id, user_id, granted_by, granted_at) VALUES (?1, ?2, ?3, ?4)").run(cloudId, userId, by, now.toISOString()).changes > 0; | |
| 154 | } | |
| 155 | ||
| 156 | /** The key, opened for one look; undefined once it is deleted. Never logged, never kept. */ | |
| 157 | export function openKey(db: Database, dataDir: string, cloudId: string): string | undefined { | |
| 158 | tables(db); | |
| 159 | const r = db.query<{ sealed: string | null }, [string]>("SELECT sealed FROM client_cloud WHERE id = ?1").get(cloudId); | |
| 160 | if (!r || r.sealed === null) return undefined; | |
| 161 | const opened = open(dataDir, r.sealed, aad(cloudId)); | |
| 162 | return opened.ok ? opened.value : undefined; | |
| 163 | } | |
| 164 | ||
| 165 | /** Delete the key now (a person's choice); the view and its audit stay, and say so. */ | |
| 166 | export function endClientCloud(db: Database, cloudId: string, now: Date): boolean { | |
| 167 | tables(db); | |
| 168 | return db.query("UPDATE client_cloud SET sealed = NULL, ended_at = ?2 WHERE id = ?1 AND ended_at IS NULL").run(cloudId, now.toISOString()).changes > 0; | |
| 169 | } | |
| 170 | ||
| 171 | export interface ClientRead { | |
| 172 | readonly at: string; | |
| 173 | readonly userId: string; | |
| 174 | readonly what: string; | |
| 175 | readonly ok: boolean; | |
| 176 | } | |
| 177 | ||
| 178 | export function recordRead(db: Database, cloudId: string, userId: string, what: string, ok: boolean, now: Date): void { | |
| 179 | tables(db); | |
| 180 | db.query("INSERT INTO client_cloud_read (cloud_id, user_id, at, what, ok) VALUES (?1, ?2, ?3, ?4, ?5)").run(cloudId, userId, now.toISOString(), what.slice(0, 200), ok ? 1 : 0); | |
| 181 | } | |
| 182 | ||
| 183 | /** Every look at one view, newest first. */ | |
| 184 | export function readsOf(db: Database, cloudId: string, limit = 50): ClientRead[] { | |
| 185 | tables(db); | |
| 186 | return db | |
| 187 | .query<{ at: string; user_id: string; what: string; ok: number }, [string, number]>("SELECT at, user_id, what, ok FROM client_cloud_read WHERE cloud_id = ?1 ORDER BY seq DESC LIMIT ?2") | |
| 188 | .all(cloudId, limit) | |
| 189 | .map((r) => ({ at: r.at, userId: r.user_id, what: r.what, ok: r.ok === 1 })); | |
| 190 | } | |
| 191 | ||
| 192 | /** Whether this person read this view live within the last `seconds` (a reload guard). */ | |
| 193 | export function lookedWithin(db: Database, cloudId: string, userId: string, now: Date, seconds: number): boolean { | |
| 194 | tables(db); | |
| 195 | const since = new Date(now.getTime() - seconds * 1000).toISOString(); | |
| 196 | return db.query("SELECT 1 FROM client_cloud_read WHERE cloud_id = ?1 AND user_id = ?2 AND what = 'looked' AND ok = 1 AND at > ?3 LIMIT 1").get(cloudId, userId, since) !== null; | |
| 197 | } | |
| 198 | ||
| 199 | /** | |
| 200 | * Every view, newest first: an admin's list, so the key of one they are not named on can still be | |
| 201 | * deleted. | |
| 202 | */ | |
| 203 | export function allClientClouds(db: Database): ClientCloud[] { | |
| 204 | tables(db); | |
| 205 | return db | |
| 206 | .query<Row, []>("SELECT id, provider, label, expires_at, created_by, created_at, ended_at FROM client_cloud ORDER BY created_at DESC, id DESC") | |
| 207 | .all() | |
| 208 | .map(toCloud); | |
| 209 | } |
src/core/reserved.ts +1
src/generated/duties.ts +1
| @@ -10,6 +10,7 @@ export const DUTY_MODULES: readonly (readonly [string, () => { duty?: unknown }] | ||
| 10 | 10 | ["backup_age.ts", () => require("../maintain/duties/backup_age.ts")], |
| 11 | 11 | ["backup_growth.ts", () => require("../maintain/duties/backup_growth.ts")], |
| 12 | 12 | ["chapter_stall.ts", () => require("../maintain/duties/chapter_stall.ts")], |
| 13 | ["client_keys.ts", () => require("../maintain/duties/client_keys.ts")], | |
| 13 | 14 | ["cloud_projects.ts", () => require("../maintain/duties/cloud_projects.ts")], |
| 14 | 15 | ["cloud_watch.ts", () => require("../maintain/duties/cloud_watch.ts")], |
| 15 | 16 | ["daily_proof.ts", () => require("../maintain/duties/daily_proof.ts")], |
src/generated/marks.ts +110 −108
| @@ -100,114 +100,115 @@ import k95 from "../http/marks/broker.json"; | ||
| 100 | 100 | import k96 from "../http/marks/changelog.atom.json"; |
| 101 | 101 | import k97 from "../http/marks/changelog.json"; |
| 102 | 102 | import k98 from "../http/marks/claim.json"; |
| 103 | import k99 from "../http/marks/cloud.json"; | |
| 104 | import k100 from "../http/marks/cockpit.json"; | |
| 105 | import k101 from "../http/marks/contract.json"; | |
| 106 | import k102 from "../http/marks/contribute.json"; | |
| 107 | import k103 from "../http/marks/csp-report.json"; | |
| 108 | import k104 from "../http/marks/dash.json"; | |
| 109 | import k105 from "../http/marks/data.json"; | |
| 110 | import k106 from "../http/marks/dataset.json"; | |
| 111 | import k107 from "../http/marks/deploy-to.json"; | |
| 112 | import k108 from "../http/marks/design.json"; | |
| 113 | import k109 from "../http/marks/desk.json"; | |
| 114 | import k110 from "../http/marks/displays.json"; | |
| 115 | import k111 from "../http/marks/docs.json"; | |
| 116 | import k112 from "../http/marks/edge.json"; | |
| 117 | import k113 from "../http/marks/edition.json"; | |
| 118 | import k114 from "../http/marks/events.json"; | |
| 119 | import k115 from "../http/marks/explore.atom.json"; | |
| 120 | import k116 from "../http/marks/explore.json"; | |
| 121 | import k117 from "../http/marks/explore.json.json"; | |
| 122 | import k118 from "../http/marks/family.json"; | |
| 123 | import k119 from "../http/marks/favicon.ico.json"; | |
| 124 | import k120 from "../http/marks/feed.json"; | |
| 125 | import k121 from "../http/marks/feed.json.json"; | |
| 126 | import k122 from "../http/marks/first-admin.json"; | |
| 127 | import k123 from "../http/marks/fleet.json"; | |
| 128 | import k124 from "../http/marks/flow.json"; | |
| 129 | import k125 from "../http/marks/forge.json"; | |
| 130 | import k126 from "../http/marks/forges.json"; | |
| 131 | import k127 from "../http/marks/forks.json"; | |
| 132 | import k128 from "../http/marks/front.json"; | |
| 133 | import k129 from "../http/marks/funnel.json"; | |
| 134 | import k130 from "../http/marks/games.json"; | |
| 135 | import k131 from "../http/marks/go.json"; | |
| 136 | import k132 from "../http/marks/health.json"; | |
| 137 | import k133 from "../http/marks/home.json"; | |
| 138 | import k134 from "../http/marks/hooks.json"; | |
| 139 | import k135 from "../http/marks/icons.json"; | |
| 140 | import k136 from "../http/marks/infra.json"; | |
| 141 | import k137 from "../http/marks/join.json"; | |
| 142 | import k138 from "../http/marks/live.json"; | |
| 143 | import k139 from "../http/marks/llms-full.txt.json"; | |
| 144 | import k140 from "../http/marks/llms.txt.json"; | |
| 145 | import k141 from "../http/marks/login.json"; | |
| 146 | import k142 from "../http/marks/logout.json"; | |
| 147 | import k143 from "../http/marks/maintenance-json.json"; | |
| 148 | import k144 from "../http/marks/maintenance.json"; | |
| 149 | import k145 from "../http/marks/manifest.webmanifest.json"; | |
| 150 | import k146 from "../http/marks/map.json"; | |
| 151 | import k147 from "../http/marks/mcp.json"; | |
| 152 | import k148 from "../http/marks/measure.json"; | |
| 153 | import k149 from "../http/marks/metrics.json"; | |
| 154 | import k150 from "../http/marks/migrate.json"; | |
| 155 | import k151 from "../http/marks/new.json"; | |
| 156 | import k152 from "../http/marks/next.json"; | |
| 157 | import k153 from "../http/marks/notes.json"; | |
| 158 | import k154 from "../http/marks/now.json"; | |
| 159 | import k155 from "../http/marks/oauth.json"; | |
| 160 | import k156 from "../http/marks/oembed.json"; | |
| 161 | import k157 from "../http/marks/offers.json"; | |
| 162 | import k158 from "../http/marks/offline.json"; | |
| 163 | import k159 from "../http/marks/og.json"; | |
| 164 | import k160 from "../http/marks/openapi.json.json"; | |
| 165 | import k161 from "../http/marks/opensearch.xml.json"; | |
| 166 | import k162 from "../http/marks/organizations.json"; | |
| 167 | import k163 from "../http/marks/origins.json"; | |
| 168 | import k164 from "../http/marks/owner.atom.json"; | |
| 169 | import k165 from "../http/marks/owner.json"; | |
| 170 | import k166 from "../http/marks/packs.json"; | |
| 171 | import k167 from "../http/marks/peek.json"; | |
| 172 | import k168 from "../http/marks/pinned.json"; | |
| 173 | import k169 from "../http/marks/pipeline.json"; | |
| 174 | import k170 from "../http/marks/plugins.json"; | |
| 175 | import k171 from "../http/marks/pricing.json"; | |
| 176 | import k172 from "../http/marks/privacy.json"; | |
| 177 | import k173 from "../http/marks/r.json"; | |
| 178 | import k174 from "../http/marks/recover.json"; | |
| 179 | import k175 from "../http/marks/releases.json"; | |
| 180 | import k176 from "../http/marks/releases.json.json"; | |
| 181 | import k177 from "../http/marks/repos.json"; | |
| 182 | import k178 from "../http/marks/resilience.json"; | |
| 183 | import k179 from "../http/marks/review.json"; | |
| 184 | import k180 from "../http/marks/robots.txt.json"; | |
| 185 | import k181 from "../http/marks/root.json"; | |
| 186 | import k182 from "../http/marks/runs.json"; | |
| 187 | import k183 from "../http/marks/script-error.json"; | |
| 188 | import k184 from "../http/marks/search.json"; | |
| 189 | import k185 from "../http/marks/security.json"; | |
| 190 | import k186 from "../http/marks/settings.json"; | |
| 191 | import k187 from "../http/marks/sign-in.json"; | |
| 192 | import k188 from "../http/marks/signin.json"; | |
| 193 | import k189 from "../http/marks/signup.json"; | |
| 194 | import k190 from "../http/marks/sitemap.xml.json"; | |
| 195 | import k191 from "../http/marks/status.json"; | |
| 196 | import k192 from "../http/marks/sw.js.json"; | |
| 197 | import k193 from "../http/marks/system.json"; | |
| 198 | import k194 from "../http/marks/tab.json"; | |
| 199 | import k195 from "../http/marks/tabforge.json"; | |
| 200 | import k196 from "../http/marks/talk.json"; | |
| 201 | import k197 from "../http/marks/tell.json"; | |
| 202 | import k198 from "../http/marks/templates.json"; | |
| 203 | import k199 from "../http/marks/templates.json.json"; | |
| 204 | import k200 from "../http/marks/terms.json"; | |
| 205 | import k201 from "../http/marks/theme.json"; | |
| 206 | import k202 from "../http/marks/toolbar-lab.js.json"; | |
| 207 | import k203 from "../http/marks/toolbar-lab.json"; | |
| 208 | import k204 from "../http/marks/verify.json"; | |
| 209 | import k205 from "../http/marks/welcome.json"; | |
| 210 | import k206 from "../http/marks/well-known.json"; | |
| 103 | import k99 from "../http/marks/client-clouds.json"; | |
| 104 | import k100 from "../http/marks/cloud.json"; | |
| 105 | import k101 from "../http/marks/cockpit.json"; | |
| 106 | import k102 from "../http/marks/contract.json"; | |
| 107 | import k103 from "../http/marks/contribute.json"; | |
| 108 | import k104 from "../http/marks/csp-report.json"; | |
| 109 | import k105 from "../http/marks/dash.json"; | |
| 110 | import k106 from "../http/marks/data.json"; | |
| 111 | import k107 from "../http/marks/dataset.json"; | |
| 112 | import k108 from "../http/marks/deploy-to.json"; | |
| 113 | import k109 from "../http/marks/design.json"; | |
| 114 | import k110 from "../http/marks/desk.json"; | |
| 115 | import k111 from "../http/marks/displays.json"; | |
| 116 | import k112 from "../http/marks/docs.json"; | |
| 117 | import k113 from "../http/marks/edge.json"; | |
| 118 | import k114 from "../http/marks/edition.json"; | |
| 119 | import k115 from "../http/marks/events.json"; | |
| 120 | import k116 from "../http/marks/explore.atom.json"; | |
| 121 | import k117 from "../http/marks/explore.json"; | |
| 122 | import k118 from "../http/marks/explore.json.json"; | |
| 123 | import k119 from "../http/marks/family.json"; | |
| 124 | import k120 from "../http/marks/favicon.ico.json"; | |
| 125 | import k121 from "../http/marks/feed.json"; | |
| 126 | import k122 from "../http/marks/feed.json.json"; | |
| 127 | import k123 from "../http/marks/first-admin.json"; | |
| 128 | import k124 from "../http/marks/fleet.json"; | |
| 129 | import k125 from "../http/marks/flow.json"; | |
| 130 | import k126 from "../http/marks/forge.json"; | |
| 131 | import k127 from "../http/marks/forges.json"; | |
| 132 | import k128 from "../http/marks/forks.json"; | |
| 133 | import k129 from "../http/marks/front.json"; | |
| 134 | import k130 from "../http/marks/funnel.json"; | |
| 135 | import k131 from "../http/marks/games.json"; | |
| 136 | import k132 from "../http/marks/go.json"; | |
| 137 | import k133 from "../http/marks/health.json"; | |
| 138 | import k134 from "../http/marks/home.json"; | |
| 139 | import k135 from "../http/marks/hooks.json"; | |
| 140 | import k136 from "../http/marks/icons.json"; | |
| 141 | import k137 from "../http/marks/infra.json"; | |
| 142 | import k138 from "../http/marks/join.json"; | |
| 143 | import k139 from "../http/marks/live.json"; | |
| 144 | import k140 from "../http/marks/llms-full.txt.json"; | |
| 145 | import k141 from "../http/marks/llms.txt.json"; | |
| 146 | import k142 from "../http/marks/login.json"; | |
| 147 | import k143 from "../http/marks/logout.json"; | |
| 148 | import k144 from "../http/marks/maintenance-json.json"; | |
| 149 | import k145 from "../http/marks/maintenance.json"; | |
| 150 | import k146 from "../http/marks/manifest.webmanifest.json"; | |
| 151 | import k147 from "../http/marks/map.json"; | |
| 152 | import k148 from "../http/marks/mcp.json"; | |
| 153 | import k149 from "../http/marks/measure.json"; | |
| 154 | import k150 from "../http/marks/metrics.json"; | |
| 155 | import k151 from "../http/marks/migrate.json"; | |
| 156 | import k152 from "../http/marks/new.json"; | |
| 157 | import k153 from "../http/marks/next.json"; | |
| 158 | import k154 from "../http/marks/notes.json"; | |
| 159 | import k155 from "../http/marks/now.json"; | |
| 160 | import k156 from "../http/marks/oauth.json"; | |
| 161 | import k157 from "../http/marks/oembed.json"; | |
| 162 | import k158 from "../http/marks/offers.json"; | |
| 163 | import k159 from "../http/marks/offline.json"; | |
| 164 | import k160 from "../http/marks/og.json"; | |
| 165 | import k161 from "../http/marks/openapi.json.json"; | |
| 166 | import k162 from "../http/marks/opensearch.xml.json"; | |
| 167 | import k163 from "../http/marks/organizations.json"; | |
| 168 | import k164 from "../http/marks/origins.json"; | |
| 169 | import k165 from "../http/marks/owner.atom.json"; | |
| 170 | import k166 from "../http/marks/owner.json"; | |
| 171 | import k167 from "../http/marks/packs.json"; | |
| 172 | import k168 from "../http/marks/peek.json"; | |
| 173 | import k169 from "../http/marks/pinned.json"; | |
| 174 | import k170 from "../http/marks/pipeline.json"; | |
| 175 | import k171 from "../http/marks/plugins.json"; | |
| 176 | import k172 from "../http/marks/pricing.json"; | |
| 177 | import k173 from "../http/marks/privacy.json"; | |
| 178 | import k174 from "../http/marks/r.json"; | |
| 179 | import k175 from "../http/marks/recover.json"; | |
| 180 | import k176 from "../http/marks/releases.json"; | |
| 181 | import k177 from "../http/marks/releases.json.json"; | |
| 182 | import k178 from "../http/marks/repos.json"; | |
| 183 | import k179 from "../http/marks/resilience.json"; | |
| 184 | import k180 from "../http/marks/review.json"; | |
| 185 | import k181 from "../http/marks/robots.txt.json"; | |
| 186 | import k182 from "../http/marks/root.json"; | |
| 187 | import k183 from "../http/marks/runs.json"; | |
| 188 | import k184 from "../http/marks/script-error.json"; | |
| 189 | import k185 from "../http/marks/search.json"; | |
| 190 | import k186 from "../http/marks/security.json"; | |
| 191 | import k187 from "../http/marks/settings.json"; | |
| 192 | import k188 from "../http/marks/sign-in.json"; | |
| 193 | import k189 from "../http/marks/signin.json"; | |
| 194 | import k190 from "../http/marks/signup.json"; | |
| 195 | import k191 from "../http/marks/sitemap.xml.json"; | |
| 196 | import k192 from "../http/marks/status.json"; | |
| 197 | import k193 from "../http/marks/sw.js.json"; | |
| 198 | import k194 from "../http/marks/system.json"; | |
| 199 | import k195 from "../http/marks/tab.json"; | |
| 200 | import k196 from "../http/marks/tabforge.json"; | |
| 201 | import k197 from "../http/marks/talk.json"; | |
| 202 | import k198 from "../http/marks/tell.json"; | |
| 203 | import k199 from "../http/marks/templates.json"; | |
| 204 | import k200 from "../http/marks/templates.json.json"; | |
| 205 | import k201 from "../http/marks/terms.json"; | |
| 206 | import k202 from "../http/marks/theme.json"; | |
| 207 | import k203 from "../http/marks/toolbar-lab.js.json"; | |
| 208 | import k204 from "../http/marks/toolbar-lab.json"; | |
| 209 | import k205 from "../http/marks/verify.json"; | |
| 210 | import k206 from "../http/marks/welcome.json"; | |
| 211 | import k207 from "../http/marks/well-known.json"; | |
| 211 | 212 | |
| 212 | 213 | /** Each file of `http/marks/`, parsed, in name order. */ |
| 213 | 214 | export const MARK_FILES: readonly unknown[] = [ |
| @@ -418,4 +419,5 @@ export const MARK_FILES: readonly unknown[] = [ | ||
| 418 | 419 | k204, |
| 419 | 420 | k205, |
| 420 | 421 | k206, |
| 422 | k207, | |
| 421 | 423 | ]; |
src/generated/screens.ts +114 −112
| @@ -24,114 +24,115 @@ import * as s19 from "../tui/screens/captain.ts"; | ||
| 24 | 24 | import * as s20 from "../tui/screens/childcredit.ts"; |
| 25 | 25 | import * as s21 from "../tui/screens/claim_link.ts"; |
| 26 | 26 | import * as s22 from "../tui/screens/claim_start.ts"; |
| 27 | import * as s23 from "../tui/screens/cloud.ts"; | |
| 28 | import * as s24 from "../tui/screens/cloudtree.ts"; | |
| 29 | import * as s25 from "../tui/screens/codes.ts"; | |
| 30 | import * as s26 from "../tui/screens/connections.ts"; | |
| 31 | import * as s27 from "../tui/screens/controls.ts"; | |
| 32 | import * as s28 from "../tui/screens/cores.ts"; | |
| 33 | import * as s29 from "../tui/screens/crewbudgets.ts"; | |
| 34 | import * as s30 from "../tui/screens/crewfallback.ts"; | |
| 35 | import * as s31 from "../tui/screens/crewhandover.ts"; | |
| 36 | import * as s32 from "../tui/screens/crewkey.ts"; | |
| 37 | import * as s33 from "../tui/screens/crewsplits.ts"; | |
| 38 | import * as s34 from "../tui/screens/crewtop.ts"; | |
| 39 | import * as s35 from "../tui/screens/dataset.ts"; | |
| 40 | import * as s36 from "../tui/screens/design.ts"; | |
| 41 | import * as s37 from "../tui/screens/design_gallery.ts"; | |
| 42 | import * as s38 from "../tui/screens/devices.ts"; | |
| 43 | import * as s39 from "../tui/screens/disks.ts"; | |
| 44 | import * as s40 from "../tui/screens/displays.ts"; | |
| 45 | import * as s41 from "../tui/screens/domains.ts"; | |
| 46 | import * as s42 from "../tui/screens/dotfiles.ts"; | |
| 47 | import * as s43 from "../tui/screens/drift.ts"; | |
| 48 | import * as s44 from "../tui/screens/dutybudgets.ts"; | |
| 49 | import * as s45 from "../tui/screens/dutyswitch.ts"; | |
| 50 | import * as s46 from "../tui/screens/economics.ts"; | |
| 51 | import * as s47 from "../tui/screens/edgeonly.ts"; | |
| 52 | import * as s48 from "../tui/screens/experiments.ts"; | |
| 53 | import * as s49 from "../tui/screens/featurefeed.ts"; | |
| 54 | import * as s50 from "../tui/screens/features.ts"; | |
| 55 | import * as s51 from "../tui/screens/featureswitch.ts"; | |
| 56 | import * as s52 from "../tui/screens/feed.ts"; | |
| 57 | import * as s53 from "../tui/screens/flowsall.ts"; | |
| 58 | import * as s54 from "../tui/screens/footing.ts"; | |
| 59 | import * as s55 from "../tui/screens/forgeready.ts"; | |
| 60 | import * as s56 from "../tui/screens/forges.ts"; | |
| 61 | import * as s57 from "../tui/screens/forgeview.ts"; | |
| 62 | import * as s58 from "../tui/screens/front.ts"; | |
| 63 | import * as s59 from "../tui/screens/frontms.ts"; | |
| 64 | import * as s60 from "../tui/screens/funnel.ts"; | |
| 65 | import * as s61 from "../tui/screens/games.ts"; | |
| 66 | import * as s62 from "../tui/screens/gifts.ts"; | |
| 67 | import * as s63 from "../tui/screens/health_voice.ts"; | |
| 68 | import * as s64 from "../tui/screens/home_pins.ts"; | |
| 69 | import * as s65 from "../tui/screens/hostreach.ts"; | |
| 70 | import * as s66 from "../tui/screens/infra.ts"; | |
| 71 | import * as s67 from "../tui/screens/inventory.ts"; | |
| 72 | import * as s68 from "../tui/screens/invites.ts"; | |
| 73 | import * as s69 from "../tui/screens/knobs.ts"; | |
| 74 | import * as s70 from "../tui/screens/lapsed.ts"; | |
| 75 | import * as s71 from "../tui/screens/limits.ts"; | |
| 76 | import * as s72 from "../tui/screens/loopstalls.ts"; | |
| 77 | import * as s73 from "../tui/screens/madefrom.ts"; | |
| 78 | import * as s74 from "../tui/screens/maintainruns.ts"; | |
| 79 | import * as s75 from "../tui/screens/maintenance.ts"; | |
| 80 | import * as s76 from "../tui/screens/maintenanceweek.ts"; | |
| 81 | import * as s77 from "../tui/screens/mergedbranches.ts"; | |
| 82 | import * as s78 from "../tui/screens/mirrorpacks.ts"; | |
| 83 | import * as s79 from "../tui/screens/model.ts"; | |
| 84 | import * as s80 from "../tui/screens/money.ts"; | |
| 85 | import * as s81 from "../tui/screens/newissue.ts"; | |
| 86 | import * as s82 from "../tui/screens/next.ts"; | |
| 87 | import * as s83 from "../tui/screens/nowlist.ts"; | |
| 88 | import * as s84 from "../tui/screens/offers.ts"; | |
| 89 | import * as s85 from "../tui/screens/offsite.ts"; | |
| 90 | import * as s86 from "../tui/screens/orggrants.ts"; | |
| 91 | import * as s87 from "../tui/screens/orgteams.ts"; | |
| 92 | import * as s88 from "../tui/screens/originahead.ts"; | |
| 93 | import * as s89 from "../tui/screens/owner.ts"; | |
| 94 | import * as s90 from "../tui/screens/packrepos.ts"; | |
| 95 | import * as s91 from "../tui/screens/payments.ts"; | |
| 96 | import * as s92 from "../tui/screens/people.ts"; | |
| 97 | import * as s93 from "../tui/screens/pinned.ts"; | |
| 98 | import * as s94 from "../tui/screens/planner.ts"; | |
| 99 | import * as s95 from "../tui/screens/planrow.ts"; | |
| 100 | import * as s96 from "../tui/screens/plans.ts"; | |
| 101 | import * as s97 from "../tui/screens/previewdirs.ts"; | |
| 102 | import * as s98 from "../tui/screens/profile.ts"; | |
| 103 | import * as s99 from "../tui/screens/quotas.ts"; | |
| 104 | import * as s100 from "../tui/screens/recoverykit.ts"; | |
| 105 | import * as s101 from "../tui/screens/refused.ts"; | |
| 106 | import * as s102 from "../tui/screens/registry_items.ts"; | |
| 107 | import * as s103 from "../tui/screens/repolist.ts"; | |
| 108 | import * as s104 from "../tui/screens/requests.ts"; | |
| 109 | import * as s105 from "../tui/screens/resilience.ts"; | |
| 110 | import * as s106 from "../tui/screens/returning.ts"; | |
| 111 | import * as s107 from "../tui/screens/returns.ts"; | |
| 112 | import * as s108 from "../tui/screens/scorecard.ts"; | |
| 113 | import * as s109 from "../tui/screens/scrapes.ts"; | |
| 114 | import * as s110 from "../tui/screens/secrets.ts"; | |
| 115 | import * as s111 from "../tui/screens/sentinel.ts"; | |
| 116 | import * as s112 from "../tui/screens/series.ts"; | |
| 117 | import * as s113 from "../tui/screens/ship_time.ts"; | |
| 118 | import * as s114 from "../tui/screens/slowpages.ts"; | |
| 119 | import * as s115 from "../tui/screens/sold.ts"; | |
| 120 | import * as s116 from "../tui/screens/spend.ts"; | |
| 121 | import * as s117 from "../tui/screens/stalepulls.ts"; | |
| 122 | import * as s118 from "../tui/screens/subscriptions.ts"; | |
| 123 | import * as s119 from "../tui/screens/system.ts"; | |
| 124 | import * as s120 from "../tui/screens/tab.ts"; | |
| 125 | import * as s121 from "../tui/screens/teams.ts"; | |
| 126 | import * as s122 from "../tui/screens/telemetry.ts"; | |
| 127 | import * as s123 from "../tui/screens/tell_undo.ts"; | |
| 128 | import * as s124 from "../tui/screens/traffic.ts"; | |
| 129 | import * as s125 from "../tui/screens/trafficview.ts"; | |
| 130 | import * as s126 from "../tui/screens/valves.ts"; | |
| 131 | import * as s127 from "../tui/screens/waiting.ts"; | |
| 132 | import * as s128 from "../tui/screens/waiting_for_me.ts"; | |
| 133 | import * as s129 from "../tui/screens/wayback.ts"; | |
| 134 | import * as s130 from "../tui/screens/weekcard.ts"; | |
| 27 | import * as s23 from "../tui/screens/client_clouds.ts"; | |
| 28 | import * as s24 from "../tui/screens/cloud.ts"; | |
| 29 | import * as s25 from "../tui/screens/cloudtree.ts"; | |
| 30 | import * as s26 from "../tui/screens/codes.ts"; | |
| 31 | import * as s27 from "../tui/screens/connections.ts"; | |
| 32 | import * as s28 from "../tui/screens/controls.ts"; | |
| 33 | import * as s29 from "../tui/screens/cores.ts"; | |
| 34 | import * as s30 from "../tui/screens/crewbudgets.ts"; | |
| 35 | import * as s31 from "../tui/screens/crewfallback.ts"; | |
| 36 | import * as s32 from "../tui/screens/crewhandover.ts"; | |
| 37 | import * as s33 from "../tui/screens/crewkey.ts"; | |
| 38 | import * as s34 from "../tui/screens/crewsplits.ts"; | |
| 39 | import * as s35 from "../tui/screens/crewtop.ts"; | |
| 40 | import * as s36 from "../tui/screens/dataset.ts"; | |
| 41 | import * as s37 from "../tui/screens/design.ts"; | |
| 42 | import * as s38 from "../tui/screens/design_gallery.ts"; | |
| 43 | import * as s39 from "../tui/screens/devices.ts"; | |
| 44 | import * as s40 from "../tui/screens/disks.ts"; | |
| 45 | import * as s41 from "../tui/screens/displays.ts"; | |
| 46 | import * as s42 from "../tui/screens/domains.ts"; | |
| 47 | import * as s43 from "../tui/screens/dotfiles.ts"; | |
| 48 | import * as s44 from "../tui/screens/drift.ts"; | |
| 49 | import * as s45 from "../tui/screens/dutybudgets.ts"; | |
| 50 | import * as s46 from "../tui/screens/dutyswitch.ts"; | |
| 51 | import * as s47 from "../tui/screens/economics.ts"; | |
| 52 | import * as s48 from "../tui/screens/edgeonly.ts"; | |
| 53 | import * as s49 from "../tui/screens/experiments.ts"; | |
| 54 | import * as s50 from "../tui/screens/featurefeed.ts"; | |
| 55 | import * as s51 from "../tui/screens/features.ts"; | |
| 56 | import * as s52 from "../tui/screens/featureswitch.ts"; | |
| 57 | import * as s53 from "../tui/screens/feed.ts"; | |
| 58 | import * as s54 from "../tui/screens/flowsall.ts"; | |
| 59 | import * as s55 from "../tui/screens/footing.ts"; | |
| 60 | import * as s56 from "../tui/screens/forgeready.ts"; | |
| 61 | import * as s57 from "../tui/screens/forges.ts"; | |
| 62 | import * as s58 from "../tui/screens/forgeview.ts"; | |
| 63 | import * as s59 from "../tui/screens/front.ts"; | |
| 64 | import * as s60 from "../tui/screens/frontms.ts"; | |
| 65 | import * as s61 from "../tui/screens/funnel.ts"; | |
| 66 | import * as s62 from "../tui/screens/games.ts"; | |
| 67 | import * as s63 from "../tui/screens/gifts.ts"; | |
| 68 | import * as s64 from "../tui/screens/health_voice.ts"; | |
| 69 | import * as s65 from "../tui/screens/home_pins.ts"; | |
| 70 | import * as s66 from "../tui/screens/hostreach.ts"; | |
| 71 | import * as s67 from "../tui/screens/infra.ts"; | |
| 72 | import * as s68 from "../tui/screens/inventory.ts"; | |
| 73 | import * as s69 from "../tui/screens/invites.ts"; | |
| 74 | import * as s70 from "../tui/screens/knobs.ts"; | |
| 75 | import * as s71 from "../tui/screens/lapsed.ts"; | |
| 76 | import * as s72 from "../tui/screens/limits.ts"; | |
| 77 | import * as s73 from "../tui/screens/loopstalls.ts"; | |
| 78 | import * as s74 from "../tui/screens/madefrom.ts"; | |
| 79 | import * as s75 from "../tui/screens/maintainruns.ts"; | |
| 80 | import * as s76 from "../tui/screens/maintenance.ts"; | |
| 81 | import * as s77 from "../tui/screens/maintenanceweek.ts"; | |
| 82 | import * as s78 from "../tui/screens/mergedbranches.ts"; | |
| 83 | import * as s79 from "../tui/screens/mirrorpacks.ts"; | |
| 84 | import * as s80 from "../tui/screens/model.ts"; | |
| 85 | import * as s81 from "../tui/screens/money.ts"; | |
| 86 | import * as s82 from "../tui/screens/newissue.ts"; | |
| 87 | import * as s83 from "../tui/screens/next.ts"; | |
| 88 | import * as s84 from "../tui/screens/nowlist.ts"; | |
| 89 | import * as s85 from "../tui/screens/offers.ts"; | |
| 90 | import * as s86 from "../tui/screens/offsite.ts"; | |
| 91 | import * as s87 from "../tui/screens/orggrants.ts"; | |
| 92 | import * as s88 from "../tui/screens/orgteams.ts"; | |
| 93 | import * as s89 from "../tui/screens/originahead.ts"; | |
| 94 | import * as s90 from "../tui/screens/owner.ts"; | |
| 95 | import * as s91 from "../tui/screens/packrepos.ts"; | |
| 96 | import * as s92 from "../tui/screens/payments.ts"; | |
| 97 | import * as s93 from "../tui/screens/people.ts"; | |
| 98 | import * as s94 from "../tui/screens/pinned.ts"; | |
| 99 | import * as s95 from "../tui/screens/planner.ts"; | |
| 100 | import * as s96 from "../tui/screens/planrow.ts"; | |
| 101 | import * as s97 from "../tui/screens/plans.ts"; | |
| 102 | import * as s98 from "../tui/screens/previewdirs.ts"; | |
| 103 | import * as s99 from "../tui/screens/profile.ts"; | |
| 104 | import * as s100 from "../tui/screens/quotas.ts"; | |
| 105 | import * as s101 from "../tui/screens/recoverykit.ts"; | |
| 106 | import * as s102 from "../tui/screens/refused.ts"; | |
| 107 | import * as s103 from "../tui/screens/registry_items.ts"; | |
| 108 | import * as s104 from "../tui/screens/repolist.ts"; | |
| 109 | import * as s105 from "../tui/screens/requests.ts"; | |
| 110 | import * as s106 from "../tui/screens/resilience.ts"; | |
| 111 | import * as s107 from "../tui/screens/returning.ts"; | |
| 112 | import * as s108 from "../tui/screens/returns.ts"; | |
| 113 | import * as s109 from "../tui/screens/scorecard.ts"; | |
| 114 | import * as s110 from "../tui/screens/scrapes.ts"; | |
| 115 | import * as s111 from "../tui/screens/secrets.ts"; | |
| 116 | import * as s112 from "../tui/screens/sentinel.ts"; | |
| 117 | import * as s113 from "../tui/screens/series.ts"; | |
| 118 | import * as s114 from "../tui/screens/ship_time.ts"; | |
| 119 | import * as s115 from "../tui/screens/slowpages.ts"; | |
| 120 | import * as s116 from "../tui/screens/sold.ts"; | |
| 121 | import * as s117 from "../tui/screens/spend.ts"; | |
| 122 | import * as s118 from "../tui/screens/stalepulls.ts"; | |
| 123 | import * as s119 from "../tui/screens/subscriptions.ts"; | |
| 124 | import * as s120 from "../tui/screens/system.ts"; | |
| 125 | import * as s121 from "../tui/screens/tab.ts"; | |
| 126 | import * as s122 from "../tui/screens/teams.ts"; | |
| 127 | import * as s123 from "../tui/screens/telemetry.ts"; | |
| 128 | import * as s124 from "../tui/screens/tell_undo.ts"; | |
| 129 | import * as s125 from "../tui/screens/traffic.ts"; | |
| 130 | import * as s126 from "../tui/screens/trafficview.ts"; | |
| 131 | import * as s127 from "../tui/screens/valves.ts"; | |
| 132 | import * as s128 from "../tui/screens/waiting.ts"; | |
| 133 | import * as s129 from "../tui/screens/waiting_for_me.ts"; | |
| 134 | import * as s130 from "../tui/screens/wayback.ts"; | |
| 135 | import * as s131 from "../tui/screens/weekcard.ts"; | |
| 135 | 136 | |
| 136 | 137 | /** Each screen file that declares palette entries: its module and the export names. */ |
| 137 | 138 | export const SCREEN_MODULES: readonly (readonly [Record<string, unknown>, readonly string[]])[] = [ |
| @@ -214,11 +215,11 @@ export const SCREEN_MODULES: readonly (readonly [Record<string, unknown>, readon | ||
| 214 | 215 | [s76, ["entry"]], |
| 215 | 216 | [s77, ["entry"]], |
| 216 | 217 | [s78, ["entry"]], |
| 217 | [s79, ["modelGrantEntry","modelCeilingEntry"]], | |
| 218 | [s80, ["entry"]], | |
| 218 | [s79, ["entry"]], | |
| 219 | [s80, ["modelGrantEntry","modelCeilingEntry"]], | |
| 219 | 220 | [s81, ["entry"]], |
| 220 | [s82, ["nextAllEntry"]], | |
| 221 | [s83, ["entry"]], | |
| 221 | [s82, ["entry"]], | |
| 222 | [s83, ["nextAllEntry"]], | |
| 222 | 223 | [s84, ["entry"]], |
| 223 | 224 | [s85, ["entry"]], |
| 224 | 225 | [s86, ["entry"]], |
| @@ -266,4 +267,5 @@ export const SCREEN_MODULES: readonly (readonly [Record<string, unknown>, readon | ||
| 266 | 267 | [s128, ["entry"]], |
| 267 | 268 | [s129, ["entry"]], |
| 268 | 269 | [s130, ["entry"]], |
| 270 | [s131, ["entry"]], | |
| 269 | 271 | ]; |
src/http/lazy_lists.ts +5
| @@ -610,6 +610,11 @@ export const OPERATIONS_ROUTES = [ | ||
| 610 | 610 | ["POST", "/cloud/connect/:provider/build"], |
| 611 | 611 | ["GET", "/plugins/claude-code/marketplace.json"], |
| 612 | 612 | ["GET", "/plugins/opencode/forge.ts"], |
| 613 | ["GET", "/client-clouds"], | |
| 614 | ["POST", "/client-clouds"], | |
| 615 | ["GET", "/client-clouds/:id"], | |
| 616 | ["POST", "/client-clouds/:id/grant"], | |
| 617 | ["POST", "/client-clouds/:id/end"], | |
| 613 | 618 | ["GET", "/pinned"], |
| 614 | 619 | ["POST", "/pinned/domain"], |
| 615 | 620 | ["POST", "/pinned/paid"], |
src/http/marks/client-clouds.json added +10
src/http/routes/operations.ts +7
| @@ -10,6 +10,7 @@ import { resolveAppHostname } from "../../apps/proxy.ts"; | ||
| 10 | 10 | import { appsRuntime } from "../../apps/runtime_registry.ts"; |
| 11 | 11 | import { getVerifiedDomain } from "../../core/domains.ts"; |
| 12 | 12 | import { brokerStart } from "../../spawn/origin_broker.ts"; |
| 13 | import { clientCloudAttach, clientCloudEnd, clientCloudGrant, clientCloudPage, clientCloudsPage } from "../../web/pages/client_cloud.ts"; | |
| 13 | 14 | import { cloudConnectPage, cloudConnectProvider, cloudConnectSubmit, cloudConnectBuild } from "../../web/pages/cloud.ts"; |
| 14 | 15 | import { fleetGraphPage, fleetGraphLive, fleetGraphCsv } from "../../web/pages/fleet-graph.ts"; |
| 15 | 16 | import { fleetAct, fleetReceipt, fleetUndo } from "../../web/pages/fleet-ops.ts"; |
| @@ -58,6 +59,12 @@ export function operationsRoutes(router: Router<Handler>, knownPatterns: () => s | ||
| 58 | 59 | // The OpenCode plugin file (#10198); literal, above /:owner. |
| 59 | 60 | pluginRoutes(router); |
| 60 | 61 | // The Deploy to… page for a pinned forge (#8744); literal, above /:owner. |
| 62 | // A client's cloud, sealed (#17937): its own head, open to the named people and no one else. | |
| 63 | router.add("GET", "/client-clouds", clientCloudsPage); | |
| 64 | router.add("POST", "/client-clouds", clientCloudAttach); | |
| 65 | router.add("GET", "/client-clouds/:id", clientCloudPage); | |
| 66 | router.add("POST", "/client-clouds/:id/grant", clientCloudGrant); | |
| 67 | router.add("POST", "/client-clouds/:id/end", clientCloudEnd); | |
| 61 | 68 | pinnedRoutes(router); |
| 62 | 69 | infraRoutes(router); |
| 63 | 70 | gamesRoutes(router); |
src/maintain/duties/client_keys.ts added +19
| @@ -0,0 +1,19 @@ | ||
| 1 | /** | |
| 2 | * The client-keys duty (#17937): a client's key is deleted at its expiry, and every way in asks | |
| 3 | * first, but nobody may ask for a long while, so this asks every ten minutes. It names nothing of | |
| 4 | * a client: only how many keys it deleted. | |
| 5 | */ | |
| 6 | ||
| 7 | import { sweepKeys } from "../../core/client_cloud.ts"; | |
| 8 | import type { Duty } from "../duty.ts"; | |
| 9 | ||
| 10 | export const duty: Duty = { | |
| 11 | name: "client-keys", | |
| 12 | intervalMs: 10 * 60_000, | |
| 13 | budget: { runsPerDay: 150, dollarsPerDay: 0, reason: "every ten minutes is 144 a day, a handful of rows each, and no money is spent" }, | |
| 14 | run({ now, app }) { | |
| 15 | if (app === undefined) return { findings: [], actions: [] }; | |
| 16 | sweepKeys(app.db, now); | |
| 17 | return { findings: [], actions: [] }; | |
| 18 | }, | |
| 19 | }; |
src/tui/screens/client_clouds.ts added +165
| @@ -0,0 +1,165 @@ | ||
| 1 | /** | |
| 2 | * Clients' clouds in the terminal (#17937): what /client-clouds shows, through the same actions | |
| 3 | * (`actions/client_cloud.ts`). The list is the views the person is named on; enter reads one live, | |
| 4 | * read-only and audited, with who is named and every look; `n` names one more person; `x` deletes | |
| 5 | * the key now; `a` attaches a client's key (an admin's), typed masked and never drawn. Anyone not | |
| 6 | * named is offered nothing. | |
| 7 | */ | |
| 8 | ||
| 9 | import { OFF_SWITCH, attachClientCloud, endClientCloudKey, grantClientCloud, lookAtClientCloud, myClientClouds, type ClientCloudRow, type ClientCloudView } from "../../actions/client_cloud.ts"; | |
| 10 | import { CLIENT_PROVIDERS } from "../../cloud/client_read.ts"; | |
| 11 | import { KEEP_DAYS } from "../../core/client_cloud.ts"; | |
| 12 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 13 | import { binding } from "../app/keys.ts"; | |
| 14 | import { style } from "../term/style.ts"; | |
| 15 | import { truncate } from "../term/width.ts"; | |
| 16 | import type { Session } from "../session.ts"; | |
| 17 | import { fill, len, split } from "../ui/layout.ts"; | |
| 18 | import { emptyState } from "../ui/widgets.ts"; | |
| 19 | import { ListState, drawList, later, promptScreen, type ListRow } from "./common.ts"; | |
| 20 | import type { PaletteEntry } from "./entries.ts"; | |
| 21 | ||
| 22 | const day = (at: string): string => at.slice(0, 16).replace("T", " "); | |
| 23 | ||
| 24 | /** One view, read live: what it sees, who is named, every look. */ | |
| 25 | function viewScreen(f: Session, ctx: Ctx, row: ClientCloudRow): Screen { | |
| 26 | const state = new ListState(); | |
| 27 | let view: ClientCloudView | undefined; | |
| 28 | let said = "Reading…"; | |
| 29 | const load = (): void => { | |
| 30 | void lookAtClientCloud(f.app, f.user, row.id).then((r) => { | |
| 31 | if (r.ok) { | |
| 32 | view = r.value; | |
| 33 | said = ""; | |
| 34 | } else said = "That view is gone."; | |
| 35 | ctx.invalidate(); | |
| 36 | }); | |
| 37 | }; | |
| 38 | load(); | |
| 39 | const lines = (): ListRow[] => { | |
| 40 | if (view === undefined) return []; | |
| 41 | const v = view; | |
| 42 | return [ | |
| 43 | ...(v.seen === undefined | |
| 44 | ? [{ title: v.cloud.endedAt === null ? `Not read: ${v.why ?? "no answer"}` : `Key deleted ${day(v.cloud.endedAt)}: nothing to read` }] | |
| 45 | : v.seen.things.map((t) => ({ title: t.name, secondary: `${t.kind} · ${t.region} · ${t.size}${t.state === "" ? "" : ` · ${t.state}`}`, meta: v.seen!.projects.find((p) => p.id === t.project)?.name ?? "" }))), | |
| 46 | ...v.members.map((m) => ({ title: `named: ${m.username}`, secondary: `by ${m.grantedBy} ${day(m.grantedAt)}` })), | |
| 47 | ...v.reads.map((r) => ({ title: `${r.username}: ${r.what}`, secondary: day(r.at) })), | |
| 48 | ]; | |
| 49 | }; | |
| 50 | const screen: Screen = { | |
| 51 | title: row.label, | |
| 52 | keys: [binding(["j", "k"], "move cursor"), binding(["n"], "name someone"), binding(["x"], "delete the key"), binding(["esc"], "back")], | |
| 53 | render(area, s) { | |
| 54 | const c = ctx.theme.c; | |
| 55 | const [head, body] = split(area, "v", [len(3), fill(1)]); | |
| 56 | const now = view?.cloud ?? row; | |
| 57 | const until = now.endedAt === null ? `read-only · key deleted ${day(now.expiresAt)} UTC` : `key deleted ${day(now.endedAt)} UTC`; | |
| 58 | s.text(head!.x, head!.y, truncate(`${until}${said === "" ? "" : ` · ${said}`}`, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 59 | s.text(head!.x, head!.y + 1, truncate(OFF_SWITCH, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 60 | drawList(s, body!, c, state, lines()); | |
| 61 | }, | |
| 62 | key(e) { | |
| 63 | if (state.key(e, lines().length)) return true; | |
| 64 | if (e.ctrl || e.alt) return false; | |
| 65 | if (e.key === "n" && row.endedAt === null) | |
| 66 | ctx.push( | |
| 67 | promptScreen(ctx, screen, { | |
| 68 | title: `Name someone on ${row.label}`, | |
| 69 | label: "username", | |
| 70 | onSubmit: (value) => { | |
| 71 | const r = grantClientCloud(f.app, f.user, row.id, value); | |
| 72 | if (!r.ok) return r.error; | |
| 73 | ctx.toast(`${r.value} can look`, "success"); | |
| 74 | load(); | |
| 75 | return undefined; | |
| 76 | }, | |
| 77 | }), | |
| 78 | ); | |
| 79 | else if (e.key === "x" && row.endedAt === null) | |
| 80 | ctx.push( | |
| 81 | promptScreen(ctx, screen, { | |
| 82 | title: `Delete the key of ${row.label}`, | |
| 83 | label: "type delete to confirm", | |
| 84 | hint: "The client's own principal still stands until they end it.", | |
| 85 | onSubmit: (typed) => { | |
| 86 | if (typed !== "delete") return "Type delete to confirm."; | |
| 87 | const r = endClientCloudKey(f.app, f.user, row.id); | |
| 88 | if (!r.ok) return r.error; | |
| 89 | ctx.toast("key deleted here; the client's principal still stands until they end it", "success"); | |
| 90 | load(); | |
| 91 | return undefined; | |
| 92 | }, | |
| 93 | }), | |
| 94 | ); | |
| 95 | else return false; | |
| 96 | return true; | |
| 97 | }, | |
| 98 | }; | |
| 99 | return screen; | |
| 100 | } | |
| 101 | ||
| 102 | export function clientCloudsScreen(f: Session, ctx: Ctx): Screen { | |
| 103 | const state = new ListState(); | |
| 104 | let rows = myClientClouds(f.app, f.user); | |
| 105 | const reload = (): void => { | |
| 106 | rows = myClientClouds(f.app, f.user); | |
| 107 | state.clamp(rows.length); | |
| 108 | }; | |
| 109 | const screen: Screen = { | |
| 110 | title: "Clients' clouds", | |
| 111 | keys: [binding(["j", "k"], "move cursor"), binding(["enter"], "read it"), ...(f.user?.isAdmin === true ? [binding(["a"], "attach a key")] : [])], | |
| 112 | render(area, s) { | |
| 113 | const c = ctx.theme.c; | |
| 114 | const [head, body] = split(area, "v", [len(1), fill(1)]); | |
| 115 | s.text(head!.x, head!.y, truncate(OFF_SWITCH, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 116 | if (rows.length === 0) { | |
| 117 | emptyState(s, body!, c, { title: "No client's cloud is attached." }); | |
| 118 | return; | |
| 119 | } | |
| 120 | drawList(s, body!, c, state, rows.map((r) => ({ title: r.label, secondary: `${r.provider} · ${r.state === "held" ? `key deleted ${day(r.expiresAt)} UTC` : `key deleted ${day(r.endedAt ?? r.expiresAt)} UTC`}` }))); | |
| 121 | }, | |
| 122 | key(e) { | |
| 123 | if (state.key(e, rows.length)) return true; | |
| 124 | if (e.ctrl || e.alt) return false; | |
| 125 | const row = rows[state.index]; | |
| 126 | if (e.key === "enter" && row !== undefined) ctx.push(viewScreen(f, ctx, row)); | |
| 127 | else if (e.key === "a" && f.user?.isAdmin === true) | |
| 128 | ctx.push( | |
| 129 | promptScreen(ctx, screen, { | |
| 130 | title: "Attach a client's key", | |
| 131 | label: "TENANT_ID:CLIENT_ID:CLIENT_SECRET of a Reader principal", | |
| 132 | mask: true, | |
| 133 | hint: `Read once to check it, sealed, deleted in ${KEEP_DAYS.min} to ${KEEP_DAYS.max} days. Next: a name, then the days.`, | |
| 134 | onSubmit: (key) => | |
| 135 | later(ctx, () => | |
| 136 | promptScreen(ctx, screen, { | |
| 137 | title: "Whose cloud", | |
| 138 | label: "name, then a comma and the days to keep it (acme, 7)", | |
| 139 | onSubmit: async (value) => { | |
| 140 | const [label = "", days = ""] = value.split(",").map((x) => x.trim()); | |
| 141 | const r = await attachClientCloud(f.app, f.user, { provider: CLIENT_PROVIDERS[0], label, key, days: Number(days) }); | |
| 142 | if (r.ok) reload(); | |
| 143 | ctx.toast(r.ok ? `attached; the key is deleted ${day(r.value.expiresAt)} UTC` : r.error === "not_found" ? "Only an admin attaches a key." : r.error, r.ok ? "success" : "danger"); | |
| 144 | ctx.invalidate(); | |
| 145 | }, | |
| 146 | }), | |
| 147 | ), | |
| 148 | }), | |
| 149 | ); | |
| 150 | else return false; | |
| 151 | return true; | |
| 152 | }, | |
| 153 | }; | |
| 154 | return screen; | |
| 155 | } | |
| 156 | ||
| 157 | /** Clients' clouds, as /client-clouds has them: anyone named on one, or an admin who attaches. */ | |
| 158 | export const entry: PaletteEntry = { | |
| 159 | rank: 865, | |
| 160 | id: "client-clouds", | |
| 161 | title: "Clients' clouds", | |
| 162 | hint: "sealed, expiring, read-only views of a client's cloud", | |
| 163 | offered: (session) => session.user?.kind === "user" && (session.user.isAdmin || myClientClouds(session.app, session.user).length > 0), | |
| 164 | run: (session, ctx) => ctx.push(clientCloudsScreen(session, ctx)), | |
| 165 | }; |
src/web/pages/client_cloud.ts added +163
| @@ -0,0 +1,163 @@ | ||
| 1 | /** | |
| 2 | * A client's cloud, sealed (#17937): /client-clouds lists the views a person is named on, and an | |
| 3 | * admin attaches a client's Reader key there for some days; /client-clouds/:id reads the cloud | |
| 4 | * live, read-only and audited, with who is named, every look so far, and the one thing the page | |
| 5 | * must say: the client's own expiring Reader principal is the real off switch. Anyone not named | |
| 6 | * finds no such page. Nothing here is cached, indexed or linked from a public page. | |
| 7 | */ | |
| 8 | ||
| 9 | import { OFF_SWITCH, attachClientCloud, endClientCloudKey, grantClientCloud, lookAtClientCloud, myClientClouds, type ClientCloudView } from "../../actions/client_cloud.ts"; | |
| 10 | import { CLIENT_PROVIDERS } from "../../cloud/client_read.ts"; | |
| 11 | import { KEEP_DAYS, LABEL_MAX } from "../../core/client_cloud.ts"; | |
| 12 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; | |
| 13 | import type { Ctx } from "../../http/context.ts"; | |
| 14 | import { notFoundPage, pageHead, signInFirst } from "../chrome.ts"; | |
| 15 | import { field, readForm } from "../form.ts"; | |
| 16 | import { html, type Html } from "../html.ts"; | |
| 17 | import { flashTo, page } from "../layout.ts"; | |
| 18 | import { btn, confirmAction, field as input, row, rowList, time } from "../ui.ts"; | |
| 19 | ||
| 20 | const HOME = "/client-clouds"; | |
| 21 | ||
| 22 | /** A private page: never stored by a cache, never indexed. */ | |
| 23 | function sealed(r: Response): Response { | |
| 24 | r.headers.set("cache-control", "no-store"); | |
| 25 | r.headers.set("x-robots-tag", "noindex"); | |
| 26 | return r; | |
| 27 | } | |
| 28 | ||
| 29 | const ended = (at: string): Html => html`key deleted ${time(at)}`; | |
| 30 | ||
| 31 | /** The attach form: an admin's, with the key masked and what happens to it said under it. */ | |
| 32 | function attachForm(): Html { | |
| 33 | return html`<form method="post" action="${HOME}" class="stack"> | |
| 34 | ${input({ name: "label", label: "Whose cloud", required: true, hint: `Only the named people see this name (up to ${LABEL_MAX} characters).` })} | |
| 35 | <input type="hidden" name="provider" value="${CLIENT_PROVIDERS[0]}" /> | |
| 36 | ${input({ name: "key", label: "The client's Reader key, TENANT_ID:CLIENT_ID:CLIENT_SECRET", type: "password", autocomplete: "off", required: true })} | |
| 37 | ${input({ name: "days", label: `Keep it for how many days (${KEEP_DAYS.min} to ${KEEP_DAYS.max})`, type: "number", value: "7", required: true, hint: "The key is read once to check it, sealed, and deleted at its expiry." })} | |
| 38 | ${btn("Attach", { variant: "primary" })} | |
| 39 | </form>`; | |
| 40 | } | |
| 41 | ||
| 42 | // GET /client-clouds | |
| 43 | export function clientCloudsPage(ctx: Ctx): Response { | |
| 44 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 45 | const rendering = performance.now(); | |
| 46 | const res = clientCloudsBody(ctx); | |
| 47 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 48 | return res; | |
| 49 | } | |
| 50 | ||
| 51 | function clientCloudsBody(ctx: Ctx): Response { | |
| 52 | const user = ctx.auth.user; | |
| 53 | if (!user) return signInFirst(ctx); | |
| 54 | const mine = myClientClouds(ctx.app, user); | |
| 55 | if (mine.length === 0 && !user.isAdmin) return notFoundPage(ctx); | |
| 56 | return sealed( | |
| 57 | page({ | |
| 58 | ctx, | |
| 59 | title: "Clients' clouds", | |
| 60 | body: html`${pageHead("Clients' clouds", { sub: "Sealed, expiring, read-only views of a client's cloud." })} | |
| 61 | ${mine.length === 0 | |
| 62 | ? html`<p id="client-clouds-empty" class="muted">No client's cloud is attached.</p>` | |
| 63 | : rowList( | |
| 64 | mine.map((c) => | |
| 65 | row({ | |
| 66 | title: c.named ? html`<a href="${HOME}/${c.id}">${c.label}</a>` : html`${c.label}`, | |
| 67 | meta: c.state === "held" ? html`${c.provider} · key deleted ${time(c.expiresAt)}` : html`${c.provider} · ${ended(c.endedAt ?? c.expiresAt)}`, | |
| 68 | // An admin not named on a view cannot read it, but can still delete its key. | |
| 69 | ...(c.named || c.state !== "held" ? {} : { trail: confirmAction({ action: `${HOME}/${c.id}/end`, verb: "Delete the key now" }) }), | |
| 70 | }), | |
| 71 | ), | |
| 72 | { label: "Clients' clouds" }, | |
| 73 | )} | |
| 74 | <p class="muted small">${OFF_SWITCH}</p> | |
| 75 | ${user.isAdmin ? attachForm() : null}`, | |
| 76 | }), | |
| 77 | ); | |
| 78 | } | |
| 79 | ||
| 80 | // POST /client-clouds | |
| 81 | export async function clientCloudAttach(ctx: Ctx): Promise<Response> { | |
| 82 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 83 | const form = await readForm(ctx, "admin"); | |
| 84 | if (form instanceof Response) return form; | |
| 85 | const r = await attachClientCloud(ctx.app, ctx.auth.user, { | |
| 86 | provider: field(form, "provider"), | |
| 87 | label: field(form, "label"), | |
| 88 | key: field(form, "key"), | |
| 89 | days: Number(field(form, "days")), | |
| 90 | }); | |
| 91 | if (!r.ok) return r.error === "not_found" ? notFoundPage(ctx) : sealed(flashTo(ctx, HOME, { tone: "danger", message: r.error })); | |
| 92 | return sealed(flashTo(ctx, `${HOME}/${r.value.id}`, { message: `Attached. The key is deleted ${r.value.expiresAt.slice(0, 16).replace("T", " ")} UTC.` })); | |
| 93 | } | |
| 94 | ||
| 95 | /** What the key sees, by subscription: the kind, name, region, size and state of each thing. */ | |
| 96 | function seenCard(v: ClientCloudView): Html { | |
| 97 | if (v.seen === undefined) | |
| 98 | return html`<p class="muted">${v.cloud.endedAt === null ? `Not read: ${v.why ?? "no answer"}.` : "The key is deleted, so there is nothing to read."}</p>`; | |
| 99 | const seen = v.seen; | |
| 100 | return html`${seen.projects.map( | |
| 101 | (p) => html`<section class="stack"><h2>${p.name}</h2>${p.note === undefined ? null : html`<p class="muted small">${p.note}</p>`} | |
| 102 | ${(() => { | |
| 103 | const here = seen.things.filter((t) => t.project === p.id); | |
| 104 | return here.length === 0 | |
| 105 | ? html`<p class="muted small">Nothing found.</p>` | |
| 106 | : rowList(here.map((t) => row({ title: html`${t.name}`, meta: html`${t.kind} · ${t.region} · ${t.size}${t.state === "" ? "" : ` · ${t.state}`}${t.label === "" ? "" : ` · ${t.label}`}` })), { label: p.name }); | |
| 107 | })()} | |
| 108 | </section>`, | |
| 109 | )} | |
| 110 | ${seen.gaps.length === 0 ? null : html`<p class="muted small">Not read: ${seen.gaps.map((g) => `${g.kind} (${g.reason})`).join("; ")}</p>`}`; | |
| 111 | } | |
| 112 | ||
| 113 | // GET /client-clouds/:id | |
| 114 | export async function clientCloudPage(ctx: Ctx): Promise<Response> { | |
| 115 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 116 | const r = await lookAtClientCloud(ctx.app, ctx.auth.user, ctx.params.id ?? ""); | |
| 117 | if (!r.ok) return notFoundPage(ctx); | |
| 118 | const v = r.value; | |
| 119 | const live = v.cloud.endedAt === null; | |
| 120 | return sealed( | |
| 121 | page({ | |
| 122 | ctx, | |
| 123 | title: v.cloud.label, | |
| 124 | body: html`${pageHead(v.cloud.label, { sub: live ? html`read-only · key deleted ${time(v.cloud.expiresAt)}` : ended(v.cloud.endedAt!) })} | |
| 125 | <p class="muted" id="off-switch">${v.offSwitch}</p> | |
| 126 | ${seenCard(v)} | |
| 127 | <h2>Named</h2> | |
| 128 | ${rowList(v.members.map((m) => row({ title: m.username, meta: html`named by ${m.grantedBy} ${time(m.grantedAt)}` })), { label: "Named people" })} | |
| 129 | ${live | |
| 130 | ? html`<form method="post" action="${HOME}/${v.cloud.id}/grant" class="stack"> | |
| 131 | ${input({ name: "username", label: "Name one more person", required: true, autocomplete: "off" })} | |
| 132 | ${btn("Name them")} | |
| 133 | </form> | |
| 134 | <p>${confirmAction({ action: `${HOME}/${v.cloud.id}/end`, verb: "Delete the key now" })}</p>` | |
| 135 | : null} | |
| 136 | <h2>Every look</h2> | |
| 137 | ${rowList(v.reads.map((x) => row({ title: html`${x.username}: ${x.what}`, meta: time(x.at) })), { label: "Looks" })} | |
| 138 | <p class="muted small"><a href="${HOME}">Clients' clouds</a></p>`, | |
| 139 | }), | |
| 140 | ); | |
| 141 | } | |
| 142 | ||
| 143 | // POST /client-clouds/:id/grant | |
| 144 | export async function clientCloudGrant(ctx: Ctx): Promise<Response> { | |
| 145 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 146 | const form = await readForm(ctx, "admin"); | |
| 147 | if (form instanceof Response) return form; | |
| 148 | const id = ctx.params.id ?? ""; | |
| 149 | const r = grantClientCloud(ctx.app, ctx.auth.user, id, field(form, "username")); | |
| 150 | if (!r.ok && r.error === "not_found") return notFoundPage(ctx); | |
| 151 | return sealed(flashTo(ctx, `${HOME}/${encodeURIComponent(id)}`, r.ok ? { message: `${r.value} can look.` } : { tone: "danger", message: r.error })); | |
| 152 | } | |
| 153 | ||
| 154 | // POST /client-clouds/:id/end | |
| 155 | export async function clientCloudEnd(ctx: Ctx): Promise<Response> { | |
| 156 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 157 | const form = await readForm(ctx, "admin"); | |
| 158 | if (form instanceof Response) return form; | |
| 159 | const id = ctx.params.id ?? ""; | |
| 160 | const r = endClientCloudKey(ctx.app, ctx.auth.user, id); | |
| 161 | if (!r.ok && r.error === "not_found") return notFoundPage(ctx); | |
| 162 | return sealed(flashTo(ctx, `${HOME}/${encodeURIComponent(id)}`, r.ok ? { message: "The key is deleted here. The client's own principal still stands until they end it." } : { tone: "danger", message: r.error })); | |
| 163 | } |
test/budgets/unfixtured/client-clouds-id.json added +4
test/client-cloud.test.ts added +279
| @@ -0,0 +1,279 @@ | ||
| 1 | /** | |
| 2 | * A client's cloud, sealed (#17937): the key is read with reads only, sealed, deleted at its | |
| 3 | * expiry, looked at by the named people alone (who may name more), every look audited, and none of | |
| 4 | * it in the owner's cloud tables, the event outbox, secrets or the crew's reach. Hand check: 7 days | |
| 5 | * from 2026-12-03T10:00Z is 2026-12-10T10:00Z. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { attachClientCloud, endClientCloudKey, grantClientCloud, lookAtClientCloud, myClientClouds, OFF_SWITCH } from "../src/actions/client_cloud.ts"; | |
| 12 | import { net } from "../src/actions/cloud.ts"; | |
| 13 | import { createApp, type App } from "../src/app.ts"; | |
| 14 | import { NotARead, readOnly } from "../src/cloud/client_read.ts"; | |
| 15 | import { isMember, openKey, sweepKeys } from "../src/core/client_cloud.ts"; | |
| 16 | import { createAgentRow } from "../src/core/agents.ts"; | |
| 17 | import { createSession } from "../src/core/sessions.ts"; | |
| 18 | import { createUser, type User } from "../src/core/users.ts"; | |
| 19 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 20 | import { quietLogs } from "./helpers/globals.ts"; | |
| 21 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 22 | import { proveAll } from "./helpers/verified.ts"; | |
| 23 | ||
| 24 | quietLogs(); | |
| 25 | ||
| 26 | const SUB = "11111111-1111-1111-1111-111111111111"; | |
| 27 | const KEY = "tenant-1:client-1:the-client-secret"; | |
| 28 | const T0 = new Date("2026-12-03T10:00:00Z"); | |
| 29 | ||
| 30 | let calls: string[] = []; | |
| 31 | const realFetch = net.fetch; | |
| 32 | net.fetch = async (url, init) => { | |
| 33 | const u = new URL(String(url)); | |
| 34 | calls.push(`${init?.method ?? "GET"} ${u.host}${u.pathname}`); | |
| 35 | if (u.host === "login.microsoftonline.com") return Response.json({ access_token: "tok" }); | |
| 36 | if (u.pathname === "/subscriptions") return Response.json({ value: [{ subscriptionId: SUB, displayName: "Client Prod", state: "Enabled" }] }); | |
| 37 | if (u.pathname === "/providers/Microsoft.ResourceGraph/resources") | |
| 38 | return Response.json({ data: [{ id: `/subscriptions/${SUB}/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/web`, name: "web", type: "Microsoft.Compute/virtualMachines", location: "eastus", subscriptionId: SUB }] }); | |
| 39 | return new Response("{}", { status: 404 }); | |
| 40 | }; | |
| 41 | ||
| 42 | let dir = ""; | |
| 43 | let app: App; | |
| 44 | let servers: Servers; | |
| 45 | let owner: User; | |
| 46 | let reader: User; | |
| 47 | let friend: User; | |
| 48 | let stranger: User; | |
| 49 | let bot: User; | |
| 50 | let id = ""; | |
| 51 | const cookie = (u: User): string => `forge_session=${createSession(app.db, u.id).token}`; | |
| 52 | ||
| 53 | async function person(username: string, agent = false): Promise<User> { | |
| 54 | const made = await createUser(app.db, { | |
| 55 | username, | |
| 56 | email: `${username}@forge.test`, | |
| 57 | ...(agent ? { agent: true, origin: "agent" as const } : { password: "a-good-passphrase", origin: "seed" as const, trusted: true }), | |
| 58 | }); | |
| 59 | if (!made.ok) throw new Error(made.error); | |
| 60 | if (agent) createAgentRow(app.db, { userId: made.value.id, brief: "crew." }); | |
| 61 | return made.value; | |
| 62 | } | |
| 63 | ||
| 64 | beforeAll(async () => { | |
| 65 | dir = mkdtempSync(join(tmpdir(), "forge-client-cloud-")); | |
| 66 | app = createApp({ dataDir: dir, port: 0 }); | |
| 67 | const a = await seedAdmin(app, { username: "olivia", email: "[email protected]", password: "a-good-passphrase" }); | |
| 68 | if (!a.ok) throw new Error(a.error); | |
| 69 | owner = a.value; | |
| 70 | reader = await person("reader"); | |
| 71 | friend = await person("friend"); | |
| 72 | stranger = await person("stranger"); | |
| 73 | bot = await person("crewbot", true); | |
| 74 | proveAll(app); | |
| 75 | servers = await serve(app); | |
| 76 | }); | |
| 77 | afterAll(() => { | |
| 78 | net.fetch = realFetch; | |
| 79 | servers.stop(); | |
| 80 | app.close(); | |
| 81 | rmSync(dir, { recursive: true, force: true }); | |
| 82 | }); | |
| 83 | ||
| 84 | describe("attaching", () => { | |
| 85 | test("only an admin attaches, and a bad request is refused before anything is read", async () => { | |
| 86 | expect((await attachClientCloud(app, reader, { provider: "azure", label: "Acme", key: KEY, days: 7 }, T0)).ok).toBe(false); | |
| 87 | for (const days of [0, 91, 1.5, Number.NaN]) { | |
| 88 | const r = await attachClientCloud(app, owner, { provider: "azure", label: "Acme", key: KEY, days }, T0); | |
| 89 | expect(r.ok).toBe(false); | |
| 90 | } | |
| 91 | expect((await attachClientCloud(app, owner, { provider: "aws", label: "Acme", key: KEY, days: 7 }, T0)).ok).toBe(false); | |
| 92 | expect((await attachClientCloud(app, owner, { provider: "azure", label: " ", key: KEY, days: 7 }, T0)).ok).toBe(false); | |
| 93 | expect(calls).toEqual([]); | |
| 94 | }); | |
| 95 | ||
| 96 | test("the key is read, sealed, and its expiry is the days asked", async () => { | |
| 97 | const r = await attachClientCloud(app, owner, { provider: "azure", label: "Acme", key: KEY, days: 7 }, T0); | |
| 98 | if (!r.ok) throw new Error(r.error); | |
| 99 | id = r.value.id; | |
| 100 | expect(r.value.expiresAt).toBe("2026-12-10T10:00:00.000Z"); | |
| 101 | expect(openKey(app.db, dir, id)).toBe(KEY); | |
| 102 | // At rest it is sealed, and the plaintext is nowhere in the row. | |
| 103 | const row = app.db.query<{ sealed: string }, [string]>("SELECT sealed FROM client_cloud WHERE id = ?1").get(id)!; | |
| 104 | expect(row.sealed.startsWith("v3:")).toBe(true); | |
| 105 | expect(JSON.stringify(row)).not.toContain("the-client-secret"); | |
| 106 | expect(calls.filter((c) => c.startsWith("POST") && !c.includes("login.microsoftonline.com") && !c.includes("ResourceGraph"))).toEqual([]); | |
| 107 | }); | |
| 108 | ||
| 109 | test("it is in none of the owner's cloud, secret or event tables", () => { | |
| 110 | for (const t of ["cloud_account", "cloud_resource", "cloud_project", "cloud_audit", "secret", "event"]) { | |
| 111 | const dump = JSON.stringify(app.db.query(`SELECT * FROM ${t}`).all()); | |
| 112 | expect(dump).not.toContain("the-client-secret"); | |
| 113 | expect(dump).not.toContain("Acme"); | |
| 114 | expect(dump).not.toContain(id); | |
| 115 | } | |
| 116 | }); | |
| 117 | }); | |
| 118 | ||
| 119 | describe("looking", () => { | |
| 120 | test("a named person reads it live and the look is audited; the page says the real off switch", async () => { | |
| 121 | const r = await lookAtClientCloud(app, owner, id, T0); | |
| 122 | if (!r.ok) throw new Error(r.error); | |
| 123 | expect(r.value.seen?.things.map((t) => t.name)).toEqual(["web"]); | |
| 124 | expect(r.value.reads[0]?.what).toBe("looked"); | |
| 125 | expect(r.value.reads[0]?.username).toBe("olivia"); | |
| 126 | expect(r.value.offSwitch).toBe(OFF_SWITCH); | |
| 127 | expect(OFF_SWITCH).toContain("Reader principal"); | |
| 128 | }); | |
| 129 | ||
| 130 | test("anyone not named, an agent and a signed-out visitor find nothing, and are not audited", async () => { | |
| 131 | const before = calls.length; | |
| 132 | for (const who of [stranger, bot, undefined]) expect(await lookAtClientCloud(app, who, id, T0)).toEqual({ ok: false, error: "not_found" }); | |
| 133 | expect(myClientClouds(app, stranger, T0)).toEqual([]); | |
| 134 | expect(calls.length).toBe(before); | |
| 135 | for (const u of [stranger, bot]) { | |
| 136 | const res = await fetch(`${servers.url}/client-clouds/${id}`, { headers: { cookie: cookie(u) } }); | |
| 137 | expect(res.status).toBe(404); | |
| 138 | expect(await res.text()).not.toContain("Acme"); | |
| 139 | } | |
| 140 | }); | |
| 141 | ||
| 142 | test("a named person names another; never an agent, nobody unknown", async () => { | |
| 143 | expect(grantClientCloud(app, stranger, id, "friend", T0)).toEqual({ ok: false, error: "not_found" }); | |
| 144 | const bad = grantClientCloud(app, owner, id, "crewbot", T0); | |
| 145 | expect(bad.ok).toBe(false); | |
| 146 | expect(grantClientCloud(app, owner, id, "nobody", T0).ok).toBe(false); | |
| 147 | expect(grantClientCloud(app, owner, id, "reader", T0)).toEqual({ ok: true, value: "reader" }); | |
| 148 | expect(grantClientCloud(app, owner, id, "reader", T0).ok).toBe(false); | |
| 149 | // The one named may name another in turn. | |
| 150 | expect(grantClientCloud(app, reader, id, "friend", T0)).toEqual({ ok: true, value: "friend" }); | |
| 151 | expect((await lookAtClientCloud(app, friend, id, T0)).ok).toBe(true); | |
| 152 | }); | |
| 153 | ||
| 154 | test("the page: private headers, the off switch, every look; the key never appears", async () => { | |
| 155 | const res = await fetch(`${servers.url}/client-clouds/${id}`, { headers: { cookie: cookie(reader) } }); | |
| 156 | expect(res.status).toBe(200); | |
| 157 | expect(res.headers.get("cache-control")).toBe("no-store"); | |
| 158 | const text = await res.text(); | |
| 159 | expect(text).toContain("Client Prod"); | |
| 160 | expect(text).toContain("real off switch"); | |
| 161 | expect(text).toContain("reader: looked"); | |
| 162 | expect(text).not.toContain("the-client-secret"); | |
| 163 | const list = await fetch(`${servers.url}/client-clouds`, { headers: { cookie: cookie(reader) } }); | |
| 164 | expect(list.status).toBe(200); | |
| 165 | expect(await list.text()).toContain("Acme"); | |
| 166 | // Nothing public mentions it. | |
| 167 | for (const path of ["/", "/explore", "/feed.json", "/sitemap.xml"]) { | |
| 168 | const open = await fetch(`${servers.url}${path}`); | |
| 169 | expect(await open.text()).not.toContain("Acme"); | |
| 170 | } | |
| 171 | }); | |
| 172 | ||
| 173 | test("a form post from another origin is refused", async () => { | |
| 174 | const res = await fetch(`${servers.url}/client-clouds/${id}/grant`, { | |
| 175 | method: "POST", | |
| 176 | headers: { cookie: cookie(reader), origin: "https://evil.example" }, | |
| 177 | body: new URLSearchParams({ username: "stranger" }), | |
| 178 | }); | |
| 179 | expect(res.status).toBe(403); | |
| 180 | expect(grantClientCloud(app, owner, id, "friend", T0).ok).toBe(false); | |
| 181 | }); | |
| 182 | ||
| 183 | test("no event is appended and the crew's secret list never holds it", () => { | |
| 184 | const kinds = app.db.query<{ kind: string }, []>("SELECT DISTINCT kind FROM event").all().map((e) => e.kind); | |
| 185 | expect(kinds.filter((k) => /client|cloud/.test(k))).toEqual([]); | |
| 186 | }); | |
| 187 | }); | |
| 188 | ||
| 189 | describe("expiry and the real off switch", () => { | |
| 190 | test("the key is deleted at its expiry, by the sweep and by any way in", async () => { | |
| 191 | expect(sweepKeys(app.db, new Date("2026-12-10T09:59:59Z"))).toBe(0); | |
| 192 | expect(openKey(app.db, dir, id)).toBe(KEY); | |
| 193 | const before = calls.length; | |
| 194 | const r = await lookAtClientCloud(app, owner, id, new Date("2026-12-10T10:00:00Z")); | |
| 195 | if (!r.ok) throw new Error(r.error); | |
| 196 | expect(r.value.seen).toBeUndefined(); | |
| 197 | expect(r.value.cloud.endedAt).toBe("2026-12-10T10:00:00.000Z"); | |
| 198 | expect(openKey(app.db, dir, id)).toBeUndefined(); | |
| 199 | expect(app.db.query<{ sealed: string | null }, [string]>("SELECT sealed FROM client_cloud WHERE id = ?1").get(id)!.sealed).toBeNull(); | |
| 200 | expect(calls.length).toBe(before); | |
| 201 | expect(grantClientCloud(app, owner, id, "stranger", new Date("2026-12-11T00:00:00Z")).ok).toBe(false); | |
| 202 | }); | |
| 203 | ||
| 204 | test("an admin or whoever attached it deletes the key early; a member who did not cannot", async () => { | |
| 205 | const made = await attachClientCloud(app, owner, { provider: "azure", label: "Beta", key: KEY, days: 3 }, T0); | |
| 206 | if (!made.ok) throw new Error(made.error); | |
| 207 | grantClientCloud(app, owner, made.value.id, "reader", T0); | |
| 208 | const no = endClientCloudKey(app, reader, made.value.id, T0); | |
| 209 | expect(no.ok).toBe(false); | |
| 210 | expect(openKey(app.db, dir, made.value.id)).toBe(KEY); | |
| 211 | expect(endClientCloudKey(app, owner, made.value.id, T0).ok).toBe(true); | |
| 212 | expect(openKey(app.db, dir, made.value.id)).toBeUndefined(); | |
| 213 | }); | |
| 214 | ||
| 215 | test("an admin who is not named still deletes the key; anyone else not named finds nothing", async () => { | |
| 216 | const admin = await person("otheradmin"); | |
| 217 | const made = await attachClientCloud(app, owner, { provider: "azure", label: "Gamma", key: KEY, days: 3 }, T0); | |
| 218 | if (!made.ok) throw new Error(made.error); | |
| 219 | const asAdmin = { ...admin, isAdmin: true }; | |
| 220 | expect(isMember(app.db, made.value.id, admin.id)).toBe(false); | |
| 221 | expect(endClientCloudKey(app, stranger, made.value.id, T0)).toEqual({ ok: false, error: "not_found" }); | |
| 222 | expect(openKey(app.db, dir, made.value.id)).toBe(KEY); | |
| 223 | expect(myClientClouds(app, asAdmin, T0).find((c) => c.id === made.value.id)?.named).toBe(false); | |
| 224 | expect(endClientCloudKey(app, asAdmin, made.value.id, T0).ok).toBe(true); | |
| 225 | expect(openKey(app.db, dir, made.value.id)).toBeUndefined(); | |
| 226 | }); | |
| 227 | }); | |
| 228 | ||
| 229 | describe("one person reloading", () => { | |
| 230 | test("a second look within seconds is not read live, and the audit says one look", async () => { | |
| 231 | const made = await attachClientCloud(app, owner, { provider: "azure", label: "Delta", key: KEY, days: 3 }, T0); | |
| 232 | if (!made.ok) throw new Error(made.error); | |
| 233 | const t = new Date("2026-12-03T11:00:00Z"); | |
| 234 | const first = await lookAtClientCloud(app, owner, made.value.id, t); | |
| 235 | expect(first.ok && first.value.seen !== undefined).toBe(true); | |
| 236 | const before = calls.length; | |
| 237 | const again = await lookAtClientCloud(app, owner, made.value.id, new Date(t.getTime() + 2000)); | |
| 238 | expect(again.ok && again.value.seen === undefined && again.value.why?.includes("a moment ago")).toBe(true); | |
| 239 | expect(calls.length).toBe(before); | |
| 240 | const later = await lookAtClientCloud(app, owner, made.value.id, new Date(t.getTime() + 6000)); | |
| 241 | expect(later.ok && later.value.seen !== undefined).toBe(true); | |
| 242 | }); | |
| 243 | }); | |
| 244 | ||
| 245 | describe("no write verbs", () => { | |
| 246 | test("the network the reader gets refuses anything that is not a read", async () => { | |
| 247 | const seen: string[] = []; | |
| 248 | const f = readOnly(async (url, init) => { | |
| 249 | seen.push(`${init?.method ?? "GET"} ${url}`); | |
| 250 | return new Response("{}"); | |
| 251 | }); | |
| 252 | await f("https://management.azure.com/subscriptions?api-version=1"); | |
| 253 | await f(`https://management.azure.com/subscriptions/${SUB}/providers/Microsoft.CostManagement/query?api-version=1`, { method: "POST", body: "{}" }); | |
| 254 | for (const [method, url] of [ | |
| 255 | ["PUT", `https://management.azure.com/subscriptions/${SUB}/resourceGroups/rg?api-version=1`], | |
| 256 | ["DELETE", `https://management.azure.com/subscriptions/${SUB}/resourceGroups/rg`], | |
| 257 | ["PATCH", "https://management.azure.com/subscriptions"], | |
| 258 | ["POST", `https://management.azure.com/subscriptions/${SUB}/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/web/deallocate`], | |
| 259 | ["POST", "https://evil.example/providers/Microsoft.ResourceGraph/resources"], | |
| 260 | ["GET", "https://evil.example/steal"], | |
| 261 | ["GET", "http://management.azure.com/subscriptions"], | |
| 262 | ["GET", "https://management.azure.com.evil.example/subscriptions"], | |
| 263 | ] as const) | |
| 264 | expect(() => f(url, { method })).toThrow(NotARead); | |
| 265 | expect(seen.length).toBe(2); | |
| 266 | }); | |
| 267 | }); | |
| 268 | ||
| 269 | describe("deleting from the page asks first", () => { | |
| 270 | test("the button is a link to the confirm page, and the confirmed post deletes the key", async () => { | |
| 271 | const made = await attachClientCloud(app, owner, { provider: "azure", label: "Gamma", key: KEY, days: 2 }); | |
| 272 | if (!made.ok) throw new Error(made.error); | |
| 273 | const page = await (await fetch(`${servers.url}/client-clouds/${made.value.id}`, { headers: { cookie: cookie(owner) } })).text(); | |
| 274 | expect(page).toContain(`/-/confirm?to=${encodeURIComponent(`/client-clouds/${made.value.id}/end`)}`); | |
| 275 | const res = await fetch(`${servers.url}/client-clouds/${made.value.id}/end`, { method: "POST", headers: { cookie: cookie(owner), origin: servers.url }, redirect: "manual" }); | |
| 276 | expect(res.status).toBe(303); | |
| 277 | expect(openKey(app.db, dir, made.value.id)).toBeUndefined(); | |
| 278 | }); | |
| 279 | }); |
test/forge-looks.test.ts +1
| @@ -24,6 +24,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 24 | 24 | "/tab": "no picture: it boots a forge in the browser (wasm, OPFS), which a screenshot cannot hold; covered by test/tab.test.ts", |
| 25 | 25 | "/home": "the home's old address: a redirect to /, which is pictured", |
| 26 | 26 | "/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", |
| 27 | "/client-clouds": "no picture: not in app.looks; a guest sees the not-found page, and the page is covered by test/client-cloud.test.ts", | |
| 27 | 28 | "/design": "no picture: not in app.looks (its slots are full); the Design tab is covered by test/design-theme.test.ts", |
| 28 | 29 | "/feed": "no picture: its slot went to /docs; the page is covered by its own tests", |
| 29 | 30 | "/front": "no picture: its slot went to /settings/security/controls, the security controls (#13001); covered by its own tests", |
test/no-polling.test.ts +1
| @@ -365,6 +365,7 @@ const NOT_WALKED: Record<string, string> = { | ||
| 365 | 365 | "/settings/origins/flows/:id": ORIGIN, |
| 366 | 366 | "/settings/origins/flows/:id/stream": ORIGIN, |
| 367 | 367 | "/settings/teams/:slug": "needs a team", |
| 368 | "/client-clouds/:id": "needs a client's cloud the signed-in person is named on", | |
| 368 | 369 | "/talk/:id": "needs a conversation of the signed-in person", |
| 369 | 370 | "/talk/:id/download": "needs a conversation of the signed-in person", |
| 370 | 371 | }; |
test/palette-roster.test.ts +1
| @@ -243,6 +243,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 243 | 243 | ["pinned", "Pinned forges", "deploy, update and roll back a forge on your cloud"], |
| 244 | 244 | ["experiments", "Experiments", "what each cloud machine costs and answers"], |
| 245 | 245 | ["games", "Games", "game servers on your cloud: state, start, stop, restart"], |
| 246 | ["client-clouds", "Clients' clouds", "sealed, expiring, read-only views of a client's cloud"], | |
| 246 | 247 | ["bets", "Bets", "back, stop and finish a repository\'s bets"], |
| 247 | 248 | ["origins", "Connected accounts", "the hosts your mirrors come from"], |
| 248 | 249 | ["design-gallery", "Component gallery", "every component the design names"], |
test/security-floor-routes.test.ts +1
| @@ -88,6 +88,7 @@ const UNSEEDED: Record<string, string> = { | ||
| 88 | 88 | "/api/v1/repos/:owner/:name/drop/:file": "a file name in an app's private drop; the seed drops none", |
| 89 | 89 | "/api/v1/runner/jobs/:id/git/info/refs": "a job a runner holds, read with that job's own token; the seed offers none (test/checks-runner-placement.test.ts covers it)", |
| 90 | 90 | "/api/v1/runner/jobs/:id/seed": "a file a runner's job is seeded with, read with that job's own token; the seed offers none (test/runner-seeds.test.ts covers it)", |
| 91 | "/client-clouds/:id": "needs a client's cloud the signed-in person is named on; the seed has none (test/client-cloud.test.ts covers it)", | |
| 91 | 92 | "/claim/start/:token": "needs a one-time start claim token, which the seed does not mint (test/start.test.ts covers it)", |
| 92 | 93 | "/join/:token": "needs a one-use link to work on a repository, which the seed does not mint (test/invite-contributors.test.ts covers it)", |
| 93 | 94 | "/signin/access/:token": "needs a one-time access link an admin minted", |
test/tui-client-clouds.test.ts added +107
| @@ -0,0 +1,107 @@ | ||
| 1 | /** | |
| 2 | * Clients' clouds in the terminal (#17937): the screen shows what the page shows, through the same | |
| 3 | * actions: the view's name, that the client's own principal is the real off switch, what the key | |
| 4 | * sees, who is named and every look. Anyone not named is offered nothing and sees nothing. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { attachClientCloud } from "../src/actions/client_cloud.ts"; | |
| 11 | import { net } from "../src/actions/cloud.ts"; | |
| 12 | import { createApp, type App as Forge } from "../src/app.ts"; | |
| 13 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 14 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 15 | import type { TuiIdentity } from "../src/tui/session.ts"; | |
| 16 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | import { settleApp } from "./helpers/tui.ts"; | |
| 19 | ||
| 20 | quietLogs(); | |
| 21 | ||
| 22 | const SUB = "11111111-1111-1111-1111-111111111111"; | |
| 23 | const realFetch = net.fetch; | |
| 24 | ||
| 25 | describe("clients' clouds in the terminal", () => { | |
| 26 | let dataDir: string; | |
| 27 | let forge: Forge; | |
| 28 | ||
| 29 | function boot(username: string) { | |
| 30 | const terminal = headlessTerminal(140, 32); | |
| 31 | const user = getUserByName(forge.db, username)!; | |
| 32 | const identity: TuiIdentity = { sshUsername: "t", remoteAddress: "127.0.0.1", user }; | |
| 33 | const { app } = createForgeApp(forge, identity, { terminal, exitHooks: false }); | |
| 34 | app.start(); | |
| 35 | const key = (k: string, ctrl = false) => app.dispatch({ type: "key", key: k, ctrl, alt: false, shift: false }); | |
| 36 | return { | |
| 37 | text: () => app.screen.toText(), | |
| 38 | press: async (...keys: string[]) => { | |
| 39 | keys.forEach((k) => key(k)); | |
| 40 | await settleApp(app); | |
| 41 | }, | |
| 42 | palette: async () => { | |
| 43 | key("k", true); | |
| 44 | for (const ch of "Clients") key(ch); | |
| 45 | key("enter"); | |
| 46 | await settleApp(app); | |
| 47 | }, | |
| 48 | stop: () => app.stop(), | |
| 49 | }; | |
| 50 | } | |
| 51 | ||
| 52 | beforeAll(async () => { | |
| 53 | dataDir = await mkdtemp(join(tmpdir(), "forge-tui-client-cloud-")); | |
| 54 | forge = createApp({ dataDir, port: 0 }); | |
| 55 | for (const [username, adminIfFirst] of [["alice", true], ["bob", false]] as const) { | |
| 56 | const made = await createUser(forge.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst }); | |
| 57 | if (!made.ok) throw new Error(made.error); | |
| 58 | } | |
| 59 | net.fetch = async (url) => { | |
| 60 | const u = new URL(String(url)); | |
| 61 | if (u.host === "login.microsoftonline.com") return Response.json({ access_token: "tok" }); | |
| 62 | if (u.pathname === "/subscriptions") return Response.json({ value: [{ subscriptionId: SUB, displayName: "Client Prod", state: "Enabled" }] }); | |
| 63 | return Response.json({ data: [{ id: `/subscriptions/${SUB}/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/webvm`, name: "webvm", type: "Microsoft.Compute/virtualMachines", location: "eastus", subscriptionId: SUB }] }); | |
| 64 | }; | |
| 65 | const made = await attachClientCloud(forge, getUserByName(forge.db, "alice")!, { provider: "azure", label: "Acme", key: "t:c:s", days: 7 }); | |
| 66 | if (!made.ok) throw new Error(made.error); | |
| 67 | }); | |
| 68 | afterAll(async () => { | |
| 69 | net.fetch = realFetch; | |
| 70 | forge.close(); | |
| 71 | await rm(dataDir, { recursive: true, force: true }); | |
| 72 | }); | |
| 73 | ||
| 74 | test("the named admin reads it: the off switch, what the key sees, who is named, the looks", async () => { | |
| 75 | const t = boot("alice"); | |
| 76 | await t.palette(); | |
| 77 | expect(t.text()).toContain("Acme"); | |
| 78 | expect(t.text()).toContain("real off switch"); | |
| 79 | await t.press("enter"); | |
| 80 | const text = t.text(); | |
| 81 | expect(text).toContain("webvm"); | |
| 82 | expect(text).toContain("named: alice"); | |
| 83 | expect(text).toContain("alice: looked"); | |
| 84 | t.stop(); | |
| 85 | }); | |
| 86 | ||
| 87 | test("x asks first, then deletes the key and the screen says so", async () => { | |
| 88 | const t = boot("alice"); | |
| 89 | await t.palette(); | |
| 90 | await t.press("enter", "x"); | |
| 91 | expect(t.text()).toContain("type delete to confirm"); | |
| 92 | await t.press(..."nope".split(""), "enter"); | |
| 93 | expect(t.text()).toContain("Type delete to confirm."); | |
| 94 | await t.press("backspace", "backspace", "backspace", "backspace", ..."delete".split(""), "enter"); | |
| 95 | expect(t.text()).toContain("key deleted"); | |
| 96 | expect(t.text()).toContain("Key deleted"); | |
| 97 | t.stop(); | |
| 98 | }); | |
| 99 | ||
| 100 | test("someone not named is offered nothing", async () => { | |
| 101 | const t = boot("bob"); | |
| 102 | await t.palette(); | |
| 103 | expect(t.text()).not.toContain("Acme"); | |
| 104 | expect(t.text()).not.toContain("real off switch"); | |
| 105 | t.stop(); | |
| 106 | }); | |
| 107 | }); |
new above
offline
High: an admin who is not a member gets not_found here, so the documented 'an admin deletes the key early' is false and the real in-forge off switch is unavailable to the admin. Allow admin before the isMember check (and test it).