Repository navigation
fix(projects): address SSH follow-ups from the #1388 review - #1389
Conversation
…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.
|
第 2 次检视,更新于 2026-11-25 13:17 UTC,检视提交 5b0bf4c Review of
|
|
Reviewed head What I verified
Non-blocking observation
|
The pid of a running session comes from its task's agent/state.json, which every process of the computer can write. rearm() accepted any agent the daemon had registered, so a task could point another task's state.json at its own agent and receive that run's grant on the next start or continue. The daemon now records the workspace an agent was started for and moves an agent only for a call from the same workspace.
|
F1 is fixed in
|
| onSpawn: pid => { onSpawn?.(pid); if (sshBroker.register(pid, taken.grant, taken.kind)) taken.spawned.push(pid); }, | ||
| onSpawn: pid => { onSpawn?.(pid); if (sshBroker.register(pid, taken.grant, taken.kind, taken.workspace)) taken.spawned.push(pid); }, | ||
| // The pid of a running session comes from a task-writable file: only an agent started for this workspace moves. | ||
| onAttach: pid => { if (taken.kind === 'agent') sshBroker.rearm(pid, taken.grant, taken.workspace); }, |
There was a problem hiding this comment.
F2 (suggestion, non-blocking) — the rearm() result is discarded, so a refused attach still reports success.
This arrow function is the only consumer of the boolean, and it ignores it. When the workspace check refuses (the state.json names another task's agent, or a pid the daemon never registered as an agent), the operation still answers {written:true} from workspace_agent_continue (runner/agent.mjs:275) and {started:true} from startAgent (runner/agent.mjs:184) — both also ignore onAttach's return value. The session then keeps the previous run's grant for the rest of the run.
This is not an authority leak: the control plane re-checks a signature/askpass request against the run token and lease behind that grant, and the previous run's lease is normally gone, so the stale secret is refused there. What is lost is diagnosability — exactly the case F1 was about now looks like ssh_target_denied on every command, indistinguishable from a role that simply has no host, and nothing is logged.
Suggestion: keep the boolean, e.g. onAttach: pid => { if (taken.kind === 'agent' && !sshBroker.rearm(pid, taken.grant, taken.workspace)) console.error('[ssh-agent] rearm refused for pid ' + pid); }, and, if the control plane wants to react, surface it in the answer (ssh_rearmed: false from workspace_agent_continue) so a mismatch ends the run with a real error instead of a silently downgraded session. Either half closes the observability gap; the log line alone is enough to keep this from blocking.
|
Post-merge:
The F2 suggestion (log a refused re-arm) remains valid for that follow-up. Separately, the queue race is worth handling in the automation: when the head changes while a PR is queued, dequeue the stale entry or verify the entry's head against the current head before merging. |
|
This PR merged from the merge queue at |
Refs #1379. Follow-up to #1388, which merged at
32a77034while these review points (#1388 (comment), follow-ups in #1388 (comment)) were being fixed. This PR carries the remaining fixes on top ofmain3534893c.Review points from #1388
1. Test determinism and helper output
runner/ssh-gate.mjsnow exits only after stdout and stderr have handed every byte to their pipes (write('', cb)beforeprocess.exit). The tunnel pipes the socket into stdout with{ end: false }and exits after the socket closes, once stdout is flushed.SshAgentBroker.register()runs fromonSpawn, synchronously in the same turn in whichspawn()returns. libuv returns from spawn only after the child has runsetsidandexec(it waits on the exec status pipe). This process accepts the child's connection, and reads its data, only after that turn returns to the event loop, so the child's first request always finds its registration. This is now stated inrunner/daemon.mjsand inregister(). The first runner test starts the agent client as the shell's very first command, without a delay. Its registration happens in the same test process, so the test does not depend on timing.The CI failure on
eab56b44was a real half-close bug, fixed in feat(projects): SSH targets for project computer tasks #1388. When the caller half-closed, the agent server, created withallowHalfOpenfalse, ended its own side. The daemon then destroyed both sides, so the remote's last answer was lost. The control-plane tunnel had the same pattern. Now both sides end each direction on its own and destroy only on error, timeout or revocation. The tests use delayed echo servers (UT: fake upstream; ST: a tunnel target through daemon and control plane). Both fail deterministically on the previous code: I put the previousrunner/ssh-agent.mjsandsrc/projects/ssh-access.tsback and ran them.ssh2.utils.generateKeyPairSync('ed25519')occasionally drops a leading zero byte of the public key (about 1 in 250, reproduced 12 in 3000) and then cannot parse its own key. ssh-keygen keys are unaffected, butssh-signaturefailed once locally for this reason. The tests now draw again until both halves parse.2. Narrow layout. The labels are now
解除绑定/绑定. Action buttons wrap. Below 650 px each host is one block: alias and route on the first line, address on the second, actions on their own line. The screenshot script checks every view at 1440, 390 and 320 px: no button of the card ends past the card's edge, andscrollWidth == innerWidth. The fixture now has a bound and an unbound global host. Screenshots are below.3.
configuredRedactor()cache. The cache is now per project (Mapkeyed by project,''for deployment-wide callers, at most 256 entries). Measured on the fixture: 4 SSH targets plus 2 other sealed rows, 2000 calls alternating with and without a project as the trace and trajectory paths do. Before: 119 µs per call. After: 45 µs per call. What remains is the revision query that existed before this PR. The gap grows with the number of sealed rows, because each miss re-opens every one of them.Follow-ups
workspace_agent_start/ lastworkspace_agent_configchunk,workspace_agent_continue(added toSSH_AGENT_TYPES), andworkspace_harness_startfor a live instance. When the process is already running,runner/agent.mjshands its pid to the daemon (onAttach).SshAgentBroker.rearm()then moves it to the new grant, but only if the daemon registered that pid as an agent itself. A pid read fromstate.json, which tasks can write, is ignored. Tests: re-arming switches a live agent's child groups to the new targets; an unregistered process cannot be re-armed; start and continue of a running session attach instead of spawning.src/agent/loop.tsnow gets an SSH context too, roledev. Its liveness follows the task claim (taskSsh, shared with the test-command grants), because these entries have no run token.invalid_ssh_credential, detailpassword_too_short). Redaction stays literal with no 8-character minimum, as [远程执行/SSH] 虚拟电脑内轻量 SSH 远程连接:受控 SSH_AUTH_SOCK 签名代理、网络通路与远端验证 #1379 asks; 4 characters avoid wiping ordinary text.Verification on
8ebaae45npm run check: exit 0.BOT_TEST_JOBS=4 npm test: exit 1, 351 test sets, 2841 tests, 2840 passed. The one failure iscodex-harness"Codex model reroute stops the run within the grace period even when the interrupt is ignored" (test/st/src/harness/codex-harness.test.mjs:395, a timing assertion under 4-way parallel load). That test and the Codex harness code are unchanged againstmain. Run alone on the same head (node test/framework/test-sets.mjs --jobs 1 test/st/src/harness/codex-harness.test.mjs) it passes in 309 s.ssh-agent,ssh-access,ssh-targets,ssh-grant,ssh-signature) pass, run throughtest/framework/test-sets.mjs. The rearm test, the attach test and the password minimum fail onmainwithout this change.Screenshots (1440 / 390 / 320)
Super admin, project hosts after a connectivity check:
Super admin, global hosts with a bound (
解除绑定) and an unbound (绑定) host:Super admin, new host form:
Project admin, read-only list: