Skip to content

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

Description

@raido

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

Activity

  1. cjihrig commented on Jan 25, 2019

    @cjihrig
    Contributor

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

  2. raido commented on Jan 25, 2019

    @raido
    ContributorAuthor

    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?

  3. cjihrig commented on Jan 25, 2019

    @cjihrig
    Contributor

    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.

  4. added
    osIssues and PRs related to the os subsystem.
    docIssues and PRs related to Node.js documentation.
    on Jan 26, 2019
  5. zardaloop commented on May 25, 2020

    @zardaloop

    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

  6. raido commented on May 25, 2020

    @raido
    ContributorAuthor

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

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

  7. zardaloop commented on May 25, 2020

    @zardaloop

    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.

  8. raido commented on May 25, 2020

    @raido
    ContributorAuthor

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

  9. zardaloop commented on May 25, 2020

    @zardaloop

    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
            }
            
        }
    
  10. zardaloop commented on May 26, 2020

    @zardaloop

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.osIssues and PRs related to the os subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions