Repository navigation
fix(docker): support non-root runtime execution - #2560
Merged
Merged
Conversation
ko3n1g
force-pushed
the
fix/docker-rootless-runtime
branch
from
August 14, 2026 23:00
ca89f84 to
797acd8
Compare
cmunley1
previously approved these changes
Aug 17, 2026
thomasdhc
suggested changes
Aug 17, 2026
thomasdhc
left a comment
There was a problem hiding this comment.
Changes requested.
Review notes
- Server venvs resolve to
<server_dir>/.venvunder/opt/nemo-gymand the server uv cache to/opt/nemo-gym/cache/uv, which matches the runtimeUV_CACHE_DIRthis image now sets. global_config.pypins server venvs to the running interpreter version, souv venv --pythonnever has to write a new managed Python into the root-owned/opt/uv/pythonat runtime.
| RUN venv_site_packages="$(/opt/nemo_gym_venv/bin/python -c \ | ||
| 'import site; print(site.getsitepackages()[0])')" && \ | ||
| touch "${venv_site_packages}/.nonroot-uninstall-probe" && \ | ||
| chown -R "${RUNTIME_UID}:${RUNTIME_GID}" /opt/nemo-gym && \ |
There was a problem hiding this comment.
[P2] Findings: this recursive chown runs in a layer after the gym env prefetch RUN that created /opt/nemo-gym/cache/uv and the per-server <server_dir>/.venv trees, and OCI layer diffs carry no metadata-only delta, so any build passing --build-arg NEMO_GYM_PREFETCH_CONFIGS=... rewrites that multi-GB content in full into a second layer. Proposal: apply the runtime ownership inside the prefetch RUN so this final RUN only covers the source tree, matching the find ... -type d treatment already used for /opt/nemo_gym_venv.
Signed-off-by: oliver könig <[email protected]>
Signed-off-by: oliver könig <[email protected]>
Signed-off-by: oliver könig <[email protected]>
Signed-off-by: oliver könig <[email protected]>
Signed-off-by: oliver könig <[email protected]>
Signed-off-by: oliver könig <[email protected]>
ko3n1g
force-pushed
the
fix/docker-rootless-runtime
branch
from
August 18, 2026 08:33
d9851b9 to
17a5295
Compare
thomasdhc
approved these changes
Aug 18, 2026
thomasdhc
left a comment
There was a problem hiding this comment.
LGTM.
Review notes
- Runtime ownership of
/opt/nemo-gym/cacheand prefetched server.venvtrees is now applied inside the RUN that creates them, so prefetched layers are no longer duplicated by the final ownership pass. - The in-build UID 65532 stage proves the CLI, uv toolchain, project environment, and cache/results/site-packages writability, and the final instruction restores root as the published default.
ko3n1g
enabled auto-merge (squash)
August 18, 2026 20:16
kajalj22
added a commit
that referenced
this pull request
Sep 5, 2026
## What does this PR do?
Adds `--chown` to the release-stage source copy in `docker/Dockerfile`,
matching the hermetic-stage copies directly above it.
## Why
The release stage copies the full checkout without `--chown`, so the
source keeps whatever ownership and mode the build context supplied. The
ownership pass that follows covers **directories only** — deliberately,
to avoid duplicating the source tree into another layer:
```dockerfile
find /opt/nemo-gym ... -type d -exec chown "${RUNTIME_UID}:${RUNTIME_GID}" {} +
```
That leaves the files root-owned. Fine whenever the context is
world-readable, which is true for the self-contained path where the
`nemo-gym` stage is populated by `ADD` from GitHub — so this passes in
our own CI.
It does not hold for every builder. NeMo CI builds this image with
`--build-context nemo-gym=.` from a checkout made under `umask 0007`, so
files arrive as mode `0660` owned by root. After `USER ${RUNTIME_UID}`
the interpreter cannot read them:
```
File "/opt/nemo_gym_venv/bin/gym", line 4, in <module>
from nemo_gym.cli.main import main
...
PermissionError: [Errno 13] Permission denied: '/opt/nemo-gym/nemo_gym/__init__.py'
```
The non-root probe added in #2560 turns that into a hard build failure.
**The image does not currently build under NeMo CI on either amd64 or
arm64** — failing at `Dockerfile:214`, identically on both.
This went unnoticed because NeMo CI stopped building this Dockerfile on
2026-08-11 (an unrelated CI change repointed the Gym build at a
different Dockerfile). Restoring that build is what surfaced it.
## Why this fix
Applying ownership during `COPY` costs no extra layer, so the reason the
later pass skips files still holds. The image stops depending on the
umask of whoever builds it, which seems worth having regardless of who
the builder is.
An alternative would be fixing modes on the NeMo CI side before the
build. That works too, but leaves the image sensitive to build-context
permissions for anyone else building it. Happy to go that route instead
if you'd prefer the Dockerfile stay as-is.
## Testing
- `docker build --check -f docker/Dockerfile .` — clean, no warnings
- `pre-commit run --files docker/Dockerfile` — pass
- Failure reproduced in NeMo CI [pipeline
63613873](https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/pipelines/63613873)
(Gym `main`, both arches fail)
- Same NeMo CI pipeline against `f8d4318b6`, which predates #2560,
builds green on both arches —
[63619803](https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/pipelines/63619803)
I have **not** yet run a full image build with this change applied — a
NeMo CI run against this branch is the direct verification and I'd like
to do that before this merges. Flagging it rather than implying more
validation than I've done.
Signed-off-by: Kajal Jain <[email protected]>
jkyi-nvidia
pushed a commit
that referenced
this pull request
Sep 11, 2026
## What does this PR do?
Adds `--chown` to the release-stage source copy in `docker/Dockerfile`,
matching the hermetic-stage copies directly above it.
## Why
The release stage copies the full checkout without `--chown`, so the
source keeps whatever ownership and mode the build context supplied. The
ownership pass that follows covers **directories only** — deliberately,
to avoid duplicating the source tree into another layer:
```dockerfile
find /opt/nemo-gym ... -type d -exec chown "${RUNTIME_UID}:${RUNTIME_GID}" {} +
```
That leaves the files root-owned. Fine whenever the context is
world-readable, which is true for the self-contained path where the
`nemo-gym` stage is populated by `ADD` from GitHub — so this passes in
our own CI.
It does not hold for every builder. NeMo CI builds this image with
`--build-context nemo-gym=.` from a checkout made under `umask 0007`, so
files arrive as mode `0660` owned by root. After `USER ${RUNTIME_UID}`
the interpreter cannot read them:
```
File "/opt/nemo_gym_venv/bin/gym", line 4, in <module>
from nemo_gym.cli.main import main
...
PermissionError: [Errno 13] Permission denied: '/opt/nemo-gym/nemo_gym/__init__.py'
```
The non-root probe added in #2560 turns that into a hard build failure.
**The image does not currently build under NeMo CI on either amd64 or
arm64** — failing at `Dockerfile:214`, identically on both.
This went unnoticed because NeMo CI stopped building this Dockerfile on
2026-08-11 (an unrelated CI change repointed the Gym build at a
different Dockerfile). Restoring that build is what surfaced it.
## Why this fix
Applying ownership during `COPY` costs no extra layer, so the reason the
later pass skips files still holds. The image stops depending on the
umask of whoever builds it, which seems worth having regardless of who
the builder is.
An alternative would be fixing modes on the NeMo CI side before the
build. That works too, but leaves the image sensitive to build-context
permissions for anyone else building it. Happy to go that route instead
if you'd prefer the Dockerfile stay as-is.
## Testing
- `docker build --check -f docker/Dockerfile .` — clean, no warnings
- `pre-commit run --files docker/Dockerfile` — pass
- Failure reproduced in NeMo CI [pipeline
63613873](https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/pipelines/63613873)
(Gym `main`, both arches fail)
- Same NeMo CI pipeline against `f8d4318b6`, which predates #2560,
builds green on both arches —
[63619803](https://gitlab-master.nvidia.com/dl/JoC/nemo-ci/-/pipelines/63619803)
I have **not** yet run a full image build with this change applied — a
NeMo CI run against this branch is the direct verification and I'd like
to do that before this merges. Flagging it rather than implying more
validation than I've done.
Signed-off-by: Kajal Jain <[email protected]>
Signed-off-by: Junkeun Yi <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background / motivation
/root, and runtime paths were root-owned.What changed
uvanduvxrelease archives in/usr/local/binafter architecture-specific SHA-256 verification, with managed Python under/opt/uv/python.RUNTIME_UIDandRUNTIME_GIDbuild arguments, defaulting to65532:65532./home/nemo-runtime.USER root..venvcontent from Docker build contexts.uvarchive checksums for the change-set secrets scan.Details
--user 65532:65532and explicitly setHOME=/home/nemo-runtimeandXDG_CACHE_HOME=/opt/nemo-gym/cache/xdg./opt/uv/cache./opt/nemo-gym/cache/uv; Gym cache, results, source, and prefetched environments are owned by UID/GID 65532.uv,uvx, and the project interpreter.gym --help.uv.USER root.detect-secretsflagged bothuv_sha256literals asHex High Entropy String. Each is preceded by a column-0# pragma: allowlist nextline secretline; the inline same-line form is unusable here because BuildKit joinsRUNcontinuation lines into a single shell command, so a trailing#would comment out the remainder of the instruction.Tested
docker buildx build --check --build-context nemo-gym=. --target release -f docker/Dockerfile .52e5eac7d1f917b43622cbe6a2f04a0a2c091b13.docker buildx build --builder multiarch --progress=plain --build-context nemo-gym=. -f docker/Dockerfile --tag nemo-gym-rootless:pr2560 --load .nemo-gym-rootless:pr2560.docker image inspect --format {{json .Config.User}} nemo-gym-rootless:pr2560root.docker run --rm --entrypoint id nemo-gym-rootless:pr2560 -u0.docker run --rm --user 65532:65532 --env HOME=/home/nemo-runtime --env XDG_CACHE_HOME=/opt/nemo-gym/cache/xdg nemo-gym-rootless:pr2560 --helpruntime-user=65532.uv run --locked --extra dev pytest tests/unit_tests/ -quv run pre-commit run --all-filesoci-90e81a1077c4365e79891ccf:52e5eac7d1f917b43622cbe6a2f04a0a2c091b13foramd64.nvcr.io/nvidia/cuda-dl-base:26.03-cuda13.2-devel-ubuntu24.04base through the documented flattened-filesystem path; no alternate base image was selected.gvisor-dpkg-hardlink.766267172432.dkr.ecr.us-east-1.amazonaws.com/nemo-autobot/agent-sandbox@sha256:6cb5462321dda99f1eaadb273efe3a30b62806d91ec059b0f5f26b39ca189177.gym-pr-2560-rootless-52e5eac7-amd64at the same digest; pushed2026-08-15T01:55:48Z.detect-secrets-hook --baseline .github/workflows/config/.secrets.baselineover the CI change-set (git diff --name-only --diff-filter=d --merge-base origin/main)c4d47d7c3df4b547ea4c7b0f422cf5b714208cfb; previously exit 123 ondocker/Dockerfile:83and:87.caseblock with the same column-0 comment lines)PROBE arch=x86_64 sha=04f8b82f…be829.docker buildx build --check --build-context nemo-gym=. --target release -f docker/Dockerfile .