Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port-forwarding with SSH ProxyCommand fails with "exec ssh ... not found" #1817

Open
stygian-coffee opened this issue Apr 26, 2024 · 1 comment

Comments

@stygian-coffee
Copy link

stygian-coffee commented Apr 26, 2024

Describe the bug

If using a Libvirt daemon on a remote host and attempting to forward ports, port forwarding fails.

I think that this is related to

options += ['-o', "ProxyCommand=\"#{ssh_info[:proxy_command]}\""] if machine.provider_config.proxy_command && !machine.provider_config.proxy_command.empty?

Namely, I think that "ProxyCommand=\"#{ssh_info[:proxy_command]}\"" should be changed to "ProxyCommand=#{ssh_info[:proxy_command]}"

I think that this bug was introduced in 55a220f.

To Reproduce

Set up an SSH server so that you can SSH to localhost.

Use the following Vagrantfile:

Vagrant.configure("2") do |config|
  config.vagrant.plugins = "vagrant-libvirt"

  config.vm.box = "generic/ubuntu2204"

  config.vm.hostname = "test"
  config.vm.network("forwarded_port", guest: 8080, host: 8080)
  config.vm.provider("libvirt") do |lv|
    lv.host = "localhost"
    lv.connect_via_ssh = true
  end
end

Run vagrant up. Notice that port 8080 is not forwarded. Read the log in .vagrant/machines/default/libvirt/logs/ssh-forwarding-\*_8080-192.168.121.250_8080.log. It will say something similar to:

zsh:1: command not found: ssh 'localhost' -W 192.168.121.250:22
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535

Expected behavior
Port 8080 is forwarded.

Versions (please complete the following information)::

  • Libvirt version: 8.0.0
  • Vagrant version: 2.3.7
  • Vagrant flavour: upstream (NixOS)
  • Vagrant plugins versions (including vagrant-libvirt): vagrant-libvirt (0.12.2, system)

Debug Log
Attach Output of VAGRANT_LOG=debug vagrant ... --provider=libvirt >vagrant.log 2>&1
vagrant.log

@stygian-coffee stygian-coffee changed the title Port-forwarding with SSH ProxyCommand fails "exec ssh ... not found" Port-forwarding with SSH ProxyCommand fails with "exec ssh ... not found" Apr 26, 2024
@stygian-coffee
Copy link
Author

stygian-coffee commented Apr 26, 2024

For anyone else who runs into this issue, I was able to find this workaround:

Vagrant.configure("2") do |config|
  config.vagrant.plugins = "vagrant-libvirt"

  config.vm.box = "generic/ubuntu2204"

  config.vm.hostname = "test"
  config.vm.network("forwarded_port", guest: 8080, host: 8080)
  config.vm.provider("libvirt") do |lv|
    lv.host = "localhost"
    lv.connect_via_ssh = true

    tmpdir = Dir.mktmpdir()
    ENV["PATH"] += ":#{tmpdir}"
    ["\"", "\\\"", "\" "].each do |filename|
      File.open("#{tmpdir}/#{filename}", "w") do |f|
        f.write(<<-EOF
          #!/bin/sh
          exec $@
        EOF
        )
      end
      FileUtils.chmod("+x", "#{tmpdir}/#{filename}")
    end
    lv.proxy_command = "\\\" \" ssh localhost -W %h:%p #\""
  end
end

Unfortunately, this only works for non-privileged ports since vagrant-libvirt invokes sudo for privileged ports, and sudo strips the PATH variable.

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

No branches or pull requests

1 participant