Repository navigation
perf(ssh): opt-in proxy connection reuse for system SSH on Windows - #33030
Conversation
Windows OpenSSH cannot multiplex (ControlMaster fails with "getsockname failed: Not a socket"), so every system-SSH exec for a ProxyCommand or ProxyJump target re-ran the proxy handshake. Hold one `ssh -N -L` through the real proxy per session and dial later execs over 127.0.0.1 with HostName/Port/ProxyCommand=none/ProxyJump=none/HostKeyAlias overrides. The route starts after connect, is proven with a login before use, falls back to per-command proxying on any failure, honors systemSshConnectionReuse: false, and is torn down with its proxy child. Rebased from #31731 (commits b1cdd46, 3835c2d, 6268f2f) onto current main, including the pending-route cancellation fix from b301b6a. Co-authored-by: Neil <[email protected]>
…kill Reuse signalProcessTree instead of a hand-rolled taskkill-then-kill fallback: it already joins an in-flight tree kill, refuses a reaped PID, and falls back to killing the root, so the route keeps no parallel copy of that logic.
- Manual targets: take the forward's sshd port and the HostKeyAlias from the stored endpoint; `ssh -G` ran on the label and named another host. - Hold the forward with ServerAlive probes so a silently dead proxy ends it and commands fall back instead of stalling on 127.0.0.1. - Never route forwards: their argv must stay stable for orphan recovery, and the route's own forward must take the real proxy. - Upload sessions read the route per file, so an exited route's port is not dialled after it closes. - Skip the route for security-key identities, whose forward and probe logins would each ask for an unprompted touch.
…aims The unclaimed-alias endpoint rewrite only applies to config-backed targets, so manual targets with a configHost no block names stay eligible.
The forward is an optional background login; with BatchMode=no a password or passphrase login raised an extra prompt right after connect, which the non-interactive probe then discarded anyway.
…he route Overriding HostName to 127.0.0.1 changes which ssh_config blocks match, so a `Match host <real host>` block could silently switch the remote User (or identities, certificates, known-hosts files) for every routed command. Run `ssh -G` with and without the route options and refuse the route on any difference outside HostName/Port/HostKeyAlias/ProxyCommand/ProxyJump. Also ask the agent with `ssh-add -L` and refuse the route when it may hold a security key, so the background forward and probe never request a touch. Both checks run through process-host and fail closed.
…etting The loopback route rewrites HostName, which ssh_config can key settings on, so it no longer turns on by itself: a new optional systemSshProxyConnectionReuse field (default off, Windows only) enables it from the SSH host's Advanced settings. Old clients and servers ignore or omit the field. Admission stays as the safety net and now: - takes the forward's sshd port and HostKeyAlias from the direct `ssh -G`, so a manual host's own Host block cannot send the route to another sshd; - refuses any non-routing value with a `%` token, which `ssh -G` can leave unexpanded while a routed login expands `%h` to 127.0.0.1; - checks the security-key and agent identities of every ProxyJump hop; - asserts the routed config really dials 127.0.0.1 with no proxy left.
… ${VAR} paths
- The switch now appears only for this desktop's own SSH hosts. A paired
server's add-host dialog never shows or sends it, so an older server's
strict schema is never handed the new field, and a client's platform no
longer decides a server's setting.
- Admission also refuses `${VAR}` references, which `ssh -G` prints
unexpanded while a login expands them.
- Advanced no longer auto-opens just for the opt-in.
|
No actionable comments were generated in the recent review.
|
ELI5
On Windows, Orca connects to SSH hosts behind a proxy (AWS SSM, GCP IAP, a bastion jump host) by starting a new
sshfor every remote command. Each one pays the proxy's slow setup again. On macOS and Linux, OpenSSH shares one connection, but Windows OpenSSH can't. This PR adds an opt-in setting: Orca keeps one tunnel open through the proxy and sends later commands through it, so the slow proxy setup happens once instead of about 55 times per connect.What Changed
Before: a Windows connect to a proxied host ran every setup command through the proxy. We measured 55 proxy handshakes during connect and 59 after 30 s idle; macOS needs 2. With a proxy that takes 3 s to connect, a connect took 203 s. The reporter saw about 10 minutes on a real 9 s proxy.
After, with the new setting on: Orca holds one
ssh -N -L 127.0.0.1:<port>:localhost:<sshd port>through the real proxy. Later commands dial 127.0.0.1, withHostName,Port,ProxyCommand=none,ProxyJump=noneandHostKeyAliasoverrides, so the user'sUser, identities and known_hosts trust still apply. With the same 3 s proxy, connect dropped to 33 s and proxy handshakes from 59 to 4.The mechanism:
systemSshProxyConnectionReuse. It defaults to off and only applies on Windows. It's offered in the SSH host's Advanced settings only for hosts this desktop dials itself; a paired server's add-host dialog never shows or sends it.ssh -Gwith and without the route options and refuses on any difference outside the rewritten keys. This catches, for example, aMatch hostblock that would switchUser.%tokens or${VAR}, whichssh -Gcan leave unexpanded.HostKeyAliasfrom the directssh -G.ssh-add -Llists ansk-key, for the target and for every ProxyJump hop.BatchMode=yeslogin probe must succeed over the route.ServerAliveInterval=15), and is stopped through process-host's tree kill.Why
This builds on @bing-xbx's design and implementation from #31731. Their work is kept as the first commit, under their authorship. The issue is the Windows gap left by OpenSSH ControlMaster reuse.
Alternatives considered:
getsockname failed: Not a socket.Match host,%h,${VAR}, jump-host identities). So it's opt-in, with the automatic checks kept as a safety net.Credit to @bing-xbx for the report, design, Windows measurements and original implementation.
Linked Issue
Fixes #31558
Fixes #32582
Visual Proof
The new "Reuse one proxy connection" switch in an SSH host's Advanced settings, shown on Windows only. Captured from a hidden e2e window with a Windows user agent.
Testing
Measured: a full hidden-app connect against a Docker sshd through a ProxyCommand that counts its own launches, with multiplexing off to match Windows.
Windows (OpenSSH_for_Windows 9.5p2): the exact ssh commands the branch builds work. The forward, probe and routed commands run. Existing known_hosts trust carries over through HostKeyAlias, and a wrong alias is rejected under strict checking. Tree kill also stops the ProxyJump child and frees the port. A
Match hostUser drift reproduces with Windowsssh -G, which the admission check catches. Not done on Windows: a speed measurement on a slow proxy, and a full Orca app run.Automated: unit tests cover:
ssh -Gwith temporary configs (Match hostUser drift,%hand${VAR}refusal, jump-host security key, manual-host Host block remap);Checks run:
Review
Independent reviews (Codex and Opus) ran over several rounds, and their findings are fixed. The final Opus review is clean. The final Codex round raised two issues that are listed under known limits below. Both apply only when the opt-in is on.
Agent skill upstream boundary
Notes
Known limits, all only when the opt-in is on:
SSH_ASKPASS. OpenSSH's jump subprocess doesn't inheritBatchMode.[host]:portHostKeyAlias fails principal validation, so the probe fails and the route stays off. This is safe.ssh -W: they aren't inspected.ssh-addcan't reach under a non-default IdentityAgent fails closed. A default agent that can't be reached counts as no agent.StrictHostKeyChecking nolose MITM protection on that hop.Follow-up: about 55 separate ssh commands per connect on Windows without multiplexing. That's the root cause, and it's worth reducing directly.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)