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

test: Errors when running tests as root sudo make test #19594

Closed
dsinecos opened this issue Mar 25, 2018 · 9 comments
Closed

test: Errors when running tests as root sudo make test #19594

dsinecos opened this issue Mar 25, 2018 · 9 comments

Comments

@dsinecos
Copy link
Contributor

  • Version: master
  • Platform: 16.04.1, Ubuntu
  • Subsystem: test

When running tests as root, sudo make test I get the following errors

Error 1 -

=== release test-child-process-spawnsync-validation-errors ===                 
Path: parallel/test-child-process-spawnsync-validation-errors
Mismatched innerFn function calls. Expected exactly 62, actual 42.
    at Object.exports.mustCall (/home/divyanshu/programming/node/test/common/index.js:427:10)
    at Object.expectsError (/home/divyanshu/programming/node/test/common/index.js:717:18)
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-child-process-spawnsync-validation-errors.js:14:12)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-child-process-spawnsync-validation-errors.js

Error 2

=== release test-fs-access ===                                                 
Path: parallel/test-fs-access
fs.js:110
    throw err;
    ^

Error: EACCES: permission denied, access '/home/divyanshu/programming/node/test/parallel/test-fs-access.js'
    at Object.fs.accessSync (fs.js:200:3)
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-fs-access.js:116:4)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
    at startup (internal/bootstrap/node.js:225:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-fs-access.js

Error 3

=== release test-process-geteuid-getegid ===                                   
Path: parallel/test-process-geteuid-getegid
/home/divyanshu/programming/node/test/parallel/test-process-geteuid-getegid.js:41
process.setegid('nobody');
        ^

Error: setegid group id does not exist
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-process-geteuid-getegid.js:41:9)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
    at startup (internal/bootstrap/node.js:225:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-process-geteuid-getegid.js

Error 4

=== release test-process-setuid-setgid ===                                     
Path: parallel/test-process-setuid-setgid
/home/divyanshu/programming/node/test/parallel/test-process-setuid-setgid.js:60
process.setgid('nobody');
        ^

Error: setgid group id does not exist
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-process-setuid-setgid.js:60:9)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
    at startup (internal/bootstrap/node.js:225:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-process-setuid-setgid.js

Error 1 is covered in Issue 19371

Error 3 and Error 4

The lines that throw these errors in the respective files

On reading further, I figured that this is because the standard nobody group in UNIX systems is named nogroup in Ubuntu.

When I changed the lines which were throwing errors to the following - which checks if nobody group does not exist on the UNIX system it tries to set the group to nogroup before throwing an error

try {
  process.setegid('nobody');
} catch (err) {
  if (err.message !== 'setegid group id does not exist') {
    throw err;
  } else {
    process.setegid('nogroup');
  }
}

and

try {
  process.setgid('nobody');
} catch (err) {
  if (err.message !== 'setgid group id does not exist') {
    throw err;
  } else {
    process.setgid('nogroup');
  }
}

respectively in the two files, Errors 3 and 4 were resolved

I'd like to work on Errors 3 and 4 and if the changes I have made make sense I'd like to submit a PR for it

@gireeshpunathil
Copy link
Member

@dsinecos - as you already pointed out, the first failure is covered under #19554 . Please go ahead for the remaining! Let me know if you need any help with that!

@dsinecos
Copy link
Contributor Author

@gireeshpunathil I have resolved errors 3 and 4 both relating to group id does not exist Can i submit a PR for that?

I was thinking to open another issue for Error 2 Error: EACCES: permission denied, access '/home/divyanshu/programming/node/test/parallel/test-fs-access.js' and work on that separately?

Or should I submit a single PR for all three?

@gireeshpunathil
Copy link
Member

I suggest one PR per test file, for the benefit of isolation between changes.

@dsinecos
Copy link
Contributor Author

@gireeshpunathil

I ran sudo make test to verify that the error 2 is resolved after I add my code.

However, if I run make test after sudo make test I get a bunch of EACCES permission denied errors on files, because they were created with root privileges when I ran sudo make test.

If I run only make test the error I'm working on won't occur so I need to run sudo make test to verify the error I'm working on is resolved.

Should I submit the PR as long as that error is resolved in sudo make test?

@gireeshpunathil
Copy link
Member

as long as make test with normal user and independent run on the modified test as root and non-root (node test/paralel/x.js) pass, we should be good!

@dsinecos
Copy link
Contributor Author

dsinecos commented Apr 1, 2018

Got your point on how to test this PR, thanks :)

@gireeshpunathil Need some more help here, I think I messed up my build.

After I ran sudo make test I deleted the folders that had root permissions (test/.tmp.0 ..., test/addons/01_function_arguments ...), thinking that they would be recreated when I run make test (I had tried that earlier and it had worked) This time around though, I get errors eg.

Building addon /home/divyanshu/programming/node/test/addons/async-hello-world/
Makefile:329: recipe for target 'test/addons/.buildstamp' failed
make[1]: *** [test/addons/.buildstamp] Error 1
Makefile:242: recipe for target 'test' failed
make: *** [test] Error 2

Is there a way to start clean, but without having to refork and rebuild? I'd prefer not to refork and rebuild as there is another pull request active currently from the forked repo.

@gireeshpunathil
Copy link
Member

  • make clean and make test
    if that fails
  • ./configure && make test
    if that too fails due to missing sources,
  • git status will tell you the list of missing files, do git checkout on them and do a rebuild

@dsinecos
Copy link
Contributor Author

dsinecos commented Apr 2, 2018

I tried make clean but it gave EACCES permission denied errors, So I ran sudo make clean and then make test. That worked :)

dsinecos added a commit to dsinecos/node that referenced this issue Apr 2, 2018
When the tests are run as root in Ubuntu, process.setegid is called with
'nobody' as an argument. This throws an error in Ubuntu. This is because
in Ubuntu the equivalent of 'nobody' group is named as 'nogroup'.

This commit sets egid to 'nobody' first and if it throws a `group id
does not exist` error, it attempts to set egid to 'nogroup'. If it still
causes an error, the error is thrown.

Refs: nodejs#19594
lpinca pushed a commit that referenced this issue Apr 6, 2018
When the tests are run as root in Ubuntu, process.setegid is called with
'nobody' as an argument. This throws an error in Ubuntu. This is because
in Ubuntu the equivalent of 'nobody' group is named as 'nogroup'.

This commit sets egid to 'nobody' first and if it throws a `group id
does not exist` error, it attempts to set egid to 'nogroup'. If it still
causes an error, the error is thrown.

PR-URL: #19757
Refs: #19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit that referenced this issue Apr 6, 2018
When the tests are run as root in Ubuntu, process.setegid is called with
'nobody' as an argument. This throws an error in Ubuntu. This is because
in Ubuntu the equivalent of 'nobody' group is named as 'nogroup'.

This commit sets egid to 'nobody' first and if it throws a `group id
does not exist` error, it attempts to set egid to 'nogroup'. If it still
causes an error, the error is thrown.

PR-URL: #19757
Refs: #19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
dsinecos added a commit to dsinecos/node that referenced this issue Apr 10, 2018
When the tests are run as root in Ubuntu, process.setgid is called with
'nobody' as an argument. This throws an error in Ubuntu. This is because
in Ubuntu the equivalent of 'nobody' group is named as 'nogroup'

This commit sets gid to 'nobody' first and if it throws a `group id does
not exist` error, it attempts to set gid to 'nogroup'. If it still
causes an error, the error is thrown.

Refs: nodejs#19594
dsinecos added a commit to dsinecos/node that referenced this issue Apr 10, 2018
Else block removed as the `throw` in the preceding block makes it
redundant

Refs: nodejs#19594
targos pushed a commit that referenced this issue Apr 12, 2018
When the tests are run as root in Ubuntu, process.setegid is called with
'nobody' as an argument. This throws an error in Ubuntu. This is because
in Ubuntu the equivalent of 'nobody' group is named as 'nogroup'.

This commit sets egid to 'nobody' first and if it throws a `group id
does not exist` error, it attempts to set egid to 'nogroup'. If it still
causes an error, the error is thrown.

PR-URL: #19757
Refs: #19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
lpinca pushed a commit that referenced this issue Apr 21, 2018
When the tests are run as root in Ubuntu, process.setgid() is called
with 'nobody' as an argument. This throws an error in Ubuntu and is
because, in Ubuntu, the equivalent of 'nobody' group is named as
'nogroup'.

This commit sets gid to 'nobody' first and if it throws a "group id
does not exist" error, it attempts to set gid to 'nogroup'. If it still
causes an error, the error is thrown.

PR-URL: #19755
Refs: #19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
jasnell pushed a commit that referenced this issue Apr 23, 2018
When the tests are run as root in Ubuntu, process.setgid() is called
with 'nobody' as an argument. This throws an error in Ubuntu and is
because, in Ubuntu, the equivalent of 'nobody' group is named as
'nogroup'.

This commit sets gid to 'nobody' first and if it throws a "group id
does not exist" error, it attempts to set gid to 'nogroup'. If it still
causes an error, the error is thrown.

PR-URL: #19755
Refs: #19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@gireeshpunathil
Copy link
Member

covered through #19554 and #19757 , closing

ssample812 pushed a commit to ssample812/node that referenced this issue Jun 14, 2019
This change adds coverage for the error code received when
process.setgid('nobody') is called on Ubuntu, where the standard
'nobody' group from UNIX systems is named 'nogroup'.

Refs: nodejs#19594
sam-github pushed a commit to sam-github/node that referenced this issue Jun 18, 2019
When the 'nobody' user is missing use .code to detect this, its more
robust than than the .message string.

Refs: nodejs#19594
Trott pushed a commit to Trott/io.js that referenced this issue Jun 20, 2019
When the 'nobody' user is missing use .code to detect this, its more
robust than than the .message string.

Refs: nodejs#19594

PR-URL: nodejs#28219
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
targos pushed a commit that referenced this issue Jul 2, 2019
When the 'nobody' user is missing use .code to detect this, its more
robust than than the .message string.

Refs: #19594

PR-URL: #28219
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
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