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

Allow Docker image to work with non-root users, Docker streamlining #323

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jbylsma
Copy link

@jbylsma jbylsma commented Nov 9, 2024

npm commands run through the provided Docker image were failing to run when the files in the mounted /app folder weren't owned by root. This occurred from a confluence of two issues:

  • npm was switching the executed user away from root
  • nvm was inaccessible because /root is 700

npm spawns processes using the @npmcli/promise-spawn package. The current supported npm version, 8.9.14, uses a version of @npmcli/promise-spawn that will detect if npm is running as root. If root is detected, npm will use functionality from the infer-owner package to infer a non-root user through file ownership and ultimately execute the command with that user. This functionality is provided by the infer-owner package. This functionality was later removed from @npmcli/promise-spawn in npm/promise-spawn@a8b21fc.

Separately, the provided Docker image is built and configured to run as root. As nvm defaults to installing in the current user's home directory, nvm was installed in /root/.nvm. Additionally, the Docker image's base, ubuntu:20.04, uses 700 permissions for /root.

Therefore, user-inferred commands spawned by npm would not have permissions to run commands in non-globally accessible /root/.nvm. By moving nvm to a globally accessible location, npm is able to spawn
user-inferred commands.

As part of this debugging, I streamlined the Dockerfile creation, which significantly sped up builds.

npm commands run through the provided Docker image were failing
to run when the files in the mounted /app folder weren't owned by root.
This occurred from a confluence of two issues:

* npm was switching the executed user away from root
* nvm was inaccessible because /root is 700

npm spawns processes using the `@npmcli/promise-spawn` package. The
current supported npm version, 8.9.14, uses a version of
`@npmcli/promise-spawn` that will detect if npm is running as root. If
root is detected, npm will use functionality from the `infer-owner`
package to infer a non-root user through file ownership and ultimately
execute the command with that user. This functionality is provided by
the `infer-owner` package. This functionality was later removed from
`@npmcli/promise-spawn` in
<npm/promise-spawn@a8b21fc>.

Separately, the provided Docker image is built and configured to run as
root. As nvm defaults to installing in the current user's home
directory, nvm was installed in `/root/.nvm`. Additionally, the Docker
image's base, `ubuntu:20.04`, uses 700 permissions for `/root`.

Therefore, user-inferred commands spawned by npm would not have
permissions to run commands in non-globally accessible `/root/.nvm`.
By moving nvm to a globally accessible location, npm is able to spawn
user-inferred commands.
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

Successfully merging this pull request may close these issues.

1 participant