Compare commits

...
Author SHA1 Message Date
Julius Marmingeandcodex d2de125352 fix(ssh): disable tunnel multiplexing (#3533)
Issue #3533 requires the supervised port-forward process to own its lifecycle even when the user's SSH config enables ControlMaster or ControlPersist.

Co-authored-by: codex <[email protected]>
2026-07-20 18:23:30 +02:00
2 changed files with 94 additions and 15 deletions

No files matched your search

+56
View File
@@ -14,6 +14,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import { SshPasswordPrompt } from "./auth.ts";
import {
buildSupervisedSshTunnelArgs,
buildRemoteLaunchScript,
buildRemotePairingScript,
buildRemoteStopScript,
@@ -89,6 +90,50 @@ function commandArgs(command: ChildProcess.Command): ReadonlyArray<string> {
}
describe("ssh tunnel scripts", () => {
it("disables connection multiplexing for the supervised port-forward command", () => {
const target = {
alias: "devbox",
hostname: "devbox.example.com",
username: "julius",
port: 2222,
} as const;
assert.deepEqual(
buildSupervisedSshTunnelArgs({
target,
batchMode: "no",
localPort: 41_773,
remotePort: 3_773,
hostSpec: "julius@devbox",
}),
[
"-o",
"BatchMode=no",
"-o",
"ConnectTimeout=10",
"-p",
"2222",
"-o",
"ControlMaster=no",
"-o",
"ControlPath=none",
"-o",
"ControlPersist=no",
"-o",
"ExitOnForwardFailure=yes",
"-o",
"ServerAliveInterval=15",
"-o",
"ServerAliveCountMax=3",
"-n",
"-N",
"-L",
"41773:127.0.0.1:3773",
"julius@devbox",
],
);
});
it("builds the remote t3 runner with npx and npm fallbacks", () => {
const script = buildRemoteT3RunnerScript({ nodeEngineRange: TEST_NODE_ENGINE_RANGE });
@@ -382,6 +427,17 @@ describe("ssh tunnel scripts", () => {
const first = yield* manager.ensureEnvironment(target);
assert.equal(first.httpBaseUrl, "http://127.0.0.1:41773/");
const firstTunnelArgs = spawnedCommands.find((args) => args.includes("-N"));
assert.isDefined(firstTunnelArgs);
assert.include(firstTunnelArgs, "ControlMaster=no");
assert.include(firstTunnelArgs, "ControlPath=none");
assert.include(firstTunnelArgs, "ControlPersist=no");
for (const args of spawnedCommands.filter((entry) => !entry.includes("-N"))) {
assert.notInclude(args, "ControlMaster=no");
assert.notInclude(args, "ControlPath=none");
assert.notInclude(args, "ControlPersist=no");
}
yield* manager.disconnectEnvironment(target);
assert.equal(tunnelKillCount, 1);
assert.equal(stopCommandCount, 1);
+38 -15
View File
@@ -917,6 +917,38 @@ const reserveLocalTunnelPort = Effect.fn("ssh/tunnel.reserveLocalTunnelPort")(fu
return yield* net.reserveLoopbackPort();
});
export function buildSupervisedSshTunnelArgs(input: {
readonly target: DesktopSshEnvironmentTarget;
readonly batchMode: "yes" | "no";
readonly localPort: number;
readonly remotePort: number;
readonly hostSpec: string;
}): ReadonlyArray<string> {
return [
...baseSshArgs(input.target, { batchMode: input.batchMode }),
// This process owns the tunnel lifecycle. Inherited ControlMaster settings
// can otherwise hand the forward to an existing master and let `ssh -N`
// exit while the manager believes it still supervises the connection.
"-o",
"ControlMaster=no",
"-o",
"ControlPath=none",
"-o",
"ControlPersist=no",
"-o",
"ExitOnForwardFailure=yes",
"-o",
"ServerAliveInterval=15",
"-o",
"ServerAliveCountMax=3",
"-n",
"-N",
"-L",
`${input.localPort}:127.0.0.1:${input.remotePort}`,
input.hostSpec,
];
}
const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input: {
readonly key: string;
readonly resolvedTarget: DesktopSshEnvironmentTarget;
@@ -956,22 +988,13 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
}),
),
);
const args = [
...baseSshArgs(input.resolvedTarget, {
batchMode: input.authOptions.batchMode ?? "no",
}),
"-o",
"ExitOnForwardFailure=yes",
"-o",
"ServerAliveInterval=15",
"-o",
"ServerAliveCountMax=3",
"-n",
"-N",
"-L",
`${input.localPort}:127.0.0.1:${input.remotePort}`,
const args = buildSupervisedSshTunnelArgs({
target: input.resolvedTarget,
batchMode: input.authOptions.batchMode ?? "no",
localPort: input.localPort,
remotePort: input.remotePort,
hostSpec,
];
});
const sshCommand = yield* resolveSshCommand;
const tunnelCommand = [sshCommand, ...args];
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;