Skip to content

fix: handle paths with spaces in Match exec clause of SSH config - #18266

Merged
spikecurtis merged 5 commits into
mainfrom
spike/18199-path-with-spaces
Jun 6, 2025
Merged

spikecurtis merged 5 commits into
mainfrom
spike/18199-path-with-spaces

Conversation

@spikecurtis

Copy link
Copy Markdown
Collaborator

fixes #18199

Corrects handling of paths with spaces in the Match !exec clause we use to determine whether Coder Connect is running. This is handled differently than the ProxyCommand, so we have a different escape routine, which also varies by OS.

On Windows, we resort to a pretty gnarly hack, but it does work and I feel the only other option would be to reduce functionality such that we could not detect the Coder Connect state.

@spikecurtis
spikecurtis force-pushed the spike/18199-path-with-spaces branch from 6f0ac31 to caee378 Compare June 6, 2025 10:35

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the research and docs here. Although this is indisputably gnarly, I much prefer it to the alternative of reducing functionality. Kudos on finding this hack 👍🏻

Please note QQ in inline comment, but other than that, approved!

Comment thread cli/configssh_windows.go
// Constructing the string and then passing it to another instance of cmd.exe does this trick here.
// - OpenSSH passes the `Match exec` command to cmd.exe regardless of whether the user has a unix-like shell like
// git bash, so we don't have a `forceUnixPath` option like for the ProxyCommand which does respect the user's
// configured shell on Windows.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great write-up! ❤️

QQ: Is there a chance the "default shell" that OpenSSH uses can be configured to be powershell instead of cmd.exe? And if yes, would the for loop break?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread cli/configssh_windows.go

if strings.ContainsAny(path, " ") {
// c.f. function comment for how this works.
path = fmt.Sprintf("for /f %%%%a in ('powershell.exe -Command [char]34') do @cmd.exe /c %%%%a%s%%%%a", path) //nolint:gocritic // We don't want %q here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💫😵💫 %%%%%%%%%%%%%%%%%%%%%%%% 💫😵💫

@spikecurtis
spikecurtis merged commit d47a53d into main Jun 6, 2025
@spikecurtis
spikecurtis deleted the spike/18199-path-with-spaces branch June 6, 2025 12:44
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 6, 2025
@stirby

stirby commented Jul 7, 2025

Copy link
Copy Markdown
Collaborator

/cherry-pick release/2.23

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: config-ssh writes bad Match exec clause on Windows

3 participants