nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
79.62k stars 7.97k forks source link

nvm install not respecting umask #2951

Closed AbdealiLoKo closed 2 months ago

AbdealiLoKo commented 1 year ago

Operating system and version:

Centos 7

nvm debug output:

```sh nvm --version: v0.39.2 $SHELL: /bin/bash $SHLVL: 1 whoami: 'root' ${HOME}: /root ${NVM_DIR}: '/opt/nvm' ${PATH}: ${NVM_DIR}/versions/node/v16.18.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' shell version: 'GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)' uname -a: 'Linux 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux' checksum binary: 'sha256sum' OS version: CentOS Linux 7 (Core) curl: /usr/bin/curl, curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.44 zlib/1.2.7 libidn/1.28 libssh2/1.8.0 wget: not found git: not found grep: /usr/bin/grep (grep --color=auto), grep (GNU grep) 2.20 awk: /usr/bin/awk, GNU Awk 4.0.2 sed: /usr/bin/sed, sed (GNU sed) 4.2.2 cut: /usr/bin/cut, cut (GNU coreutils) 8.22 basename: /usr/bin/basename, basename (GNU coreutils) 8.22 rm: /usr/bin/rm (rm -i), rm (GNU coreutils) 8.22 mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.22 xargs: /usr/bin/xargs, xargs (GNU findutils) 4.5.11 nvm current: v16.18.1 which node: ${NVM_DIR}/versions/node/v16.18.1/bin/node which iojs: which: no iojs in (${NVM_DIR}/versions/node/v16.18.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin) which npm: ${NVM_DIR}/versions/node/v16.18.1/bin/npm npm config get prefix: ${NVM_DIR}/versions/node/v16.18.1 npm root -g: ${NVM_DIR}/versions/node/v16.18.1/lib/node_modules ```

nvm ls output:

```sh # nvm ls -> v16.18.1 default -> 16.18.1 (-> v16.18.1) iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v16.18.1) (default) stable -> 16.18 (-> v16.18.1) (default) lts/* -> lts/hydrogen (-> N/A) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 (-> N/A) lts/dubnium -> v10.24.1 (-> N/A) lts/erbium -> v12.22.12 (-> N/A) lts/fermium -> v14.21.1 (-> N/A) lts/gallium -> v16.18.1 lts/hydrogen -> v18.12.1 (-> N/A) ```

How did you install nvm?

script

What steps did you perform?

$ docker run --rm it centos:7 bash
# export NVM_DIR=/opt/nvm
# export NODE_VERSION=16.18.1
# umask 0000 \
    && curl https://raw.githubusercontent.com/creationix/nvm/v0.39.2/install.sh -o /tmp/nvm.sh \
    && mkdir -p $NVM_DIR \
    && bash /tmp/nvm.sh \
    && rm -f /tmp/nvm.sh \
    && source $NVM_DIR/nvm.sh \
    && nvm install $NODE_VERSION \
    && nvm alias default $NODE_VERSION \
    && nvm use default

# ls -lh /opt/ | grep nvm
drwxrwxrwx. 5 root root 102 Nov 24 03:24 nvm

# ls -lh /opt/nvm/versions/node/v16.18.1/
total 804K
-rw-r--r--. 1 1001 1001 678K Nov  4 11:33 CHANGELOG.md
-rw-r--r--. 1 1001 1001  87K Nov  4 11:33 LICENSE
-rw-r--r--. 1 1001 1001  35K Nov  4 11:33 README.md
drwxr-xr-x. 2 1001 1001   56 Nov  4 11:33 bin
drwxr-xr-x. 3 1001 1001   18 Nov  4 11:33 include
drwxr-xr-x. 3 1001 1001   26 Nov  4 11:33 lib
drwxr-xr-x. 4 1001 1001   28 Nov  4 11:33 share

What happened?

nvm got installed, node also got installed successfully. But the permissions were not what I expected

What did you expect to happen?

I was expecting all files to be created with the umask 0000 (i.e. files should have permission rwx rwx rwx) - but the nvm install command does not seem to respect it (and the files have rwx r-x r-x) i.e. I was expecting my group to be able to write to all folders in /opt/nvm

Is there anything in any of your profile files that modifies the PATH?

no

ljharb commented 1 year ago

I'm confused - how do you expect nvm to operate if it doesn't have full control of everything in $NVM_DIR?

AbdealiLoKo commented 1 year ago

I was expecting all files in /opt/nvm to be read+write by my group. But nvm is creating my group permissions as r-x instead of rwx

I am using umask 0000 so that all files should be created with rwx rwx rwx And nvm.sh is creating it right - i.e. /opt/nvm is rwx rwx rwx But nvm install v16.18.1 is created files with rwx r-x r-x ... I wanted it to be more permissive

My usecase is:

  1. In a Dockerfile I am installing nvm and nodejs with root
  2. When the container starts (i.e. in the entrypoint) I am creating a new user called user
  3. The new user will then run a script which is doing npm install -g PACKAGE - which fails

It fails because user does not have access to the nvm folder as it is owned by root. So, I was trying to make it read+write by everyone in the docker using umask 0000

ljharb commented 1 year ago

nvm is per-user - if you want to use it with user, it must be installed with user.

AbdealiLoKo commented 1 year ago

Hm, I see - so I guess that's just a limitation I'll have to deal with.

Currently - I need to dynamically change my UserID and GroupID when I run my docker (to avoid permission issue swith my mounted volumes) So, I cannot pre-install nvm in the docker image if my UserID and GroupID are dynamic

Currently doing a chown -R /opt/nvm seems to work - but it takes an additional 3-5mins to startup my container if I add that (which again makes things very slow)

Having multi user (atleast within the same group) who could use nvm would be a super useful feature in my case. Hoping it can be implemented in the future.

For now, looks like I will need to use something like nodesources or something Thanks for helping me understand the root cause

kingwill3 commented 1 year ago

Duplicate of #

kingwill3 commented 1 year ago