crewbus 10.0.11 → 10.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/lib/web.js CHANGED
@@ -13,6 +13,7 @@
13
13
  // monolith lines ~692-1010) — export crew must add them for web.js to link.
14
14
 
15
15
  import fs from "node:fs";
16
+ import { spawn } from "node:child_process";
16
17
  import path from "node:path";
17
18
  import http from "node:http";
18
19
  import { fileURLToPath } from "node:url";
@@ -786,7 +787,6 @@ details.tech-details summary{cursor:pointer;font-weight:500;user-select:none}
786
787
  <span class="dim" style="margin-left:8px">Coordinator:</span>
787
788
  <select id="launch-lead" style="background:var(--panel);color:var(--ink);border:1px solid var(--line);border-radius:4px;padding:3px 8px;font-size:12px" title="Observer coordinator lane: auto provisions a persistent background coordinator (lead) to triage workers and report to you">
788
789
  <option value="auto">auto (Observer coordinator)</option>
789
- <option value="none">none (direct to me)</option>
790
790
  </select>
791
791
  <label class="dim" style="cursor:pointer;margin-left:6px"><input id="launch-dry" type="checkbox" checked> Dry-run</label>
792
792
  </div>
@@ -1657,7 +1657,7 @@ function paletteActivate(m){
1657
1657
  else if(m.action==='openfolder'){document.getElementById('open-folder-btn').click();}
1658
1658
  else if(m.action==='pairmobile'){
1659
1659
  try{window.parent.postMessage({type:'crewbus:open-pair', dashboard: location.origin},'*');}catch(_){}
1660
- try{window.open('./pair.html','_blank','width=420,height=560');}catch(_){}
1660
+ try{window.open('/pair','_blank','width=420,height=560');}catch(_){}
1661
1661
  }
1662
1662
  else if(m.action==='refresh'){refresh();}
1663
1663
  else if(m.action==='installcli'){document.getElementById('pop-install-cli-btn').click();}
@@ -1889,7 +1889,7 @@ document.getElementById('copy-board-btn').onclick=copyBoardPath;
1889
1889
  var ppb=document.getElementById('pop-pair-btn');
1890
1890
  if(ppb){ppb.onclick=function(){
1891
1891
  try{window.parent.postMessage({type:'crewbus:open-pair', dashboard: location.origin},'*');}catch(_){}
1892
- try{window.open('./pair.html','_blank','width=420,height=560');}catch(_){}
1892
+ try{window.open('/pair','_blank','width=420,height=560');}catch(_){}
1893
1893
  };}
1894
1894
  var picb=document.getElementById('pop-install-cli-btn');
1895
1895
  if(picb){picb.onclick=async function(){
@@ -2107,7 +2107,215 @@ export const readKillBody = (req) =>
2107
2107
 
2108
2108
  // Shared web dashboard API routes for both `crewbus web` and `crewbus serve`
2109
2109
  // (embedded Tauri webview). Returns true if the route was handled, false otherwise.
2110
+
2111
+ let _qrSrc = null;
2112
+ function getQrSrc() {
2113
+ if (_qrSrc === null) {
2114
+ try {
2115
+ _qrSrc = fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "qrcode.js"), "utf8");
2116
+ } catch {
2117
+ _qrSrc = "";
2118
+ }
2119
+ }
2120
+ return _qrSrc;
2121
+ }
2122
+
2123
+ export function renderPairHtml(root) {
2124
+ const qrCodeSrc = getQrSrc();
2125
+ return `<!DOCTYPE html>
2126
+ <html lang="en">
2127
+ <head>
2128
+ <meta charset="utf-8">
2129
+ <meta name="viewport" content="width=device-width, initial-scale=1">
2130
+ <title>Pair Mobile Client — CrewBus</title>
2131
+ <script>
2132
+ try{var __t=null;try{__t=localStorage.getItem('crewbus-theme')||localStorage.getItem('crewbus-desktop-theme');}catch(_){}if(__t==='light'||__t==='dark'){document.documentElement.setAttribute('data-theme',__t);}}catch(_){}
2133
+ </script>
2134
+ <style>
2135
+ :root{
2136
+ --bg:#f4f6f3;
2137
+ --panel:#ffffff;
2138
+ --ink:#14201a;
2139
+ --dim:#5b6a62;
2140
+ --acc:#5b6a62;
2141
+ --acc-ink:#ffffff;
2142
+ --warn:#b86e00;
2143
+ --line:#d5ddd7;
2144
+ --scroll:rgba(0,0,0,.18);
2145
+ --scroll-hi:rgba(0,0,0,.32);
2146
+ --danger:#f85149;
2147
+ --danger-bg:rgba(248,81,73,0.12);
2148
+ --ok:#3d8f66;
2149
+ }
2150
+ @media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
2151
+ --bg:#0f1419;--panel:#182028;--ink:#e3e9ee;--dim:#8b98a5;--acc:#8b98a5;--acc-ink:#07130d;--warn:#ffb454;--line:#2a343e;
2152
+ --scroll:rgba(255,255,255,.16);
2153
+ --scroll-hi:rgba(255,255,255,.32);
2154
+ --ok:#4fb07f;
2155
+ }}
2156
+ :root[data-theme="light"]{--bg:#f4f6f3;--panel:#ffffff;--ink:#14201a;--dim:#5b6a62;--acc:#5b6a62;--acc-ink:#ffffff;--warn:#b86e00;--line:#d5ddd7;--scroll:rgba(0,0,0,.18);--scroll-hi:rgba(0,0,0,.32);--ok:#3d8f66}
2157
+ :root[data-theme="dark"]{--bg:#0f1419;--panel:#182028;--ink:#e3e9ee;--dim:#8b98a5;--acc:#8b98a5;--acc-ink:#07130d;--warn:#ffb454;--line:#2a343e;--scroll:rgba(255,255,255,.16);--scroll-hi:rgba(255,255,255,.32);--ok:#4fb07f}
2158
+ * {
2159
+ box-sizing:border-box;
2160
+ scrollbar-width: thin;
2161
+ scrollbar-color: var(--scroll) transparent;
2162
+ }
2163
+ body{margin:0;background:var(--bg);color:var(--ink);font:13px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;padding:20px}
2164
+ h2{margin:0 0 6px;font-size:17px;font-weight:700;color:var(--ink)}
2165
+ .dim{color:var(--dim);font-size:12px;line-height:1.4}
2166
+ #qr-wrap{width:220px;height:220px;margin:16px auto;border:1px solid var(--line);background:var(--panel);border-radius:12px;display:flex;align-items:center;justify-content:center;text-align:center;padding:10px;overflow:hidden}
2167
+ #qr-wrap svg{width:100%;height:100%;display:block;border-radius:6px}
2168
+ #qr{color:var(--dim);font-size:12px}
2169
+ textarea{width:100%;background:var(--panel);border:1px solid var(--line);color:var(--ink);border-radius:8px;padding:8px 10px;font-size:12px;resize:vertical;font-family:monospace}
2170
+ textarea:focus{border-color:var(--acc);outline:none}
2171
+ .btn-row{display:flex;gap:8px;margin-top:10px}
2172
+ button{background:var(--panel);border:1px solid var(--line);color:var(--ink);border-radius:6px;padding:7px 14px;font-size:12px;font-weight:600;cursor:pointer;transition:all .15s}
2173
+ button:hover{border-color:var(--acc);color:var(--acc)}
2174
+ button.primary{background:var(--acc);border-color:var(--acc);color:var(--acc-ink)}
2175
+ button.primary:hover{filter:brightness(1.1)}
2176
+ #msg{min-height:1.5em;margin-top:10px;font-size:12px}
2177
+ .warn{color:var(--danger)}
2178
+ .ok{color:var(--ok)}
2179
+ </style>
2180
+ </head>
2181
+ <body>
2182
+ <h2>Pair Mobile Client</h2>
2183
+ <p class="dim">A one-time pairing link is minted automatically from the local
2184
+ board — scan the QR with CrewBus Mobile. (Advanced: paste a
2185
+ <code>crewbus://pair</code> URL from <code>relay pair qr</code> or
2186
+ <code>serve --pair-qrcode</code> to render it instead.)</p>
2187
+
2188
+ <div id="qr-wrap">
2189
+ <div id="qr" aria-label="pairing QR">QR code will appear here after rendering</div>
2190
+ </div>
2191
+
2192
+ <label class="dim" for="pair-url">Pairing URL (in-memory only, secret in #fragment never saved):</label>
2193
+ <textarea id="pair-url" rows="3" placeholder="crewbus://pair?env=…&amp;routes=…&amp;caps=…#abp-…"></textarea>
2194
+
2195
+ <div class="btn-row">
2196
+ <button id="pair-render" class="primary">Render QR</button>
2197
+ <button id="pair-clear">Clear</button>
2198
+ </div>
2199
+
2200
+ <div id="msg" class="dim" role="status"></div>
2201
+ <script type="module">
2202
+ ${qrCodeSrc}
2203
+
2204
+ var box = document.getElementById('pair-url');
2205
+ var qr = document.getElementById('qr');
2206
+ var qrWrap = document.getElementById('qr-wrap') || (qr ? qr.parentElement : null);
2207
+ var msg = document.getElementById('msg');
2208
+ var renderBtn = document.getElementById('pair-render');
2209
+ var clearBtn = document.getElementById('pair-clear');
2210
+
2211
+ function say(t, isErr) {
2212
+ if (!msg) return;
2213
+ msg.textContent = t;
2214
+ msg.className = isErr ? 'warn' : 'ok';
2215
+ }
2216
+
2217
+ function qrThemeColors() {
2218
+ var theme = null;
2219
+ try { theme = localStorage.getItem('crewbus-theme') || localStorage.getItem('crewbus-desktop-theme'); } catch (_) {}
2220
+ if (theme !== 'light' && theme !== 'dark') {
2221
+ try { theme = document.documentElement.getAttribute('data-theme'); } catch (_) {}
2222
+ }
2223
+ if (theme !== 'light' && theme !== 'dark') {
2224
+ try { theme = (window.matchMedia && window.matchMedia('(prefers-color-scheme:dark)').matches) ? 'dark' : 'light'; }
2225
+ catch (_) { theme = 'light'; }
2226
+ }
2227
+ if (theme === 'dark') return { dark: '#e3e9ee', light: '#182028' };
2228
+ return { dark: '#14201a', light: '#ffffff' };
2229
+ }
2230
+
2231
+ function validatePairUrl(raw) {
2232
+ var s = String(raw == null ? '' : raw).trim();
2233
+ if (!s.startsWith('crewbus://pair')) throw new Error('not a crewbus pair URL');
2234
+ var u = new URL(s);
2235
+ for (var p of u.searchParams) {
2236
+ var k = p[0].toLowerCase();
2237
+ var v = p[1];
2238
+ if (['secret', 'token', 'pairtoken', 'pair_token', 'pair-token', 'credential'].indexOf(k) !== -1 || v.startsWith('abp-')) {
2239
+ throw new Error('pairing secret in query — secrets travel in #fragment only');
2240
+ }
2241
+ }
2242
+ var frag = u.hash ? decodeURIComponent(u.hash.slice(1)) : '';
2243
+ if (!frag) throw new Error('missing #fragment pairing secret');
2244
+ if (!frag.startsWith('abp-')) throw new Error('fragment is not a pairing secret (want abp-...)');
2245
+ return { env: u.searchParams.get('env') || '(local)', pairToken: frag };
2246
+ }
2247
+
2248
+ function describeForDisplay(u) {
2249
+ return String(u).split('#')[0];
2250
+ }
2251
+
2252
+ function clearAll() {
2253
+ if (box) box.value = '';
2254
+ if (qrWrap) qrWrap.innerHTML = '<div id="qr" aria-label="pairing QR">QR code will appear here after rendering</div>';
2255
+ qr = document.getElementById('qr');
2256
+ say('');
2257
+ }
2258
+
2259
+ function renderUrl(raw) {
2260
+ var parsed = validatePairUrl(raw);
2261
+ var svg = renderQrSvg(raw.trim(), {
2262
+ width: 200,
2263
+ margin: 1,
2264
+ color: qrThemeColors(),
2265
+ });
2266
+ if (qrWrap) qrWrap.innerHTML = svg;
2267
+ say('QR code ready for ' + describeForDisplay(raw) + ' — scan with CrewBus Mobile.');
2268
+ }
2269
+
2270
+ if (renderBtn) {
2271
+ renderBtn.addEventListener('click', function () {
2272
+ var raw = box ? box.value : '';
2273
+ if (!raw.trim()) { say('paste a pair URL first', true); return; }
2274
+ try {
2275
+ renderUrl(raw);
2276
+ } catch (e) {
2277
+ say('rejected: ' + String((e && e.message) || e), true);
2278
+ }
2279
+ });
2280
+ }
2281
+
2282
+ if (clearBtn) {
2283
+ clearBtn.addEventListener('click', clearAll);
2284
+ }
2285
+
2286
+ async function autoMint() {
2287
+ say('minting a one-time pairing link…');
2288
+ try {
2289
+ var r = await fetch('/api/pair-qr', { method: 'POST' });
2290
+ var j = null;
2291
+ try { j = await r.json(); } catch (_) {}
2292
+ if (!r.ok || !j || !j.ok || !j.pairUrl) {
2293
+ say('auto-mint failed (' + (j && j.error ? j.error : ('HTTP ' + r.status)) + ') — paste a pair URL manually', true);
2294
+ return;
2295
+ }
2296
+ if (box) box.value = j.pairUrl;
2297
+ renderUrl(j.pairUrl);
2298
+ var exp = j.expiresAt ? new Date(j.expiresAt) : null;
2299
+ say('QR ready — scan with CrewBus Mobile.' + (exp ? ' Link expires ' + exp.toLocaleTimeString() + ' (single-use).' : ''));
2300
+ } catch (e) {
2301
+ say('auto-mint failed: ' + String((e && e.message) || e) + ' — paste a pair URL manually', true);
2302
+ }
2303
+ }
2304
+
2305
+ autoMint();
2306
+ </script>
2307
+ </body>
2308
+ </html>`;
2309
+ }
2310
+
2110
2311
  export async function handleWebDashboardRoute(req, res, url, d) {
2312
+ if (req.method === "GET" && url.pathname === "/pair") {
2313
+ const body = renderPairHtml(d.root);
2314
+ res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
2315
+ res.end(body);
2316
+ return true;
2317
+ }
2318
+
2111
2319
  if (req.method === "GET" && url.pathname === "/api/board") {
2112
2320
  const body = JSON.stringify(boardSnapshot(d, 300));
2113
2321
  res.writeHead(200, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
@@ -2484,6 +2692,12 @@ export async function cmdWeb(args) {
2484
2692
  res.end(body);
2485
2693
  return;
2486
2694
  }
2695
+ if (req.method === "GET" && url.pathname === "/pair") {
2696
+ const body = renderPairHtml(d.root);
2697
+ res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
2698
+ res.end(body);
2699
+ return;
2700
+ }
2487
2701
  res.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
2488
2702
  res.end("not found (try / or /api/board /api/fleet /api/channels /api/results /api/audit /api/holds /api/quotas /api/inbox /api/harnesses /api/routes)");
2489
2703
  } catch (e) {
@@ -2499,7 +2713,15 @@ export async function cmdWeb(args) {
2499
2713
  server.listen(port, host, () => {
2500
2714
  const a = server.address();
2501
2715
  const shown = a && typeof a === "object" ? `${a.address}:${a.port}` : `${host}:${port}`;
2502
- console.log(`crewbus web at http://${shown} [board ${d.root}]`);
2716
+ const webUrl = `http://${shown}`;
2717
+ console.log(`crewbus web at ${webUrl} [board ${d.root}]`);
2718
+ if (args.includes("--open")) {
2719
+ try {
2720
+ if (process.platform === "win32") spawn("cmd.exe", ["/c", "start", webUrl], { detached: true, stdio: "ignore" }).unref();
2721
+ else if (process.platform === "darwin") spawn("open", [webUrl], { detached: true, stdio: "ignore" }).unref();
2722
+ else spawn("xdg-open", [webUrl], { detached: true, stdio: "ignore" }).unref();
2723
+ } catch {}
2724
+ }
2503
2725
  resolve();
2504
2726
  });
2505
2727
  });
@@ -2562,15 +2784,11 @@ export async function handleApiLaunch(d, body) {
2562
2784
  if (!v.ok) return { status: 400, payload: { error: "launch plan invalid", errors: v.errors, warnings: v.warnings } };
2563
2785
  const p = v.plan;
2564
2786
  const harnesses = Array.isArray(p.harnesses) && p.harnesses.length > 0 ? p.harnesses : [p.harness || "opencode"];
2565
- const hasCodingHarness = harnesses.some((h) => h !== "generic");
2566
- let leadMode = p.lead || "auto";
2567
- if (leadMode === "auto") {
2568
- leadMode = hasCodingHarness ? "board" : "none";
2569
- }
2570
- if (leadMode === "board" && !hasCodingHarness) {
2571
- return { status: 400, payload: { error: 'lead "board" needs a coding harness for the auto-coordinator (add a harness like opencode, or use lead "none")' } };
2787
+ const leadMode = p.lead || "auto";
2788
+ if (leadMode !== "auto") {
2789
+ return { status: 400, payload: { error: `invalid lead mode "${p.lead}" (only "auto" supported)` } };
2572
2790
  }
2573
- const leadTarget = leadMode === "board" ? LEAD_NAME : from;
2791
+ const leadTarget = LEAD_NAME;
2574
2792
  const names = p.to ? String(p.to).split(",").map((s) => cleanWebName(s)).filter(Boolean)
2575
2793
  : Array.from({ length: p.count }, (_, i) => `${cleanWebName(p.prefix || "w") || "w"}-${i + 1}`);
2576
2794
  if (names.length === 0) return { status: 400, payload: { error: "no worker names (pass to or count)" } };
@@ -2579,16 +2797,13 @@ export async function handleApiLaunch(d, body) {
2579
2797
  let cwdOk = false;
2580
2798
  try { cwdOk = fs.statSync(cwd).isDirectory(); } catch {}
2581
2799
  if (!cwdOk) return { status: 400, payload: { error: `cwd is not a directory: ${cwd}` } };
2582
- if (harnesses.includes("generic") && !(body && body.cmd && String(body.cmd).trim())) {
2583
- return { status: 400, payload: { error: 'generic harness needs cmd "..."' } };
2584
- }
2585
2800
  if (v.plan.dryRun) {
2586
2801
  const previewBatch = names.length > 1 ? newId("batch") : undefined;
2587
2802
  const rows = names.map((to, i) => {
2588
2803
  const driver = harnesses[i % harnesses.length];
2589
2804
  const previewPrompt = buildSpawnPrompt({ name: to, from, lead: leadTarget, subject: p.subject, body: p.body.trim(), replyId: previewBatch ? `${previewBatch}-${i + 1}` : "msg-<id>", rev, cwd, root: d.root });
2590
2805
  const t = buildSpawnTarget({
2591
- harness: driver, cmd: body && body.cmd ? String(body.cmd) : undefined, model: p.model,
2806
+ harness: driver, model: p.model,
2592
2807
  auto: p.permission === "auto" || p.permission === "full" ? true : undefined,
2593
2808
  maxTurns: p.maxTurns, allowTools: p.allowTools, cwd,
2594
2809
  name: to, promptPath: path.join("<board>", "logs", `${to}-<stamp>.prompt.md`), prompt: previewPrompt,
@@ -2596,7 +2811,7 @@ export async function handleApiLaunch(d, body) {
2596
2811
  return { to, harness: driver, command: formatSpawnCmd(t) };
2597
2812
  });
2598
2813
  let coordinator = undefined;
2599
- if (leadMode === "board") {
2814
+ if (leadMode === "auto") {
2600
2815
  const existingLead = readAgent(d, LEAD_NAME);
2601
2816
  // Stale-pid guard (C2): reuse only a live, non-stale coordinator; a
2602
2817
  // pid-recycled after reboot record gets the fresh-provision branch.
@@ -2606,7 +2821,7 @@ export async function handleApiLaunch(d, body) {
2606
2821
  } else if (existingLead && existingLead.offboarded) {
2607
2822
  coordinator = { name: LEAD_NAME, action: "skipped", reason: "lane is offboarded" };
2608
2823
  } else {
2609
- const coordDriver = harnesses.find((h) => h !== "generic") || "opencode";
2824
+ const coordDriver = harnesses[0] || "opencode";
2610
2825
  const previewCoordPrompt = buildCoordinatorPrompt({
2611
2826
  name: LEAD_NAME, from, subject: p.subject, body: p.body.trim(), batch: previewBatch,
2612
2827
  workers: names.map((name, i) => ({ name, id: previewBatch ? `${previewBatch}-${i + 1}` : "msg-<id>", harness: harnesses[i % harnesses.length] })),
@@ -2644,8 +2859,8 @@ export async function handleApiLaunch(d, body) {
2644
2859
  }
2645
2860
  }
2646
2861
  let coordinator = undefined;
2647
- if (leadMode === "board") {
2648
- const coordHarness = harnesses.find((h) => h !== "generic") || "opencode";
2862
+ if (leadMode === "auto") {
2863
+ const coordHarness = harnesses[0] || "opencode";
2649
2864
  const coordSpawnOpts = { harness: coordHarness, cmd: body && body.cmd ? String(body.cmd) : undefined, model: p.model, auto, cwd, root: d.root, prompt: null };
2650
2865
  try {
2651
2866
  coordinator = provisionAutoLead(d, {
@@ -1,120 +1,120 @@
1
- # Cert-readiness checklist
2
-
3
- Control-by-control mapping of common audit expectations to what the product
4
- implements (with exact commands/flags) and what remains a customer runbook
5
- item. Statuses: **done** (in the tree, covered by `npm test`), **manual**
6
- (stub runbook below — your cadence, your evidence).
7
-
8
- ## 1. Access control (RBAC)
9
-
10
- - [done] Roles + authorization gates: `agents`, `role-grant`, privileged
11
- ops gated by `authorize()` (`prune`, `acl-set`, `role-grant`, `offboard`,
12
- `group-restrict`, `serve-remote`, `import`, `snapshot-schedule`,
13
- `quota-set`, `hold-place`, `hold-lift`). See `docs/RBAC.md`.
14
- - [done] Default-deny remote spawn/kill: `serve` without
15
- `--allow-remote-spawn` answers 403; `--allow-cmd` regex constrains remote
16
- `--cmd`; `--workdir-root` constrains remote cwd.
17
- - [done] Standby replicas refuse writes: `serve --standby` answers 503 +
18
- `X-Relay-Role: standby` on `POST /sync/put`, `/api/spawn`, `/api/kill`.
19
- See `docs/HA.md`.
20
- - [manual] **Access-review cadence (quarterly stub):** run `agents --json`,
21
- confirm each identity still needs its role, `offboard` leavers
22
- (`register --offboard <name> --from <admin>` preserves inbox for audit),
23
- record the review date + reviewer. Evidence: the signed `role-grant` /
24
- `offboard` events in the log.
25
-
26
- ## 2. Authentication
27
-
28
- - [done] Per-identity tokens: first claim mints (`register --from <you>`
29
- prints `abt-…` once), afterwards `--token` / `CREWBUS_TOKEN` required;
30
- only salted hashes stored; `token rotate`, `token status`, `token revoke`
31
- (revocations sync, never resurrected). Service accounts:
32
- `register --service <name>`; expiry: `register --expires-in 30/90s/15m/
33
- 24h/7d`.
34
- - [done] OIDC: `login --issuer <url> --client-id <id> --token <jwt>` binds
35
- `oidc-<sub>`; relays accept Bearer with
36
- `serve --oidc-issuer <url> [--oidc-audience <id>]`; `sync`/`listen` send
37
- it via `--bearer` / `--oidc-token`. See `docs/OIDC_TLS.md`.
38
- - [done] Relay secret: `--secret` / `CREWBUS_SECRET` via
39
- `x-crewbus-secret` / `?secret=` (constant-time compare); remote serve
40
- without one refuses + warns.
41
- - [manual] **Credential-lifecycle schedule (stub):** rotate service-account
42
- tokens every N days (`token rotate --from <svc>`), rotate the relay
43
- secret on staff changes (restart relays), expire IdP clients for leavers.
44
- Evidence: `token status` output + signed rotation events.
45
-
46
- ## 3. Encryption
47
-
48
- - [done] In transit: in-box TLS `serve --tls-cert <pem> --tls-key <pem>`;
49
- mTLS on `/sync/*` with `--tls-ca` / `--mtls-ca`; outbound
50
- `--mtls-cert`/`--mtls-key`; plain-HTTP-behind-terminator stays supported.
51
- See `docs/OIDC_TLS.md`.
52
- - [done] At rest (backups): `board export` encrypts AES-256-GCM
53
- (32-byte hex/base64 used raw, else scrypt + random salt in the header);
54
- GCM tag verified *before* any byte is written on `import`; secrets
55
- stripped unless `--include-secrets` (loud warning).
56
- - [manual] **Key-rotation schedule (stub):** rotate backup keys yearly (or
57
- on incident): set the new `CREWBUS_BACKUP_KEY`, take a fresh export,
58
- verify `board import --into <fresh-dir>` decrypts, retire the old key in
59
- the vault. Evidence: dated exports + restore-drill log (below).
60
-
61
- ## 4. Audit logging
62
-
63
- - [done] Hash-chained tamper-evident log (`logs/chain.jsonl` for CLI ops,
64
- `logs/audit.jsonl` for relay ops); per-event HMAC signatures;
65
- `log [--audit] [--verify] [--limit 50]` verifies chain + sigs.
66
- - [done] SIEM export: versioned `v:1` envelope
67
- (`seq/at/actor/role/action/target/board/result/prevHash/sig`, `sig` =
68
- 64-hex HMAC); `serve --audit-forward <https-url>
69
- [--audit-forward-key <bearer>]` POSTs off-box with an `audit-spool/`
70
- at-least-once retry queue that drains (never blocks the relay path).
71
- See `docs/AUDIT_EXPORT.md`.
72
- - [done] Legal holds: `hold place --from <admin> [--reason]` /
73
- `hold lift` / `hold status`; `prune` (and `import` over a held board)
74
- refuse while held; hold record syncs to peers.
75
- - [manual] **Log-review + retention (stub):** forward to your SIEM, alert
76
- on `audit-spool/` growth (forwarder down), review privileged actions
77
- (`role-grant`, `offboard`, `hold-*`, `import`, `quota-set`) weekly,
78
- retain per your policy (`prune --older-than` only when no hold).
79
- Evidence: SIEM queries + `log --verify` output.
80
-
81
- ## 5. Backup
82
-
83
- - [done] Portable encrypted backups (`board export --from <admin|auditor>
84
- --out <file>`), safe restore (`board import --force` semantics + hold
85
- interaction), declarative schedules (`snapshot schedule --from <admin>
86
- --every 24h --keep 7 --out-dir <dir>`), `snapshot run` for cron/systemd/
87
- Task Scheduler, quotas/tenancy (`quota set/show`, `storage`, separate
88
- boards per tenant). See `docs/TENANCY.md`.
89
- - [manual] **Restore-drill runbook (quarterly stub):**
90
- 1. `board export --from <admin> --out /offsite/drill-<date>.abbackup.json`
91
- 2. `board import --in /offsite/drill-<date>.abbackup.json --into <fresh-dir> --force`
92
- 3. `gather`/inbox spot-checks + `log --verify` on the restored board
93
- 4. Record date, operator, result. Evidence: the drill log + restored-board
94
- `log --verify` output.
95
-
96
- ## 6. Incident response hooks
97
-
98
- - [done] Kill switches: `spawn-kill --to <w,…> | --all`, `stop --all
99
- --from <you>`, remote `/api/kill` (token-checked, RBAC matrix = CLI).
100
- - [done] Containment: `offboard` (tokens die now, inbox preserved),
101
- `token revoke`, `hold place` (freeze destructive retention), standby
102
- promotion path (`relay promote`, `/healthz`; see `docs/HA.md`).
103
- - [done] Evidence capture: `board export` (encrypted), `log --verify`,
104
- SIEM stream, `relay status --json` + `/healthz` snapshots.
105
- - [manual] **IR runbook stub:** detect (SIEM alert / spool growth / anomalous
106
- `agents --active`), contain (offboard + revoke + hold), preserve
107
- (export before prune), recover (promote standby / restore import),
108
- review (access review + key rotation out of cycle). Assign owners and a
109
- severity scale; rehearse with the restore drill above.
110
-
111
- ## Auditor evidence index (where to look)
112
-
113
- | Artifact | Produces |
114
- |---|---|
115
- | `log --verify` | chain + signature validity (first-broken-seq on tamper) |
116
- | SIEM receiver | `v:1` envelopes (`role`, `authMethod`, `board`, `sig`) |
117
- | `holds/legal.json` + `hold status` | hold provenance (placer, reason, time) |
118
- | `quota show` / `storage --json` | tenant label + limit-vs-actual |
119
- | `relay status --json` / `/healthz` | HA role, lag, promotion history |
120
- | `board export` envelope | `{manifest, files[]}` + algo/kdf header |
1
+ # Cert-readiness checklist
2
+
3
+ Control-by-control mapping of common audit expectations to what the product
4
+ implements (with exact commands/flags) and what remains a customer runbook
5
+ item. Statuses: **done** (in the tree, covered by `npm test`), **manual**
6
+ (stub runbook below — your cadence, your evidence).
7
+
8
+ ## 1. Access control (RBAC)
9
+
10
+ - [done] Roles + authorization gates: `agents`, `role-grant`, privileged
11
+ ops gated by `authorize()` (`prune`, `acl-set`, `role-grant`, `offboard`,
12
+ `group-restrict`, `serve-remote`, `import`, `snapshot-schedule`,
13
+ `quota-set`, `hold-place`, `hold-lift`). See `docs/RBAC.md`.
14
+ - [done] Default-deny remote spawn/kill: `serve` without
15
+ `--allow-remote-spawn` answers 403; `--allow-cmd` regex constrains remote
16
+ `--cmd`; `--workdir-root` constrains remote cwd.
17
+ - [done] Standby replicas refuse writes: `serve --standby` answers 503 +
18
+ `X-Relay-Role: standby` on `POST /sync/put`, `/api/spawn`, `/api/kill`.
19
+ See `docs/HA.md`.
20
+ - [manual] **Access-review cadence (quarterly stub):** run `agents --json`,
21
+ confirm each identity still needs its role, `offboard` leavers
22
+ (`register --offboard <name> --from <admin>` preserves inbox for audit),
23
+ record the review date + reviewer. Evidence: the signed `role-grant` /
24
+ `offboard` events in the log.
25
+
26
+ ## 2. Authentication
27
+
28
+ - [done] Per-identity tokens: first claim mints (`register --from <you>`
29
+ prints `abt-…` once), afterwards `--token` / `CREWBUS_TOKEN` required;
30
+ only salted hashes stored; `token rotate`, `token status`, `token revoke`
31
+ (revocations sync, never resurrected). Service accounts:
32
+ `register --service <name>`; expiry: `register --expires-in 30/90s/15m/
33
+ 24h/7d`.
34
+ - [done] OIDC: `login --issuer <url> --client-id <id> --token <jwt>` binds
35
+ `oidc-<sub>`; relays accept Bearer with
36
+ `serve --oidc-issuer <url> [--oidc-audience <id>]`; `sync`/`listen` send
37
+ it via `--bearer` / `--oidc-token`. See `docs/OIDC_TLS.md`.
38
+ - [done] Relay secret: `--secret` / `CREWBUS_SECRET` via
39
+ `x-crewbus-secret` / `?secret=` (constant-time compare); remote serve
40
+ without one refuses + warns.
41
+ - [manual] **Credential-lifecycle schedule (stub):** rotate service-account
42
+ tokens every N days (`token rotate --from <svc>`), rotate the relay
43
+ secret on staff changes (restart relays), expire IdP clients for leavers.
44
+ Evidence: `token status` output + signed rotation events.
45
+
46
+ ## 3. Encryption
47
+
48
+ - [done] In transit: in-box TLS `serve --tls-cert <pem> --tls-key <pem>`;
49
+ mTLS on `/sync/*` with `--tls-ca` / `--mtls-ca`; outbound
50
+ `--mtls-cert`/`--mtls-key`; plain-HTTP-behind-terminator stays supported.
51
+ See `docs/OIDC_TLS.md`.
52
+ - [done] At rest (backups): `board export` encrypts AES-256-GCM
53
+ (32-byte hex/base64 used raw, else scrypt + random salt in the header);
54
+ GCM tag verified *before* any byte is written on `import`; secrets
55
+ stripped unless `--include-secrets` (loud warning).
56
+ - [manual] **Key-rotation schedule (stub):** rotate backup keys yearly (or
57
+ on incident): set the new `CREWBUS_BACKUP_KEY`, take a fresh export,
58
+ verify `board import --into <fresh-dir>` decrypts, retire the old key in
59
+ the vault. Evidence: dated exports + restore-drill log (below).
60
+
61
+ ## 4. Audit logging
62
+
63
+ - [done] Hash-chained tamper-evident log (`logs/chain.jsonl` for CLI ops,
64
+ `logs/audit.jsonl` for relay ops); per-event HMAC signatures;
65
+ `log [--audit] [--verify] [--limit 50]` verifies chain + sigs.
66
+ - [done] SIEM export: versioned `v:1` envelope
67
+ (`seq/at/actor/role/action/target/board/result/prevHash/sig`, `sig` =
68
+ 64-hex HMAC); `serve --audit-forward <https-url>
69
+ [--audit-forward-key <bearer>]` POSTs off-box with an `audit-spool/`
70
+ at-least-once retry queue that drains (never blocks the relay path).
71
+ See `docs/AUDIT_EXPORT.md`.
72
+ - [done] Legal holds: `hold place --from <admin> [--reason]` /
73
+ `hold lift` / `hold status`; `prune` (and `import` over a held board)
74
+ refuse while held; hold record syncs to peers.
75
+ - [manual] **Log-review + retention (stub):** forward to your SIEM, alert
76
+ on `audit-spool/` growth (forwarder down), review privileged actions
77
+ (`role-grant`, `offboard`, `hold-*`, `import`, `quota-set`) weekly,
78
+ retain per your policy (`prune --older-than` only when no hold).
79
+ Evidence: SIEM queries + `log --verify` output.
80
+
81
+ ## 5. Backup
82
+
83
+ - [done] Portable encrypted backups (`board export --from <admin|auditor>
84
+ --out <file>`), safe restore (`board import --force` semantics + hold
85
+ interaction), declarative schedules (`snapshot schedule --from <admin>
86
+ --every 24h --keep 7 --out-dir <dir>`), `snapshot run` for cron/systemd/
87
+ Task Scheduler, quotas/tenancy (`quota set/show`, `storage`, separate
88
+ boards per tenant). See `docs/TENANCY.md`.
89
+ - [manual] **Restore-drill runbook (quarterly stub):**
90
+ 1. `board export --from <admin> --out /offsite/drill-<date>.abbackup.json`
91
+ 2. `board import --in /offsite/drill-<date>.abbackup.json --into <fresh-dir> --force`
92
+ 3. `gather`/inbox spot-checks + `log --verify` on the restored board
93
+ 4. Record date, operator, result. Evidence: the drill log + restored-board
94
+ `log --verify` output.
95
+
96
+ ## 6. Incident response hooks
97
+
98
+ - [done] Kill switches: `spawn-kill --to <w,…> | --all`, `stop --all
99
+ --from <you>`, remote `/api/kill` (token-checked, RBAC matrix = CLI).
100
+ - [done] Containment: `offboard` (tokens die now, inbox preserved),
101
+ `token revoke`, `hold place` (freeze destructive retention), standby
102
+ promotion path (`relay promote`, `/healthz`; see `docs/HA.md`).
103
+ - [done] Evidence capture: `board export` (encrypted), `log --verify`,
104
+ SIEM stream, `relay status --json` + `/healthz` snapshots.
105
+ - [manual] **IR runbook stub:** detect (SIEM alert / spool growth / anomalous
106
+ `agents --active`), contain (offboard + revoke + hold), preserve
107
+ (export before prune), recover (promote standby / restore import),
108
+ review (access review + key rotation out of cycle). Assign owners and a
109
+ severity scale; rehearse with the restore drill above.
110
+
111
+ ## Auditor evidence index (where to look)
112
+
113
+ | Artifact | Produces |
114
+ |---|---|
115
+ | `log --verify` | chain + signature validity (first-broken-seq on tamper) |
116
+ | SIEM receiver | `v:1` envelopes (`role`, `authMethod`, `board`, `sig`) |
117
+ | `holds/legal.json` + `hold status` | hold provenance (placer, reason, time) |
118
+ | `quota show` / `storage --json` | tenant label + limit-vs-actual |
119
+ | `relay status --json` / `/healthz` | HA role, lag, promotion history |
120
+ | `board export` envelope | `{manifest, files[]}` + algo/kdf header |