From 1a8dc33f189c5d1da915459c6fa836677f6e5b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 01:06:55 +0100 Subject: [PATCH 01/12] feat: anchor install, the service package hand-off (W7 T28a, PC-247) passioncode anchor install checks a service package as the person and hands it to macOS Installer, which alone asks for the administrator password: Gatekeeper on, SHA-256 against SHA256SUMS and a deployment manifest's pin, the GitHub build attestation, pkgutil's notarised Developer ID Installer signature of team KJ35UYYL22 to the Apple Root CA, spctl as a further check (it accepted a package with a flipped byte that pkgutil refused), and the package's embedded pin. Never sudo, never a password. Not in the help yet; not released. Co-Authored-By: Claude Opus 5.5 --- SECURITY.md | 13 ++ bin/passioncode.js | 24 ++- docs/backlog.md | 1 + .../handoffs/2026-11-25-w7-anchor-launcher.md | 39 ++++ lib/anchor.js | 196 ++++++++++++++++++ test/anchor.test.js | 134 ++++++++++++ test/fixtures/anchor/pkgutil-modified.txt | 2 + test/fixtures/anchor/pkgutil-unsigned.txt | 2 + .../fixtures/anchor/pkgutil-vendor-signed.txt | 23 ++ 9 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 docs/handoffs/2026-11-25-w7-anchor-launcher.md create mode 100644 lib/anchor.js create mode 100644 test/anchor.test.js create mode 100644 test/fixtures/anchor/pkgutil-modified.txt create mode 100644 test/fixtures/anchor/pkgutil-unsigned.txt create mode 100644 test/fixtures/anchor/pkgutil-vendor-signed.txt diff --git a/SECURITY.md b/SECURITY.md index a74580bb..7ec8f01c 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -140,6 +140,19 @@ with `--confirm-bypass`, which a program can pass, so the flag records a choice, `permissions allow`. `--by` records who the caller says asked; it is not authentication (PC-125). +## What `anchor install` touches + +`passioncode anchor install` (not in the help yet; a step of a guided install) checks a service package as the person +who runs it and then hands it to macOS's own Installer: Gatekeeper assessments must be on (`spctl --status`), the +package's SHA-256 must equal its line in the release's `SHA256SUMS` (and a deployment manifest's pin when one is given), +its GitHub build attestation must verify (`gh attestation verify`), and `pkgutil --check-signature` must read a +notarised Developer ID Installer signature of team `KJ35UYYL22` that chains to the Apple Root CA by its fingerprint. +`spctl -a -t install` is a further check only: it accepted a signed package with one byte changed, which `pkgutil` +refused (2026-11-25). The launcher refuses to run as root, never runs `sudo` and never reads or passes a password: +the password goes only into Installer's own prompt. It writes `~/.passioncode/brain-anchor.json` (the role, and the +organisation for an organisation space; nothing else) and opens Installer with `open -a Installer`. A failed check +writes nothing and opens nothing. + ## What anonymous counts send Each command sends, when it ends, the events listed in [docs/analytics-events.md](docs/analytics-events.md) to diff --git a/bin/passioncode.js b/bin/passioncode.js index 9e75a453..f3fb332d 100755 --- a/bin/passioncode.js +++ b/bin/passioncode.js @@ -252,7 +252,7 @@ function analyticsCommand(rest) { async function main(argv) { const [cmd = 'help', ...rest] = argv; if (cmd === 'permissions') return await permissionsCommand(rest); - if (cmd === 'analytics') return analyticsCommand(rest); + if (cmd === 'analytics') return analyticsCommand(rest); if (cmd === 'anchor') return await anchorCommand(rest); // W7 T28a: anchorCommand at the end if (cmd === 'setup' || cmd === 'onboard' || cmd === 'doctor') { try { return await setupOrDoctor(cmd === 'onboard' ? 'setup' : cmd, rest); } catch (error) { threw = true; @@ -359,3 +359,25 @@ main(argv).then(async (code) => { const errorCode = cmd === 'doctor' && !argv.includes('--fix') && !threw ? 'check-failed' : 'other'; await require('../lib/analytics').after({ command: cmd, code, errorCode, json: argv.includes('--json'), quiet: argv.includes('--quiet'), existing, startedAt, version: VERSION, state: L.paths().state }); }); + +// W7 T28a: `anchor install`, the service package hand-off (lib/anchor.js). Checks as the person, then macOS Installer asks +// for the password in its own prompt. Not in the help yet: it is a step of the owner's sitting, run with its runbook. +async function anchorCommand(rest) { + const A = require('../lib/anchor'); + const json = rest.includes('--json'); + const [verb, ...args] = rest.filter((a) => a !== '--json'); + const o = { dryRun: false }; + const names = { '--pkg': 'pkg', '--url': 'url', '--sums': 'sumsFile', '--deploy': 'deployFile', '--role': 'role', '--org': 'org' }; + for (let i = 0; i < args.length; i++) { + if (args[i] === '--dry-run') { o.dryRun = true; continue; } + const key = names[args[i]]; + if (!key || args[i + 1] === undefined || o[key] !== undefined) return usage('anchor install takes --pkg PATH --sums PATH | --url URL, [--deploy FILE] [--role person|owner|org-space] [--org ORG] [--dry-run] [--json]'); + o[key] = args[++i]; + } + if (verb !== 'install') return usage('anchor takes install'); + let r; + try { r = await A.anchor(o); } catch (error) { process.stderr.write(`passioncode: ${error.message}\n`); return 1; } + const lines = (r.checks || []).map((c) => `${c.ok ? 'ok ' : 'FAILED'} ${c.check.padEnd(16)} ${c.detail}`); + process.stdout.write(json ? JSON.stringify(r, null, 2) + '\n' : [...lines, r.message].join('\n') + '\n'); + return r.code; +} diff --git a/docs/backlog.md b/docs/backlog.md index 4bb340a3..20b0f40a 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -252,3 +252,4 @@ derives its common backlog from [backlog-sources.json](backlog-sources.json). | PC-244 | Pin Fabric `0.3.29` (Fabric Base 1) in `trains/fabric-base-1.json` once session 01 publishes it non-prerelease, and Dashboards `0.8.226` when tagged (A-APP-11 Lunch line); a launcher release | open 2026-11-24: waits on the fabric release (session 01) | base manifest `fabric-base-1.json` (fabric-workspace) | | PC-245 | The owner's MacBook to the base manifest: run the owner's line in [fabric-base-1-install.md](reference/fabric-base-1-install.md#the-owners-mac-a-app-11) on the MacBook (Inbox 1.7.1 to 1.9.2, adapter 0.102.0), done when `doctor` exits 0 and Inbox reads 1.9.2. The build machine cannot open a shell on the MacBook (SSH timed out, 2026-11-24; access runs only the other way), so a MacBook session or the owner runs it | open 2026-11-24: needs a process on the MacBook; 0.2.83 is on npm (`latest`, release run 45294028388 success), so the line runs as written | W2 session 06 | | PC-246 | `PC-163: the server end of this account's own connection reads \`own\` from the real socket table` (`test/listener.test.js`) fails on a build machine whose `netstat` prints no row for the server end of the test's own loopback connection (`table-restricted … netstat printed no table`); it fails the same on unchanged `origin/main` `df80ead` there, 2026-11-24. Make the test skip with its reason where the table is restricted, or read the table the way that machine allows | open 2026-11-24: P3 | W2 session 06, full `npm test` on `agent/w2-s06-base1-owner-mac` (681 of 687 pass, 2 fail: this one and a strings.md drift fixed in the same branch) | +| PC-247 | W7 T28a, the service package hand-off: `passioncode anchor install` (`lib/anchor.js`, `test/anchor.test.js`, SECURITY.md "What `anchor install` touches") checks a package as the person (Gatekeeper on, SHA256SUMS and a manifest pin, the build attestation, `pkgutil` signature of team `KJ35UYYL22` to the Apple Root CA, `spctl`, the embedded pin) and hands it to macOS Installer; never sudo. Left: a help line and strings.md rows when it ships, and a launcher release after the owner's sitting (T28d) proves it on the live package | open 2026-11-25: built on branch `w7-anchor-launcher-2026-11-25`, not merged, not released | Studio session 45 (W7 trust-anchor lane, thread `bb204715`); fabric-workspace `w7-anchor-2026-11-25` `tools/brain/anchor/` | diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md new file mode 100644 index 00000000..859ea62f --- /dev/null +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -0,0 +1,39 @@ +# Handoff: the service package hand-off on the launcher (W7 trust-anchor lane, Studio session 45), 2026-11-25 + +Objective: task T28a's launcher part: fetch the trust anchor's installer package, check it as the person and hand it +to macOS Installer, which alone asks for the administrator password. Program thread `bb204715`. Backlog row: PC-247 in +[docs/backlog.md](../backlog.md). The package, its workflow and its machine proof live in fabric-workspace, branch +`w7-anchor-2026-11-25`, `tools/brain/anchor/` (handoff `docs/handoffs/2026-11-25-w7-anchor-lane.md` there). + +## Done + +- `lib/anchor.js` and `passioncode anchor install --pkg PATH --sums PATH | --url URL [--deploy FILE] [--role + person|owner|org-space] [--org ORG] [--dry-run] [--json]` (dispatched from `bin/passioncode.js`, the function at the + file's end so no line a strings.md row cites moves). Checks in order: Gatekeeper on, SHA-256 against SHA256SUMS and + a deployment manifest's pin, `gh attestation verify` for `passioncode-ai/fabric-workspace`'s `brain-anchor.yml`, + `pkgutil --check-signature` (notarised, Developer ID Installer of `KJ35UYYL22`, Developer ID CA, Apple Root CA by + fingerprint, the manifest's certificate pin), `spctl -a -t install`, the embedded pin (shown; equal to the manifest's + tool tree hash when given). Then it writes `~/.passioncode/brain-anchor.json` and runs `open -a Installer`. +- SECURITY.md: "What `anchor install` touches". + +## Checks actually run + +- `node scripts/test.mjs test/anchor.test.js`: 15 of 15 (fixtures are real `pkgutil` outputs, `test/fixtures/anchor`; + one test builds an unsigned package with the real `pkgbuild` and sees the real `pkgutil` refuse it). +- Full `npm test` on this machine: 678 tests, 672 pass, 4 skipped, 1 fail: PC-163's socket-table test, the known PC-246 + failure of this build machine (fails the same on unchanged `origin/main`). `test/setup.test.js` was cut by the run's + time cap and ran again on its own (see the final report of the session). +- IP gate (`ip_gate.py scan --destination public:npm-passioncode`) on `lib/anchor.js`, the CLI lines and the SECURITY + section: pass. +- The same refusals on a real machine: fabric-workspace `tools/brain/anchor/evidence/2026-11-25-vm-acc.json` (the + unsigned, tampered, flipped-byte and other-team packages refused by the agents' user before any elevation). + +## Open + +- Not merged and not released (W7 runs on branches; a launcher release follows the owner's sitting, T28d). +- A help line and strings.md rows when the command ships to people. + +## The next task + +After T28d's first signed package exists: run `passioncode anchor install --url --dry-run` on the +MacBook as the owner, then merge this branch through a PR and release the launcher. diff --git a/lib/anchor.js b/lib/anchor.js new file mode 100644 index 00000000..69084aa5 --- /dev/null +++ b/lib/anchor.js @@ -0,0 +1,196 @@ +'use strict'; +/** + * The service package hand-off (`passioncode anchor`): fetch an installer package, check it as the person (never as + * root), and hand it to macOS's own Installer, which shows the administrator password prompt. The launcher never runs + * sudo, never reads or passes a password, and stops before the hand-off on the first failed check: + * 1. the machine: Gatekeeper assessments enabled (`spctl --status`); + * 2. the bytes: the package's SHA-256 equals its line in the release's SHA256SUMS, and the pinned value when a + * deployment manifest is given; + * 3. the build: the GitHub attestation of the package verifies for the expected repository and workflow; + * 4. the signature: `pkgutil --check-signature` reads signed by Apple for distribution, notarised, a Developer ID + * Installer certificate of the PassionCode.ai team, the Developer ID CA and the Apple Root CA by its fingerprint. + * `pkgutil` is required: `spctl -a -t install` alone accepted a signed package with a flipped byte (measured + * 2026-11-25), so it is a further check, never the only one; + * 5. the contents: the package's embedded pin is shown (its tree hash), and must equal the manifest's when given. + */ +const crypto = require('crypto'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const catalog = require('./catalog'); + +const ROOT_CA_SHA256 = 'B0B1730ECBC7FF4505142C49F1295E6EDA6BCAED7E2C68C5BE91B5A11001F024'; // Apple Root CA +const STATUS_OK = 'signed by a developer certificate issued by Apple for distribution'; +const NOTARY_OK = 'trusted by the Apple notary service'; +const REPO = 'passioncode-ai/fabric-workspace'; +const WORKFLOW = `${REPO}/.github/workflows/brain-anchor.yml`; +const ROLES = ['person', 'owner', 'org-space']; + +function defaultRun(cmd, args, opts) { return require('./releases').run(cmd, args, opts); } + +/** `pkgutil --check-signature` output: status, notarisation, and the certificate chain with SHA-256 fingerprints. */ +function parsePkgutil(text) { + const status = /^\s*Status:\s*(.+)$/m.exec(text); + const notary = /^\s*Notarization:\s*(.+)$/m.exec(text); + const chain = []; + const lines = text.split('\n'); + for (let i = 0; i < lines.length; i++) { + const m = /^\s*(\d+)\.\s+(.+?)\s*$/.exec(lines[i]); + if (!m) continue; + let j = i + 1; + while (j < lines.length && !/SHA256 Fingerprint:/.test(lines[j]) && !/^\s*\d+\.\s/.test(lines[j])) j++; + if (j >= lines.length || !/SHA256 Fingerprint:/.test(lines[j])) continue; + let hex = ''; + for (let k = j + 1; k < lines.length && /^\s+([0-9A-F]{2}\s?)+\s*$/.test(lines[k]); k++) hex += lines[k].replace(/\s+/g, ''); + chain.push({ n: Number(m[1]), name: m[2], sha256: hex }); + } + return { status: status ? status[1].trim() : null, notarization: notary ? notary[1].trim() : null, chain }; +} + +/** Null when the signature is the PassionCode.ai team's Developer ID Installer chain, else the reason. */ +function signatureProblem(text, { team = catalog.TEAM_ID, certSha256 = null } = {}) { + const p = parsePkgutil(text); + if (p.status !== STATUS_OK) return `signature: ${p.status || 'none'}`; + if (p.notarization !== NOTARY_OK) return `notarisation: ${p.notarization || 'none'}`; + if (p.chain.length !== 3) return `certificate chain of ${p.chain.length}, not leaf, Developer ID CA and Apple Root CA`; + const [leaf, mid, root] = p.chain; + if (!leaf.name.startsWith('Developer ID Installer:') || !leaf.name.endsWith(`(${team})`)) return `signed by ${leaf.name}, not a Developer ID Installer of team ${team}`; + if (mid.name !== 'Developer ID Certification Authority') return `intermediate ${mid.name}`; + if (root.name !== 'Apple Root CA' || root.sha256 !== ROOT_CA_SHA256) return 'the chain does not end at the Apple Root CA'; + if (certSha256 && leaf.sha256.toUpperCase() !== certSha256.toUpperCase()) return `installer certificate ${leaf.sha256} is not the pinned one`; + return null; +} + +function sha256File(file) { + const h = crypto.createHash('sha256'); + const fd = fs.openSync(file, 'r'); + try { + const buf = Buffer.alloc(1 << 20); + let n; + while ((n = fs.readSync(fd, buf, 0, buf.length, null)) > 0) h.update(buf.subarray(0, n)); + } finally { fs.closeSync(fd); } + return h.digest('hex'); +} + +/** The SHA-256 a SHA256SUMS text gives for a file name, or null. */ +function sumFor(sumsText, name) { + for (const line of String(sumsText).split('\n')) { + const m = /^([0-9a-f]{64})\s+\*?(.+)$/.exec(line.trim()); + if (m && m[2] === name) return m[1]; + } + return null; +} + +/** The pin embedded in the package's scripts (read with pkgutil, nothing executed). */ +function readPin(pkg, { run = defaultRun, tmp = os.tmpdir() } = {}) { + const dir = fs.mkdtempSync(path.join(tmp, 'pc-anchor-')); + const out = path.join(dir, 'x'); + try { + const r = run('pkgutil', ['--expand-full', pkg, out], { timeout: 300000 }); + if (r.code !== 0) return { error: `pkgutil --expand-full: ${(r.err || r.out).trim().split('\n')[0]}` }; + const candidates = [path.join(out, 'component.pkg', 'Scripts', 'pin.json'), path.join(out, 'Scripts', 'pin.json')]; + const file = candidates.find((f) => fs.existsSync(f)); + if (!file) return { error: 'the package carries no pin' }; + const pin = JSON.parse(fs.readFileSync(file, 'utf8')); + if (!/^[0-9a-f]{64}$/.test(pin.tree_hash || '')) return { error: 'the pin holds no tree hash' }; + return { pin }; + } catch (error) { + return { error: `the pin is unreadable: ${error.message}` }; + } finally { fs.rmSync(dir, { recursive: true, force: true }); } +} + +/** + * Every check before the hand-off. Returns { ok, checks, pin }. `deploy` is a parsed deployment manifest (optional): + * its tool.package.sha256, tool.package.signer_certificate_sha256 and tool.tree_hash are then pinned too. + */ +function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEAM_ID, requireAttestation = true } = {}) { + const checks = []; + const add = (check, ok, detail) => { checks.push({ check, ok, detail }); return ok; }; + const done = (pin = null) => ({ ok: checks.every((c) => c.ok), checks, pin }); + + const status = run('spctl', ['--status'], { timeout: 20000 }); + const st = `${status.out}${status.err}`.trim(); + if (!add('gatekeeper', st === 'assessments enabled', st || 'no answer')) return done(); + + const sha = sha256File(pkg); + const listed = sumFor(sums, path.basename(pkg)); + if (!add('sha256', listed === sha, listed ? (listed === sha ? sha : `${sha} differs from SHA256SUMS ${listed}`) : `${path.basename(pkg)} is not in SHA256SUMS`)) return done(); + const pinned = deploy && deploy.tool && deploy.tool.package ? deploy.tool.package : null; + if (pinned && !add('manifest-sha256', pinned.sha256 === sha, pinned.sha256 === sha ? 'equals the deployment manifest' : `the deployment manifest pins ${pinned.sha256}`)) return done(); + + if (requireAttestation) { + const a = run('gh', ['attestation', 'verify', pkg, '--repo', REPO, '--signer-workflow', WORKFLOW], { timeout: 120000 }); + if (!add('attestation', a.code === 0, a.code === 0 ? `attested by ${WORKFLOW}` : a.code === 127 ? 'gh is not installed; the build attestation cannot be checked' : (a.err || a.out).trim().split('\n').pop())) return done(); + } + + const sig = run('pkgutil', ['--check-signature', pkg], { timeout: 60000 }); + const problem = signatureProblem(sig.out, { team, certSha256: pinned ? pinned.signer_certificate_sha256 : null }); + if (!add('signature', !problem, problem || `Developer ID Installer of ${team}, notarised`)) return done(); + + const gk = run('spctl', ['-a', '-vv', '-t', 'install', pkg], { timeout: 120000 }); + const src = /source=([^\n]+)/.exec(`${gk.err}\n${gk.out}`); + if (!add('assessment', gk.code === 0 && !!src && src[1].trim() === 'Notarized Developer ID', src ? `source=${src[1].trim()}` : `spctl exit ${gk.code}`)) return done(); + + const { pin, error } = readPin(pkg, { run }); + if (!add('pin', !!pin, pin ? `payload tree hash ${pin.tree_hash}` : error)) return done(); + if (deploy && deploy.tool && deploy.tool.tree_hash) { + add('manifest-tool', pin.tool_tree_hash === deploy.tool.tree_hash, pin.tool_tree_hash === deploy.tool.tree_hash ? 'tool tree hash equals the deployment manifest' : `tool tree hash ${pin.tool_tree_hash} is not the manifest's ${deploy.tool.tree_hash}`); + } + return done(pin); +} + +/** The request the package reads from the person's home: the role, and the organisation of an organisation space. */ +function writeRequest(home, { role, org }) { + if (!ROLES.includes(role)) throw new Error(`role must be one of ${ROLES.join(', ')}`); + if (role === 'org-space' && !/^[a-z][a-z0-9-]{1,20}$/.test(org || '')) throw new Error('an organisation space needs --org'); + if (role !== 'org-space' && org) throw new Error('--org belongs to an organisation space only'); + const dir = path.join(home, '.passioncode'); + fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); + const file = path.join(dir, 'brain-anchor.json'); + const tmp = `${file}.tmp`; + fs.writeFileSync(tmp, JSON.stringify(role === 'org-space' ? { role, org } : { role }) + '\n', { mode: 0o600 }); + fs.renameSync(tmp, file); + return file; +} + +/** Hand the checked package to macOS's Installer, which asks for the administrator password itself. */ +function handOff(pkg, { run = defaultRun } = {}) { + const r = run('open', ['-a', 'Installer', pkg], { timeout: 30000 }); + return { ok: r.code === 0, detail: r.code === 0 ? 'handed to macOS Installer; type the password only into its own prompt' : (r.err || r.out).trim() }; +} + +async function fetchRelease(url, dir) { + const { download } = require('./releases'); + const name = decodeURIComponent(url.split('/').pop()); + if (!/^[A-Za-z0-9._+-]+\.pkg$/.test(name)) throw new Error(`not a package URL: ${url}`); + const pkg = path.join(dir, name); + await download(url, pkg); + const sumsUrl = url.replace(/[^/]+$/, 'SHA256SUMS'); + const res = await fetch(sumsUrl, { headers: { 'User-Agent': 'passioncode-launcher' }, signal: AbortSignal.timeout(60000) }); + if (!res.ok) throw new Error(`${sumsUrl}: HTTP ${res.status}`); + return { pkg, sums: await res.text() }; +} + +/** The whole command. Exit codes: 0 handed off (or checked, with dryRun), 1 a check failed, 2 usage. */ +async function anchor({ pkg, url, sumsFile, deployFile, role = 'person', org = null, dryRun = false, uid = process.getuid ? process.getuid() : null, home = os.homedir(), run = defaultRun, platform = process.platform }) { + if (platform !== 'darwin') return { code: 2, message: 'the service package installs on macOS only' }; + if (uid === 0) return { code: 2, message: 'run it as yourself, without sudo: macOS Installer asks for the administrator password in its own prompt' }; + if (!pkg === !url) return { code: 2, message: 'name the package with --pkg PATH (and --sums PATH) or --url URL' }; + let sums; + if (url) { + // The download stays in the temp folder: Installer reads the package after `open` returns. + ({ pkg, sums } = await fetchRelease(url, fs.mkdtempSync(path.join(os.tmpdir(), 'pc-anchor-dl-')))); + } else { + if (!sumsFile) return { code: 2, message: '--pkg needs --sums, the release SHA256SUMS' }; + sums = fs.readFileSync(sumsFile, 'utf8'); + } + const deploy = deployFile ? JSON.parse(fs.readFileSync(deployFile, 'utf8')) : null; + const v = verify(pkg, { sums, deploy, run }); + if (!v.ok) return { code: 1, message: 'refused before elevation; nothing was installed', ...v }; + if (dryRun) return { code: 0, message: 'every check passed; dry run: not handed to the Installer', ...v }; + const request = writeRequest(home, { role, org }); + const h = handOff(pkg, { run }); + return { code: h.ok ? 0 : 1, message: h.detail, request, ...v }; +} + +module.exports = { anchor, verify, signatureProblem, parsePkgutil, sumFor, readPin, writeRequest, handOff, ROOT_CA_SHA256, WORKFLOW }; diff --git a/test/anchor.test.js b/test/anchor.test.js new file mode 100644 index 00000000..80835ff0 --- /dev/null +++ b/test/anchor.test.js @@ -0,0 +1,134 @@ +'use strict'; +delete process.env.CLAUDE_CONFIG_DIR; +delete process.env.SWITCHBOARD_CLAUDE_SOURCE_DIR; +// W7 T28a: the service package hand-off. Every check runs as the person before macOS Installer is opened; a modified or +// unsigned package, a package of another team, a Gatekeeper that is off, a missing SHA256SUMS line or attestation all +// stop before the hand-off, and the launcher never runs sudo. Fixtures: real pkgutil output (test/fixtures/anchor). +const assert = require('node:assert/strict'); +const { spawnSync } = require('node:child_process'); +const crypto = require('node:crypto'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const test = require('node:test'); + +const A = require('../lib/anchor'); + +const FX = path.join(__dirname, 'fixtures', 'anchor'); +const vendor = fs.readFileSync(path.join(FX, 'pkgutil-vendor-signed.txt'), 'utf8'); +const ours = vendor.replace('AMZN Mobile LLC (94KV3E626L)', 'Fixture Owner (KJ35UYYL22)'); + +function world({ signature = ours, gatekeeper = 'assessments enabled', assess = 'source=Notarized Developer ID', attest = 0, pin = { tree_hash: 'a'.repeat(64), tool_tree_hash: 'b'.repeat(64) } } = {}) { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'anchor-test-')); + const pkg = path.join(dir, 'passioncode-brain-anchor-0.1.0.pkg'); + fs.writeFileSync(pkg, 'package bytes'); + const sha = crypto.createHash('sha256').update('package bytes').digest('hex'); + const calls = []; + const run = (cmd, args) => { + calls.push([cmd, ...args].join(' ')); + if (cmd === 'spctl' && args[0] === '--status') return { code: 0, out: `${gatekeeper}\n`, err: '' }; + if (cmd === 'spctl') return { code: assess.includes('Notarized') ? 0 : 3, out: '', err: `${pkg}: x\n${assess}\n` }; + if (cmd === 'gh') return attest === 127 ? { code: 127, out: '', err: 'gh not found' } : { code: attest, out: '', err: attest ? 'no matching attestation' : '' }; + if (cmd === 'pkgutil' && args[0] === '--check-signature') return { code: 0, out: signature, err: '' }; + if (cmd === 'pkgutil' && args[0] === '--expand-full') { + const scripts = path.join(args[2], 'component.pkg', 'Scripts'); + fs.mkdirSync(scripts, { recursive: true }); + if (pin) fs.writeFileSync(path.join(scripts, 'pin.json'), JSON.stringify(pin)); + return { code: 0, out: '', err: '' }; + } + if (cmd === 'open') return { code: 0, out: '', err: '' }; + return { code: 127, out: '', err: `${cmd} not expected` }; + }; + return { dir, pkg, sha, sums: `${sha} passioncode-brain-anchor-0.1.0.pkg\n`, run, calls }; +} + +test('T28a: a package of the team, notarised, listed and attested passes every check and is handed to Installer', async () => { + const w = world(); + const r = await A.anchor({ pkg: w.pkg, sumsFile: (fs.writeFileSync(path.join(w.dir, 'S'), w.sums), path.join(w.dir, 'S')), run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 0, JSON.stringify(r)); + assert.deepEqual(r.checks.map((c) => c.check), ['gatekeeper', 'sha256', 'attestation', 'signature', 'assessment', 'pin']); + assert.ok(w.calls.includes(`open -a Installer ${w.pkg}`)); + assert.ok(!w.calls.some((c) => /sudo|installer -pkg/.test(c)), 'never sudo, never the installer CLI'); + assert.deepEqual(JSON.parse(fs.readFileSync(path.join(w.dir, '.passioncode', 'brain-anchor.json'), 'utf8')), { role: 'person' }); +}); + +const refusals = [ + ['an unsigned package', { signature: fs.readFileSync(path.join(FX, 'pkgutil-unsigned.txt'), 'utf8') }, 'signature'], + ['a modified package', { signature: fs.readFileSync(path.join(FX, 'pkgutil-modified.txt'), 'utf8') }, 'signature'], + ['a package signed by another team', { signature: vendor }, 'signature'], + ['a package that is not notarised', { signature: ours.replace(/^\s*Notarization:.*\n/m, '') }, 'signature'], + ['a chain that does not end at the Apple Root CA', { signature: ours.replace('B0 B1 73 0E', 'B0 B1 73 0F') }, 'signature'], + ['a machine with Gatekeeper assessments off', { gatekeeper: 'assessments disabled' }, 'gatekeeper'], + ['a package without a build attestation', { attest: 1 }, 'attestation'], + ['a machine without gh to read the attestation', { attest: 127 }, 'attestation'], + ['a package Gatekeeper does not accept', { assess: 'source=no usable signature' }, 'assessment'], + ['a package without a pin', { pin: null }, 'pin'], +]; +for (const [name, opts, failed] of refusals) { + test(`T28a: ${name} is refused before elevation`, async () => { + const w = world(opts); + fs.writeFileSync(path.join(w.dir, 'S'), w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 1); + assert.equal(r.checks.at(-1).check, failed); + assert.equal(r.checks.at(-1).ok, false); + assert.ok(!w.calls.some((c) => c.startsWith('open ')), 'not handed off'); + assert.ok(!fs.existsSync(path.join(w.dir, '.passioncode')), 'no request written'); + }); +} + +test('T28a: bytes that differ from SHA256SUMS, or a file it does not list, are refused', async () => { + const w = world(); + for (const sums of [`${'0'.repeat(64)} passioncode-brain-anchor-0.1.0.pkg\n`, `${w.sha} other.pkg\n`]) { + fs.writeFileSync(path.join(w.dir, 'S'), sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 1); + assert.equal(r.checks.at(-1).check, 'sha256'); + } +}); + +test('T28a: a deployment manifest pins the package bytes, the installer certificate and the tool tree hash', async () => { + const w = world(); + fs.writeFileSync(path.join(w.dir, 'S'), w.sums); + const leaf = A.parsePkgutil(ours).chain[0].sha256; + const deploy = (o) => { const f = path.join(w.dir, 'D'); fs.writeFileSync(f, JSON.stringify({ tool: { tree_hash: 'b'.repeat(64), package: { sha256: w.sha, signer_certificate_sha256: leaf, ...o } } })); return f; }; + const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', dryRun: true }; + assert.equal((await A.anchor({ ...base, deployFile: deploy({}) })).code, 0); + let r = await A.anchor({ ...base, deployFile: deploy({ sha256: '1'.repeat(64) }) }); + assert.equal(r.checks.at(-1).check, 'manifest-sha256'); + r = await A.anchor({ ...base, deployFile: deploy({ signer_certificate_sha256: '1'.repeat(64) }) }); + assert.equal(r.checks.at(-1).check, 'signature'); +}); + +test('T28a: never as root, macOS only, a dry run does not hand off, and the request is validated', async () => { + const w = world(); + fs.writeFileSync(path.join(w.dir, 'S'), w.sums); + const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, home: w.dir, platform: 'darwin' }; + assert.equal((await A.anchor({ ...base, uid: 0 })).code, 2); + assert.equal((await A.anchor({ ...base, uid: 501, platform: 'linux' })).code, 2); + const d = await A.anchor({ ...base, uid: 501, dryRun: true }); + assert.equal(d.code, 0); + assert.ok(!w.calls.some((c) => c.startsWith('open '))); + assert.throws(() => A.writeRequest(w.dir, { role: 'org-space' }), /needs --org/); + assert.throws(() => A.writeRequest(w.dir, { role: 'root' }), /role must be/); + assert.throws(() => A.writeRequest(w.dir, { role: 'person', org: 'x' }), /organisation space only/); +}); + +const darwin = process.platform === 'darwin' && !spawnSync('pkgbuild', ['--help']).error; +test('T28a: with the real pkgutil, an unsigned package built here is refused at the signature', { skip: !darwin && 'needs macOS pkgbuild' }, () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'anchor-real-')); + const scripts = path.join(dir, 'scripts'); + fs.mkdirSync(scripts); + fs.writeFileSync(path.join(scripts, 'postinstall'), '#!/bin/sh\nexit 0\n', { mode: 0o755 }); + const pkg = path.join(dir, 'unsigned.pkg'); + assert.equal(spawnSync('pkgbuild', ['--nopayload', '--scripts', scripts, '--identifier', 'ai.passioncode.test', '--version', '1', pkg]).status, 0); + const sha = crypto.createHash('sha256').update(fs.readFileSync(pkg)).digest('hex'); + const gatekeeperOn = { code: 0, out: 'assessments enabled\n', err: '' }; + const real = require('../lib/releases').run; + const run = (cmd, args, o) => (cmd === 'spctl' && args[0] === '--status' ? gatekeeperOn : real(cmd, args, o)); + const r = A.verify(pkg, { sums: `${sha} unsigned.pkg\n`, run, requireAttestation: false }); + assert.equal(r.ok, false); + assert.equal(r.checks.at(-1).check, 'signature'); + assert.match(r.checks.at(-1).detail, /no signature/); + fs.rmSync(dir, { recursive: true, force: true }); +}); diff --git a/test/fixtures/anchor/pkgutil-modified.txt b/test/fixtures/anchor/pkgutil-modified.txt new file mode 100644 index 00000000..9fce8ce6 --- /dev/null +++ b/test/fixtures/anchor/pkgutil-modified.txt @@ -0,0 +1,2 @@ +Package "sample-modified.pkg": + Status: package is invalid (checksum did not verify) diff --git a/test/fixtures/anchor/pkgutil-unsigned.txt b/test/fixtures/anchor/pkgutil-unsigned.txt new file mode 100644 index 00000000..b308d2c3 --- /dev/null +++ b/test/fixtures/anchor/pkgutil-unsigned.txt @@ -0,0 +1,2 @@ +Package "sample-unsigned.pkg": + Status: no signature diff --git a/test/fixtures/anchor/pkgutil-vendor-signed.txt b/test/fixtures/anchor/pkgutil-vendor-signed.txt new file mode 100644 index 00000000..68fcb327 --- /dev/null +++ b/test/fixtures/anchor/pkgutil-vendor-signed.txt @@ -0,0 +1,23 @@ +Package "sample-signed.pkg": + Status: signed by a developer certificate issued by Apple for distribution + Notarization: trusted by the Apple notary service + Signed with a trusted timestamp on: 2026-11-24 19:14:05 +0000 + Certificate Chain: + 1. Developer ID Installer: AMZN Mobile LLC (94KV3E626L) + Expires: 2030-09-26 00:18:06 +0000 + SHA256 Fingerprint: + 5C 45 BE 63 FD 52 10 07 2D 66 56 77 5C A9 FF 25 91 6D 3F 01 F7 0E + 9A 8A 05 F6 2D 62 B2 88 8D A9 + ------------------------------------------------------------------------ + 2. Developer ID Certification Authority + Expires: 2031-09-17 00:00:00 +0000 + SHA256 Fingerprint: + F1 6C D3 C5 4C 7F 83 CE A4 BF 1A 3E 6A 08 19 C8 AA A8 E4 A1 52 8F + D1 44 71 5F 35 06 43 D2 DF 3A + ------------------------------------------------------------------------ + 3. Apple Root CA + Expires: 2035-02-09 21:40:36 +0000 + SHA256 Fingerprint: + B0 B1 73 0E CB C7 FF 45 05 14 2C 49 F1 29 5E 6E DA 6B CA ED 7E 2C + 68 C5 BE 91 B5 A1 10 01 F0 24 + From 11d527e2eadb9b2d291a61eccef83fc3c553d2aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 01:22:53 +0100 Subject: [PATCH 02/12] docs(handoff): W7 anchor launcher, setup and docs tests 195 of 195 Co-Authored-By: Claude Opus 5.5 --- docs/handoffs/2026-11-25-w7-anchor-launcher.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index 859ea62f..27ff2074 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -22,7 +22,7 @@ to macOS Installer, which alone asks for the administrator password. Program thr one test builds an unsigned package with the real `pkgbuild` and sees the real `pkgutil` refuse it). - Full `npm test` on this machine: 678 tests, 672 pass, 4 skipped, 1 fail: PC-163's socket-table test, the known PC-246 failure of this build machine (fails the same on unchanged `origin/main`). `test/setup.test.js` was cut by the run's - time cap and ran again on its own (see the final report of the session). + time cap and ran again on its own with help, strings, no-em-dash, repo-rules and docs: 195 of 195, exit 0. - IP gate (`ip_gate.py scan --destination public:npm-passioncode`) on `lib/anchor.js`, the CLI lines and the SECURITY section: pass. - The same refusals on a real machine: fabric-workspace `tools/brain/anchor/evidence/2026-11-25-vm-acc.json` (the From b8564fcaefaa694a8b23d05270bdb24ead7b87c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 05:04:01 +0100 Subject: [PATCH 03/12] feat(anchor): attestation must come from a brain-anchor tag; the request carries the roster row (W7 T28a, T28b review round 1) gh attestation verify ran without a ref check, so before brain-deploy-1 a package built by a modified workflow on a branch passed as attested; the launcher now reads the verified attestations as JSON and refuses any whose source ref is not refs/tags/brain-anchor-vX.Y.Z (the workflow signs only on such a tag). The pin's commit is shown. --row puts the roster row into the request so the package's install step enrols its keys (fabric-workspace a24fae8e). SECURITY.md names the same-user window between the checks and Installer's read, filed as PC-248. Co-Authored-By: Claude Opus 5.5 --- SECURITY.md | 15 +++++++++++---- bin/passioncode.js | 4 ++-- docs/backlog.md | 1 + lib/anchor.js | 44 ++++++++++++++++++++++++++++++++++++-------- test/anchor.test.js | 21 +++++++++++++++++++-- 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 7ec8f01c..b9aaee98 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -145,13 +145,20 @@ with `--confirm-bypass`, which a program can pass, so the flag records a choice, `passioncode anchor install` (not in the help yet; a step of a guided install) checks a service package as the person who runs it and then hands it to macOS's own Installer: Gatekeeper assessments must be on (`spctl --status`), the package's SHA-256 must equal its line in the release's `SHA256SUMS` (and a deployment manifest's pin when one is given), -its GitHub build attestation must verify (`gh attestation verify`), and `pkgutil --check-signature` must read a +its GitHub build attestation must verify (`gh attestation verify`) as made by the anchor workflow on a pushed +`brain-anchor-v` tag (a build from any other ref is refused), and `pkgutil --check-signature` must read a notarised Developer ID Installer signature of team `KJ35UYYL22` that chains to the Apple Root CA by its fingerprint. `spctl -a -t install` is a further check only: it accepted a signed package with one byte changed, which `pkgutil` refused (2026-11-25). The launcher refuses to run as root, never runs `sudo` and never reads or passes a password: -the password goes only into Installer's own prompt. It writes `~/.passioncode/brain-anchor.json` (the role, and the -organisation for an organisation space; nothing else) and opens Installer with `open -a Installer`. A failed check -writes nothing and opens nothing. +the password goes only into Installer's own prompt. It writes `~/.passioncode/brain-anchor.json` (the role, the +organisation for an organisation space, and the roster row the install step enrols; nothing else) and opens Installer +with `open -a Installer`. A failed check writes nothing and opens nothing. The limit of a check made as the person: +the package and the request sit where that user (and so any agent session of that user) can write, between the checks +and the moment Installer reads them. macOS Installer still refuses a package that is not notarised Developer ID, and +the package's own first elevated step compares its payload with the signed pin before anything changes, but it does +not check the team. So a same-user swap of the package for another team's notarised package, or of the request, is +not caught by the launcher; what still holds is that the store paths come from the package, never from the request, +and that an unsigned or modified anchor package aborts before any change. This is a known limit (PC-248). ## What anonymous counts send diff --git a/bin/passioncode.js b/bin/passioncode.js index f3fb332d..0190743f 100755 --- a/bin/passioncode.js +++ b/bin/passioncode.js @@ -367,11 +367,11 @@ async function anchorCommand(rest) { const json = rest.includes('--json'); const [verb, ...args] = rest.filter((a) => a !== '--json'); const o = { dryRun: false }; - const names = { '--pkg': 'pkg', '--url': 'url', '--sums': 'sumsFile', '--deploy': 'deployFile', '--role': 'role', '--org': 'org' }; + const names = { '--pkg': 'pkg', '--url': 'url', '--sums': 'sumsFile', '--deploy': 'deployFile', '--role': 'role', '--org': 'org', '--row': 'row' }; for (let i = 0; i < args.length; i++) { if (args[i] === '--dry-run') { o.dryRun = true; continue; } const key = names[args[i]]; - if (!key || args[i + 1] === undefined || o[key] !== undefined) return usage('anchor install takes --pkg PATH --sums PATH | --url URL, [--deploy FILE] [--role person|owner|org-space] [--org ORG] [--dry-run] [--json]'); + if (!key || args[i + 1] === undefined || o[key] !== undefined) return usage('anchor install takes --pkg PATH --sums PATH | --url URL, [--deploy FILE] [--role person|owner|org-space] [--org ORG] [--row ROW] [--dry-run] [--json]'); o[key] = args[++i]; } if (verb !== 'install') return usage('anchor takes install'); diff --git a/docs/backlog.md b/docs/backlog.md index 20b0f40a..053b89d3 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -253,3 +253,4 @@ derives its common backlog from [backlog-sources.json](backlog-sources.json). | PC-245 | The owner's MacBook to the base manifest: run the owner's line in [fabric-base-1-install.md](reference/fabric-base-1-install.md#the-owners-mac-a-app-11) on the MacBook (Inbox 1.7.1 to 1.9.2, adapter 0.102.0), done when `doctor` exits 0 and Inbox reads 1.9.2. The build machine cannot open a shell on the MacBook (SSH timed out, 2026-11-24; access runs only the other way), so a MacBook session or the owner runs it | open 2026-11-24: needs a process on the MacBook; 0.2.83 is on npm (`latest`, release run 45294028388 success), so the line runs as written | W2 session 06 | | PC-246 | `PC-163: the server end of this account's own connection reads \`own\` from the real socket table` (`test/listener.test.js`) fails on a build machine whose `netstat` prints no row for the server end of the test's own loopback connection (`table-restricted … netstat printed no table`); it fails the same on unchanged `origin/main` `df80ead` there, 2026-11-24. Make the test skip with its reason where the table is restricted, or read the table the way that machine allows | open 2026-11-24: P3 | W2 session 06, full `npm test` on `agent/w2-s06-base1-owner-mac` (681 of 687 pass, 2 fail: this one and a strings.md drift fixed in the same branch) | | PC-247 | W7 T28a, the service package hand-off: `passioncode anchor install` (`lib/anchor.js`, `test/anchor.test.js`, SECURITY.md "What `anchor install` touches") checks a package as the person (Gatekeeper on, SHA256SUMS and a manifest pin, the build attestation, `pkgutil` signature of team `KJ35UYYL22` to the Apple Root CA, `spctl`, the embedded pin) and hands it to macOS Installer; never sudo. Left: a help line and strings.md rows when it ships, and a launcher release after the owner's sitting (T28d) proves it on the live package | open 2026-11-25: built on branch `w7-anchor-launcher-2026-11-25`, not merged, not released | Studio session 45 (W7 trust-anchor lane, thread `bb204715`); fabric-workspace `w7-anchor-2026-11-25` `tools/brain/anchor/` | +| PC-248 | The anchor hand-off's same-user window (W7 T28a, review round 1 of Studio session 59): `passioncode anchor install` checks the package and writes `~/.passioncode/brain-anchor.json` as the person, so any process of that user (an agent session included) can swap the package for another team's notarised package, or rewrite the request, between the checks and the moment macOS Installer reads them; Installer checks notarisation but not the team. SECURITY.md "What `anchor install` touches" names the limit. A fix needs a hand-off the user cannot write between check and read (for example the package's own first elevated step checking the team of its own signature, or Installer reading a copy the user cannot change) | open 2026-11-25 | Studio session 59, review finding 9 of round 1 (W7 trust-anchor lane, thread `bb204715`); nothing in T28a's done line depends on it (the payload still aborts off its pin) | diff --git a/lib/anchor.js b/lib/anchor.js index 69084aa5..710dc3df 100644 --- a/lib/anchor.js +++ b/lib/anchor.js @@ -99,6 +99,25 @@ function readPin(pkg, { run = defaultRun, tmp = os.tmpdir() } = {}) { } finally { fs.rmSync(dir, { recursive: true, force: true }); } } +/** The workflow signs only on a pushed tag (fabric-workspace brain-anchor.yml); a build from any other ref is refused. */ +const TAG_PREFIX = 'brain-anchor-v'; +const ROW = /^[a-z0-9][a-z0-9._:-]{2,80}$/; + +/** Null when every verified attestation was made on a brain-anchor-v tag, else the reason. */ +function attestedRefProblem(out) { + let list; + try { list = JSON.parse(out); } catch { return 'the attestation answer is not JSON'; } + if (!Array.isArray(list) || list.length === 0) return 'no verified attestation in the answer'; + for (const item of list) { + const ref = item && item.verificationResult && item.verificationResult.signature && item.verificationResult.signature.certificate + ? item.verificationResult.signature.certificate.sourceRepositoryRef : null; + if (typeof ref !== 'string' || !new RegExp(`^refs/tags/${TAG_PREFIX}\\d+\\.\\d+\\.\\d+$`).test(ref)) { + return `attested from ${ref || 'an unnamed ref'}, not a ${TAG_PREFIX} tag`; + } + } + return null; +} + /** * Every check before the hand-off. Returns { ok, checks, pin }. `deploy` is a parsed deployment manifest (optional): * its tool.package.sha256, tool.package.signer_certificate_sha256 and tool.tree_hash are then pinned too. @@ -119,8 +138,12 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA if (pinned && !add('manifest-sha256', pinned.sha256 === sha, pinned.sha256 === sha ? 'equals the deployment manifest' : `the deployment manifest pins ${pinned.sha256}`)) return done(); if (requireAttestation) { - const a = run('gh', ['attestation', 'verify', pkg, '--repo', REPO, '--signer-workflow', WORKFLOW], { timeout: 120000 }); - if (!add('attestation', a.code === 0, a.code === 0 ? `attested by ${WORKFLOW}` : a.code === 127 ? 'gh is not installed; the build attestation cannot be checked' : (a.err || a.out).trim().split('\n').pop())) return done(); + const a = run('gh', ['attestation', 'verify', pkg, '--repo', REPO, '--signer-workflow', WORKFLOW, '--format', 'json'], { timeout: 120000 }); + const refProblem = a.code === 0 ? attestedRefProblem(a.out) : null; + const detail = a.code === 127 ? 'gh is not installed; the build attestation cannot be checked' + : a.code !== 0 ? (a.err || a.out).trim().split('\n').pop() + : refProblem || `attested by ${WORKFLOW} on a ${TAG_PREFIX} tag`; + if (!add('attestation', a.code === 0 && !refProblem, detail)) return done(); } const sig = run('pkgutil', ['--check-signature', pkg], { timeout: 60000 }); @@ -132,23 +155,28 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA if (!add('assessment', gk.code === 0 && !!src && src[1].trim() === 'Notarized Developer ID', src ? `source=${src[1].trim()}` : `spctl exit ${gk.code}`)) return done(); const { pin, error } = readPin(pkg, { run }); - if (!add('pin', !!pin, pin ? `payload tree hash ${pin.tree_hash}` : error)) return done(); + if (!add('pin', !!pin, pin ? `payload tree hash ${pin.tree_hash}, built at commit ${pin.tool_commit || 'unnamed'}` : error)) return done(); if (deploy && deploy.tool && deploy.tool.tree_hash) { add('manifest-tool', pin.tool_tree_hash === deploy.tool.tree_hash, pin.tool_tree_hash === deploy.tool.tree_hash ? 'tool tree hash equals the deployment manifest' : `tool tree hash ${pin.tool_tree_hash} is not the manifest's ${deploy.tool.tree_hash}`); } return done(pin); } -/** The request the package reads from the person's home: the role, and the organisation of an organisation space. */ -function writeRequest(home, { role, org }) { +/** + * The request the package reads from the person's home: the role, the organisation of an organisation space, and the + * roster row the install step enrols (the Studio made the row; the code then shows in the installer's own window). + */ +function writeRequest(home, { role, org, row = null }) { if (!ROLES.includes(role)) throw new Error(`role must be one of ${ROLES.join(', ')}`); if (role === 'org-space' && !/^[a-z][a-z0-9-]{1,20}$/.test(org || '')) throw new Error('an organisation space needs --org'); if (role !== 'org-space' && org) throw new Error('--org belongs to an organisation space only'); + if (row !== null && !ROW.test(row)) throw new Error('--row must be a roster row id'); const dir = path.join(home, '.passioncode'); fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); const file = path.join(dir, 'brain-anchor.json'); const tmp = `${file}.tmp`; - fs.writeFileSync(tmp, JSON.stringify(role === 'org-space' ? { role, org } : { role }) + '\n', { mode: 0o600 }); + const body = { role, ...(role === 'org-space' ? { org } : {}), ...(row ? { row } : {}) }; + fs.writeFileSync(tmp, JSON.stringify(body) + '\n', { mode: 0o600 }); fs.renameSync(tmp, file); return file; } @@ -172,7 +200,7 @@ async function fetchRelease(url, dir) { } /** The whole command. Exit codes: 0 handed off (or checked, with dryRun), 1 a check failed, 2 usage. */ -async function anchor({ pkg, url, sumsFile, deployFile, role = 'person', org = null, dryRun = false, uid = process.getuid ? process.getuid() : null, home = os.homedir(), run = defaultRun, platform = process.platform }) { +async function anchor({ pkg, url, sumsFile, deployFile, role = 'person', org = null, row = null, dryRun = false, uid = process.getuid ? process.getuid() : null, home = os.homedir(), run = defaultRun, platform = process.platform }) { if (platform !== 'darwin') return { code: 2, message: 'the service package installs on macOS only' }; if (uid === 0) return { code: 2, message: 'run it as yourself, without sudo: macOS Installer asks for the administrator password in its own prompt' }; if (!pkg === !url) return { code: 2, message: 'name the package with --pkg PATH (and --sums PATH) or --url URL' }; @@ -188,7 +216,7 @@ async function anchor({ pkg, url, sumsFile, deployFile, role = 'person', org = n const v = verify(pkg, { sums, deploy, run }); if (!v.ok) return { code: 1, message: 'refused before elevation; nothing was installed', ...v }; if (dryRun) return { code: 0, message: 'every check passed; dry run: not handed to the Installer', ...v }; - const request = writeRequest(home, { role, org }); + const request = writeRequest(home, { role, org, row }); const h = handOff(pkg, { run }); return { code: h.ok ? 0 : 1, message: h.detail, request, ...v }; } diff --git a/test/anchor.test.js b/test/anchor.test.js index 80835ff0..824bf99a 100644 --- a/test/anchor.test.js +++ b/test/anchor.test.js @@ -18,7 +18,9 @@ const FX = path.join(__dirname, 'fixtures', 'anchor'); const vendor = fs.readFileSync(path.join(FX, 'pkgutil-vendor-signed.txt'), 'utf8'); const ours = vendor.replace('AMZN Mobile LLC (94KV3E626L)', 'Fixture Owner (KJ35UYYL22)'); -function world({ signature = ours, gatekeeper = 'assessments enabled', assess = 'source=Notarized Developer ID', attest = 0, pin = { tree_hash: 'a'.repeat(64), tool_tree_hash: 'b'.repeat(64) } } = {}) { +const attested = (ref) => JSON.stringify([{ verificationResult: { signature: { certificate: { sourceRepositoryRef: ref } } } }]); + +function world({ signature = ours, gatekeeper = 'assessments enabled', assess = 'source=Notarized Developer ID', attest = 0, attestOut = attested('refs/tags/brain-anchor-v0.1.0'), pin = { tree_hash: 'a'.repeat(64), tool_tree_hash: 'b'.repeat(64), tool_commit: 'c'.repeat(40) } } = {}) { const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'anchor-test-')); const pkg = path.join(dir, 'passioncode-brain-anchor-0.1.0.pkg'); fs.writeFileSync(pkg, 'package bytes'); @@ -28,7 +30,7 @@ function world({ signature = ours, gatekeeper = 'assessments enabled', assess = calls.push([cmd, ...args].join(' ')); if (cmd === 'spctl' && args[0] === '--status') return { code: 0, out: `${gatekeeper}\n`, err: '' }; if (cmd === 'spctl') return { code: assess.includes('Notarized') ? 0 : 3, out: '', err: `${pkg}: x\n${assess}\n` }; - if (cmd === 'gh') return attest === 127 ? { code: 127, out: '', err: 'gh not found' } : { code: attest, out: '', err: attest ? 'no matching attestation' : '' }; + if (cmd === 'gh') return attest === 127 ? { code: 127, out: '', err: 'gh not found' } : { code: attest, out: attest ? '' : attestOut, err: attest ? 'no matching attestation' : '' }; if (cmd === 'pkgutil' && args[0] === '--check-signature') return { code: 0, out: signature, err: '' }; if (cmd === 'pkgutil' && args[0] === '--expand-full') { const scripts = path.join(args[2], 'component.pkg', 'Scripts'); @@ -61,6 +63,8 @@ const refusals = [ ['a machine with Gatekeeper assessments off', { gatekeeper: 'assessments disabled' }, 'gatekeeper'], ['a package without a build attestation', { attest: 1 }, 'attestation'], ['a machine without gh to read the attestation', { attest: 127 }, 'attestation'], + ['a build attested from a branch, not a brain-anchor tag', { attestOut: attested('refs/heads/feature') }, 'attestation'], + ['an attestation answer that cannot be read', { attestOut: 'not json' }, 'attestation'], ['a package Gatekeeper does not accept', { assess: 'source=no usable signature' }, 'assessment'], ['a package without a pin', { pin: null }, 'pin'], ]; @@ -132,3 +136,16 @@ test('T28a: with the real pkgutil, an unsigned package built here is refused at assert.match(r.checks.at(-1).detail, /no signature/); fs.rmSync(dir, { recursive: true, force: true }); }); + +test('T28b: the request may carry the roster row the install step enrols; a bad row is refused before the hand-off', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, role: 'org-space', org: 'passioncode', row: 'machine:studio-passioncode', run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 0, JSON.stringify(r)); + assert.deepEqual(JSON.parse(fs.readFileSync(path.join(w.dir, '.passioncode', 'brain-anchor.json'), 'utf8')), { role: 'org-space', org: 'passioncode', row: 'machine:studio-passioncode' }); + assert.throws(() => A.writeRequest(w.dir, { role: 'person', row: '../x' }), /row/); + const calls = w.calls.filter((c) => c.startsWith('gh ')); + assert.ok(calls.every((c) => c.includes('--format json')), calls.join('\n')); + assert.ok(r.checks.find((c) => c.check === 'pin').detail.includes('c'.repeat(40)), 'the pinned commit is shown'); +}); From b0c132f47e6c2dba1c4b898cefcc25f27810a8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 05:41:51 +0100 Subject: [PATCH 04/12] fix(anchor): a deployment manifest must pin the package bytes; SECURITY.md states the package's own check exactly (W7 T28a review round 2) A manifest with a tool tree hash and no package sha256 let a package with the same tool and another anchor runtime pass; such a manifest is now refused. SECURITY.md said an unsigned anchor package aborts before any change; the package's first step only compares its payload with the pin inside the same package, so the same-user window (PC-248) covers a self-built package too, now stated. The handoff takes the workflow's artifact with --pkg and --sums (nothing is published as a release). Co-Authored-By: Claude Opus 5.5 --- SECURITY.md | 9 +++++---- docs/backlog.md | 2 +- .../handoffs/2026-11-25-w7-anchor-launcher.md | 20 +++++++++++++------ lib/anchor.js | 6 ++++++ test/anchor.test.js | 5 +++++ 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index b9aaee98..f65d9df2 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -155,10 +155,11 @@ organisation for an organisation space, and the roster row the install step enro with `open -a Installer`. A failed check writes nothing and opens nothing. The limit of a check made as the person: the package and the request sit where that user (and so any agent session of that user) can write, between the checks and the moment Installer reads them. macOS Installer still refuses a package that is not notarised Developer ID, and -the package's own first elevated step compares its payload with the signed pin before anything changes, but it does -not check the team. So a same-user swap of the package for another team's notarised package, or of the request, is -not caught by the launcher; what still holds is that the store paths come from the package, never from the request, -and that an unsigned or modified anchor package aborts before any change. This is a known limit (PC-248). +the package's own first elevated step compares its payload with the pin shipped inside the same package before +anything changes, which catches a modified payload of a genuine package but checks no signature and no team. So a +same-user swap, between the checks and Installer's read, of the package (for another team's notarised package, or a +package that Installer opens without a notarisation check) or of the request is not caught by the launcher; what still +holds is that the store paths come from the package, never from the request. This is a known limit (PC-248). ## What anonymous counts send diff --git a/docs/backlog.md b/docs/backlog.md index 053b89d3..488fea9b 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -253,4 +253,4 @@ derives its common backlog from [backlog-sources.json](backlog-sources.json). | PC-245 | The owner's MacBook to the base manifest: run the owner's line in [fabric-base-1-install.md](reference/fabric-base-1-install.md#the-owners-mac-a-app-11) on the MacBook (Inbox 1.7.1 to 1.9.2, adapter 0.102.0), done when `doctor` exits 0 and Inbox reads 1.9.2. The build machine cannot open a shell on the MacBook (SSH timed out, 2026-11-24; access runs only the other way), so a MacBook session or the owner runs it | open 2026-11-24: needs a process on the MacBook; 0.2.83 is on npm (`latest`, release run 45294028388 success), so the line runs as written | W2 session 06 | | PC-246 | `PC-163: the server end of this account's own connection reads \`own\` from the real socket table` (`test/listener.test.js`) fails on a build machine whose `netstat` prints no row for the server end of the test's own loopback connection (`table-restricted … netstat printed no table`); it fails the same on unchanged `origin/main` `df80ead` there, 2026-11-24. Make the test skip with its reason where the table is restricted, or read the table the way that machine allows | open 2026-11-24: P3 | W2 session 06, full `npm test` on `agent/w2-s06-base1-owner-mac` (681 of 687 pass, 2 fail: this one and a strings.md drift fixed in the same branch) | | PC-247 | W7 T28a, the service package hand-off: `passioncode anchor install` (`lib/anchor.js`, `test/anchor.test.js`, SECURITY.md "What `anchor install` touches") checks a package as the person (Gatekeeper on, SHA256SUMS and a manifest pin, the build attestation, `pkgutil` signature of team `KJ35UYYL22` to the Apple Root CA, `spctl`, the embedded pin) and hands it to macOS Installer; never sudo. Left: a help line and strings.md rows when it ships, and a launcher release after the owner's sitting (T28d) proves it on the live package | open 2026-11-25: built on branch `w7-anchor-launcher-2026-11-25`, not merged, not released | Studio session 45 (W7 trust-anchor lane, thread `bb204715`); fabric-workspace `w7-anchor-2026-11-25` `tools/brain/anchor/` | -| PC-248 | The anchor hand-off's same-user window (W7 T28a, review round 1 of Studio session 59): `passioncode anchor install` checks the package and writes `~/.passioncode/brain-anchor.json` as the person, so any process of that user (an agent session included) can swap the package for another team's notarised package, or rewrite the request, between the checks and the moment macOS Installer reads them; Installer checks notarisation but not the team. SECURITY.md "What `anchor install` touches" names the limit. A fix needs a hand-off the user cannot write between check and read (for example the package's own first elevated step checking the team of its own signature, or Installer reading a copy the user cannot change) | open 2026-11-25 | Studio session 59, review finding 9 of round 1 (W7 trust-anchor lane, thread `bb204715`); nothing in T28a's done line depends on it (the payload still aborts off its pin) | +| PC-248 | The anchor hand-off's same-user window (W7 T28a, review round 1 of Studio session 59): `passioncode anchor install` checks the package and writes `~/.passioncode/brain-anchor.json` as the person, so any process of that user (an agent session included) can swap the package (for another team's notarised package, or a self-built package Installer opens without a notarisation check, whose own pin matches its own payload) or rewrite the request, between the checks and the moment macOS Installer reads them; the package's first step compares only its payload with its own pin, and Installer checks no team. SECURITY.md "What `anchor install` touches" names the limit. A fix needs a hand-off the user cannot write between check and read (for example the package's own first elevated step checking the team of its own signature, or Installer reading a copy the user cannot change) | open 2026-11-25 | Studio session 59, review finding 9 of round 1 (W7 trust-anchor lane, thread `bb204715`); nothing in T28a's done line depends on it (the payload still aborts off its pin) | diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index 27ff2074..e8c73022 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -8,16 +8,24 @@ to macOS Installer, which alone asks for the administrator password. Program thr ## Done - `lib/anchor.js` and `passioncode anchor install --pkg PATH --sums PATH | --url URL [--deploy FILE] [--role - person|owner|org-space] [--org ORG] [--dry-run] [--json]` (dispatched from `bin/passioncode.js`, the function at the + person|owner|org-space] [--org ORG] [--row ROW] [--dry-run] [--json]` (dispatched from `bin/passioncode.js`, the function at the file's end so no line a strings.md row cites moves). Checks in order: Gatekeeper on, SHA-256 against SHA256SUMS and - a deployment manifest's pin, `gh attestation verify` for `passioncode-ai/fabric-workspace`'s `brain-anchor.yml`, + a deployment manifest's pin, `gh attestation verify` for `passioncode-ai/fabric-workspace`'s `brain-anchor.yml`, made on a pushed `brain-anchor-v` tag (any other source ref refused), `pkgutil --check-signature` (notarised, Developer ID Installer of `KJ35UYYL22`, Developer ID CA, Apple Root CA by - fingerprint, the manifest's certificate pin), `spctl -a -t install`, the embedded pin (shown; equal to the manifest's - tool tree hash when given). Then it writes `~/.passioncode/brain-anchor.json` and runs `open -a Installer`. -- SECURITY.md: "What `anchor install` touches". + fingerprint, the manifest's certificate pin), `spctl -a -t install`, the embedded pin (shown with its commit; equal to the manifest's + tool tree hash when given; a manifest that pins no package sha256 is refused). Then it writes + `~/.passioncode/brain-anchor.json` (role, organisation, roster row) and runs `open -a Installer`. +- SECURITY.md: "What `anchor install` touches", with the same-user window between the checks and Installer's read + (PC-248). +- Studio session 59 (integration and blind review rounds): the attestation's source ref, `--row`, the manifest's + package pin, PC-248; `origin/main` merged in. ## Checks actually run +- Session 59: `node --test test/anchor.test.js` 18 of 18; full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the + known PC-246); IP gate (`public:npm-passioncode`) on the changed `lib/anchor.js`, `bin/passioncode.js`, SECURITY.md, + the PC-248 row and the commit messages: pass. + - `node scripts/test.mjs test/anchor.test.js`: 15 of 15 (fixtures are real `pkgutil` outputs, `test/fixtures/anchor`; one test builds an unsigned package with the real `pkgbuild` and sees the real `pkgutil` refuse it). - Full `npm test` on this machine: 678 tests, 672 pass, 4 skipped, 1 fail: PC-163's socket-table test, the known PC-246 @@ -35,5 +43,5 @@ to macOS Installer, which alone asks for the administrator password. Program thr ## The next task -After T28d's first signed package exists: run `passioncode anchor install --url --dry-run` on the +After T28d's first signed package exists: download the workflow's artifact (`gh run download -R passioncode-ai/fabric-workspace -n brain-anchor-signed`: nothing is published as a release) and run `passioncode anchor install --pkg --sums --dry-run` on the MacBook as the owner, then merge this branch through a PR and release the launcher. diff --git a/lib/anchor.js b/lib/anchor.js index 710dc3df..8d356320 100644 --- a/lib/anchor.js +++ b/lib/anchor.js @@ -135,6 +135,12 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA const listed = sumFor(sums, path.basename(pkg)); if (!add('sha256', listed === sha, listed ? (listed === sha ? sha : `${sha} differs from SHA256SUMS ${listed}`) : `${path.basename(pkg)} is not in SHA256SUMS`)) return done(); const pinned = deploy && deploy.tool && deploy.tool.package ? deploy.tool.package : null; + // A manifest pins the package bytes (brain-deploy/0.1 tool.package.sha256): without them it would pin only the tool + // tree hash, which a package with the same tool and another anchor runtime also carries. + if (deploy && !(pinned && /^[0-9a-f]{64}$/.test(pinned.sha256 || ''))) { + add('manifest-sha256', false, 'the deployment manifest pins no package sha256'); + return done(); + } if (pinned && !add('manifest-sha256', pinned.sha256 === sha, pinned.sha256 === sha ? 'equals the deployment manifest' : `the deployment manifest pins ${pinned.sha256}`)) return done(); if (requireAttestation) { diff --git a/test/anchor.test.js b/test/anchor.test.js index 824bf99a..1af79e0c 100644 --- a/test/anchor.test.js +++ b/test/anchor.test.js @@ -102,6 +102,11 @@ test('T28a: a deployment manifest pins the package bytes, the installer certific assert.equal(r.checks.at(-1).check, 'manifest-sha256'); r = await A.anchor({ ...base, deployFile: deploy({ signer_certificate_sha256: '1'.repeat(64) }) }); assert.equal(r.checks.at(-1).check, 'signature'); + // A manifest that pins no package bytes pins nothing a same-tool, different-runtime package would fail. + fs.writeFileSync(path.join(w.dir, 'D2'), JSON.stringify({ tool: { tree_hash: 'b'.repeat(64) } })); + r = await A.anchor({ ...base, deployFile: path.join(w.dir, 'D2') }); + assert.equal(r.code, 1); + assert.equal(r.checks.at(-1).check, 'manifest-sha256'); }); test('T28a: never as root, macOS only, a dry run does not hand off, and the request is validated', async () => { From d4be5fd0ec76777f61541cdd44c194dd36441cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 06:15:48 +0100 Subject: [PATCH 05/12] fix(anchor): refuse a fixture package; count the anchor command; the handoff credits the VM with the Python twin only (W7 T28a review round 3) A pin that says fixture is a test vector the workflow never signs; the launcher now refuses it like any other failed check. 'anchor' joins the analytics command words (docs/analytics-events.md in the same change) instead of being sent as 'other'. The VM ran fabric-workspace's assert_identity.py, never lib/anchor.js; the handoff says so. Co-Authored-By: Claude Opus 5.5 --- docs/analytics-events.md | 2 +- docs/handoffs/2026-11-25-w7-anchor-launcher.md | 5 +++-- lib/analytics.js | 2 +- lib/anchor.js | 2 ++ test/anchor.test.js | 1 + 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/analytics-events.md b/docs/analytics-events.md index 6463c7cc..11010bf9 100644 --- a/docs/analytics-events.md +++ b/docs/analytics-events.md @@ -33,7 +33,7 @@ for any other (`-rc.N`, `-beta.N`, a build tag). | `app_installed` | live | lib/analytics.js:164 | the first command on this machine that tries to send (a send that fails is not repeated, so an offline first run never reports it) | `existing`: `"true"` when the launcher was installed here before the counts existed (its `~/.passioncode/state.json` was there when the first run of a counting version started, whatever its flags; that answer is kept in `analytics.json`; so a machine an agent sets up with `setup --json` counts as a new install), `"false"` for a new install (a string, as every property: growth filters only string properties) | 2026-11-04 | | `app_updated` | live | lib/analytics.js:165 | the first command after the launcher's version changed (an update the SessionStart hook ran is counted at the next command, so it can arrive a session late) | `from`: the previous version | 2026-11-04 | | `app_active` | live | lib/analytics.js:168 | the first command of a UTC day on this machine (counts daily active machines; two commands that end at the same moment on a new day may both send it) | none | 2026-11-04 | -| `command_run` | live | lib/analytics.js:171 | every command, when it ends | `command`: `setup`, `doctor`, `update`, `status`, `restore`, `config`, `uninstall`, `permissions`, `analytics` or `help` (any other word is sent as `other`, never as typed; a new command gets a new value here in the same change, a removed one is marked retired and its value is never reused); `outcome`: `ok` (exit 0), `failed` (exit 1: a check or a step failed) or `usage` (exit 2: the words given were not a command the launcher takes); `duration`: `under-1s`, `1-10s`, `10-60s` or `over-60s` (the bounds are part of the series: other bounds would be a new property, never new meanings of these); `json`: `"true"` or `"false"` (strings) | 2026-11-04 | +| `command_run` | live | lib/analytics.js:171 | every command, when it ends | `command`: `setup`, `doctor`, `update`, `status`, `restore`, `config`, `uninstall`, `permissions`, `analytics`, `help` or `anchor` (`anchor` added 2026-11-25 with `anchor install`, W7 T28a; any other word is sent as `other`, never as typed; a new command gets a new value here in the same change, a removed one is marked retired and its value is never reused); `outcome`: `ok` (exit 0), `failed` (exit 1: a check or a step failed) or `usage` (exit 2: the words given were not a command the launcher takes); `duration`: `under-1s`, `1-10s`, `10-60s` or `over-60s` (the bounds are part of the series: other bounds would be a new property, never new meanings of these); `json`: `"true"` or `"false"` (strings) | 2026-11-04 | | `app_error` | live | lib/analytics.js:172 | a command that ends with exit 1 | `where`: the command, as above; `code`: `check-failed` for a plain `doctor` whose checks found a problem on the machine (not a fault in the launcher; not `doctor --fix`, whose exit 1 can be a failed repair, and not a run that ended on a thrown error; added 2026-11-04 before the first release) or `other` (fixed codes per failure come later, each added here first) | 2026-11-04 | Never sent: a path, a file or folder name, a user name, a rule, an argument, an app id the person typed, a token, an diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index e8c73022..4b975678 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -33,8 +33,9 @@ to macOS Installer, which alone asks for the administrator password. Program thr time cap and ran again on its own with help, strings, no-em-dash, repo-rules and docs: 195 of 195, exit 0. - IP gate (`ip_gate.py scan --destination public:npm-passioncode`) on `lib/anchor.js`, the CLI lines and the SECURITY section: pass. -- The same refusals on a real machine: fabric-workspace `tools/brain/anchor/evidence/2026-11-25-vm-acc.json` (the - unsigned, tampered, flipped-byte and other-team packages refused by the agents' user before any elevation). +- The same refusals by the Python twin of this check on a real machine (fabric-workspace `assert_identity.py`, the same + `pkgutil` reading; the VM never ran `lib/anchor.js`): `tools/brain/anchor/evidence/` there (the unsigned, tampered, + flipped-byte and other-team packages refused by the agents' user before any elevation). ## Open diff --git a/lib/analytics.js b/lib/analytics.js index 34a6194a..28417637 100644 --- a/lib/analytics.js +++ b/lib/analytics.js @@ -24,7 +24,7 @@ const APP_KEY = /^A-[A-Z]{2,4}-\d{10}$/; const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; // an app may write it upper case: sent as written const SEND_MS = 2000; // The words a property may carry; anything else is dropped (a free string could hold a name or a path). -const COMMANDS = new Set(['setup', 'doctor', 'update', 'status', 'restore', 'config', 'uninstall', 'permissions', 'analytics', 'help']); +const COMMANDS = new Set(['setup', 'doctor', 'update', 'status', 'restore', 'config', 'uninstall', 'permissions', 'analytics', 'help', 'anchor']); const OUTCOMES = new Set(['ok', 'failed', 'usage']); // check-failed: a plain doctor whose checks found a problem on the machine (not --fix, not a thrown error); other: the rest. const ERROR_CODES = new Set(['check-failed', 'other']); diff --git a/lib/anchor.js b/lib/anchor.js index 8d356320..f22679f5 100644 --- a/lib/anchor.js +++ b/lib/anchor.js @@ -162,6 +162,8 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA const { pin, error } = readPin(pkg, { run }); if (!add('pin', !!pin, pin ? `payload tree hash ${pin.tree_hash}, built at commit ${pin.tool_commit || 'unnamed'}` : error)) return done(); + // A fixture package is a test vector, never signed by the workflow; one that reached here is refused all the same. + if (pin.fixture === true && !add('pin-mode', false, 'a fixture package (test only)')) return done(); if (deploy && deploy.tool && deploy.tool.tree_hash) { add('manifest-tool', pin.tool_tree_hash === deploy.tool.tree_hash, pin.tool_tree_hash === deploy.tool.tree_hash ? 'tool tree hash equals the deployment manifest' : `tool tree hash ${pin.tool_tree_hash} is not the manifest's ${deploy.tool.tree_hash}`); } diff --git a/test/anchor.test.js b/test/anchor.test.js index 1af79e0c..2d5e245f 100644 --- a/test/anchor.test.js +++ b/test/anchor.test.js @@ -64,6 +64,7 @@ const refusals = [ ['a package without a build attestation', { attest: 1 }, 'attestation'], ['a machine without gh to read the attestation', { attest: 127 }, 'attestation'], ['a build attested from a branch, not a brain-anchor tag', { attestOut: attested('refs/heads/feature') }, 'attestation'], + ['a fixture package', { pin: { tree_hash: 'a'.repeat(64), tool_tree_hash: 'b'.repeat(64), fixture: true } }, 'pin-mode'], ['an attestation answer that cannot be read', { attestOut: 'not json' }, 'attestation'], ['a package Gatekeeper does not accept', { assess: 'source=no usable signature' }, 'assessment'], ['a package without a pin', { pin: null }, 'pin'], From 80e36a3748a97cb0ad245db48f69d360f250fa02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 06:51:50 +0100 Subject: [PATCH 06/12] docs(handoff): anchor tests 19 of 19 after the fixture refusal Co-Authored-By: Claude Opus 5.5 --- docs/handoffs/2026-11-25-w7-anchor-launcher.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index 4b975678..7a424833 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -22,7 +22,7 @@ to macOS Installer, which alone asks for the administrator password. Program thr ## Checks actually run -- Session 59: `node --test test/anchor.test.js` 18 of 18; full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the +- Session 59: `node --test test/anchor.test.js` 19 of 19; full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the known PC-246); IP gate (`public:npm-passioncode`) on the changed `lib/anchor.js`, `bin/passioncode.js`, SECURITY.md, the PC-248 row and the commit messages: pass. From b00beca47a9af75e340eef6429969da14d85b214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 07:16:19 +0100 Subject: [PATCH 07/12] fix(anchor): the request's words are checked before any download or check, dry run included (W7 T28a review round 5) A dry run with --role org-space and no --org printed 'every check passed', and the real run then failed with exit 1 after the gh and pkgutil calls. The request is now checked first and a bad one is a usage error (exit 2) with no check run and nothing written. Co-Authored-By: Claude Opus 5.5 --- docs/handoffs/2026-11-25-w7-anchor-launcher.md | 2 +- lib/anchor.js | 17 +++++++++++++---- test/anchor.test.js | 12 ++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index 7a424833..1e366d45 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -22,7 +22,7 @@ to macOS Installer, which alone asks for the administrator password. Program thr ## Checks actually run -- Session 59: `node --test test/anchor.test.js` 19 of 19; full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the +- Session 59: `node --test test/anchor.test.js` 20 of 20; full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the known PC-246); IP gate (`public:npm-passioncode`) on the changed `lib/anchor.js`, `bin/passioncode.js`, SECURITY.md, the PC-248 row and the commit messages: pass. diff --git a/lib/anchor.js b/lib/anchor.js index f22679f5..962648a0 100644 --- a/lib/anchor.js +++ b/lib/anchor.js @@ -174,11 +174,17 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA * The request the package reads from the person's home: the role, the organisation of an organisation space, and the * roster row the install step enrols (the Studio made the row; the code then shows in the installer's own window). */ +function requestProblem({ role, org = null, row = null }) { + if (!ROLES.includes(role)) return `role must be one of ${ROLES.join(', ')}`; + if (role === 'org-space' && !/^[a-z][a-z0-9-]{1,20}$/.test(org || '')) return 'an organisation space needs --org'; + if (role !== 'org-space' && org) return '--org belongs to an organisation space only'; + if (row !== null && !ROW.test(row)) return '--row must be a roster row id'; + return null; +} + function writeRequest(home, { role, org, row = null }) { - if (!ROLES.includes(role)) throw new Error(`role must be one of ${ROLES.join(', ')}`); - if (role === 'org-space' && !/^[a-z][a-z0-9-]{1,20}$/.test(org || '')) throw new Error('an organisation space needs --org'); - if (role !== 'org-space' && org) throw new Error('--org belongs to an organisation space only'); - if (row !== null && !ROW.test(row)) throw new Error('--row must be a roster row id'); + const problem = requestProblem({ role, org, row }); + if (problem) throw new Error(problem); const dir = path.join(home, '.passioncode'); fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); const file = path.join(dir, 'brain-anchor.json'); @@ -212,6 +218,9 @@ async function anchor({ pkg, url, sumsFile, deployFile, role = 'person', org = n if (platform !== 'darwin') return { code: 2, message: 'the service package installs on macOS only' }; if (uid === 0) return { code: 2, message: 'run it as yourself, without sudo: macOS Installer asks for the administrator password in its own prompt' }; if (!pkg === !url) return { code: 2, message: 'name the package with --pkg PATH (and --sums PATH) or --url URL' }; + // The request is checked before any download or check, so a dry run proves the words the real run will take. + const problem = requestProblem({ role, org, row }); + if (problem) return { code: 2, message: problem }; let sums; if (url) { // The download stays in the temp folder: Installer reads the package after `open` returns. diff --git a/test/anchor.test.js b/test/anchor.test.js index 2d5e245f..0ee07cef 100644 --- a/test/anchor.test.js +++ b/test/anchor.test.js @@ -155,3 +155,15 @@ test('T28b: the request may carry the roster row the install step enrols; a bad assert.ok(calls.every((c) => c.includes('--format json')), calls.join('\n')); assert.ok(r.checks.find((c) => c.check === 'pin').detail.includes('c'.repeat(40)), 'the pinned commit is shown'); }); + +test('T28a: a request that cannot be written is a usage error before any check runs, dry run included', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + for (const bad of [{ role: 'org-space' }, { role: 'person', org: 'passioncode' }, { role: 'nobody' }, { role: 'person', row: '../x' }]) { + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, ...bad, dryRun: true, run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 2, JSON.stringify(bad)); + } + assert.ok(!w.calls.some((c) => c.startsWith('gh ') || c.startsWith('pkgutil')), 'no check ran for a bad request'); + assert.ok(!fs.existsSync(path.join(w.dir, '.passioncode', 'brain-anchor.json'))); +}); From 6fd8a3f083b3c5d7d383e75b684da7e433fcf139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 07:40:20 +0100 Subject: [PATCH 08/12] fix(anchor): show the tool tree hash beside the payload's; SECURITY.md says where Gatekeeper's notarisation check applies (W7 T28a review round 6) The deployment manifest pins the tool tree hash, so the launcher shows it beside the payload tree hash it compares at install. SECURITY.md claimed Installer refuses a package that is not notarised; Gatekeeper's check applies to a quarantined download, and a package taken with gh run download carries none. Co-Authored-By: Claude Opus 5.5 --- SECURITY.md | 4 ++-- lib/anchor.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index f65d9df2..b53ce76a 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -154,8 +154,8 @@ the password goes only into Installer's own prompt. It writes `~/.passioncode/br organisation for an organisation space, and the roster row the install step enrols; nothing else) and opens Installer with `open -a Installer`. A failed check writes nothing and opens nothing. The limit of a check made as the person: the package and the request sit where that user (and so any agent session of that user) can write, between the checks -and the moment Installer reads them. macOS Installer still refuses a package that is not notarised Developer ID, and -the package's own first elevated step compares its payload with the pin shipped inside the same package before +and the moment Installer reads them. Gatekeeper's notarisation check applies to a package that carries the +download quarantine (a browser download does; a package taken with `gh run download` or copied by hand does not), and the package's own first elevated step compares its payload with the pin shipped inside the same package before anything changes, which catches a modified payload of a genuine package but checks no signature and no team. So a same-user swap, between the checks and Installer's read, of the package (for another team's notarised package, or a package that Installer opens without a notarisation check) or of the request is not caught by the launcher; what still diff --git a/lib/anchor.js b/lib/anchor.js index 962648a0..de86e6fb 100644 --- a/lib/anchor.js +++ b/lib/anchor.js @@ -161,7 +161,7 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA if (!add('assessment', gk.code === 0 && !!src && src[1].trim() === 'Notarized Developer ID', src ? `source=${src[1].trim()}` : `spctl exit ${gk.code}`)) return done(); const { pin, error } = readPin(pkg, { run }); - if (!add('pin', !!pin, pin ? `payload tree hash ${pin.tree_hash}, built at commit ${pin.tool_commit || 'unnamed'}` : error)) return done(); + if (!add('pin', !!pin, pin ? `payload tree hash ${pin.tree_hash}, tool tree hash ${pin.tool_tree_hash}, built at commit ${pin.tool_commit || 'unnamed'}` : error)) return done(); // A fixture package is a test vector, never signed by the workflow; one that reached here is refused all the same. if (pin.fixture === true && !add('pin-mode', false, 'a fixture package (test only)')) return done(); if (deploy && deploy.tool && deploy.tool.tree_hash) { From cb27adaa932c425a9830c98a2fb4e90cc1055286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 11:00:08 +0100 Subject: [PATCH 09/12] fix(anchor): the role is required; spctl, pkgutil and open run by absolute path (W7 T28a review round 8) - anchor() no longer defaults the role to person: without --role it is a usage error before any check or write (an organisation space run without --role would have installed a person account). - The system checking tools run as /usr/sbin/spctl, /usr/sbin/pkgutil and /usr/bin/open, never through the person's PATH; gh stays on the PATH and SECURITY.md and PC-248 say what a shimmed gh can fake. Red first. Co-Authored-By: Claude Opus 5.5 --- SECURITY.md | 5 +++ bin/passioncode.js | 2 +- docs/backlog.md | 2 +- .../handoffs/2026-11-25-w7-anchor-launcher.md | 8 ++-- lib/anchor.js | 19 +++++---- test/anchor.test.js | 40 +++++++++++++++---- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index b53ce76a..e753498e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -160,6 +160,11 @@ anything changes, which catches a modified payload of a genuine package but chec same-user swap, between the checks and Installer's read, of the package (for another team's notarised package, or a package that Installer opens without a notarisation check) or of the request is not caught by the launcher; what still holds is that the store paths come from the package, never from the request. This is a known limit (PC-248). +`spctl`, `pkgutil` and `open` run by their absolute paths under `/usr` (System Integrity Protection keeps them), never +through the person's `PATH`, so a shim a process of the same user puts on the `PATH` cannot report a check as passed; +`gh` is not a system tool and is found on the `PATH`, so a shimmed `gh` could fake the attestation check alone, while +the signature check still runs through `/usr/sbin/pkgutil`. The role is never defaulted: `--role` is required, and +without it nothing is checked or written. ## What anonymous counts send diff --git a/bin/passioncode.js b/bin/passioncode.js index 0190743f..e89bf62a 100755 --- a/bin/passioncode.js +++ b/bin/passioncode.js @@ -371,7 +371,7 @@ async function anchorCommand(rest) { for (let i = 0; i < args.length; i++) { if (args[i] === '--dry-run') { o.dryRun = true; continue; } const key = names[args[i]]; - if (!key || args[i + 1] === undefined || o[key] !== undefined) return usage('anchor install takes --pkg PATH --sums PATH | --url URL, [--deploy FILE] [--role person|owner|org-space] [--org ORG] [--row ROW] [--dry-run] [--json]'); + if (!key || args[i + 1] === undefined || o[key] !== undefined) return usage('anchor install takes --pkg PATH --sums PATH | --url URL, [--deploy FILE] --role person|owner|org-space [--org ORG] [--row ROW] [--dry-run] [--json]'); o[key] = args[++i]; } if (verb !== 'install') return usage('anchor takes install'); diff --git a/docs/backlog.md b/docs/backlog.md index 488fea9b..3bfa4756 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -253,4 +253,4 @@ derives its common backlog from [backlog-sources.json](backlog-sources.json). | PC-245 | The owner's MacBook to the base manifest: run the owner's line in [fabric-base-1-install.md](reference/fabric-base-1-install.md#the-owners-mac-a-app-11) on the MacBook (Inbox 1.7.1 to 1.9.2, adapter 0.102.0), done when `doctor` exits 0 and Inbox reads 1.9.2. The build machine cannot open a shell on the MacBook (SSH timed out, 2026-11-24; access runs only the other way), so a MacBook session or the owner runs it | open 2026-11-24: needs a process on the MacBook; 0.2.83 is on npm (`latest`, release run 45294028388 success), so the line runs as written | W2 session 06 | | PC-246 | `PC-163: the server end of this account's own connection reads \`own\` from the real socket table` (`test/listener.test.js`) fails on a build machine whose `netstat` prints no row for the server end of the test's own loopback connection (`table-restricted … netstat printed no table`); it fails the same on unchanged `origin/main` `df80ead` there, 2026-11-24. Make the test skip with its reason where the table is restricted, or read the table the way that machine allows | open 2026-11-24: P3 | W2 session 06, full `npm test` on `agent/w2-s06-base1-owner-mac` (681 of 687 pass, 2 fail: this one and a strings.md drift fixed in the same branch) | | PC-247 | W7 T28a, the service package hand-off: `passioncode anchor install` (`lib/anchor.js`, `test/anchor.test.js`, SECURITY.md "What `anchor install` touches") checks a package as the person (Gatekeeper on, SHA256SUMS and a manifest pin, the build attestation, `pkgutil` signature of team `KJ35UYYL22` to the Apple Root CA, `spctl`, the embedded pin) and hands it to macOS Installer; never sudo. Left: a help line and strings.md rows when it ships, and a launcher release after the owner's sitting (T28d) proves it on the live package | open 2026-11-25: built on branch `w7-anchor-launcher-2026-11-25`, not merged, not released | Studio session 45 (W7 trust-anchor lane, thread `bb204715`); fabric-workspace `w7-anchor-2026-11-25` `tools/brain/anchor/` | -| PC-248 | The anchor hand-off's same-user window (W7 T28a, review round 1 of Studio session 59): `passioncode anchor install` checks the package and writes `~/.passioncode/brain-anchor.json` as the person, so any process of that user (an agent session included) can swap the package (for another team's notarised package, or a self-built package Installer opens without a notarisation check, whose own pin matches its own payload) or rewrite the request, between the checks and the moment macOS Installer reads them; the package's first step compares only its payload with its own pin, and Installer checks no team. SECURITY.md "What `anchor install` touches" names the limit. A fix needs a hand-off the user cannot write between check and read (for example the package's own first elevated step checking the team of its own signature, or Installer reading a copy the user cannot change) | open 2026-11-25 | Studio session 59, review finding 9 of round 1 (W7 trust-anchor lane, thread `bb204715`); nothing in T28a's done line depends on it (the payload still aborts off its pin) | +| PC-248 | The anchor hand-off's same-user window (W7 T28a, review round 1 of Studio session 59): `passioncode anchor install` checks the package and writes `~/.passioncode/brain-anchor.json` as the person, so any process of that user (an agent session included) can swap the package (for another team's notarised package, or a self-built package Installer opens without a notarisation check, whose own pin matches its own payload) or rewrite the request, between the checks and the moment macOS Installer reads them; the package's first step compares only its payload with its own pin, and Installer checks no team. SECURITY.md "What `anchor install` touches" names the limit. The same user can also shim `gh` on the `PATH` (it is found there; `spctl`, `pkgutil` and `open` run by absolute path since review round 8), which fakes the attestation check alone. A fix needs a hand-off the user cannot write between check and read (for example the package's own first elevated step checking the team of its own signature, or Installer reading a copy the user cannot change) | open 2026-11-25 | Studio session 59, review finding 9 of round 1 (W7 trust-anchor lane, thread `bb204715`); nothing in T28a's done line depends on it (the payload still aborts off its pin) | diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index 1e366d45..b38755f8 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -7,15 +7,17 @@ to macOS Installer, which alone asks for the administrator password. Program thr ## Done -- `lib/anchor.js` and `passioncode anchor install --pkg PATH --sums PATH | --url URL [--deploy FILE] [--role - person|owner|org-space] [--org ORG] [--row ROW] [--dry-run] [--json]` (dispatched from `bin/passioncode.js`, the function at the +- `lib/anchor.js` and `passioncode anchor install --pkg PATH --sums PATH | --url URL [--deploy FILE] --role + person|owner|org-space [--org ORG] [--row ROW] [--dry-run] [--json]` (dispatched from `bin/passioncode.js`, the function at the file's end so no line a strings.md row cites moves). Checks in order: Gatekeeper on, SHA-256 against SHA256SUMS and a deployment manifest's pin, `gh attestation verify` for `passioncode-ai/fabric-workspace`'s `brain-anchor.yml`, made on a pushed `brain-anchor-v` tag (any other source ref refused), `pkgutil --check-signature` (notarised, Developer ID Installer of `KJ35UYYL22`, Developer ID CA, Apple Root CA by fingerprint, the manifest's certificate pin), `spctl -a -t install`, the embedded pin (shown with its commit; equal to the manifest's tool tree hash when given; a manifest that pins no package sha256 is refused). Then it writes `~/.passioncode/brain-anchor.json` (role, organisation, roster row) and runs `open -a Installer`. -- SECURITY.md: "What `anchor install` touches", with the same-user window between the checks and Installer's read +- SECURITY.md: "What `anchor install` touches", with the same-user window between the checks and Installer's read, + and the system tools run by absolute path (`TOOL` in `lib/anchor.js`; `gh` from the `PATH`), the role required + (review round 8 of Studio session 59) (PC-248). - Studio session 59 (integration and blind review rounds): the attestation's source ref, `--row`, the manifest's package pin, PC-248; `origin/main` merged in. diff --git a/lib/anchor.js b/lib/anchor.js index de86e6fb..9fd43337 100644 --- a/lib/anchor.js +++ b/lib/anchor.js @@ -25,6 +25,10 @@ const NOTARY_OK = 'trusted by the Apple notary service'; const REPO = 'passioncode-ai/fabric-workspace'; const WORKFLOW = `${REPO}/.github/workflows/brain-anchor.yml`; const ROLES = ['person', 'owner', 'org-space']; +// The system tools run by absolute path (SIP-protected), never through the person's PATH, where a process of the same +// user could put a shim that reports ok. `gh` is not a system tool and is found on the PATH: a shimmed `gh` can only +// fake the attestation check; the signature check still runs through /usr/sbin/pkgutil (SECURITY.md, PC-248). +const TOOL = { spctl: '/usr/sbin/spctl', pkgutil: '/usr/sbin/pkgutil', open: '/usr/bin/open' }; function defaultRun(cmd, args, opts) { return require('./releases').run(cmd, args, opts); } @@ -86,7 +90,7 @@ function readPin(pkg, { run = defaultRun, tmp = os.tmpdir() } = {}) { const dir = fs.mkdtempSync(path.join(tmp, 'pc-anchor-')); const out = path.join(dir, 'x'); try { - const r = run('pkgutil', ['--expand-full', pkg, out], { timeout: 300000 }); + const r = run(TOOL.pkgutil, ['--expand-full', pkg, out], { timeout: 300000 }); if (r.code !== 0) return { error: `pkgutil --expand-full: ${(r.err || r.out).trim().split('\n')[0]}` }; const candidates = [path.join(out, 'component.pkg', 'Scripts', 'pin.json'), path.join(out, 'Scripts', 'pin.json')]; const file = candidates.find((f) => fs.existsSync(f)); @@ -127,7 +131,7 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA const add = (check, ok, detail) => { checks.push({ check, ok, detail }); return ok; }; const done = (pin = null) => ({ ok: checks.every((c) => c.ok), checks, pin }); - const status = run('spctl', ['--status'], { timeout: 20000 }); + const status = run(TOOL.spctl, ['--status'], { timeout: 20000 }); const st = `${status.out}${status.err}`.trim(); if (!add('gatekeeper', st === 'assessments enabled', st || 'no answer')) return done(); @@ -152,11 +156,11 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA if (!add('attestation', a.code === 0 && !refProblem, detail)) return done(); } - const sig = run('pkgutil', ['--check-signature', pkg], { timeout: 60000 }); + const sig = run(TOOL.pkgutil, ['--check-signature', pkg], { timeout: 60000 }); const problem = signatureProblem(sig.out, { team, certSha256: pinned ? pinned.signer_certificate_sha256 : null }); if (!add('signature', !problem, problem || `Developer ID Installer of ${team}, notarised`)) return done(); - const gk = run('spctl', ['-a', '-vv', '-t', 'install', pkg], { timeout: 120000 }); + const gk = run(TOOL.spctl, ['-a', '-vv', '-t', 'install', pkg], { timeout: 120000 }); const src = /source=([^\n]+)/.exec(`${gk.err}\n${gk.out}`); if (!add('assessment', gk.code === 0 && !!src && src[1].trim() === 'Notarized Developer ID', src ? `source=${src[1].trim()}` : `spctl exit ${gk.code}`)) return done(); @@ -175,6 +179,7 @@ function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEA * roster row the install step enrols (the Studio made the row; the code then shows in the installer's own window). */ function requestProblem({ role, org = null, row = null }) { + if (role === null || role === undefined) return `name the role with --role ${ROLES.join('|')}: it is never defaulted`; if (!ROLES.includes(role)) return `role must be one of ${ROLES.join(', ')}`; if (role === 'org-space' && !/^[a-z][a-z0-9-]{1,20}$/.test(org || '')) return 'an organisation space needs --org'; if (role !== 'org-space' && org) return '--org belongs to an organisation space only'; @@ -197,7 +202,7 @@ function writeRequest(home, { role, org, row = null }) { /** Hand the checked package to macOS's Installer, which asks for the administrator password itself. */ function handOff(pkg, { run = defaultRun } = {}) { - const r = run('open', ['-a', 'Installer', pkg], { timeout: 30000 }); + const r = run(TOOL.open, ['-a', 'Installer', pkg], { timeout: 30000 }); return { ok: r.code === 0, detail: r.code === 0 ? 'handed to macOS Installer; type the password only into its own prompt' : (r.err || r.out).trim() }; } @@ -214,7 +219,7 @@ async function fetchRelease(url, dir) { } /** The whole command. Exit codes: 0 handed off (or checked, with dryRun), 1 a check failed, 2 usage. */ -async function anchor({ pkg, url, sumsFile, deployFile, role = 'person', org = null, row = null, dryRun = false, uid = process.getuid ? process.getuid() : null, home = os.homedir(), run = defaultRun, platform = process.platform }) { +async function anchor({ pkg, url, sumsFile, deployFile, role = null, org = null, row = null, dryRun = false, uid = process.getuid ? process.getuid() : null, home = os.homedir(), run = defaultRun, platform = process.platform }) { if (platform !== 'darwin') return { code: 2, message: 'the service package installs on macOS only' }; if (uid === 0) return { code: 2, message: 'run it as yourself, without sudo: macOS Installer asks for the administrator password in its own prompt' }; if (!pkg === !url) return { code: 2, message: 'name the package with --pkg PATH (and --sums PATH) or --url URL' }; @@ -238,4 +243,4 @@ async function anchor({ pkg, url, sumsFile, deployFile, role = 'person', org = n return { code: h.ok ? 0 : 1, message: h.detail, request, ...v }; } -module.exports = { anchor, verify, signatureProblem, parsePkgutil, sumFor, readPin, writeRequest, handOff, ROOT_CA_SHA256, WORKFLOW }; +module.exports = { TOOL, anchor, verify, signatureProblem, parsePkgutil, sumFor, readPin, writeRequest, handOff, ROOT_CA_SHA256, WORKFLOW }; diff --git a/test/anchor.test.js b/test/anchor.test.js index 0ee07cef..3dcca5f4 100644 --- a/test/anchor.test.js +++ b/test/anchor.test.js @@ -26,7 +26,10 @@ function world({ signature = ours, gatekeeper = 'assessments enabled', assess = fs.writeFileSync(pkg, 'package bytes'); const sha = crypto.createHash('sha256').update('package bytes').digest('hex'); const calls = []; - const run = (cmd, args) => { + const paths = []; + const run = (full, args) => { + paths.push(full); + const cmd = path.basename(full); calls.push([cmd, ...args].join(' ')); if (cmd === 'spctl' && args[0] === '--status') return { code: 0, out: `${gatekeeper}\n`, err: '' }; if (cmd === 'spctl') return { code: assess.includes('Notarized') ? 0 : 3, out: '', err: `${pkg}: x\n${assess}\n` }; @@ -41,12 +44,12 @@ function world({ signature = ours, gatekeeper = 'assessments enabled', assess = if (cmd === 'open') return { code: 0, out: '', err: '' }; return { code: 127, out: '', err: `${cmd} not expected` }; }; - return { dir, pkg, sha, sums: `${sha} passioncode-brain-anchor-0.1.0.pkg\n`, run, calls }; + return { dir, pkg, sha, sums: `${sha} passioncode-brain-anchor-0.1.0.pkg\n`, run, calls, paths }; } test('T28a: a package of the team, notarised, listed and attested passes every check and is handed to Installer', async () => { const w = world(); - const r = await A.anchor({ pkg: w.pkg, sumsFile: (fs.writeFileSync(path.join(w.dir, 'S'), w.sums), path.join(w.dir, 'S')), run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + const r = await A.anchor({ pkg: w.pkg, sumsFile: (fs.writeFileSync(path.join(w.dir, 'S'), w.sums), path.join(w.dir, 'S')), run: w.run, uid: 501, home: w.dir, platform: 'darwin', role: 'person' }); assert.equal(r.code, 0, JSON.stringify(r)); assert.deepEqual(r.checks.map((c) => c.check), ['gatekeeper', 'sha256', 'attestation', 'signature', 'assessment', 'pin']); assert.ok(w.calls.includes(`open -a Installer ${w.pkg}`)); @@ -73,7 +76,7 @@ for (const [name, opts, failed] of refusals) { test(`T28a: ${name} is refused before elevation`, async () => { const w = world(opts); fs.writeFileSync(path.join(w.dir, 'S'), w.sums); - const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', role: 'person' }); assert.equal(r.code, 1); assert.equal(r.checks.at(-1).check, failed); assert.equal(r.checks.at(-1).ok, false); @@ -86,7 +89,7 @@ test('T28a: bytes that differ from SHA256SUMS, or a file it does not list, are r const w = world(); for (const sums of [`${'0'.repeat(64)} passioncode-brain-anchor-0.1.0.pkg\n`, `${w.sha} other.pkg\n`]) { fs.writeFileSync(path.join(w.dir, 'S'), sums); - const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', role: 'person' }); assert.equal(r.code, 1); assert.equal(r.checks.at(-1).check, 'sha256'); } @@ -97,7 +100,7 @@ test('T28a: a deployment manifest pins the package bytes, the installer certific fs.writeFileSync(path.join(w.dir, 'S'), w.sums); const leaf = A.parsePkgutil(ours).chain[0].sha256; const deploy = (o) => { const f = path.join(w.dir, 'D'); fs.writeFileSync(f, JSON.stringify({ tool: { tree_hash: 'b'.repeat(64), package: { sha256: w.sha, signer_certificate_sha256: leaf, ...o } } })); return f; }; - const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', dryRun: true }; + const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', dryRun: true, role: 'person' }; assert.equal((await A.anchor({ ...base, deployFile: deploy({}) })).code, 0); let r = await A.anchor({ ...base, deployFile: deploy({ sha256: '1'.repeat(64) }) }); assert.equal(r.checks.at(-1).check, 'manifest-sha256'); @@ -113,7 +116,7 @@ test('T28a: a deployment manifest pins the package bytes, the installer certific test('T28a: never as root, macOS only, a dry run does not hand off, and the request is validated', async () => { const w = world(); fs.writeFileSync(path.join(w.dir, 'S'), w.sums); - const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, home: w.dir, platform: 'darwin' }; + const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, home: w.dir, platform: 'darwin', role: 'person' }; assert.equal((await A.anchor({ ...base, uid: 0 })).code, 2); assert.equal((await A.anchor({ ...base, uid: 501, platform: 'linux' })).code, 2); const d = await A.anchor({ ...base, uid: 501, dryRun: true }); @@ -135,7 +138,7 @@ test('T28a: with the real pkgutil, an unsigned package built here is refused at const sha = crypto.createHash('sha256').update(fs.readFileSync(pkg)).digest('hex'); const gatekeeperOn = { code: 0, out: 'assessments enabled\n', err: '' }; const real = require('../lib/releases').run; - const run = (cmd, args, o) => (cmd === 'spctl' && args[0] === '--status' ? gatekeeperOn : real(cmd, args, o)); + const run = (cmd, args, o) => (path.basename(cmd) === 'spctl' && args[0] === '--status' ? gatekeeperOn : real(cmd, args, o)); const r = A.verify(pkg, { sums: `${sha} unsigned.pkg\n`, run, requireAttestation: false }); assert.equal(r.ok, false); assert.equal(r.checks.at(-1).check, 'signature'); @@ -167,3 +170,24 @@ test('T28a: a request that cannot be written is a usage error before any check r assert.ok(!w.calls.some((c) => c.startsWith('gh ') || c.startsWith('pkgutil')), 'no check ran for a bad request'); assert.ok(!fs.existsSync(path.join(w.dir, '.passioncode', 'brain-anchor.json'))); }); + +test('T28a: the role is named on the command line, never defaulted; no check runs without it', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, dryRun: true, run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 2); + assert.match(r.message, /--role/); + assert.deepEqual(w.calls, [], 'no check ran'); +}); + +test('T28a: the system checking tools run by absolute path, never through the person\'s PATH', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, role: 'person', run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 0, JSON.stringify(r)); + const system = w.paths.filter((p) => path.basename(p) !== 'gh'); + assert.ok(system.length >= 5, system.join(' ')); + for (const p of system) assert.ok(['/usr/sbin/spctl', '/usr/sbin/pkgutil', '/usr/bin/open'].includes(p), p); +}); From c6507e895102aeae9aa14bf0ee69f17e66f59908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 11:13:56 +0100 Subject: [PATCH 10/12] docs(handoff): anchor tests 22 of 22 at cb27ada; session 45's count named as its own (W7 T28a review round 9) Co-Authored-By: Claude Opus 5.5 --- docs/handoffs/2026-11-25-w7-anchor-launcher.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index b38755f8..bd317895 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -24,11 +24,12 @@ to macOS Installer, which alone asks for the administrator password. Program thr ## Checks actually run -- Session 59: `node --test test/anchor.test.js` 20 of 20; full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the +- Session 59: `node --test test/anchor.test.js` 22 of 22 (at `cb27ada`, review round 8: the role required, the system + tools by absolute path); full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the known PC-246); IP gate (`public:npm-passioncode`) on the changed `lib/anchor.js`, `bin/passioncode.js`, SECURITY.md, the PC-248 row and the commit messages: pass. -- `node scripts/test.mjs test/anchor.test.js`: 15 of 15 (fixtures are real `pkgutil` outputs, `test/fixtures/anchor`; +- Session 45: `node scripts/test.mjs test/anchor.test.js`: 15 of 15 (fixtures are real `pkgutil` outputs, `test/fixtures/anchor`; one test builds an unsigned package with the real `pkgbuild` and sees the real `pkgutil` refuse it). - Full `npm test` on this machine: 678 tests, 672 pass, 4 skipped, 1 fail: PC-163's socket-table test, the known PC-246 failure of this build machine (fails the same on unchanged `origin/main`). `test/setup.test.js` was cut by the run's From c56c61abe127efc37e70a3caa37a62a05b3e3adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 11:24:04 +0100 Subject: [PATCH 11/12] docs(handoff): the next task's dry run passes --role owner (W7 T28a review round 10) Co-Authored-By: Claude Opus 5.5 --- docs/handoffs/2026-11-25-w7-anchor-launcher.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index bd317895..d2246e63 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -47,5 +47,5 @@ to macOS Installer, which alone asks for the administrator password. Program thr ## The next task -After T28d's first signed package exists: download the workflow's artifact (`gh run download -R passioncode-ai/fabric-workspace -n brain-anchor-signed`: nothing is published as a release) and run `passioncode anchor install --pkg --sums --dry-run` on the +After T28d's first signed package exists: download the workflow's artifact (`gh run download -R passioncode-ai/fabric-workspace -n brain-anchor-signed`: nothing is published as a release) and run `passioncode anchor install --pkg --sums --role owner --dry-run` on the MacBook as the owner, then merge this branch through a PR and release the launcher. From d1da0f4f81b27351bdccf513af8cfdac25f05c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B1=D0=BE=D1=82?= Date: Wed, 25 Nov 2026 12:37:20 +0100 Subject: [PATCH 12/12] docs(handoff): W7 T28a launcher checks after merging main (711 tests, the one failure the known PC-246) Co-Authored-By: Claude Opus 5.5 --- docs/handoffs/2026-11-25-w7-anchor-launcher.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md index 57726540..d7d66866 100644 --- a/docs/handoffs/2026-11-25-w7-anchor-launcher.md +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -25,6 +25,10 @@ until `main` took those ids for release 0.2.84). The package, its workflow and i ## Checks actually run +- Session 59, after merging `origin/main` `7421947` (0.2.84) at `6340353`: `node --test test/anchor.test.js` 22 of 22; + full `npm test` 711 tests, 706 pass, 4 skipped, 1 fail (the known PC-246: the PC-163 socket-table test fails the same + on unchanged `origin/main` `7421947` on this machine, run again 2026-11-25); IP gate (public) on the merge's changes + and the PR text: pass. - Session 59: `node --test test/anchor.test.js` 22 of 22 (at `cb27ada`, review round 8: the role required, the system tools by absolute path); full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the known PC-246); IP gate (`public:npm-passioncode`) on the changed `lib/anchor.js`, `bin/passioncode.js`, SECURITY.md,