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

os.userInfo throws if no username in docker container #25714

Closed
raido opened this issue Jan 25, 2019 · 9 comments
Closed

os.userInfo throws if no username in docker container #25714

raido opened this issue Jan 25, 2019 · 9 comments
Labels
doc Issues and PRs related to the documentations. os Issues and PRs related to the os subsystem.

Comments

@raido
Copy link
Contributor

raido commented Jan 25, 2019

Original issue opened here: sindresorhus/username#21

It turns out that running a script with docker run with --user flag set, then user actually has no $HOME or username. This in turn causes following error: uv_os_get_passwd returned ENOENT (no such file or directory) if os.userInfo() is accessed.

Some people have resorted to try catch blocks:

https://github.com/moleculerjs/moleculer/pull/396/files#diff-38423b3db1f1c2a43666c7ad898ba126R45

But is is not documented that os.userInfo() ever throws - https://nodejs.org/dist/latest-v10.x/docs/api/os.html#os_os_userinfo_options

  • Version: v8, v10
  • Platform: Linux, Docker container
@cjihrig
Copy link
Contributor

cjihrig commented Jan 25, 2019

I think the behavior is correct. A documentation PR would be welcome though.

@raido
Copy link
Contributor Author

raido commented Jan 25, 2019

I guess it throws right here - https://github.com/nodejs/node/blob/master/lib/os.js#L253 ?

It does not seem like it ever gets to the next line to throw the generic error with empty context.

Edit: Or it actually mutates the ctx object and that's how the detailed message gets printed?

@cjihrig
Copy link
Contributor

cjihrig commented Jan 25, 2019

The error returned from uv_os_get_passwd() is attached to ctx here, and then thrown in JavaScript here. If you (or anyone else) want to update the docs, they are located here.

@addaleax addaleax added os Issues and PRs related to the os subsystem. doc Issues and PRs related to the documentations. labels Jan 26, 2019
raido added a commit to raido/node that referenced this issue Feb 3, 2019
`os.userInfo` throws an exception which was not documented
in environments like: `docker run --user $(id -u): $(id -g)`

PR-URL: nodejs#25724
Fixes: nodejs#25714
addaleax pushed a commit that referenced this issue Feb 3, 2019
`os.userInfo()` throws an exception which was not documented
in environments like: `docker run --user $(id -u): $(id -g)`.

PR-URL: #25724
Fixes: #25714
Reviewed-By: James M Snell <[email protected]>
@zardaloop
Copy link

Hi @raido even-though I am running node:12.0.0 on docker I still get the same error? Is there anything else I need to do to resolve this issue ?
I posted the question on stackoverflow as well but no luck with it yet https://stackoverflow.com/questions/61961485/a-system-error-occurred-uv-os-get-passwd-returned-enoent-no-such-file-or-direc?noredirect=1#comment109603079_61961485

@raido
Copy link
Contributor Author

raido commented May 25, 2020

Maybe you could use this package: https://github.com/sindresorhus/username?

It has fallback logic for missing username case: sindresorhus/username#22

@zardaloop
Copy link

many thanks @raido what do you mean exactly by that. instead of which package I should used that? I am trying to do ember build that's where I get this error.

@raido
Copy link
Contributor Author

raido commented May 25, 2020

Does you app happen to use ember-cli-cjs-transform package? - rwjblue/ember-cli-cjs-transform#123

@zardaloop
Copy link

no I don't have that specific package, The only package I found in my project that references uv_os_get_passwd , is in node-gyp . It seems in the latest version of it ( v 5.1.1) this issue is somehow addressed nodejs/node-gyp@c4002de, but updating it to that version still not resolving the issue :( . Is there an workaround that I can use within jenkins to fix this issue? I am using jenkins Pipeline and I have simply :

agent {
        docker { 
            image 'node:12'
            args "-v ${env.JENKINS_HOME}:/workspace"
            reuseNode true
        }
        
    }

@zardaloop
Copy link

it turned out all I needed to do was adding docker volumne mapping from /etc/passwd to /etc/passwd. like this :

agent {
        docker { 
            image 'node:12'
            args "-v /etc/passwd:/etc/passwd"
            reuseNode true
        }        
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. os Issues and PRs related to the os subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants