Skip to content

fix(ssh): include the Coder SSH config on Windows when HOME differs - #1211

Open
EhabY wants to merge 8 commits into
mainfrom
fix/vsc-58-windows-ssh-include
Open

EhabY wants to merge 8 commits into
mainfrom
fix/vsc-58-windows-ssh-include

Conversation

@EhabY

@EhabY EhabY commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

On Windows the extension writes the shared SSH Include as ~/AppData/.... Both Win32-OpenSSH and Git for Windows ssh expand ~ from HOME when it is set. With HOME on another drive (for example a network home H:\), the include matches nothing, the workspace host gets no ProxyCommand, and the connection fails. Regression since #1061.

Fix

Situation Include argument
Linux / macOS unchanged
Windows, HOME unset or equal to the profile (almost everyone) unchanged: "~/AppData/Roaming/coder.coder-remote/ssh/*.conf"
Windows, HOME elsewhere, or data dir outside the profile "C:/Users/u/.../ssh/*.conf" "/c/Users/u/.../ssh/*.conf"
Windows, UNC data dir unchanged: one //server/share/... argument
  • Win32-OpenSSH 8.1+ reads C:/..., MSYS builds such as Git for Windows read /c/.... Each build silently skips the one it cannot match, so nothing is included twice. The spellings live in one list (WINDOWS_PATH_SPELLINGS).
  • HOME is compared with the profile by real path, so casing, slashes, 8.3 short names, junctions and subst drives that reach the profile keep the ~/... line. When the real path can't be read, the resolved path is compared instead.
  • Without -F, Git for Windows ssh reads HOME\.ssh\config, so that file also gets the include block when HOME is a drive or UNC path. A failure there only logs a warning.
  • % in the path is written as the glob ?. OpenSSH 9.9+ expands % tokens in Include and older builds don't, so no escape works on both. These paths used to throw.
  • The post-write ssh -G check now runs with -v. When no ProxyCommand resolves, the logged error lists the files ssh read and the includes that matched nothing. No extra process.

Verification

Measured on Windows Server 2025 with Win32-OpenSSH 7.7p1 to 10.4p1 (including the inbox 9.5p2) and Git for Windows 2.30 to 2.56, using the branch's SshConfig to write real configs:

  • 0 regressions and 0 duplicate includes in 240 cells compared with main; 99 cells fixed.
  • 0 regressions in 330 more cells covering HOME spellings of the profile: empty, forward slashes, trailing slash, lowercase, .. segments, 8.3 short name, subst drive, junction, literal %USERPROFILE%, MSYS /c/..., relative.
  • Still broken, as on main: Win32-OpenSSH 7.7p1 (Server 2019) whenever ~ can't be used, and Git ssh without -F when HOME is an MSYS path such as /c/....
  • A real-ssh test now runs the rendered config through the inbox ssh and Git for Windows ssh on the Windows CI runner, with HOME unset, equal to the profile, and elsewhere. Another points HOME at a real junction to the profile and checks the ~/... line stays.

Closes VSC-58. Refs VSC-8, #1197.

Measurements, design and decision log

Which Include arguments each build reads

1,260 ssh -v -G -F runs across 15 builds. HOME values: unset, the profile, the profile uppercased, H:\ (a real SMB-mapped drive), C:\hshare, /c/hshare.

Argument Win32 7.7 Win32 8.1 to 10.4 Git 2.30 to 2.56
~/... (before) only if HOME unset or equal only if HOME unset or equal only if HOME unset or equal
C:/... never (read as ~/.ssh/C:/...) always never
/c/... never, silently never, silently always
/cygdrive/c/... never never never
//host/share/... always always always
"C:/..." "/c/..." never always, read once always, read once
"~/..." "/c/..." only if HOME unset or equal only if HOME unset or equal always, but read twice when HOME is equal

Other findings:

  • An argument that matches nothing never fails on any build (exit 0, "matched no files" with -v).
  • Without -F, Win32-OpenSSH always reads USERPROFILE\.ssh\config; Git ssh reads HOME/.ssh/config.
  • Spaces and bracket-escaped glob characters work in every form on every build.

Writing %

Spelling Up to 9.8 9.9+ and 10.x
% ok fatal (unknown key %z) or silently wrong (%d becomes the home dir)
%% no match ok
[%] ok fatal
? ok ok

Also confirmed on Linux OpenSSH 10.2. Cost of ?: it also matches a sibling directory that differs only in that character.

End-to-end result per scenario

The branch's SshConfig wrote the configs on the VM; every build then resolved them with -F and with default lookup.

Scenario Win32 7.7 Win32 8.1+ Git, -F Git, no -F
HOME unset, equal, or equal with other case ok ok ok ok
HOME=H:\ or C:\hshare broken before and after fixed fixed fixed
HOME=/c/hshare broken before and after fixed fixed broken before and after
Data dir on D: broken before and after ok fixed fixed
% and [] in data dir fixed when ~ works (threw before) fixed (threw before) fixed fixed

Decisions

  • Real path for the HOME check: a plain string comparison treated an 8.3 name, junction or subst drive of the profile as a different directory. That switched to absolute paths and broke Win32-OpenSSH 7.7. The check is async so a slow network HOME never blocks the extension host.
  • Empty HOME: treated as unset, so the ~/... line is unchanged. Absolute paths fixed the newer builds measured with an empty HOME (inbox 9.5p2, 10.4p1, Git 2.56) but break 7.7, which handles ~ with an empty HOME.
  • Rejected: writing "C:/..." "/c/..." for everyone. Win32-OpenSSH 7.7p1 reads C:/ as relative, so it would break users who work today.
  • Rejected: keeping ~/... and adding /c/.... Git ssh users with HOME equal to the profile would read every file twice.
  • Rejected: detecting the ssh flavor. It needs an extra process per connect and misses wrappers.
  • Kept narrow: the HOME config is only written for drive or UNC HOME values, so nothing goes to a guessed location.
  • Deferred: Cygwin /cygdrive/c/.... Adding it is one entry in WINDOWS_PATH_SPELLINGS.

🤖 Generated by Coder Agents on behalf of @EhabY.

Win32-OpenSSH and Git for Windows ssh both expand `~` from HOME when it is
set, so the `~/...` Include matched nothing when HOME pointed away from the
profile, and the workspace host lost its ProxyCommand.

- Keep the `~/...` Include whenever ssh expands `~` to the profile, so that
  output is unchanged. Otherwise write the absolute path in each spelling a
  Windows build reads: `C:/...` for Win32-OpenSSH 8.1+, `/c/...` for MSYS
  builds such as Git for Windows. Each build skips the one it cannot match.
- Without `-F`, Git for Windows ssh reads HOME's `.ssh/config`, so it gains
  the include block too when HOME is a drive or UNC path. A failure warns.
- Write `%` in Include paths as the glob `?`, since OpenSSH 9.9+ expands
  %-tokens there and older builds don't. Such paths used to throw.
- Run the post-write `ssh -G` with `-v` and report which files ssh read
  when it resolves no ProxyCommand.

Verified on Windows Server 2025 against Win32-OpenSSH 7.7p1 to 10.4p1 and
Git for Windows 2.30 to 2.56: no case that worked before regressed.

Closes VSC-58
ssh expands ~ from HOME when it is set, so the test failed on a Windows
machine whose HOME is not the profile.
@linear-code

linear-code Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

VSC-58

VSC-8

Writes the HOME ssh config inline in updateSSHConfig, shortens comments,
and folds overlapping test cases into tables that check the whole rendered
file. The % case now runs only against real OpenSSH.
An 8.3 name, junction or subst drive for the profile compared as a
different directory, so the include switched to absolute paths, which
Win32-OpenSSH 7.7 cannot read. The real path sees through all three and
falls back to the resolved path when it cannot be read.
@EhabY
EhabY marked this pull request as ready for review November 24, 2026 15:07
Pass the directory ssh expands ~ from into updateInclude instead of
re-reading HOME per call, replace the path spelling array with
toMsysPath, and report all of ssh -v's stderr when no ProxyCommand
resolves. Windows include tests now run only on Windows.
Comment thread src/remote/sshConfig.ts Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants