Skip to content

ProxyCommand incorrectly requires an absolute path #1185

Closed

Description

@jstarks

ProxyCommand requires an executable with an absolute path or a path relative to the ssh.exe installation directory. This is because it uses posix_spawn instead of posix_spawnp (although the latter is not currently implemented).

This seems wrong. OpenSSH on POSIX passes the ProxyCommand to the shell, and the shell looks up the executable in the path.

This breaks the inbox Windows hvc tool for connecting to Hyper-V VMs.

Expected:

> ssh -o "ProxyCommand=cmd.exe /c echo Invalid proxy 1>&2" abc
Invalid proxy
ssh_exchange_identification: Connection closed by remote host

Observed (Linux, relative path):

$ ssh -o "ProxyCommand=sh -c 'echo Invalid proxy 1>&2'" abc
Invalid proxy
ssh_exchange_identification: Connection closed by remote host

Observed (Windows, absolute path):

> ssh -o "ProxyCommand=c:\windows\system32\cmd.exe /c echo Invalid proxy 1>&2" abc
Invalid proxy
ssh_exchange_identification: Connection closed by remote host

Observed (Windows, relative path):

> ssh -o "ProxyCommand=cmd.exe /c echo Invalid proxy 1>&2" abc
CreateProcessW failed error:2
posix_spawn: No such file or directory

Activity

  1. NoMoreFood commented on Jul 19, 2018

    @NoMoreFood

    From what I can tell, the upstream code doesn't actually use posix_spawnp(), it uses execv() after a fork(). Regardless, it looks like Win32 fork prepends the OpenSSH directory to the executable string in spawn_child_internal() if the string is not an absolute path which subsequently causes CreateProcess() to not go through the normal PATH environment variable search routine. I imagine this might have been to ensure that an unqualified executable in sshd_config could be launched without worrying about what the working directory might have been sshd was launched. Maybe a better thing to do would be to set the working directory to the OpenSSH at launch via SetCurrentDirectory() and let the CreateProcess() executable resolution code do it's thing or maybe prepend the OpenSSH directory into the beginning of the path which should have the same effect? Thoughts?

  2. jstarks commented on Jul 19, 2018

    @jstarks
    Author

    Right, upstream uses execv, but it launches the process through the shell (arg0 = $SHELL, arg1 = -c, arg2 = the proxy command) , which will handle looking up the binary in the path internally, among other things.

    Perhaps the right fix is to do the same and run the command line through %COMSPEC% /c.

  3. manojampalam commented on Jul 20, 2018

    @manojampalam
    Contributor

    Behavior of current posix_spawn is to support launching ssh from sftp and scp.
    I like the idea of supporting a posix_spawnp variant that would respect PATH instead. Will have it supported in next drop.

  4. bingbing8 commented on Jan 11, 2019

    @bingbing8
    Contributor

    posix_spawnp is implemented to respect PATH. Relative path should work for ProxyCommand now.

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

Metadata

Metadata

Labels

Issue-Enhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions