Public: anyone can read this; the crew can change it.
Crew runs can SSH to a device the repository names: an owner-granted host:22 plus a key from the repo's secrets (the arm's Pi) #3679
A repository can now list devices its crew may SSH to, and a run on it gets a key, a pinned host and a logged ssh. I never made a real SSH connection or ran a real sandboxed run. tsc is clean, and the new tests plus the five cross files and the schema and brief tests pass.
stopped parked by the crew deploy d45ea21
3 earlier comments · 2 events
A repository can now list devices its crew may SSH to, and a run on it gets a key, a pinned host and a logged ssh. I never made a real SSH connection or ran a real sandboxed run. tsc is clean, and the new tests plus the five cross files and the schema and brief tests pass. The one failure was test/crew-sandbox-real.test.ts, because rg isn't installed in this sandbox.
What changed
- Listing and granting: a repository admin lists a device with
POST /api/v1/repos/:owner/:name/crew-devicesand{device: "[email protected]:22", secret: "ARM_PI_SSH_KEY"}. The entry must be an exactuser@host:port. Ranges, wildcards, loopback and the forge's own cluster ranges are refused, using the same rules as app egress. - Grant: a site admin calls
POST …/crew-devices/grant. The forge reads the host key the device shows at that moment and pins it, or the admin sendshost_keyinstead. The key is read withssh-keyscan, which is a new piping spawn, so it is listed intest/spawn-pipes.test.tswith its reason (that test is what failed pull #3492). Changing the secret drops the grant, andDELETEunlists the device. Agents can do none of this. - What a run gets: only granted devices count. The device's host:port goes into the sandbox's allowed hosts, in
src/crew/runner.ts. The run's temp directory gets:- a 0600 key file, taken only from a secret set at the repository's own scope, never the forge's or an org's;
- a
known_hostswith the pinned key; - an ssh config with an alias per device, set to
StrictHostKeyChecking yes, no forwarding, and a proxy script through the sandbox's SOCKS proxy; - an
sshwrapper first on PATH.
The key is never put in argv or the environment, and it is held for log redaction while the run lasts. It is removed when the run ends.
- Brief: it names each
ssh <alias>and the rules: read and test freely, restart only what sudo allows, never change the device's users, keys or network. - Session log: the wrapper records each
sshcall with its arguments, so the commands are in them. At run end each call becomes acrew.device.sessionevent on the repository and a line in the run log.GET …/crew-devicesshows the devices and sessions to anyone who administers the repository. - Where it lives: the code is
src/core/crew_devices.ts,src/crew/devices.ts,src/crew/hostkey.tsandsrc/actions/crew_devices.ts, plus a migration for thecrew_devicetable.docs/APPS.mddescribes it andtest/crew-devices.test.tscovers it. There are no new dependencies.
Left out
- A web settings page for devices. This is API-only for now, which is what the "reachable" check needs. Since you want this from your phone, a page is the obvious follow-up.
- A real SSH connection to a fake host. The tests run the wrapper against a stub
sshand check the key file, the config, the pinned host key, the sandbox hosts, the session log and redaction. - The sandbox's SOCKS proxy variable (
ALL_PROXY) andnc -X 5in the proxy script are my assumption about how Claude Code's sandbox exposes its proxy. Please try one real run against the Pi. - Anything that calls the real
sshbinary by absolute path with the key path skips the logging wrapper. The "never change the device's users, keys or network" rule is only enforced on the device, by its restricted user. - I didn't pin the new migration in
migration-pins.json; the release step does that.
Try it
- As the repository admin, set
ARM_PI_SSH_KEYas a secret on trevato/arm. Then post the device with that secret name. - As a site admin, grant it.
- Start a crew run; its brief will say
ssh piis[email protected]:22. - Read the sessions at
GET /api/v1/repos/trevato/arm/crew-devices.
The shape is good: exact user@host:port checked by the same rules as egress, a grant only a site admin can give and that pins the host key, the key file inside the run's own temp directory with redaction, and an ssh config with strict checking and no forwarding. Three things block it.
Fix first (high): the device's private key is not covered by the push-time leak guard. landWork scrubs the tree and refuses a push whose history holds a granted value, but it is passed only Object.values(grant.env) (src/crew/runner.ts, the landWork(...) call). The key from deviceKit is held for log redaction, and that is all. A run on trevato/arm (public) that does cp $TMPDIR/ssh/key-pi ./deploy_key && git commit pushes the Pi's private key, and the forge's own floor never sees it. Make the kit expose its values (readonly values: readonly string[]), pass [...Object.values(grant.env), ...(devices?.values ?? [])] to landWork, and add a test where a tree or commit that holds the device key is scrubbed or refused. The brief's "never copy its key anywhere" is a request; this is the boundary.
Medium: the session audit can be forged. sessions.log and the ssh wrapper live in the agent's writable TMPDIR. The agent can truncate the log, rewrite it, or call /usr/bin/ssh -F $TMPDIR/ssh/config pi … directly, and none of that is recorded. Yet the brief, the docs and the event all say "every ssh session is logged with its commands". Either log from a place the agent cannot write (for example, the forge reads the proxy's connection counts, or the sandbox's egress log for that host:port), or change the brief, the docs and the event so they say this is the agent's own self-reported log. Trust and calm must not promise an audit it cannot keep.
Medium (direction): done means reachable on the page and through MCP. This is JSON API only: no settings line on the repository page, no MCP tool, no src/tty.ts command. The pull itself says a page is the follow-up, and the owner wants this from their phone. At minimum add a one-line device row on the repository settings page and an MCP tool to list, grant and remove devices, or split those into linked issues and say so in the pull.
Smaller: parseDevice refuses never-grantable ranges only for an IPv4 literal. A hostname that resolves to loopback or the cluster passes, and ssh-keyscan then reaches it from the forge process. That needs a site admin, but resolve and check once at grant time. I could not reach the preview from my sandbox (the egress was refused), so I am judging from the code and the tests.
This update fixes the key leak and the audit wording. The settings row and MCP tools are split into issues #3684 and #3685, and I did not do the hostname check. I ran bun test on the devices and run-secrets tests, and tsc --noEmit. All pass. I did not run the full check.
- Leak guard (high):
deviceKitnow exposesvalues, andlandWorkgets[...Object.values(grant.env), ...(devices?.values ?? [])]. A copy of the Pi's key in the tree is scrubbed, and a commit that holds it is refused. - Second hole found and fixed:
historyHoldssearchedgit log -p, where every line carries a+prefix. A multi-line private key therefore never matched, and that would have hidden any such key from the commit check, not only this one. It now also searches the value's long lines one by one (src/crew/leak.ts). A new test intest/crew-devices.test.tscovers both the scrub and the refusal. - Audit (medium): I took your second option and reworded it. The
sshwrapper's note is called the run's own self-reported record, kept where the run can write, so it can be edited or bypassed. The brief (src/crew/devices.ts), the module comment anddocs/APPS.mdsay so, and the device's own logs are named as the real audit. I did not build an outside-the-sandbox log; that would need the egress proxy's connection counts. - Page and MCP (medium): I split these out as linked issues. #3684 is the repository settings device row. #3685 is the MCP tools and the
src/tty.tscommand. Until those land, devices are managed through the JSON API only, which does not meet the owner's phone requirement. - Hostname resolution at grant time: Not done.
parseDevicestill blocks never-grantable ranges only for IPv4 literals. A hostname that resolves to loopback or the cluster passes, andssh-keyscancan reach it, though only a site admin can grant it. Say if you want it fixed in this pull.
To try it: set a repository secret, list the device with POST …/crew-devices, grant it as a site admin with POST …/crew-devices/grant, then start a run. The run's ssh <alias> uses the pinned key.
🤖 Generated with Claude Code
Changes requested. One high finding, which is the thing to fix first.
High: the forge reads a file the run controls, follows symlinks and sets no size limit, then publishes what it read. sessions.log sits in runTmp/ssh, and the sandboxed run can write there. At run end the unsandboxed forge process runs readFileSync(log) (src/crew/devices.ts:132). It turns every line into a write() to the run log plus a crew.device.session event (src/crew/runner.ts:1597-1599). That allows three things:
- Exfiltration. The run runs
ln -sf /data/secret.key "$TMPDIR/ssh/sessions.log", or links any other forge-side file the sandbox hides from it. The forge then reads that file with its own privileges and copies it into the run log and the repository's events. The sandbox exists to stop exactly this. - Memory. A multi-GB log is read whole into memory.
- Event flood. Nothing limits the number of lines, so one run can append millions of events and run-log lines. Only each line's args are cut, at 2000 chars.
Fix: open the log with O_NOFOLLOW, or lstat it and refuse anything that is not a regular file owned by the forge. Read at most a fixed number of bytes (e.g. 64 KiB). Keep at most N sessions (e.g. the 50 that devicesView shows) and name how many were dropped. Strip control characters from args before they reach the log or an event. Add a test for each: a symlinked log yields nothing, and an oversized log is capped.
Medium: both doors. This is still API-only: there is no settings row, no src/tty.ts command and no MCP tool. The direction says done means reachable on the page and through MCP. #3684 and #3685 are linked, which is the right split. Make sure the README / docs/APPS.md name them as the way the owner will manage devices, and do not call this pillar done until they land.
Low: hostnames are not resolved at grant time. parseDevice blocks never-grantable ranges only for IPv4 literals. A hostname that resolves to loopback or the cluster passes, and ssh-keyscan dials it. Only a site admin can grant, so this is low, but resolving it at grant and refusing never-grantable addresses is cheap.
The rest looks right: every write checks repo-admin or site-admin and refuses agents; the key comes from repo-scope secrets only; host and user are validated before they reach the config or ssh-keyscan; paths in the wrapper are checked against SAFE_PATH; the host key is pinned with StrictHostKeyChecking; and the leak-guard fix for multi-line values is a real improvement. I could not reach the preview from my sandbox, so I did not judge this change by eye.
This update stops the forge trusting the run's sessions.log and resolves hostnames when a device is granted. I ran the devices tests and tsc --noEmit, and both pass. I did not run the full check.
- Hostile log (high):
src/crew/devices.tsnow reads the run's log defensively.- Files: it refuses the log unless the
sshdirectory and the log are real, non-symlink entries owned by the forge. It opens the log withO_NOFOLLOWand checks the opened file is the same one it checked. - Limits: it reads at most 64 KiB and keeps at most 50 sessions. Control characters are stripped from
at,aliasandargs. - Runner:
sessions()now returns{entries, dropped}, and the runner writes one "N more session notes dropped" line instead of flooding events. - Tests: a symlinked log yields nothing, and an oversized log is capped to 50 entries with a dropped count and no control characters. A run that swaps the directory for a symlink is covered by the directory check, but I did not test it separately.
- Files: it refuses the log unless the
- Hostnames (low):
grantCrewDevicenow resolves a non-IP host and refuses the grant if it resolves to nothing or to any never-grantable IPv4 address. Resolution is injectable, and a test covers a name that resolves to loopback. A name that resolves only to IPv6 loopback still passes, becauseneverGrantableis IPv4-only. - Both doors (medium):
docs/APPS.mdnow says the JSON API is the only way to manage devices until #3684 (settings row) and #3685 (MCP tools and terminal command) land, and that this feature is not done until they do. I did not build those here.
To try it, set a repository secret, then list the device with POST …/crew-devices. Grant it as a site admin with POST …/crew-devices/grant, then start a run.
🤖 Generated with Claude Code
Parked by the crew: the check failed ("event audience coverage > every kind the source emits is classified") and the decider saw no point in another try
A repository can now list devices its crew may SSH to, and a run on it gets a key, a pinned host and a logged
ssh. I never made a real SSH connection or ran a real sandboxed run.tscis clean, and the new tests plus the five cross files and the schema and brief tests pass. The one failure wastest/crew-sandbox-real.test.ts, becausergisn't installed in this sandbox.What changed
POST /api/v1/repos/:owner/:name/crew-devicesand{device: "[email protected]:22", secret: "ARM_PI_SSH_KEY"}. The entry must be an exactuser@host:port. Ranges, wildcards, loopback and the forge's own cluster ranges are refused, using the same rules as app egress.POST …/crew-devices/grant. The forge reads the host key the device shows at that moment and pins it, or the admin sendshost_keyinstead. The key is read withssh-keyscan, which is a new piping spawn, so it is listed intest/spawn-pipes.test.tswith its reason (that test is what failed pull #3492). Changing the secret drops the grant, andDELETEunlists the device. Agents can do none of this.src/crew/runner.ts. The run's temp directory gets:known_hostswith the pinned key;StrictHostKeyChecking yes, no forwarding, and a proxy script through the sandbox's SOCKS proxy;sshwrapper first on PATH.The key is never put in argv or the environment, and it is held for log redaction while the run lasts. It is removed when the run ends.
ssh <alias>and the rules: read and test freely, restart only what sudo allows, never change the device's users, keys or network.sshcall with its arguments, so the commands are in them. At run end each call becomes acrew.device.sessionevent on the repository and a line in the run log.GET …/crew-devicesshows the devices and sessions to anyone who administers the repository.src/core/crew_devices.ts,src/crew/devices.ts,src/crew/hostkey.tsandsrc/actions/crew_devices.ts, plus a migration for thecrew_devicetable.docs/APPS.mddescribes it andtest/crew-devices.test.tscovers it. There are no new dependencies.Left out
sshand check the key file, the config, the pinned host key, the sandbox hosts, the session log and redaction.ALL_PROXY) andnc -X 5in the proxy script are my assumption about how Claude Code's sandbox exposes its proxy. Please try one real run against the Pi.sshbinary by absolute path with the key path skips the logging wrapper. The "never change the device's users, keys or network" rule is only enforced on the device, by its restricted user.migration-pins.json; the release step does that.Try it
ARM_PI_SSH_KEYas a secret on trevato/arm. Then post the device with that secret name.ssh piis[email protected]:22.GET /api/v1/repos/trevato/arm/crew-devices.Closes #3470