jescalan / roots

a toolkit for rapid advanced front-end development
http://roots.netlify.com/
Other
1.45k stars 133 forks source link

Official nodejs Docker images need to be rewritten to support roots #735

Open roytruelove opened 8 years ago

roytruelove commented 8 years ago

I spent the day today working on Dockerizing a roots build based off of the official node images. Every install attempt, however, ended in EACCES: permission denied. The most basic attempt was this:

FROM node:6.7.0
RUN npm install roots -g 

Which gave me:

Error: EACCES: permission denied, mkdir '/root/.config/roots'
  at Error (native)
  at Object.fs.mkdirSync (fs.js:922:18)
  at Function.sync (/usr/local/lib/node_modules/roots/node_modules/mkdirp/index.js:71:13)
  at Object.<anonymous> (/usr/local/lib/node_modules/roots/post_install.js:19:8)
  <snip>

I couldn't figure out how this could happen since I was running as root. I finally happened upon this from the roots docs:

This error pops up frequently for people that are new to the unix command line. Contrary to popular belief, it is not an error with roots, it's an error with the permissions on your computer.

Then it recommends that you read an introduction to UNIX permissioning.

I immediately contacted the maintainers of the node Docker images letting them know about the errors with the permissions in their containers. They didn't seem to share my concern so I figured they were new to the unix command line and I sent them the link that you recommended. They told me that they don't see this issue in other installs and perhaps there might be something unique in Roots' installation. I told them that was impossible and again pointed them to your docs.

I tried installing a handful of the most commonly used node tools and they all installed fine, so this issue seems to be hitting roots the hardest which is why I'm reaching out. I was hoping you could help them determine what might be wrong in their images and perhaps post your findings here, or in the documentation itself?

jescalan commented 8 years ago

So if you are running as root, it doesn't really make much sense that you'd get a permissions error, as the root account should have permission to access anything, especially its own home directory.

I have not had much experience with docker, so I can't really give a lot of info about how docker works with respect to root accounts and permissions, but I can assure you that what's happening here is exactly what roots intends to happen. It's finding the user's home directory and placing a configuration file there.

It's likely that a lot of other node libraries don't use this functionality because they do not store global persistent configuration information. Roots does however. It keeps track of whether the user wants to disable analytics, their default template preferences, and stores any roots templates they have installed. Generally the active user's own home directory is pretty much a sure bet to be something that user will have access to (although apparently its not the case in this instance, confusingly).

There is no question that this is an issue with the container. The fact that the root user cannot access its own home dir is not normal, nor does it make any sense. This part of roots' installation is indeed not extremely common with other node libraries (although there are a number that do have it, and would encounter the same issue). But that doesn't change the fact that this is an issue with the docker container, and not with roots, which, judging by the error you posted here, is doing exactly what it was intended to do.

Let me lay out the issue as clearly as I can so it might help you with reporting it.

In node, you can run the following code to get a user's home directory, which that user should always have permission to view and modify or there are serious issues with the machine's configuration:

var os = require('os')
os.homedir()

From the command line, you can get the home directory as such:

echo $HOME

What roots does on installation is run exactly this code, then creates any nested folders that might be necessary inside the home dir. Generally, it will create $HOME/.config/roots, in order to store the global config information.

The issue here is that the user does not have permission to modify their own home directory. Now, if this is some type of strange docker limitation, you can always change the home directory by setting the $HOME variable in bash to somewhere that the user does have access to before running the roots install. Otherwise, I'd call this a bug with the container.