You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 644a5eb
Browse filesBrowse the repository at this point in the historyBrowse files
[Spec 1963] harness: the tripwire stops the run; ide-server settings path and network sandbox
The 2026-11-24 incident: the ide-server mode's first run wrote codev.towerPort under
--user-data-dir, which a VS Code server ignores, so the extension host used :4100, the owner's
Tower (about 9,100 requests over 25 minutes, all refused 401). The tripwire detected it within
a second but only wrote a marker and exited; the run went on.
- tripwire: on a hit, write the marker, SIGSTOP the whole harness tree (rescanning until no new
process appears), SIGKILL it, then report what it killed. A pid file counts only while its
pid's command carries the file's markers; CLI pid files now record one. Sampling every 1 s.
- ide-server settings: written to <server-data-dir>/data/Machine/settings.json. Gate 5 confirms
that from the server's own bundle (out/server-main.js) and refuses a server where it cannot,
and refuses VSCODE_PORTABLE/VSCODE_APPDATA in the server env. No --user-data-dir is passed.
- prevention (sandbox.mjs): the ide-server runs under sandbox-exec with a profile that denies
outbound TCP to :4100 on any host. A launch canary, a throwaway port the profile also denies,
must be refused inside the sandbox before the server starts.
- selftest takes sections; tripwire/settings/sandbox use throwaway listeners only: 17/17.
node $H seed one-builder # seed a scenario; gate 6 asserts its overview
@@ -27,7 +28,14 @@ node $H stop # kill the harness's own PIDs; remove runtime dirs
27
28
```
28
29
29
30
`selftest` needs both ports set and free, even though it serves no web. Its refusal cases run real
30
-
`start` processes, and each must refuse for the gate under test, not for a missing port.
31
+
`start` processes, and each must refuse for the gate under test, not for a missing port. Its
32
+
sections, run when named or all by default:
33
+
-`gates`: gates 1 and 2;
34
+
-`tower`: gates 3 and 4 against a real isolated Tower;
35
+
-`fixtures`: `stop`'s refusals;
36
+
-`tripwire`, `settings`, `sandbox`: throwaway listeners and stand-in processes only. `settings`
37
+
also reads, without launching them, the bundles of any server binaries named in
38
+
`COCKPIT_SELFTEST_SERVER_BINS` (colon-separated).
31
39
32
40
`build-vsix` records a digest of every tracked or untracked file the vsix is built from. `check`
33
41
treats the installed vsix as the branch's only while that digest still matches, so an
@@ -40,6 +48,15 @@ If `code serve-web` cannot run, start with the IDE server binary instead:
40
48
COCKPIT_VSCODE=ide-server COCKPIT_IDE_SERVER_BIN=<path to the VS Code Server's bin/code-server> node $H start
41
49
```
42
50
51
+
**ide-server mode needs the owner's go-ahead** (the 2026-11-24 incident). Its first run wrote the
52
+
machine settings under `--user-data-dir`, which this kind of server ignores. Its extension host
53
+
then used the default port and sent about 9,100 requests to the owner's Tower over 25 minutes;
54
+
every one was refused with a 401. The mode now:
55
+
- writes the settings where the server's own code says it reads them, and refuses a server whose
56
+
bundle does not show where that is (gate 5);
57
+
- runs the server inside a network sandbox (`sandbox.mjs`) that denies outbound TCP to `:4100`,
58
+
and proves the sandbox applies at each launch with a canary port.
59
+
43
60
Prerequisites:
44
61
- `packages/codev` is built, because the Tower and the fixture driver load its `dist`;
45
62
- `pnpm install` has run, because the browser driver resolves `playwright` from `packages/codev`.
@@ -56,19 +73,20 @@ Never run `playwright install`. The driver uses the Chromium already in
56
73
| Fixture driver (`fixtures.mjs`) | Runs in the isolated environment. Creates state only through:<ul><li>explicit-port HTTP calls (activation, builder terminals);</li><li>the dist's in-process writers (porch `writeState`, `upsertBuilder`);</li><li>git.</li></ul>It runs no Tower-contacting `afx` or `porch` command. |
57
74
| Fixture workspaces | Git repos in a fresh `cockpit-fixtures-*` dir (`mkdtemp`) under the real per-user temp dir (`/private/var/folders/…/T`), **not** the scratchpad. Tower's `/api/workspaces` drops every workspace under `/tmp`, `/private/tmp` or its own `os.tmpdir()` (`isTempDirectory`), and the scratchpad is under `/private/tmp`, so fixtures there never reach the fleet the Tower and Cockpit views list. The Tower's own `TMPDIR` points into the scratchpad, so this dir is not its temp dir. `start` writes a marker holding a per-run token in it; see *Teardown*. |
58
75
| Fixture sessions | Architects and builders are `/bin/bash --noprofile --norc`, through a no-op custom harness in each fixture's `.codev/config.json`. They are never agents. |
59
-
| VS Code | Runs on `$COCKPIT_WEB_PORT` in one of two modes, set by `COCKPIT_VSCODE`:<ul><li>`serve-web` (default): `code serve-web`, with the CLI, server, user and extensions dirs all under the root.</li><li>`ide-server`: the plan's alternative forwhen serve-web cannot run. It launches the VS Code Server binary Tower's IDE support uses (`COCKPIT_IDE_SERVER_BIN`) **directly**, never through any Tower's `/api/ide`. It passes the flags `ide-server.ts` passes (`--host 127.0.0.1`, `--port`, `--server-base-path /ide`, `--connection-token-file`, `--extensions-dir`), plus `--server-data-dir` and `--user-data-dir`, allin the scratchpad.</li></ul>The mode is chosen explicitly. A serve-web failure fails the start; it does not switch modes by itself.<ul><li>Machine settings: `codev.towerPort=$COCKPIT_TOWER_PORT`, `codev.autoStartTower=false`, `files.autoSave=off`.</li><li>Environment: `CODEV_TOWER_KEY` is the isolated key, `HOME` is the scratch home, and `stubs/` comes first on `PATH`.</li></ul>|
76
+
| VS Code | Runs on `$COCKPIT_WEB_PORT` in one of two modes, set by `COCKPIT_VSCODE`:<ul><li>`serve-web` (default): `code serve-web`, with the CLI, server, user and extensions dirs all under the root.</li><li>`ide-server`: the plan's alternative for when serve-web cannot run. It launches the VS Code Server binary Tower's IDE support uses (`COCKPIT_IDE_SERVER_BIN`) **directly**, never through any Tower's `/api/ide`. It passes the flags `ide-server.ts` passes (`--host 127.0.0.1`, `--port`, `--server-base-path /ide`, `--connection-token-file`, `--extensions-dir`), plus `--server-data-dir`, all in the scratchpad. It passes no `--user-data-dir`, because the server replaces it with `<server-data-dir>/data`. The server runs under `sandbox-exec` with a profile that denies outbound TCP to `:4100` and to a canary port, on any host. Before the server starts, a wrapper inside the sandbox connects to the canary port, and the server starts only if that connect is refused.</li></ul>The mode is chosen explicitly. A serve-web failure fails the start; it does not switch modes by itself.<ul><li>Machine settings: `codev.towerPort=$COCKPIT_TOWER_PORT`, `codev.autoStartTower=false`, `files.autoSave=off`. serve-web: in `<user-data-dir>/Machine/settings.json`. ide-server: in `<server-data-dir>/data/Machine/settings.json`. That is where the server's bundle (`out/server-main.js`) reads them, and gate 5 confirms it from the code before every start.</li><li>Environment: `CODEV_TOWER_KEY` is the isolated key, `HOME` is the scratch home, and `stubs/` comes first on `PATH`.</li></ul> |
60
77
| Stubs (`stubs/afx`, `porch`, `codev`) | Each call appends `{ tool, argv, cwd, caller }` to `<root>/logs/stub-calls.jsonl` and exits 0, so CLI-shelling actions are verified by their recorded argv.<br>`codev --version` prints the branch version.<br>The stubs are on the Tower's `PATH` too. |
61
78
| Browser (`workbench.mjs`) | Headless Chromium with a persistent profile under the root, so the folder-trust decision holds. Any request to `:4100` fails the check. |
62
-
| Tripwire (`tripwire.mjs`) | Samples `lsof` for ESTABLISHED connections on `:4100` every 2 s. The machine-wide socket-holder scan runs on every 5th sample only. It fails the run (writes `tripwire.tripped`, exits 3) if one belongs to the harness tree:<ul><li>the PIDs in `<root>/pids/`;</li><li>holders of sockets in the run dir;</li><li>descendants of either.</li></ul>It never connects to `:4100`. |
79
+
| Tripwire (`tripwire.mjs`) | Samples `lsof`forESTABLISHED connections on `:4100` every second. The machine-wide socket-holder scan runs on every 5th sample only. A connection counts if it belongs to the harness tree:<ul><li>the PIDsin`<root>/pids/`, each only while its command still carries the markers its pid file records;</li><li>holders of sockets in the run dir;</li><li>descendants of either.</li></ul>On one, it **stops the run at once**:<ol><li>writes `tripwire.tripped`, so every harness command refuses from then on;</li><li>freezes the whole tree with SIGSTOP, rescanning until no new process appears;</li><li>SIGKILLs the tree, which includes the CLI that ran `start` or `verify`;</li><li>adds what it killed, and any survivor, to the marker;</li><li>exits 3.</li></ol>Read the marker, or the `NOTE` that `stop` prints. It never connects to `:4100`. |
63
80
64
-
The tripwire **detects**; it does not enforce. It samples every 2 s, so a connect, request and
65
-
close to `:4100` that completes between two samples would escape it. (The extension's Tower
81
+
The tripwire **detects and stops**; it does not prevent. It samples every second, so a connect,
82
+
request and close to `:4100` that completes between two samples would escape it. (The extension's Tower
66
83
connection is a long-lived event stream, so a misdirected one would not.) Isolation is enforced by
67
84
the layers above:
68
85
- no Tower-contacting CLI;
69
86
- recording stubs on `PATH`;
70
87
- `codev.autoStartTower=false` and the pinned `codev.towerPort`;
71
-
- the isolated `CODEV_TOWER_KEY`, so a stray request to the owner's Tower would get a 401.
88
+
- the isolated `CODEV_TOWER_KEY`, so a stray request to the owner's Tower would get a 401;
89
+
- in ide-server mode, the network sandbox, which refuses the connect itself.
0 commit comments