help icon indicating copy to clipboard operation
help copied to clipboard

Why must uid and euid equal?

Open braeutigamj opened this issue 5 years ago • 6 comments

  • Node.js Version: 14.16.0
  • OS: debian:buster (Docker-Image) I got this error:
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'svgdom'
Require stack:
- /code/templates/remove_warping_transformations.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/code/templates/remove_warping_transformations.js:4:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/code/templates/remove_warping_transformations.js' ]
}

After a lot of search I found the problem. My uid and my euid are not equal. So the environment variables are not used: https://github.com/nodejs/node/blob/master/src/node_credentials.cc#L36

Can you tell me why they needs to be euqal? Thanks in advance.

This issue should also be a documentation, because I didn't found the solution by search engines and it's hard to debug.

braeutigamj avatar Jun 15 '21 07:06 braeutigamj

Are you using a Dockerfile? If so, can you share it?

bl-ue avatar Jun 15 '21 13:06 bl-ue

I can share the relevant parts. But I think it doesn't matter, because I know my bug. I don't know why the check is required. Dockerfile:

FROM debian:buster AS base
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
    apt-get update && \
    apt-get install -y nodejs

RUN npm install -g swagger-cli [email protected] [email protected]
ENTRYPOINT ["python","/usr/local/bin/entry.py"]

entry.py:

from os import environ, execvpe, setegid, setgid, seteuid, setuid

setegid(getpwnam(USER).pw_gid)  # here I also need to set setgid
seteuid(getpwnam(USER).pw_uid) # here I also need to set setuid
execvpe(self.command_line[0], self.command_line + args, env=self.env)

braeutigamj avatar Jun 17 '21 05:06 braeutigamj

Hmm, that's strange.

I notice that you're installing your packages (including svgdom) globally, via -g. I'm not sure about all of the your configuration, but in a normal environment, you can't install a module global and require() it in your code.

To demonstrate:

❯ node
Welcome to Node.js v16.3.0.
Type ".help" for more information.
> require('foo')
Uncaught Error: Cannot find module 'foo'
Require stack:
- <repl>
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}
> 
(To exit, press Ctrl+C again or Ctrl+D or type .exit)
> 

❯ npm install -g foo
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.

added 523 packages, and audited 524 packages in 14s

6 packages are looking for funding
  run `npm fund` for details

29 vulnerabilities (20 low, 4 moderate, 5 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

❯ node
Welcome to Node.js v16.3.0.
Type ".help" for more information.
> require('foo')
Uncaught Error: Cannot find module 'foo'
Require stack:
- <repl>
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}
>

I require()ed foo, it wasn't there; I installed it; that succeeded, I tried require()ing it again, and it didn't work.

However, when I install foo locally, it becomes require()able:

❯ npm install foo
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.

added 523 packages, and audited 524 packages in 10s

6 packages are looking for funding
  run `npm fund` for details

29 vulnerabilities (20 low, 4 moderate, 5 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

❯ node
Welcome to Node.js v16.3.0.
Type ".help" for more information.
> require('foo')
[Function (anonymous)]
>

bl-ue avatar Jun 17 '21 11:06 bl-ue

I'm sorry.. I missed another relevant part:

def _call_nodejs(script_name, args, input=None):
    return run(
        ['node', script_name] + args,
        env={'NODE_PATH': settings.NODEJS_LIB_PATH},
        stdout=PIPE,
        input=input
    ).stdout

I set the NODE_PATH environment. Than I can call global packages.

braeutigamj avatar Jun 18 '21 06:06 braeutigamj

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar May 09 '24 01:05 github-actions[bot]

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar Jun 09 '24 01:06 github-actions[bot]