Repository navigation
feat(ssh): support ordered multi-host commands and constrained connection options - #84
Merged
Merged
Conversation
…tion options Accept repeated --host for list, send and doctor. One host keeps the flat result; several return an ordered array whose elements keep schemaVersion, ok, host and command. Each destination gets one preflight and at most one request, and a refused or unknown host never triggers a retry or failover. Validate every host, option and message before any ssh process starts and refuse duplicate destinations. Add an allowlisted --ssh-opt (-p, -l, -i, -o Port/User/IdentityFile/IdentitiesOnly, -4, -6) re-emitted after the fixed BatchMode/StrictHostKeyChecking options; ProxyJump and every other option are refused. Accept bare and bracketed IPv6 literals and report sshUser/sshUserSource like Python. Closes #20
…ust boundaries Collect --host values before other validation so any pre-dispatch refusal with two or more hosts, including unknown options and missing values, is a per-host array; fewer hosts stay one flat object. Keep the user lookup inside per-host handling so a lookup failure leaves other results intact. Document that sshUser runs a bounded local ssh -G which evaluates the user's ssh configuration, separate the command-line allowlist from trusted user configuration, state that duplicate detection is syntactic, keep typed jump routing visible as open, and describe the lost-response fixture as an unknown classification case.
…oxyCommand Route every SSH call for every --host through one jump host given as USER@HOST[:PORT]. Instead of -J, whose hop receives no command-line BatchMode or StrictHostKeyChecking, build a fixed ProxyCommand: the shell-quoted and %-escaped ssh path with batch mode, strict host keys, no host-key updates, bounded connection attempts, no further proxy, control socket, agent or port forwarding, and no local command, then -W to the target. Validate the hop strictly, refuse it with --ssh-control-path and on Windows clients, report sshJump, and keep -J/ProxyJump/ProxyCommand refused in --ssh-opt.
With --ssh-jump, also fix ControlMaster=no, ControlPath=none and ProxyUseFdpass=no on the outer ssh before user options, so an existing master or fd-passing setting in ssh_config cannot skip or alter the hop. Verified with ssh -G against a fixture configuration.
On POSIX, start every external command in its own process group. A timeout, an output overflow or SIGINT/SIGTERM/SIGHUP to the CLI kills that group, including a jump ProxyCommand that keeps the pipes open, and the call completes after the exit plus a short grace instead of waiting for the pipes. On Windows only the child is killed and the call returns at the deadline. Timeout classification is unchanged. Document the verified ProxyCommand shells and that --ssh-opt values are not passed to the jump hop. Closes #87
Register a detached child's group synchronously when spawn() returns a PID, keeping the spawn event as a fallback, so a signal that arrives before that event still reaps the group. Document that detached children run in a new session without a controlling terminal and that cleanup covers that group only.
abruption
force-pushed
the
feat/20-multi-host-ssh
branch
from
October 3, 2026 02:35
8cbad61 to
05f1234
Compare
This was referenced Oct 3, 2026
6 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #87. Refs #20. Not a full close: typed jump routing is now implemented for POSIX clients (
--ssh-jump). On Windows clients it is refused (ssh_jump_unsupported_platform) until Win32-OpenSSHProxyCommandhandling is verified, so the jump-routing item is not fully met on every supported client platform. PARITY keeps SSH as Partial.Adds ordered multi-host SSH for
list,sendanddoctor, an allowlisted--ssh-opt, IPv6 destinations andsshUser/sshUserSourcemetadata. The existing guarded local/SSH contract is unchanged: exact-version preflight, JSON stdin request, owner verification, ambiguity refusal, pre-submit revalidation, and no retry afterunknown.Acceptance criteria
--host, output is the same flat object as before. When--hostis repeated, output is a JSON array in request order (Pythonone_or_many), and every element hasschemaVersion/ok/host(as requested)/command. If any host fails, the overall exit code is 1 (PythonEXIT_ERROR). A single host keeps its verified 0/1/2 code. Text output prints oneHost: <host>block per host.parse()validates every host,--ssh-opt, remote option and the message before anysshprocess starts, includingssh -G. Refusal contract: every--host VALUE/--host=VALUEbefore--is collected before any other check. With two or more of them, every pre-dispatch refusal is an array with onesubmitted:falseelement per host; this includes syntax errors such as an unknown option or a missing value. With fewer, it is one flat object. Python's argparse syntax errors print usage to stderr without JSON; TS always answers in JSON. Repeating the same destination givesduplicate_ssh_host. This check is syntactic (user, case-insensitive host, canonical IPv6); aliases or addresses of the same physical host are not detected. Each host gets one preflight and at most one request. A refused orunknownhost is reported in place, and later hosts still get their single attempt.--ssh-optinterface; reject local-command vectors and anything weakening batch/host-key requirements-p,-l,-i,-o Port=/User=/IdentityFile=/IdentitiesOnly=,-4,-6. Values can be separate or attached tokens, as in Python's--ssh-opt=-p --ssh-opt=2222. All other options giveunsupported_ssh_option. A bad, duplicate or dash-leading value givesinvalid_ssh_option. Identity paths refuse%and$(OpenSSH token/env expansion). Options are re-emitted canonically after the fixedBatchMode=yes,StrictHostKeyChecking=yes,ConnectTimeout=10(OpenSSH keeps the first value).sshUser/sshUserSource; keep Windows quoting and--ssh-control-path2001:db8::1,[2001:db8::1]anduser@[2001:db8::1]are accepted. Brackets are stripped forsshandsshHostshows the destination actually used. Zone IDs and bracketed IPv4 are refused.sshUserSourceisexplicit(USER@HOSTor-l),ssh_config_or_local_default(one localssh -Gper host without an explicit user, 5 s limit; it does not connect, but it evaluates the user's ssh_config, includingMatch exec, as Python's lookup does) orunknown, as in Python.-ltogether withUSER@HOSTgivesconflicting_ssh_userbecause-lsilently wins. The PowerShell-EncodedCommandpath is unchanged and applies to every host.--ssh-control-pathnow requires exactly one--host, because one socket multiplexes one destination.test/ssh-hosts.test.ts, plus a two-host case in the Windows native fixture.Option interface design
ProxyCommand,LocalCommand/PermitLocalCommand,KnownHostsCommand,Match exec,Include,-F,PKCS11Provider/-I,SecurityKeyProvider,RemoteCommand,ProxyUseFdpass, among others. None of them can pass because only these keys are recognized:port,user,identityfile,identitiesonlyand address family.-oaccepts onlyKey=Valuewithout whitespace, so OpenSSH's own-otokenizer cannot split a value into a second option.--ssh-jump USER@HOST[:PORT]). One hop with an explicit user; IPv6 needs brackets. Only shell- and %-inert characters are accepted (invalid_ssh_jump).-J/ProxyJump/ProxyCommandstay refused in--ssh-opt, because OpenSSH's own-Jhop (exec ssh -l u -W '[target]:22' jump) receives no command-lineBatchMode/StrictHostKeyChecking. Instead the CLI places one fixed option with the other fixed options:-o ProxyCommand='<ssh path>' -T -o BatchMode=yes -o StrictHostKeyChecking=yes -o UpdateHostKeys=no -o ConnectTimeout=10 -o ConnectionAttempts=1 -o ProxyCommand=none -o ProxyJump=none -o ControlPath=none -o ForwardAgent=no -o ClearAllForwardings=yes -o PermitLocalCommand=no [-p PORT] -l USER -W '[%h]:%p' -- HOST.The path is single-quoted for the shell and every
%in it is doubled. The option is refused with--ssh-control-path(conflicting_ssh_jump) and on Windows clients (ssh_jump_unsupported_platform). Results addsshJump. There is no multi-hop and no Tailscale lookup for the hop (v1).cbe29df).run()used to kill only the direct child and then wait forclose, so a pipe-holding descendant such as the jumpProxyCommanddelayed completion and outlived the timeout.detached). A timeout or output overflow kills that group only (process.kill(-pid, 'SIGKILL'), ESRCH ignored, no PID scans) and destroys the streams. Completion is the exit plus a fixed 100 ms grace, not the pipes closing.sshgroup.--ssh-jumpis refused on Windows clients.ssh_preflight_timeout(refusal) and a request timeout isunknownwith no retry.test/process.test.ts, POSIX):interrupted/spawnedtrue, and both PIDs are gone;run(), the first regression never returned (stopped after 200 s).8cbad61, non-blocking review). The process group is registered synchronously as soon asspawn()returns a PID, with thespawnevent as the fallback, so a signal that arrives before that event still reaps the group. The docs now state that POSIXdetachedstarts a new session and process group with no controlling terminal, and that cleanup covers that group only: a descendant that leaves it withsetsid()is out of scope, and there is no PID scanning. Narrow validation:test/process.test.ts,test/ssh-hosts.test.tsandtest/transport.test.tsgave 26 tests, 25 pass, 0 fail, 1 skipped (Windows-only); the repository check is OK.ProxyCommandwas verified throughsh,bashandzsh(exec <command>with an ssh path containing spaces, a quote and%, run asssh -G). Other login shells (for example fish or csh) are unverified.--ssh-optvalues, including-4/-6, apply to the target only and are not passed to the hop.0692293). With--ssh-jump, the outersshalso gets-o ControlMaster=no -o ControlPath=none -o ProxyUseFdpass=no, placed before theProxyCommandand the user options. A configuredControlMaster auto/ControlPath, which could reuse an existing master and bypass the hop, and a configuredProxyUseFdpass yesare therefore overridden. Verified with localssh -G -F <fixture>(no connection): before,controlmaster auto, a control path andproxyusefdpass yes; after,controlmaster false, no control path andproxyusefdpass no. The regression test runs this samessh -Gcheck when ansshbinary is present, and also checks that a configuredProxyJumpis replaced. The--ssh-control-pathconflict refusal stays. Unverified boundaries: Win32-OpenSSH clients (refused) andProxyCommandparsing by a non-POSIX login$SHELL.ssh -G -F <fixture config>only, OpenSSH 10.3p1, no connection):ProxyCommandoverrides both a configuredProxyJumpand a configuredProxyCommandfor the target, without error. Without the override, the configuredProxyJumpstays.${ENV}expansion only for CertificateFile, ControlPath, IdentityAgent, IdentityFile, Include, KnownHostsCommand and UserKnownHostsFile, notProxyCommand. ProxyCommand accepts only the%%,%h,%n,%p,%rtokens and runs through the user's shell; hence the single quoting,%%escaping and charset limits.-Gpreserves the option text verbatim.ProxyCommand=none/ProxyJump=noneoverride a jump host's configuredProxyCommandorProxyJump.sh -casssh -G. It resolved to user/port from--ssh-jump,batchmode yes,stricthostkeychecking true,updatehostkeys false,connectionattempts 1,connecttimeout 10,forwardagent no,clearallforwardings yes,permitlocalcommand no, with no proxy.sshcommand line. The user's and system ssh_config are trusted user configuration (ssh(1), ssh_config(5)):ProxyCommand,ProxyJump,Match exec,Includeand similar settings there apply to everysshthis CLI starts, includingssh -G, exactly as for the user's ownssh. The PARITY and guide texts state this in all four languages.sshUserlookup now runs inside per-host handling. A lookup failure givesunknownfor that host only, and that host's dispatch and all earlier and later results are kept.ConnectTimeoutis not exposed, because a user value could never override the fixed first one.Files
src/ssh.ts(new):sshOptions()allowlist/canonicalizer,sshUser()metadata (ssh -G, 5 s bound).src/protocol.ts:host()accepts IPv6 literals and returns the OpenSSH destination.src/cli.ts: repeated--host/--ssh-opt, pre-dispatch validation, duplicate/conflict checks, orderedremotes()loop, sharedfailure()envelope, per-host attribution of command-wide refusals.src/output.ts: array rendering (JSON array; textHost:blocks).src/help.ts: usage.docs/guide{,.ko,.ja,.zh-CN}.mdnew "Several hosts and connection options" section, and the old "no--ssh-opt/IPv6" sentence is removed.PARITY.mdSSH rows and a new section describing unreleased source behavior.scripts/release.mjs,test/package-smoke.tsincludedist/ssh.{js,d.ts}.test/ssh-hosts.test.ts(new). Existing POSIX fakesshscripts andtest/fixtures/windows-native.csanswerssh -Gwithout logging it as a dispatch. The Windows contract also covers two hosts.Type
Validation
npm ci --ignore-scriptsandnpm run buildSESSION_PEER_PYTHON_ROOT=/path/to/pinned/reference npm test: 89 tests, 84 pass, 0 fail, 5 skipped (Windows-only, including the Windows--ssh-jumprefusal test). Baseline was 77/73/0/4.npm run test:package:packageSmoke: pass, clean install/uninstall.npm audit: 0 vulnerabilities.node scripts/check-repository.mjs: OK.node scripts/release.mjs pack: file list includesdist/ssh.*.release gatepasses with an up-to-date base (run 36970169560 on8cbad61: contract macOS/Ubuntu × Node 22/24, windows-native 22/24, repository-policy, release gate pass. windows-native (24) first failed on the known PowerShell cold-start inspection timeout (ETIMEDOUTat 8.1 s in an unrelated Unicode-collision test; Windows does not use the changed POSIX process-group path) and passed on one rerun of the failed job. CodeQL run 36970166058 pass)New test coverage (
test/ssh-hosts.test.ts):host()IPv6 acceptance and 17 refused forms.sshOptions()canonical argv plus 43 unsupported and 21 invalid token sequences, covering the vectors listed above and bypass spellings (-oproxycommand=,-o 'Proxy Command=…',-oPort=22 -oProxyCommand=…,-F/x,-Jjump,-46).sshinvocations (including nossh -G). This includes the syntax counterexamples--host alpha --host beta --bogus,--host=alpha --host beta --all=xand a missing--remote-binvalue. Two counterexamples stay flat: a single--host, and--hosttext after--.list(exit 1),doctorand text output. A single host stays flat, andssh -Gfailure givessshUser:null/unknown. A-Gfailure for the middle of three hosts keeps all three dispatches and results.send: posted / request exit 255 (unknown,submitted:null, no resend) / preflight refusal / posted. Theunknowncase is a classification fixture: the fake exits without running the remote CLI, so it showsunknownis never retried, not that a delivered message's response was lost. Exactly two inbox deliveries. A shell-metacharacter and Unicode body is absent from every ssh argv and present only in the stdin JSON.--ssh-jump: strict parser (24 refused values) and exactProxyCommandtext for a path with spaces, a quote and%. A fakesshunder such a path expands%h/%p/%%, runs theProxyCommandvia/bin/sh -c execand records the hop argv. Checked:-p 2222give 4 outer calls and 4 hops, with exact hop argv-W [target]:2222 -- jump;;,$(…),%h,-o…, missing user, bare IPv6 with a port, newline) give a per-hostinvalid_ssh_jumpand zerossh;--ssh-control-path, a missing--host, a repeated--ssh-jump, and--ssh-opt -J/ProxyCommandare refused;--, destination. POSIX quoted--remote-binwith spaces. Windows--remote-platform win32decodes to the expected PowerShell command for each host.Tested environments / limitations
ssh -Gand a-Jproxy-command inspection against a TEST-NET address). All transport tests use fakesshexecutables. No real SSH destination or agent session was contacted.ssh.exewith-Ghandling, two-host PowerShell path) is verified only by CI. It has not been run locally.-i/-pagainst a live server, or Windows OpenSSHssh -Goutput.Release impact
No release or deployment. Additive JSON fields (
sshUser,sshUserSource,sshHoston single-host SSH failures;version/referenceVersionnow also on single-host SSH-stage failures) and a new array shape only when--hostis repeated. Stricter:--ssh-control-pathwith several hosts is refused. Both SSH endpoints still require the same version. No native dependency changes.