Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Yarn as a user using sudo crashes due several file permissions denied #2123

Closed
amatas opened this issue Dec 2, 2016 · 1 comment
Closed

Comments

@amatas
Copy link
Contributor

amatas commented Dec 2, 2016

Do you want to request a feature or report a bug?
BUG

What is the current behavior?
Ansible uses sudo to change the efective user when a command is launched. When Yarn is used using sudo with an unprivileged user, it tries to write files in the global node_modules directory.

If Yarn is executed by that user (without sudo), everything works as expected storing the modules in the node_modules directory of the directory of the project.

If the current behavior is a bug, please provide the steps to reproduce.
Here it is an example of the issue using the Fedora box with Vagrant:

[root@fedora nodejs-project]# sudo -u vagrant id
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant)


[root@fedora nodejs-project]# sudo -u vagrant yarn install
/usr/share/yarn/node_modules/mkdirp/index.js:90
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/usr/local/share/.yarn'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:922:18)
    at Function.sync (/usr/share/yarn/node_modules/mkdirp/index.js:71:13)
    at Object.<anonymous> (/usr/share/yarn/bin/yarn.js:30:8)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
[root@fedora nodejs-project]#

[root@fedora nodejs-project]# exit
[vagrant@fedora nodejs-project]$ yarn install
yarn install v0.17.10
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 7.95s.

What is the expected behavior?
Something like this:

[root@fedora nodejs-project]# sudo -u vagrant yarn install
yarn install v0.17.10
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 7.95s.

Please mention your node.js, yarn and operating system version.

[vagrant@fedora nodejs-project]$ node -v
v6.9.1
[vagrant@fedora nodejs-project]$ uname -a
Linux fedora 4.7.7-200.fc24.x86_64 #1 SMP Sat Oct 8 00:21:59 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[vagrant@fedora nodejs-project]$ yarn --version
0.17.10
@gtirloni
Copy link

gtirloni commented Dec 2, 2016

In this specific context, it seems that a combination of various sudo commands until ansible-playbook was invoked (and later, the yarn install task getting run through sudo again) made Yarn confused about which user it was running as (even though it was confirmed it was running as the 'vagrant' user through 'ps').

It's curious npm install in the same situation did not seem to face this error.

amatas added a commit to amatas/yarn that referenced this issue Dec 3, 2016
 * Use isRootUser function instead USER environment variable
 * Fix yarnpkg#2123
bestander pushed a commit that referenced this issue Dec 7, 2016
* Use isRootUser function instead USER environment variable
 * Fix #2123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants