Repository navigation
fix(runner): pin SSH grant re-arming to the task directory and stop agent socket recursion - #1390
Conversation
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.
| onAttach: pid => { if (taken.kind === 'agent') sshBroker.rearm(pid, taken.grant); }, | ||
| 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,沿用 #1389 round-2 的建议,仍成立):rearm() 的布尔结果在 runner/daemon.mjs:202 被丢弃,runner/agent.mjs:275 与 :420 也只用 try/catch 包住调用。因此一次被拒绝的 re-arm 不会留下任何记录:workspace_agent_continue 仍返回 {written:true}、workspace_agent_start 仍返回 {started:true},该 run 继续用旧的 grant 运行。
本 PR 之后,“re-arm 被拒绝”正是跨任务 agent/state.json 这一唯一攻击/异常路径的预期结果(正常续接同任务目录一定匹配),也仍可能在别的边界情形(例如 pid 已失效)发生,但控制面只能从之后某次 SSH 检查的 ssh_target_denied 间接推广,daemon 侧无法区分“没发生”与“被拒绝”。安全上没有影响(签名/检查每次都由控制面按 run 令牌、角色与目标重新授权)。
建议:把结果带出来,至少记一次,例如
onAttach: pid => {
if (taken.kind === 'agent' && !sshBroker.rearm(pid, taken.grant, taken.workspace)) {
console.error(`[ssh-agent] rearm refused: pid=${pid} workspace=${taken.workspace || 'none'}`);
}
},ssh-gate/daemon 的日志本来就会进容器日志,不需要新增持久化字段;不记录 grant secret。非阻断。
|
第 2 次检视,更新于 2026-11-25 15:14 UTC,检视提交 c6018c9 round 2 检视 状态对照上一轮
第二个提交
|
|
Thanks. The only failing check, |
|
Reviewed head
|
|
The merge queue removed this PR at 14:12 ( |
|
I read the merge-group failure from the run itself, and it matches your reading:
On re-queueing: this project's auto-merge policy lets me merge or re-queue only on an explicit request from someone with write access to the repository, so I do not re-add it on my own even though it is reviewed and green. Either re-add it with |
|
Re-enqueued the same reviewed head The previous queue attempt was removed as |
|
Removed from the queue again at 14:29 ( |
|
Re-enqueued the same reviewed head The second queue removal was |
serve() called pump() again after every pass. With a partial message buffered (at least the length field, less than the body) pump() returns without awaiting anything and the call recursed until the stack overflowed, outside the try block: an unhandled rejection that ends the runner daemon. Any process of the computer could send half a message to ssh-agent.sock and take the daemon down; a client whose request arrived in two chunks hung (seen in CI as the ssh-access set timing out). The loop already reads bytes that arrive during its awaits, so the re-entry is removed; a partial message waits for its next chunk, and a failing pump only closes its own connection.
|
The third queue run (14:36, merge group |
|
Reviewed head
|
Refs #1379. Follow-up to #1389.
#1389 merged from the merge queue at
8ebaae45(merge commitd0ed9f7e). That head was enqueued at 13:09:37, after the review's must-fix finding F1 (#1389 (comment)) and before the fix was pushed (5b0bf4cf, 13:10).maintherefore still has F1. This PR carries that fix unchanged; its tree is identical to5b0bf4cf.F1: cross-task SSH grant transfer through
agent/state.jsonThe pid of a running session comes from its task's
agent/state.json, which every process of a project computer can write (all share UID 10001).SshAgentBroker.rearm()accepted any agent the daemon had registered. A task could therefore point another task'sstate.jsonat its own agent and receive that run's grant on the nextworkspace_agent_start/workspace_agent_continue. The new grant includes that run's role and trusted-checkout targets.Fix: the daemon records the task directory an agent was started for, i.e. the
workspace_idof the starting call as validated by the manager (runner/daemon.mjstakeSsh).SshAgentBroker.register()stores it.rearm(pid, payload, workspace)refuses unless the call bringing the new grant names the same workspace (runner/ssh-agent.mjs). A non-agent pid or a missing workspace is refused as before.docs/design/agent-and-harness-runtime.mdnames the starting task directory as what pins the transfer.Tests
test/ut/runner/ssh-agent.test.mjs: a rearm for another workspace (and for none) leaves the agent on its old grant; a rearm for its own workspace moves it.test/ut/manager/ssh-grant.test.mjs: real daemon throughmanager/server.mjs. Task B'sstate.jsonnames task A's running agent; B'sworkspace_agent_continuewith B's grant leaves A's agent on A's grant, and A's own continue moves it.main(d0ed9f7e=8ebaae45): with the previousrunner/ssh-agent.mjsandrunner/daemon.mjs, B's grant ends up on A's agent.Agent socket recursion (second commit,
c6018c94)The third merge-queue run timed out in
ssh-access(900 s) withRangeError: Maximum call stack size exceededatrunner/ssh-agent.mjs:266. After every pass,serve()calledpump()again. With a partial message buffered (at least the 4-byte length, less than the body),pump()returned without awaiting anything, so the call recursed until the stack overflowed. That happened outside itstryblock, as an unhandled rejection, which ends the runner daemon. Any process on the computer could send half a message tossh-agent.sockand take the daemon down. A client whose request arrived in two chunks hung; on CI that client was OpenSSH, so the set timed out. This bug is onmainsince #1388.The loop already reads bytes that arrive during its awaits, so the re-entry is gone. A partial message waits for its next chunk, and a failing
pump()closes only its own connection. Regression test intest/ut/runner/ssh-agent.test.mjs: a message sent in two pieces is answered, and a client that leaves after half a message does not stop the socket from serving the next one. On the previous code it reproduces theRangeError.Verification
b965712f(F1 only, same tree as5b0bf4cf):npm run checkexit 0;BOT_TEST_JOBS=4 npm testexit 0, 351 test sets, 2841 tests, 2841 passed.c6018c94:npm run checkexit 0;BOT_TEST_JOBS=4 npm testexit 1, 351 test sets, 2842 tests, 2841 passed. All SSH sets pass. The one failure isdistributed-nodes(test/st/src/cluster/distributed-nodes.test.mjs:146, from [分布式部署] 支持总控与多 Linux Docker 计算节点分离:ClusterManager、node-agent 与节点管理 #1380, unchanged here):node_agent_connect_timeoutunder 4-way parallel load, as in earlier local runs; it passes in CI and passes alone on this head (node test/framework/test-sets.mjs --jobs 1 test/st/src/cluster/distributed-nodes.test.mjs).