Commit 1c183aa
committed
run-in-node-container: support rootless mode
run-in-node-container is used for javascript "rollup", so the tools
running in the container produce files which must be owned by the user
on the host.
To achieve this, the docker run --user option is used to ensure that
the tools in the container are run as host user.
However, with rootless mode - apparently in both docker and podman,
but I'm using podman - a user namespace is used and users in the
container are mapped to a range of users on the host. This means that
if we run a command as root in the container, this corresponds to the
host user. When we specify --user, this results in a different host
user being used.
There are apparently two ways of achieving what we want - not using
--user so that the commands run as root in the container, which is
mapped to the desired host user. Or we can use --userns keep-id which
means a 1:1 user mapping is used, and the user specified by --user
corresponds to the same user on the host. The former seems more like
how you'd typically use this mode.
And so we detect rootless mode using "docker system info", and avoid
the --user flag in this case.
Podman reports "rootless: (true|false)", whereas docker just includes
a "rootless" keyword.
For more on this, see:
https://www.redhat.com/sysadmin/user-flag-rootless-containers
https://docs.docker.com/engine/security/rootless
pre-commit/pre-commit#1243
pre-commit/pre-commit#1484
(Note: all of the above applies even without SELinux and was tested
with "setenforce 0")1 parent f214182 commit 1c183aa
1 file changed
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
41 | | - | |
42 | | - | |
43 | 53 | | |
44 | 54 | | |
45 | | - | |
| 55 | + | |
46 | 56 | | |
47 | 57 | | |
48 | 58 | | |
| |||
0 commit comments