multipass icon indicating copy to clipboard operation
multipass copied to clipboard

Insufficient permissions inside created Instance to install `npm` packages

Open OlegGulevskyy opened this issue 2 years ago • 16 comments

Describe the bug When created instance of Ubuntu 20.x and mount a folder to be shared - cannot install npm packages:

npm WARN tar TAR_ENTRY_ERROR EPERM: operation not permitted, open '/server/node_modules/tiny-lru/package.json'
npm WARN tar TAR_ENTRY_ERROR EPERM: operation not permitted, open '/server/node_modules/through/readme.markdown'
npm WARN tar TAR_ENTRY_ERROR EPERM: operation not permitted, open '/server/node_modules/typescript/LICENSE.txt'
npm WARN tar TAR_ENTRY_ERROR EPERM: operation not permitted, open '/server/node_modules/vscode-typescript-languageservice/out/services/codeAction.js'
npm WARN tar TAR_ENTRY_ERROR EPERM: operation not permitted, open '/server/node_modules/string.prototype.padend/.nycrc

I cannot install the packages on the host and run on Ubuntu because it seems like the installed packages are not compatible with Ubuntu (my host is MacOS), so it needs to install packages itself.

Am I mounting the folder wrongly that leaves the instance with lack of permissions or is there something else that might be missing?

To Reproduce How, and what happened?

  1. multipass mount ./project-folder-on-host instance-name:/name-alias
  2. make sure npm and nodejs are installed
  3. npm install inside the mounted folder

Expected behavior Packages to be able to install with sufficient permissions for the created instance to write / read files

Logs Above

Additional info

  • OS: MacOS monterey 12.3.1
  • multipass version - 1.8.1
  • multipass info --all
Name:           delighted-stoat
State:          Running
IPv4:           192.168.64.4
Release:        Ubuntu 20.04.4 LTS
Image hash:     ccc11e625acd (Ubuntu 20.04 LTS)
Load:           0.00 0.03 0.03
Disk usage:     1.7G out of 4.7G
Memory usage:   163.4M out of 970.0M
Mounts:         /Users/**/Desktop/altv-dayz => /server
                    UID map: 501:default
                    GID map: 20:default

Additional context Add any other context about the problem here.

OlegGulevskyy avatar Apr 18 '22 08:04 OlegGulevskyy

Hi @OlegGulevskyy, I do not see this as a bug in Multipass. I can mount a folder I own on an instance in MacOS, even under /, and manipulate files on that mount. I suggest you to check npm setup, there is nothing wrong on the Multipass side.

luis4a0 avatar Apr 18 '22 12:04 luis4a0

On the other hand, do you have write permissions (in the host) on the folder you are mounting?

I can perfectly reproduce your setup (without npm, though) and be able to create files on the mounted folder, on both the instance and the host. What seems strange to me is that the mounted folder contains two stars in the name, how is the instance folder named? In particular, is the user named **?

luis4a0 avatar Apr 18 '22 13:04 luis4a0

On the other hand, do you have write permissions (in the host) on the folder you are mounting?

I can perfectly reproduce your setup (without npm, though) and be able to create files on the mounted folder, on both the instance and the host. What seems strange to me is that the mounted folder contains two stars in the name, how is the instance folder named? In particular, is the user named **?

Nope, sorry for the confusion - ** 2 stars was just a placeholder for the user name of the PC, nothing important The issue is exactly with npm though, I cannot install any packages with given in the initial message logs, as if npm can't read necessary files. No issues with npm on plain ubuntu or mac (host) systems.

OlegGulevskyy avatar Apr 18 '22 13:04 OlegGulevskyy

Where are you running npm, on the host or the instance? Is the folder empty when you run it?

Can you give us a complete sequence to reproduce the bug?

luis4a0 avatar Apr 18 '22 13:04 luis4a0

Where are you running npm, on the host or the instance? Is the folder empty when you run it?

I was running npm on the instance. With both, node_modules present and completely removed - the same result Running npm on the host does not lead to any issues

Complete sequence is:

  1. Have a npm project on your host machine, without node_modules
  2. Mount the folder to your ubuntu instance
  3. cd to the folder on your ubuntu instance
  4. run npm install to install project dependencies

Thank you for looking into it

OlegGulevskyy avatar Apr 18 '22 13:04 OlegGulevskyy

I couldn't reproduce, npm install worked. I suggest you to check the permissions of the folders in the host.

luis4a0 avatar Apr 18 '22 15:04 luis4a0

I couldn't reproduce, npm install worked. I suggest you to check the permissions of the folders in the host.

sorry for stupid question - is there anything else I can check apart from chmod ? As the folder has 777 permissions set on host machine right now while having an error

OlegGulevskyy avatar Apr 18 '22 16:04 OlegGulevskyy

That check should suffice.

Did you check removing the mount, restarting the instance and mounting again?

luis4a0 avatar Apr 18 '22 16:04 luis4a0

That check should suffice.

Did you check removing the mount, restarting the instance and mounting again?

Just tried:

  1. creating new instance
  2. making sure to be mounted folder has chmod 777
  3. mount the folder
  4. enter new instance with shell
  5. install nodejs 16.x + npm
  6. navigate to the folder and run npm install the same result unfortunately

does it matter that the shared folder in virtual instance is on the same level as /tmp /etc and so ? instead of ~

OlegGulevskyy avatar Apr 18 '22 17:04 OlegGulevskyy

That shouldn't be a problem, but you can try in another place. Do you have sufficient disk space? Did you try with another project using npm?

luis4a0 avatar Apr 18 '22 17:04 luis4a0

Just to echo @luis4a0 here, I'm unable to reproduce either.

Could you also list which npm projects you have installed on your host's project directory and how exactly you installed them?

townsend2010 avatar Apr 18 '22 17:04 townsend2010

I get this too randomly. Sometimes installs work just fine, other times they start to get that error partway through the install. They'll be able to create a bunch of directories leading up to that point, but then suddenly partway through it seems like it loses permission somehow.

Qard avatar Jul 26 '22 10:07 Qard

@OlegGulevskyy, @Qard: I wonder if you're hitting a maxfiles limit? We have seen permissions being denied when trying to open files beyond that. Could you try these instructions and see if that helps you by any chance?

ricab avatar Jul 28 '22 15:07 ricab

@OlegGulevskyy @Qard @ricab I was able to fix this issue on Monterey, it was indeed a maxfiles limit problem. The trick is to reload the com.canonical.multipassd.plist file after rebooting, so the new files limits are activated. Instructions taken from: https://mampsupportforum.com/viewtopic.php?t=155 https://serverfault.com/questions/194832/how-to-start-stop-restart-launchd-services-from-the-command-line

  1. Create the /Library/LaunchDaemons/limit.maxfiles.plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>64000</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>
  1. Create the /Library/LaunchDaemons/limit.maxproc.plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
        <string>limit.maxproc</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxproc</string>
          <string>12784</string>
          <string>14176</string>
        </array>
      <key>RunAtLoad</key>
        <true />
      <key>ServiceIPC</key>
        <false />
    </dict>
  </plist>
  1. Change their permissions:
sudo chown -R root:wheel /Library/LaunchDaemons/limit.maxproc.plist
sudo chown -R root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
  1. Reboot
  2. Reload multipass (needs to be done after each reboot, a better solution is needed):
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

joanniclaborde avatar Sep 07 '22 15:09 joanniclaborde

I fix it by running npm install out of ubuntu instance shell. Use your default terminal and run npm install in folder of your mac(not ubuntu instance)

LLuchiKK avatar Mar 14 '23 04:03 LLuchiKK

Looks like this issue is back with the latest Ventura version... When getting the error, run the following (thanks to https://developer.apple.com/forums/thread/735798):

multipass stop --all
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist
sudo launchctl limit maxfiles 256 unlimited
sudo launchctl limit maxfiles 128000 524288
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

I have not checked how to persist this change yet, so it needs to be done after each reboot.

Edit: tested on Sonoma 14.0, works as expected.

joanniclaborde avatar Sep 05 '23 16:09 joanniclaborde