hashicorp / vagrant

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

vagrant init Operation not permitted Error #12077

Open bosungs opened 3 years ago

bosungs commented 3 years ago

Vagrant version

vagrant 2.2.6

Host operating system

Windows 10 pro and WSL

Guest operating system

ubuntu/trusty64

Debug output

bosungkim@DESKTOP-6BV2M48:/mnt/c/test_dir/vagrant-project$ vagrant init ubuntu/trusty64

Traceback (most recent call last):
        7: from /usr/bin/vagrant:23:in `<main>'
        6: from /usr/bin/vagrant:23:in `load'
        5: from /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/bin/vagrant:154:in `<top (required)>'
        4: from /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/bin/vagrant:154:in `new'
        3: from /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/lib/vagrant/environment.rb:166:in `initialize'
        2: from /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/lib/vagrant/environment.rb:1059:in `copy_insecure_private_key'
        1: from /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/lib/vagrant/environment.rb:1059:in `chmod'
/usr/share/rubygems-integration/all/gems/vagrant-2.2.6/lib/vagrant/environment.rb:1059:in `chmod': Operation not permitted @ apply2files - /mnt/c/Users/bosung-vm/.vagrant.d/insecure_private_key (Errno::EPERM)

Expected behavior

vagrant init ubuntu/trusty64 on Windows 10 WSL

Actual behavior

An error occured while executing vagrant init utubunt/trusty64

Steps to reproduce

WSL install install ubuntu on Microsoft Market

sudo apt update && apt install vagrant
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"
vagrant init utubunt/trusty64
bosungs commented 3 years ago

append info

bosungkim@DESKTOP-6BV2M48:/mnt/c/test_dir/vagrant-project$ cp /mnt/c/Users/bosung-vm/.vagrant.d/insecure_private_key .
bosungkim@DESKTOP-6BV2M48:/mnt/c/test_dir/vagrant-project$ ll
total 4
drwxrwxrwx 1 root root 4096 Nov 25 16:45 ./
drwxrwxrwx 1 root root 4096 Nov 25 13:37 ../
-rwxrwxrwx 1 root root 1675 Nov 25 16:45 insecure_private_key*
bosungs commented 3 years ago

Currently, the same issue is occurring for both my workstation and laptop. I hope it will be revised as soon as possible.

Looking at the traceback, it seems to be setting the mode of this file for copy_insecure_private_key.

The syntax in which an error occurs is written as follows. /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/lib/vagrant/environment.rb:1059 if Util::FileMode.from_octal(@default_private_key_path.stat.mode) != "600"

This syntax seems to be if there is no permission of 600, sets the permission 600. And when I saw the permissions of my corresponding files, it was 777.

So, the permissions of the corresponding file are above 0600. it seems that there is no need to change to chmod.

I tried changing the operator from != to <and confirmed that the issue no longer appears.

To summarize, this is solved by changing the following syntax to: /usr/share/rubygems-integration/all/gems/vagrant-2.2.6/lib/vagrant/environment.rb:1059

from if Util::FileMode.from_octal(@default_private_key_path.stat.mode) != "600"

to if Util::FileMode.from_octal(@default_private_key_path.stat.mode) < "600"

PeteDevoy commented 2 years ago

For anyone hitting this off Google; I was able to fix with Restart-Service LxssManager in PowerShell running with admin privileges. Credit.

N.B. It will force your WSL sessions to close.