diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 02804b5b0..b705b362e 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -764,6 +764,10 @@ module Vagrant error_key(:virtualbox_name_exists) end + class VirtualBoxUserMismatch < VagrantError + error_key(:virtualbox_user_mismatch) + end + class VirtualBoxVersionEmpty < VagrantError error_key(:virtualbox_version_empty) end diff --git a/plugins/providers/virtualbox/provider.rb b/plugins/providers/virtualbox/provider.rb index 9428fe6d7..270286341 100644 --- a/plugins/providers/virtualbox/provider.rb +++ b/plugins/providers/virtualbox/provider.rb @@ -73,6 +73,13 @@ module VagrantPlugins # # @return [Symbol] def state + # We have to check if the UID matches to avoid issues with + # VirtualBox. + uid = @machine.uid + if uid && uid.to_s == Process.uid.to_s + raise Vagrant::Errors::VirtualBoxUserMismatch, uid: uid.to_s + end + # Determine the ID of the state here. state_id = nil state_id = :not_created if !@driver.uuid diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a6abe138c..285960f39 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1317,6 +1317,13 @@ en: Vagrant uses the `VBoxManage` binary that ships with VirtualBox, and requires this to be available on the PATH. If VirtualBox is installed, please find the `VBoxManage` binary and add it to the PATH environmental variable. + virtualbox_user_mismatch: |- + The VirtualBox VM was created with a user that doesn't match the + current user running Vagrant. VirtualBox requires that the same user + be used to manage the VM that was created. Please re-run Vagrant with + that user. + + The UID used to create the VM was: %{uid} virtualbox_version_empty: |- Vagrant detected that VirtualBox appears installed on your system, but calls to detect the version are returning empty. This is often