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

Silently fails to create share for synced folder with Hyper-V on Windows host #10628

Open
fsackur opened this issue Jan 29, 2019 · 4 comments
Open

Comments

@fsackur
Copy link

fsackur commented Jan 29, 2019

Vagrant version

2.2.3

Host operating system

Windows 10.0.17763.0, clean build, no Docker. Enterprise managed, we do have security agents, but they don't pop up any notifications.

Guest operating system

Ubuntu 16.04

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.define "ubuntu", primary: true do |ubuntu|
    ubuntu.vm.box = "generic/ubuntu1604"
    config.vm.provider "hyperv" do |vb|
      vb.maxmemory = "4096"
      vb.maxmemory = "2048"
    end

    config.vm.provision "shell", inline: <<-SHELL
      apt-get install -y cifs-utils </dev/null
    SHELL

    config.vm.synced_folder '../', '/vagrant', {
      type: 'smb',
      mount_options: ['vers=3.0']
      # have tried with following options: no change
      #smb_host: '172.17.118.161',
      #smb_username: ENV['VAGRANT_SMB_USERNAME'],
      #smb_password: ENV['VAGRANT_SMB_PASSWORD']
    }
    config.vm.provision "shell", inline: <<-SHELL
      echo "export HOST_OS=#{ENV['OS']}" >> /etc/profile.d/hostos.sh
    SHELL
    config.vm.provision :shell, path: "bootstrap.sh"
  end
end

Debug output

 INFO interface: detail:     ubuntu: You will be asked for the username and password to use for the SMB
    ubuntu: folders shortly. Please use the proper username/password of your
    ubuntu: account.
    ubuntu:
    ubuntu: You will be asked for the username and password to use for the SMB
    ubuntu: folders shortly. Please use the proper username/password of your
    ubuntu: account.
    ubuntu:
 INFO interface: ask: Username:
 INFO interface: ask:     ubuntu: Username:
    ubuntu: Username: ***REDACTED***
 INFO interface: ask: Password (will be hidden):
 INFO interface: ask:     ubuntu: Password (will be hidden):
    ubuntu: Password (will be hidden):
DEBUG host: Searching for cap: smb_validate_password
DEBUG host: Checking in: windows
DEBUG host: Searching for cap: smb_start
DEBUG host: Checking in: windows
DEBUG host: Searching for cap: smb_prepare
DEBUG host: Checking in: windows
DEBUG host: Found cap: smb_prepare in windows
 INFO host: Execute capability: smb_prepare [#<Vagrant::Environment: C:/GithubData/monov/stepladder>, #<Vagrant::Machine: ubuntu (VagrantPlugins::HyperV::Provider)>, {"/vagrant"=>{:disabled=>false, :guestpath=>"/vagrant", :hostpath=>"C:/Githubdata/monov", :type=>:smb, :mount_options=>["vers=3.0"], :__vagrantfile=>true, :smb_username=>"***REDACTED***", :smb_password=>"*****"}}, {}] (windows)
 INFO subprocess: Starting process: ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\/powershell.EXE", "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", "Get-SmbShare|Format-List|Out-String -Width 4096"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout:

Name        : ADMIN$
ScopeName   : *
Path        : C:\windows
Description : Remote Admin

Name        : C$
ScopeName   : *
Path        : C:\
Description : Default share

Name        : IPC$
ScopeName   : *
Path        :
Description : Remote IPC





DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 31999
DEBUG subprocess: Exit status: 0
DEBUG smb: local share listing: {"ADMIN$"=>{"Path"=>"C:\\windows", "Description"=>"Remote Admin"}, "C$"=>{"Path"=>"C:\\", "Description"=>"Default share"}, "IPC$"=>{"Path"=>"", "Description"=>"Remote IPC"}, "test"=>{"Path"=>"C:\\test", "Description"=>""}}
DEBUG smb: generating machine ID name=ubuntu cwd=C:/GithubData/monov/stepladder
 INFO smb: creating new share name=vgt-cb537e4512c0aa89971e7a52a9c6c30e-6ad5fdbcbf2eaa93bd62f92333a2e6e5 id=vgt-cb537e4512c0aa89971e7a52a9c6c30e-6ad5fdbcbf2eaa93bd62f92333a2e6e5
 INFO interface: warn:
Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.


Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.

 INFO subprocess: Starting process: ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\/powershell.EXE", "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", "$p = Start-Process -FilePath powershell -ArgumentList @('-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', 'JABwACAAPQAgAFMAdABhAHIAdAAtAFAAcgBvAGMAZQBzAHMAIAAtAEYAaQBsAGUAUABhAHQAaAAgAHAAbwB3AGUAcgBzAGgAZQBsAGwAIAAtAEEAcgBnAHUAbQBlAG4AdABMAGkAcwB0ACAAQAAoACcALQBOAG8ATABvAGcAbwAnACwAIAAnAC0ATgBvAFAAcgBvAGYAaQBsAGUAJwAsACAAJwAtAE4AbwBuAEkAbgB0AGUAcgBhAGMAdABpAHYAZQAnACwAIAAnAC0ARQB4AGUAYwB1AHQAaQBvAG4AUABvAGwAaQBjAHkAJwAsACAAJwBCAHkAcABhAHMAcwAnACwAIAAnAC0ARQBuAGMAbwBkAGUAZABDAG8AbQBtAGEAbgBkACcALAAgACcASgBnAEEAZwBBAEMASQBBAFEAdwBBADYAQQBDADgAQQBTAEEAQgBoAEEASABNAEEAYQBBAEIAcABBAEUATQBBAGIAdwBCAHkAQQBIAEEAQQBMAHcAQgBXAEEARwBFAEEAWgB3AEIAeQBBAEcARQBBAGIAZwBCADAAQQBDADgAQQBaAFEAQgB0AEEARwBJAEEAWgBRAEIAawBBAEcAUQBBAFoAUQBCAGsAQQBDADgAQQBaAHcAQgBsAEEARwAwAEEAYwB3AEEAdgBBAEQASQBBAEwAZwBBAHkAQQBDADQAQQBNAHcAQQB2AEEARwBjAEEAWgBRAEIAdABBAEgATQBBAEwAdwBCADIAQQBHAEUAQQBaAHcAQgB5AEEARwBFAEEAYgBnAEIAMABBAEMAMABBAE0AZwBBAHUAQQBEAEkAQQBMAGcAQQB6AEEAQwA4AEEAYwBBAEIAcwBBAEgAVQBBAFoAdw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AvAFQAZQBtAHAALwB2AGEAZwByAGEAbgB0ADIAMAAxADkAMAAxADIAOQAtADEAMQA5ADQAOAAtADEAeAA5AGsANgA3AC8AcwB0AGQAZQByAHIALgB0AHgAdAAnADsAIABpAGYAKAAkAHAAKQB7ACAAZQB4AGkAdAAgACQAcAAuAEUAeABpAHQAQwBvAGQAZQA7ACAAfQBlAGwAcwBlAHsAIABlAHgAaQB0ACAAMQAgAH0A') -PassThru -WindowStyle Hidden -Wait -Verb RunAs; if($p){ exit $p.ExitCode; }else{ exit 1 }"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 31998
DEBUG subprocess: Exit status: 1
ERROR warden: Error occurred: Exporting an SMB share failed! Details about the failure are shown
below. Please inspect the error message and correct any problems.

Host path:

Stderr:

Stdout:

Expected behavior

SMB share created, visible with net share. No UAC popup expected, as running console as admin. OR, if command fails, we get diagnostic output.

Actual behavior

Share not created. HOWEVER, if I decode the Base64 string and run THAT, command completes as expected and share is created. No diagnostic output if not running with --debug`, I find this unhelpful:

ERROR warden: Error occurred: Exporting an SMB share failed! Details about the failure are shown
below. Please inspect the error message and correct any problems.

Host path:

Stderr:

Stdout:
$EncodedText = 'JABwACAAPQAgAFMAdABhAHIAdAAtAFAAcgBvAGMAZQBzAHMAIAAtAEYAaQBsAGUAUABhAHQAaAAgAHAAbwB3AGUAcgBzAGgAZQBsAGwAIAA... etc ...'
[System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedText))

Steps to reproduce

  1. Run vagrant up in a console that's running as administrator
  2. Put in valid creds
  3. Profit???
@fsackur
Copy link
Author

fsackur commented Jan 29, 2019

I believe that the debug output INFO subprocess: Starting process: ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\/powershell.EXE", "-NoLogo", "-NoProfile", "-NonInteractive" # ... etc ... can be recreated manually with:
Start-Process "C:\\windows\\System32\\WindowsPowerShell\\v1.0\\/powershell.EXE" -ArgumentList "-NoLogo", "-NoProfile", "-NonInteractive" # ... etc ...

N.B. the debug output includes the string $p. When I run Start-Process, I also try escaping that as `$p.

When I do that, I get a powershell window visible and, if not running already as admin, I get a UAC prompt. So that weird slash/backslash combo isn't breaking anything. However... why wrap a base64-encoded command in another one so many times? It appears to be the final wrapping that breaks this.

@fsackur
Copy link
Author

fsackur commented Jan 31, 2019

I can't reproduce the issue on Windows 10 update 1607, but I can on 1803.

@rgl
Copy link
Contributor

rgl commented Jan 3, 2022

I'm also experiencing this with Windows 10.0.19044.1415 (aka 21H2).

Running vagrant from an elevated shell and commenting the UAC stuff and setting sudo: false seems to help:

As a diff:

--- "C:\\HashiCorp\\Vagrant\\embedded\\gems\\2.2.19\\gems\\vagrant-2.2.19\\plugins\\hosts\\windows\\cap\\smb.rb.orig.txt"       2022-01-03 17:37:02.265982000 +0000
+++ "C:\\HashiCorp\\Vagrant\\embedded\\gems\\2.2.19\\gems\\vagrant-2.2.19\\plugins\\hosts\\windows\\cap\\smb.rb"        2022-01-03 17:21:12.930813600 +0000
@@ -51,10 +51,10 @@
           @@logger.debug("shares to be removed: #{prune_shares}")

           if prune_shares.size > 0
-            machine.env.ui.warn("\n" + I18n.t("vagrant_sf_smb.uac.prune_warning") + "\n")
-            sleep UAC_PROMPT_WAIT
+            # machine.env.ui.warn("\n" + I18n.t("vagrant_sf_smb.uac.prune_warning") + "\n")
+            # sleep UAC_PROMPT_WAIT
             @@logger.info("remove shares: #{prune_shares}")
-            result = Vagrant::Util::PowerShell.execute(script_path, *prune_shares, sudo: true)
+            result = Vagrant::Util::PowerShell.execute(script_path, *prune_shares, sudo: false)
             if result.exit_code != 0
               failed_name = result.stdout.to_s.sub("share name: ", "")
               raise SyncedFolderSMB::Errors::PruneShareFailed,
@@ -100,14 +100,14 @@
             ]
           end
           if !shares.empty?
-            uac_notified = false
+            # uac_notified = false
             shares.each_slice(10) do |s_shares|
-              if !uac_notified
-                machine.env.ui.warn("\n" + I18n.t("vagrant_sf_smb.uac.create_warning") + "\n")
-                uac_notified = true
-                sleep(UAC_PROMPT_WAIT)
-              end
-              result = Vagrant::Util::PowerShell.execute(script_path, *s_shares, sudo: true)
+              # if !uac_notified
+              #   machine.env.ui.warn("\n" + I18n.t("vagrant_sf_smb.uac.create_warning") + "\n")
+              #   uac_notified = true
+              #   sleep(UAC_PROMPT_WAIT)
+              # end
+              result = Vagrant::Util::PowerShell.execute(script_path, *s_shares, sudo: false)
               if result.exit_code != 0
                 share_path = result.stdout.to_s.sub("share path: ", "")
                 raise SyncedFolderSMB::Errors::DefineShareFailed,

@rgl
Copy link
Contributor

rgl commented Oct 3, 2022

FYI, I've created #12933 that fixes this for me.

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

No branches or pull requests

3 participants