Repository navigation
feat(projects): SSH targets for project computer tasks - #1388
Conversation
Tasks on a project computer can now run native ssh, scp, sftp and rsync against the aliases registered for their project: - The control plane issues a per-run SSH grant when it starts a Pi or Claude Code/Codex process and when it runs the project test command (before a pull request, after an integration and in the QA gate). The usable targets follow the run's role and whether its checkout was trusted at the start (allow_untrusted_pr, default off). The grant is never recorded, hashed or replayed. - The manager forwards the grant only over the daemon socket, writes a root-owned ssh_config with one gated Match block per alias and seals the runner directory once the daemon is ready. - The runner daemon serves one ssh-agent.sock. It identifies callers by SO_PEERCRED and serves only process groups it registered for a run (or direct child groups of a registered agent), checked by leader pid and start time; refused aliases fail with ssh_target_denied. - Signatures, passwords (SSH_ASKPASS for password targets only, parent must be /usr/bin/ssh) and tunnels to the registered host:port are decided by the control plane on every call, so ending, cancelling or revoking a run refuses the next one. Tunnels are bounded per run and per computer and audited. - Every target needs its own unencrypted key; relay_node is reserved for compute-node relays and refused until they exist.
|
Reviewed head Blocking1. Required check
|
eab56b4 to
32a7703
Compare
|
Re-reviewed head
I have enqueued
The candidate looks good; the above can land as a small follow-up rather than another review round. |
…view - ssh-gate exits only after stdout and stderr are flushed, so the KnownHostsCommand key line and the last tunnelled bytes reach ssh. - A start, reattach or continue of a running Pi or harness session carries the run's grant; the daemon moves an agent it started itself to the new grant (a pid read from state.json is ignored), so resumed and continued sessions keep task-side SSH. - The legacy single-executor entry gets an SSH context bound to the task claim. - configuredRedactor() caches per project instead of one entry that alternating callers rebuilt on every trace event. - Passwords need at least four characters; they are still redacted literally below eight. - The SSH host table stacks each host below 650 px and uses shorter bind labels, so its actions stay inside the card at 390 and 320 px. - Tests regenerate the ed25519 keys ssh2 occasionally produces with a missing leading zero byte.
|
This PR merged at |
…view - ssh-gate exits only after stdout and stderr are flushed, so the KnownHostsCommand key line and the last tunnelled bytes reach ssh. - A start, reattach or continue of a running Pi or harness session carries the run's grant; the daemon moves an agent it started itself to the new grant (a pid read from state.json is ignored), so resumed and continued sessions keep task-side SSH. - The legacy single-executor entry gets an SSH context bound to the task claim. - configuredRedactor() caches per project instead of one entry that alternating callers rebuilt on every trace event. - Passwords need at least four characters; they are still redacted literally below eight. - The SSH host table stacks each host below 650 px and uses shorter bind labels, so its actions stay inside the card at 390 and 320 px. - Tests regenerate the ed25519 keys ssh2 occasionally produces with a missing leading zero byte.
Fixes #1379
Summary
Tasks on a project computer can use native
ssh,scp,sftpandrsyncagainst the SSH hosts registered for their project. Private keys stay sealed in the control plane, which signs per request; passwords are released only to OpenSSH's askpass helper forpasswordtargets;tunneltargets reach only their registeredhost:portthrough the control plane.The branch has four commits:
feat(projects): register SSH targets and protect stored command output:ssh_targets/ssh_target_projects, sealed credentials, console card,configuredRedactor()with exact (no minimum length) SSH secrets,rsyncin the project-computer image.fix(console): clarify SSH inventory availability.feat(projects): verify registered SSH credentials from the console: a super admin's connectivity test (fingerprint check, one authentication, no session).feat(projects): let task commands use registered SSH targets: task-side SSH, described below.How task-side SSH works
workspace_agent_configlast chunk /workspace_agent_start), Claude Code / Codex start (workspace_harness_start), and the project test command (src/tasks/request.tsbefore a PR,src/agent/engine.tsafter an integration and before creating a PR,src/tasks/acceptance.tsin the QA gate). Usable targets are decided once at the start: the role is inallowed_roles, and the checkout was trusted (HarnessAccess.trustedCheckout;taskCheckoutContextfor test commands) or the target hasallow_untrusted_pr. Every hop of aproxy_jumpchain must be usable too. The grant is never written to task operations, the manager ledger, trajectories or operation hashes; the manager's HTTP routing (manager/server.mjs) and a compute node's driver (manager/compute-driver.mjs) accept it only beside anexecute; the manager forwards it only over the daemon socket and drops it on the one-shotdocker execpath.src/tasks/pull-request.tsonly hashes the policy; the PR-time test command runs inengine.ts.ssh_config(0640) and the targets' public keys into the computer's runner directory, which the image includes from/etc/ssh/ssh_config.d/(OpenSSH reads the passwd home, never$HOME). Each alias getsMatch originalhost <alias> exec "ssh-gate check"; a refused alias falls through to aHost <alias>block whoseProxyCommandprintsssh_target_deniedand exits non-zero before any connection. There is noHost *, sogit@github.comkeeps its defaults. Host keys are accepted only throughKnownHostsCommandagainst the registered SHA-256 fingerprint. Once the daemon answers its health check the manager seals the runner directory to0750, so no process in the computer can replacerunner.sock,ssh-agent.sockor the config.run_tokenis not put in the task environment. The daemon serves one/run/bot-runner/ssh-agent.sock(0660); connecting grants nothing. Each request reads the caller's pid viaSO_PEERCRED(throughpython3, Node has no getsockopt) and accepts only process groups the daemon registered synchronously at spawn (a command's detached shell), or groups whose leader is a direct child of a registered agent process (Pirun_commandand native bash), checking leader pid and/procstart time. A process that leaves its group withsetsid, or any other run's process, is refused.SIGN_REQUESTnames only a key: the agent lists only the group's allowed public keys, and the control plane re-checks the run (run token and lease for Pi/Harness, task claim for test commands), the target (still bound, same identity), the role and trust before signing. Every target must have its own key: a key registered for one target is refused for another (ssh_key_reused). ed25519, RSA (rsa-sha2-256/512) and ECDSA P-256/384/521 are supported; encrypted and PKCS#8 keys are refused at registration.SSH_ASKPASS=/opt/runner/ssh-askpass.mjsandSSH_ASKPASS_REQUIRE=forceare set only when the run may use a password target. The daemon answers only if the helper's parent is the image's/usr/bin/ssh(same device and inode), both are in the authorized group, and the prompt'suser@hostmatches exactly one password target of the run; otherwise the helper writes nothing to stdout. The password goes only to the helper's stdout (and, by OpenSSH'sreadpass.cpipe hand-off, briefly to thatssh); never to files, env, argv, logs, trajectories or audit. Output and trajectories pass throughconfiguredRedactor()with no minimum length and across chunk boundaries.ProxyCommandcarries only the target id; daemon and control plane ignore any address the caller adds and connect only to the registeredhost:port. No HTTP CONNECT, SOCKS or arbitrary forwarding. Each direction ends on its own (half-close), so the remote's last answer still reaches the caller; only an error, a timeout or a revoked grant cuts both sides. Limits: 16 per run, 32 per computer, 10 min idle, 2 h total. Opens and refusals are audited (ssh_target.*, target id only).relay_nodeis a reserved field for [分布式部署] 支持总控与多 Linux Docker 计算节点分离:ClusterManager、node-agent 与节点管理 #1380 node relays; such a tunnel is refused withssh_relay_unavailableuntil nodes relay.direct/proxy_jumpTCP sessions are held by the container and are not promised to be cut; this is written indocs/design/.main) the grant reaches the node'sProjectsthrough its driver and check/sign/password go through the node's relayedgateway.sock; that relay does not carry HTTP Upgrade yet, sotunneltargets answerssh_broker_unavailableon remote nodes. Local execution (BOT_LOCAL_EXECUTION) has no resident daemon, so no task-side SSH. Claude Code / Codex commands that the CLI starts in new process groups below its own process are not authorized. Isolation between same-UID processes relies on the host's Yamaptrace_scope >= 1.Docs:
docs/design/agent-and-harness-runtime.md(replaces the "task-side SSH not wired" gap with the actual boundary, sealed runner directory) anddocs/features/console-and-workspace.md.Verification
Head
32a77034, based onorigin/mainb31098e7(includes #1380).npm run check: exit 0.BOT_TEST_JOBS=4 npm test: exit 1, 351 test sets, 2839 tests, 2838 passed. The one failure isdistributed-nodes(test/st/src/cluster/distributed-nodes.test.mjs, from [分布式部署] 支持总控与多 Linux Docker 计算节点分离:ClusterManager、node-agent 与节点管理 #1380, unchanged here):node_agent_connect_timeoutin its first test while four sets ran in parallel. Run alone on the same head (node test/framework/test-sets.mjs --jobs 1 test/st/src/cluster/distributed-nodes.test.mjs) it passes in 10.7 s.test/st/src/projects/ssh-access.test.mjs: real OpenSSH client against a loopback ssh2 server through the control-plane grant service and the agent broker: key auth via agent signing, password via askpass, tunnel to the registered address (a decoy address passed by the caller gets no connection), host-key mismatch,ssh_target_deniedfor a QA-only alias, an unregistered process,setsid, a revoked role and an ended run, reserved relay refusal, audit without secrets; short password (3 chars) redacted from trace events.test/ut/runner/ssh-agent.test.mjs: agent protocol framing, identities/signing only for the registered group,setsidand release, agent child-group inheritance (direct children only), askpass parent binary / prompt / ambiguity checks, tunnel per-run limit, config rendering and grant validation, SSH env inherited only withBOT_SSH_BROKER.test/ut/manager/ssh-grant.test.mjs: executes go through the realmanager/server.mjsHTTP routing and the compute-node driver; grant forwarded to a real daemon but absent from the manager ledger, trajectory files and runner journal; config and key files written 0640; agent start registered; invalid grants refused; no grant on the one-shot exec path.test/ut/src/projects/ssh-signature.test.mjs: agent signature format for ed25519, RSA (3 flags) and ECDSA (3 curves), independently verified.test/ut/manager/runner-transport.test.mjs: runner directory sealed to 0750 after readiness and again after a restart.bot-project-computerimage with this branch's runner files, run read-only,cap_drop ALL,no-new-privileges, UID 10001, OpenSSH 9.2p1, against the real control-plane grant service and a loopback SSH server:sshwith key, password and tunnel targets,scp -O,sftpandrsyncall exit 0 with files delivered; a role-denied alias, an unregistered process andsetsid sshexit 255 withssh_target_denied;ssh -G git@github.comis unaffected.Changes after the first review head (
eab56b44)mainwith [分布式部署] 支持总控与多 Linux Docker 计算节点分离:ClusterManager、node-agent 与节点管理 #1380 (conflicts insrc/server.ts,docker/manager.Dockerfileand the deployment image table only).manager/server.mjsandmanager/compute-driver.mjsrejected any top-level key besidesoperation_id,generationandrequest, so an execute carrying a grant would have failed withinvalid_inputin a real deployment; the manager test calledProjects.operatedirectly and missed it. Both now acceptsshbeside anexecuteonly, and the test goes through the HTTP server and the node driver (it fails withinvalid_inputwithout the fix).sshstderr, since newer OpenSSH warns about the test server's key exchange.Screenshots
Machine settings → SSH remote hosts card, full viewports at 1440 and 390 CSS px (fixture data on loopback). The card note now says tasks can use the aliases; the connectivity result sits on its own line under the row's buttons.
Super admin, after a connectivity check (1440 / 390, and the row on 390):
Super admin, new project host form (1440 / 390):
Project admin, read-only list without connectivity or edit actions (1440 / 390):