hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.25k stars 4.43k forks source link

rsync type synced_folder use SSH for guest connection when winrm communitor has been provided in the configuration #13182

Open Wenzel opened 1 year ago

Wenzel commented 1 year ago

Debug output

vagrant.log

Expected behavior

The folder should have been synced, and vagrant up should have terminated with exit code 0

Actual behavior

vagrant up fails:

INFO winrm: WinRM is ready!
DEBUG guest: Searching for cap: rsync_pre
DEBUG guest: Checking in: windows
DEBUG guest: Found cap: rsync_pre in windows
 INFO guest: Execute capability: rsync_pre [#<Vagrant::Machine: vagrant-kafl-windows (VagrantPlugins::ProviderLibvirt::Provider)>, {:type=>:rsync, :guestpath=>"/vagrant", :hostpath=>"/home/wenzel/Projets/kafl.targets/windows_x86_64-userspace/template/sharedir", :disabled=>false, :__vagrantfile=>true, :plugin=>#<VagrantPlugins::SyncedFolderRSync::SyncedFolder:0x00007f99510754d0 @logger=#<Log4r::Logger:0x00007f9951075458 @fullname="vagrant::synced_folders::rsync", @outputters=[], @additive=true, @name="rsync", @path="vagrant::synced_folders", @parent=#<VagrantLogger:0x00007f9958eab250 @fullname="vagrant", @outputters=[#<Log4r::StderrOutputter:0x00007f9958ebd090 @name="stderr", @level=0, @formatter=#<Vagrant::Util::LoggingFormatter:0x00007f99592f1148 @formatter=#<Log4r::BasicFormatter:0x00007f99592c70a0 @depth=7>>, @out=#<IO:<STDERR>>>], @additive=true, @name="vagrant", @path="", @parent=#<Log4r::RootLogger:0x00007f9958eaad50 @level=0, @outputters=[]>, @level=2, @trace=false>, @level=2, @trace=false>, @cap_logger=#<Log4r::Logger:0x00007f9951058e20 @fullname="vagrant::capability_host::vagrantplugins::syncedfolderrsync::syncedfolder", @outputters=[], @additive=true, @name="syncedfolder", @path="vagrant::capability_host::vagrantplugins::syncedfolderrsync", @parent=#<VagrantLogger:0x00007f9958eab250 @fullname="vagrant", @outputters=[#<Log4r::StderrOutputter:0x00007f9958ebd090 @name="stderr", @level=0, @formatter=#<Vagrant::Util::LoggingFormatter:0x00007f99592f1148 @formatter=#<Log4r::BasicFormatter:0x00007f99592c70a0 @depth=7>>, @out=#<IO:<STDERR>>>], @additive=true, @name="vagrant", @path="", @parent=#<Log4r::RootLogger:0x00007f9958eaad50 @level=0, @outputters=[]>, @level=2, @trace=false>, @level=2, @trace=false>, @cap_host_chain=[[:rsync, #<VagrantPlugins::SyncedFolderRSync::SyncedFolder:0x00007f995106cf38 @logger=#<Log4r::Logger:0x00007f995106cec0 @fullname="vagrant::synced_folders::rsync", @outputters=[], @additive=true, @name="rsync", @path="vagrant::synced_folders", @parent=#<VagrantLogger:0x00007f9958eab250 @fullname="vagrant", @outputters=[#<Log4r::StderrOutputter:0x00007f9958ebd090 @name="stderr", @level=0, @formatter=#<Vagrant::Util::LoggingFormatter:0x00007f99592f1148 @formatter=#<Log4r::BasicFormatter:0x00007f99592c70a0 @depth=7>>, @out=#<IO:<STDERR>>>], @additive=true, @name="vagrant", @path="", @parent=#<Log4r::RootLogger:0x00007f9958eaad50 @level=0, @outputters=[]>, @level=2, @trace=false>, @level=2, @trace=false>>]], @cap_args=[#<Vagrant::Machine: vagrant-kafl-windows (VagrantPlugins::ProviderLibvirt::Provider)>], @cap_caps={:smb=>#<Vagrant::Registry:0x00007f9951059000 @items={:default_fstab_modification=>#<Proc:0x00007f9958e60ca0 /opt/vagrant/embedded/gems/gems/vagrant-2.3.6/plugins/synced_folders/smb/plugin.rb:26>, :mount_options=>#<Proc:0x00007f9958e60bb0 /opt/vagrant/embedded/gems/gems/vagrant-2.3.6/plugins/synced_folders/smb/plugin.rb:31>, :mount_name=>#<Proc:0x00007f9958e60a48 /opt/vagrant/embedded/gems/gems/vagrant-2.3.6/plugins/synced_folders/smb/plugin.rb:36>, :mount_type=>#<Proc:0x00007f9958e60958 /opt/vagrant/embedded/gems/gems/vagrant-2.3.6/plugins/synced_folders/smb/plugin.rb:41>}, @results_cache={}>, :virtualbox=>#<Vagrant::Registry:0x00007f9951058f60 @items={:mount_options=>#<Proc:0x00007f9958fb12f8 /opt/vagrant/embedded/gems/gems/vagrant-2.3.6/plugins/providers/virtualbox/plugin.rb:72>, :mount_type=>#<Proc:0x00007f9958fb0fd8 /opt/vagrant/embedded/gems/gems/vagrant-2.3.6/plugins/providers/virtualbox/plugin.rb:77>, :mount_name=>#<Proc:0x00007f9958fb0ec0 /opt/vagrant/embedded/gems/gems/vagrant-2.3.6/plugins/providers/virtualbox/plugin.rb:82>}, @results_cache={}>}>, :owner=>"vagrant", :group=>"vagrant"}] (windows)
DEBUG winrm: powershell executing:
mkdir "/vagrant" -force
DEBUG winrmshell: [WinRM] opening remote shell on http://192.168.121.134:5985/wsman
DEBUG winrmshell: [WinRM] Waiting for output...
DEBUG winrmshell: [WinRM] Processing output
DEBUG winrmshell: [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00007f99514c9bf8 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Version N=\"protocolversion\">2.2</Version><Version N=\"PSVersion\">2.0</Version><Version N=\"SerializationVersion\">1.1.0.1</Version></MS></Obj>", @destination=1, @type=65538, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000">
DEBUG winrmshell: [WinRM] Waiting for output...
DEBUG winrmshell: [WinRM] Processing output
DEBUG winrmshell: [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00007f995146b5a8 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Obj N=\"ApplicationPrivateData\" RefId=\"1\"><TN RefId=\"0\"><T>System.Management.Automation.PSPrimitiveDictionary</T><T>System.Collections.Hashtable</T><T>System.Object</T></TN><DCT><En><S N=\"Key\">DebugMode</S><I32 N=\"Value\">1</I32></En><En><S N=\"Key\">DebugStop</S><B N=\"Value\">false</B></En><En><S N=\"Key\">PSVersionTable</S><Obj N=\"Value\" RefId=\"2\"><TNRef RefId=\"0\" /><DCT><En><S N=\"Key\">PSVersion</S><Version N=\"Value\">2.0</Version></En><En><S N=\"Key\">PSCompatibleVersions</S><Obj N=\"Value\" RefId=\"3\"><TN RefId=\"1\"><T>System.Version[]</T><T>System.Array</T><T>System.Object</T></TN><LST><Version>1.0</Version><Version>2.0</Version><Version>3.0</Version><Version>4.0</Version></LST></Obj></En><En><S N=\"Key\">BuildVersion</S><Version N=\"Value\">6.3.9600.16384</Version></En><En><S N=\"Key\">CLRVersion</S><Version N=\"Value\">4.0.30319.33440</Version></En><En><S N=\"Key\">WSManStackVersion</S><Version N=\"Value\">3.0</Version></En><En><S N=\"Key\">PSRemotingProtocolVersion</S><Version N=\"Value\">2.2</Version></En><En><S N=\"Key\">SerializationVersion</S><Version N=\"Value\">1.1.0.1</Version></En></DCT></Obj></En><En><S N=\"Key\">DebugBreakpointCount</S><I32 N=\"Value\">0</I32></En></DCT></Obj></MS></Obj>", @destination=1, @type=135177, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000">
DEBUG winrmshell: [WinRM] Waiting for output...
DEBUG winrmshell: [WinRM] Processing output
DEBUG winrmshell: [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00007f9951413010 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I32 N=\"RunspaceState\">2</I32></MS></Obj>", @destination=1, @type=135173, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000">
DEBUG winrmshell: [WinRM] remote shell created with shell_id: 09A8A427-0A10-4F07-9670-F2E04931DF09
DEBUG winrmshell: [WinRM] Command created for mkdir "/vagrant" -force
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 4C5EFC49-96BB-426C-A9CA-F8E54FE8F5B4
DEBUG winrmshell: [WinRM] creating command_id: 4C5EFC49-96BB-426C-A9CA-F8E54FE8F5B4 on shell_id 09A8A427-0A10-4F07-9670-F2E04931DF09
DEBUG winrmshell: [WinRM] Waiting for output...
DEBUG winrmshell: [WinRM] Processing output
DEBUG winrmshell: [WinRM] cleaning up command_id: 4C5EFC49-96BB-426C-A9CA-F8E54FE8F5B4 on shell_id 09A8A427-0A10-4F07-9670-F2E04931DF09
DEBUG winrmshell: Output: #<WinRM::Output:0x00007f9951181f90 @data=[{:stdout=>"\r\n"}, {:stdout=>"\r\n"}, {:stdout=>"    Directory: C:\\\r\n"}, {:stdout=>"\r\n"}, {:stdout=>"\r\n"}, {:stdout=>"Mode                LastWriteTime     Length Name                                                                                                                                                                                                        \r\n"}, {:stdout=>"----                -------------     ------ ----                                                                                                                                                                                                        \r\n"}, {:stdout=>"d----         5/25/2023   9:05 AM            vagrant                                                                                                                                                                                                     \r\n"}, {:stdout=>"\r\n"}, {:stdout=>"\r\n"}], @exitcode=0>
 INFO subprocess: Starting process: ["/usr/bin/rsync", "--verbose", "--archive", "--delete", "-z", "--copy-links", "--no-owner", "--no-group", "-e", "ssh -p 22 -o LogLevel=FATAL   -o ControlMaster=auto -o ControlPath=/tmp/vagrant-rsync-20230525-213410-u66j7e -o ControlPersist=10m  -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i '/home/wenzel/.vagrant.d/insecure_private_key'", "--exclude", ".vagrant/", "/home/wenzel/Projets/kafl.targets/windows_x86_64-userspace/template/sharedir/", "vagrant@192.168.121.134:/vagrant"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 31871
DEBUG subprocess: Exit status: 255
ERROR warden: Error occurred: There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.

Host path: /home/wenzel/Projets/kafl.targets/windows_x86_64-userspace/template/sharedir/
Guest path: /vagrant
Command: "rsync" "--verbose" "--archive" "--delete" "-z" "--copy-links" "--no-owner" "--no-group" "-e" "ssh -p 22 -o LogLevel=FATAL   -o ControlMaster=auto -o ControlPath=/tmp/vagrant-rsync-20230525-213410-u66j7e -o ControlPersist=10m  -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i '/home/wenzel/.vagrant.d/insecure_private_key'" "--exclude" ".vagrant/" "/home/wenzel/Projets/kafl.targets/windows_x86_64-userspace/template/sharedir/" "vagrant@192.168.121.134:/vagrant"
Error: rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]

We can see that WinRM connexion is ready, then mkdir /vagrant is done on the guest side, and then rsync is invoked with "-e" "ssh -p 22 -o LogLevel=FATAL -o ....

Reproduction information

Vagrant version

Installed Version: 2.3.6
Latest Version: 2.3.6

You're running an up-to-date version of Vagrant!

Host operating system

Ubuntu 23.04

Guest operating system

Windows 8.1 Trial Enterprise

Steps to reproduce

The VM has been prepared with Packer. I can share the template with the maintainers for them to repro the issue if necessary.

Vagrantfile

Vagrant.configure("2") do |config|
  # The Packer box we just added
  config.vm.box = "kafl_windows"
  # our box name in libvirt
  config.vm.define "vagrant-kafl-windows"
  # we use winrm
  config.vm.communicator = "winrm"
  # credentials
  config.winrm.username = "vagrant"
  config.winrm.password = "vagrant"
  # explicitely tell Vagrant that this is a Windows guest
  # no need to guess
  config.vm.guest = :windows

  config.vm.synced_folder "sharedir", '/vagrant', type: 'rsync'
  config.vm.provider :libvirt do |libvirt|
    libvirt.disk_bus = "ide"
    libvirt.nic_model_type = "e1000e"
    # send absolute mouse movments to QEMU VNC display using a tablet
    # otherwise the guest mouse pointer is always out of sync with the host pointer, very annoying
    libvirt.input :type => "tablet", :bus => "usb"
    libvirt.memory = 4096
  end
end

Thanks !

chrisroberts commented 1 year ago

Hi there,

The rsync synced folders do not support syncing over winrm. We'll update the plugin to perform a check on the configured communicator and return an error if not set to ssh.

Cheers