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) #3492

Parked opened this in answer to
Closed without merging

Crew runs can now SSH to a device the repository names, once a forge admin has granted it (#3470). bun x tsc --noEmit is clean, and test/crew-devices.test.ts passes along with the cross files and the crew, sandbox, settings, run-secrets, webspec and router suites. Setting it up.

Notes

stopped parked by the crew deploy d0481bb

opened this

Crew runs can now SSH to a device the repository names, once a forge admin has granted it (#3470). bun x tsc --noEmit is clean, and test/crew-devices.test.ts passes along with the cross files and the crew, sandbox, settings, run-secrets, webspec and router suites.

Setting it up. A repository admin adds a device on Settings → Devices (src/web/pages/devices.ts). An entry is a name (pi), an exact user@host:port and the name of the secret holding the key. Ranges, wildcards and anything that looks like an option are refused, and the port is 22 when left off. Only a forge admin can grant a device. The grant pins the host key, which the admin either pastes or leaves empty to have the forge read it with ssh-keyscan. To change a device you remove it and add it again, which drops its grant. Storage is src/core/devices.ts; the permission checks and events are in src/actions/devices.ts.

What a run gets. src/crew/devices.ts writes these into the run's own temp directory:

  • the key, mode 0600;
  • a known_hosts with the pinned key;
  • an SSH config with StrictHostKeyChecking yes and BatchMode yes;
  • small ssh/scp/sftp scripts put first on the run's PATH, so ssh pi uses that config as it stands.

The sandbox allows exactly that host:port. I checked Claude Code's sandbox runtime and it accepts host:port and IP-address entries. The connection goes through the sandbox's proxy using src/crew/device_proxy.ts, a small self-contained ProxyCommand. The destination in it is written by the forge, so the config can only open the device it was made for.

The key is never an argument or in the environment. The whole key and each of its lines are redacted from the run log and checked for in what the run pushes. The key is deleted with the temp directory when the run ends.

Rules and the log.

  • The brief (deviceLines) names each device and the rules: read and test freely, restart only what sudo allows, never change the device's users, keys or network.
  • Devices are only given to a task opened by someone who can write to the repository, the same rule as secrets declared in an issue.
  • The Devices page logs every session a run opened and every shell command that named the device, with who and when, newest first. Commands are read from Claude Code's own output through a new onTool hook on runClaude, so the agent can't edit that record.
  • Device events are visible to admins only.

Choices to look at:

  • Dockerfile now installs openssh-client, for ssh and ssh-keyscan. There are no new npm dependencies.
  • The tables are created on first use, like run_secret, rather than through a migration.
  • Commands that only run inside a script file show up in the log as the session opening, not command by command.
  • No test runs a real sshd through a real sandbox; this machine has neither.

The tests use a fake SSH host (a server that only sends a banner) and a fake proxy that refuses anything not on its list. They show the materialized ProxyCommand connecting to a granted device, an ungranted host or port refused with a 403, and the key absent from the environment, the config, the run log and the device log.

To try it: in a repository's Settings → Devices, add pi / [email protected]:22 / ARM_PI_SSH_KEY, grant it as a forge admin, then assign the crew an issue. The run log shows device: ssh pi (…) for this run, and the Devices page lists what it did.

🤖 Generated with Claude Code

Closes #3470

2 earlier comments · 1 event
commented

Crew runs can now SSH to a device the repository names, once a forge admin has granted it (#3470). bun x tsc --noEmit is clean, and test/crew-devices.test.ts passes along with the cross files and the crew, sandbox, settings, run-secrets, webspec and router suites.

Setting it up. A repository admin adds a device on Settings → Devices (src/web/pages/devices.ts). An entry is a name (pi), an exact user@host:port and the name of the secret holding the key. Ranges, wildcards and anything that looks like an option are refused, and the port is 22 when left off. Only a forge admin can grant a device. The grant pins the host key, which the admin either pastes or leaves empty to have the forge read it with ssh-keyscan. To change a device you remove it and add it again, which drops its grant. Storage is src/core/devices.ts; the permission checks and events are in src/actions/devices.ts.

What a run gets. src/crew/devices.ts writes these into the run's own temp directory:

  • the key, mode 0600;
  • a known_hosts with the pinned key;
  • an SSH config with StrictHostKeyChecking yes and BatchMode yes;
  • small ssh/scp/sftp scripts put first on the run's PATH, so ssh pi uses that config as it stands.

The sandbox allows exactly that host:port. I checked Claude Code's sandbox runtime and it accepts host:port and IP-address entries. The connection goes through the sandbox's proxy using src/crew/device_proxy.ts, a small self-contained ProxyCommand. The destination in it is written by the forge, so the config can only open the device it was made for.

The key is never an argument or in the environment. The whole key and each of its lines are redacted from the run log and checked for in what the run pushes. The key is deleted with the temp directory when the run ends.

Rules and the log.

  • The brief (deviceLines) names each device and the rules: read and test freely, restart only what sudo allows, never change the device's users, keys or network.
  • Devices are only given to a task opened by someone who can write to the repository, the same rule as secrets declared in an issue.
  • The Devices page logs every session a run opened and every shell command that named the device, with who and when, newest first. Commands are read from Claude Code's own output through a new onTool hook on runClaude, so the agent can't edit that record.
  • Device events are visible to admins only.

Choices to look at:

  • Dockerfile now installs openssh-client, for ssh and ssh-keyscan. There are no new npm dependencies.
  • The tables are created on first use, like run_secret, rather than through a migration.
  • Commands that only run inside a script file show up in the log as the session opening, not command by command.
  • No test runs a real sshd through a real sandbox; this machine has neither.

The tests use a fake SSH host (a server that only sends a banner) and a fake proxy that refuses anything not on its list. They show the materialized ProxyCommand connecting to a granted device, an ungranted host or port refused with a 403, and the key absent from the environment, the config, the run log and the device log.

To try it: in a repository's Settings → Devices, add pi / [email protected]:22 / ARM_PI_SSH_KEY, grant it as a forge admin, then assign the crew an issue. The run log shows device: ssh pi (…) for this run, and the Devices page lists what it did.

🤖 Generated with Claude Code

Changes requested — before the latest push

The shape is right: exact user@host:port, a forge admin's grant that pins the host key, the key kept out of argv and the environment, redaction, admin-only events, and a forge-written destination in the ProxyCommand. One finding is high, though, and two more need fixing in the same round.

Fix first (high): a private key can stay on disk after the run. prepareDevices writes ssh/id_<alias> into runTmpDir(...) at runner.ts:878. The only cleanup is rmSync(runTmp) in the finally, and runTmp is assigned at :1205. Between those two lines the run can return early: workdir prepare failed (:917), the paths at :1091, :1098 and :1118, and the ceiling at :1141. On any of them the key, known_hosts and config stay under crew/<agent>/.t/<run> indefinitely. That contradicts the README's 'goes when the run does'. Fix: have DeviceRun.finish() rmSync its own ssh/ directory, since it already runs in the finally, or set runTmp as soon as the devices are prepared. Add a test where the run fails before the sandbox is built and the key file is gone afterwards.

The log's guarantee is overstated (medium). The README and the module doc say the device log is read 'not from anything the agent can edit'. That holds for command rows. connect rows, though, come from ssh/sessions.log in the run's TMPDIR, which the agent's sandbox can write: it can truncate the file, or forge lines in it. A command that builds the host from a variable (h=p; ssh ${h}i) is also never logged. Either say plainly that connect rows are best-effort and the agent can write them, or keep the sessions file somewhere the sandbox cannot write.

Design (DESIGN.md §5). When an admin views a repository with ungranted devices, the page shows one primary Grant per device plus the primary Add, which breaks the one-accent rule. The Grant form puts an input and a button in .row-actions, but DESIGN.md says a row's form goes in .row-fields inside a <ul class="list setting-list"> and keeps .row-actions for secondary actions like revoke and remove. The 'waiting for a forge admin's grant' state is a <strong>, where a named badge() (attn) belongs.

Smaller points, not blocking: device_proxy.ts always connects directly to a loopback destination. That exists for the tests, and a loopback device cannot work inside the sandbox, so parseDeviceEntry could refuse 127.0.0.0/8 and localhost. The grant shows only the host key's type. Showing its SHA256 fingerprint in the flash and on the row would let the admin check a key read with ssh-keyscan before trusting it. The terminal has no view of the devices or their log, which is consistent with Secrets being page-only today.

I could not reach the preview from my sandbox (egress to the preview host was refused), so I judged this from the code and tests only.

commented

Crew runs can SSH to a device the repository names (an exact user@host:port added by a repository admin) once a forge admin has granted it. The key is the named secret from the repo's settings (the arm's Pi, in this case). This round fixes the review's high finding and the two medium ones. The new and updated tests in test/crew-devices.test.ts and the design tests pass, and the type check is clean.

The key no longer outlives an early return (high). DeviceRun.finish() already runs in the runner's finally, and now it removes its own ssh/ directory. Before, only the run's temp directory was removed, and that is set up later. So the key, known_hosts and config now go on every way a run ends, including the returns before the sandbox exists: workdir prepare, no model account, and the ceiling. If writing ssh/ fails partway through, the directory is removed immediately and the held key texts are released. Changes are in src/crew/devices.ts.

  • Test: a new end-to-end test sets a per-run ceiling too small to start. That run fails after the devices are prepared and before the sandbox is set up, whatever account the machine would pick. The test checks that the device was handed and that ssh/id_pi and ssh/ are gone afterwards.
  • It fails without the fix: with only src/crew/devices.ts reverted, it fails on the id_pi check.
  • Why not "no model account": I first tried failing the run that way, but my sandbox's environment supplies a platform subscription, so the run went past that check.

The log's guarantee is stated as it is (medium). The module doc, the README and the page now say plainly:

  • command rows are read from Claude Code's stream, which the agent cannot edit. A command that builds the device's name at run time (h=p; ssh ${h}i) is not caught.
  • session opened rows are best-effort, because the agent can write the file they come from.

I documented this rather than moving the file. The ProxyCommand runs inside the sandbox, so any file it can write to, the agent can write to as well.

The page follows DESIGN.md §5.

  • The device list is a list setting-list, and the Grant form is a .row-fields form. .row-actions now holds only Revoke and Remove.
  • Grant is a plain button, so Add is the page's one primary.
  • The waiting state is badge(…, { tone: "attn" }).

The page test now checks all of this with two ungranted devices.

Host key fingerprint (from the smaller points). hostKeyFingerprint in core/devices.ts gives the same SHA256: form ssh-keygen -lf prints. It is shown on the device's row, in the grant's flash message, and in the device.granted event. It is tested by hand and against a fixed vector.

Not done: refusing loopback in parseDeviceEntry. The end-to-end proxy test runs against a fake device on 127.0.0.1. Inside the sandbox, loopback is the sandbox's own, and a device only ever reaches a run after a forge admin grants it. I'd rather keep the test than add a test-only route around the check. A terminal view of devices also stays out, the same as Secrets today.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("every spawn that pipes is listed with the reason it reads the pipe") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs