Skip to content

build(docker): install uv and its managed Python outside /root - #4260

Merged
ko3n1g merged 3 commits into
mainfrom
ko3n1g/build/non-root-runtime
Sep 28, 2026
Merged

ko3n1g merged 3 commits into
mainfrom
ko3n1g/build/non-root-runtime

Conversation

@ko3n1g

@ko3n1g ko3n1g commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Background / motivation

  • The NeMo-RL CI image can only be used as root. NeMo CI agent workloads never run as root: they keep an image's declared numeric non-root USER, and a root-default image like this one runs as UID/GID 65532.
  • Two things block that today:
    • uv and its managed Python live under /root (/root/.local/bin, /root/.local/share/uv/python), which other users cannot traverse, and /opt/nemo_rl_venv/bin/python symlinks into it.
    • Every runtime path a caller writes is root-owned (/opt/nemo-rl, /opt/nemo_rl_venv, /opt/ray_venvs) or missing under a root-owned parent (/opt/gym_venvs, the cache and source paths below).
  • A live test of this image as UID 65532 failed immediately: PermissionError: … '/opt/nemo-rl/datasets'.
  • This is the smallest change that makes the image usable by such a caller. It supersedes the broader build(container): support non-root runtime execution #3574 for this purpose.

What changed

  • docker/Dockerfile:
    • install uv to /usr/local/bin and its managed Python to UV_PYTHON_INSTALL_DIR=/opt/uv/python, and drop the unused /root/.local/bin PATH entry;
    • at the end of release, create the nemo-runtime user (UID/GID 65532, home /home/nemo-runtime), the same convention the Automodel and Gym images use;
    • pre-create the writable runtime paths it needs, owned by that user;
    • hand it the three prebuilt environment roots (directory only);
    • add a build-time probe run as that user, then restore USER root.

Details

  • /usr/local/bin is already on the default PATH, so every later build step still finds uv. ENV UV_PYTHON_INSTALL_DIR persists, so root callers still find the managed Python.

  • Runtime paths owned by the new user:

    Path Why
    /home/nemo-runtime home of the runtime user
    ${NEMO_GYM_VENV_DIR} (/opt/gym_venvs) Gym server venvs are created here at runtime
    /opt/nemo_rl_cache/uv, /opt/nemo_rl_python, /opt/nemo-rl-source, /nemo_run uv cache, uv Python, source-bundle, and NeMo-Run roots that the NeMo CI nemo-rl runtime profile points at; a non-root process cannot create them under / or /opt
    /opt/nemo-rl, ${UV_PROJECT_ENVIRONMENT}, ${NEMO_RL_VENV_DIR} directory only (chown, not chown -R), so the runtime user can create entries such as the datasets link or a new actor venv
  • Only directories change owner. The venvs are hardlinked against the uv cache in the hermetic layer, so a recursive chown here would copy every venv file into this layer. Their existing contents stay root-owned and readable.

  • The image still runs as root by default; nothing changes for root callers. The uv cache stays in /root/.cache/uv, so the CI cache-seeding paths in cicd-main.yml keep working.

Tested

The PR image (ad38e2bd9, Build H100 container) on the NeMo CI GCP H100 cluster. The Pod ran this commit's two RUN bodies verbatim as root, then dropped to UID/GID 65532 with no capabilities and no_new_privs. It then executed the NeMo CI launcher's production nemo-rl rank command.

  • Build-time probe as 65532 (uv --version, venv python --version, test -w on every path above): ok.
  • NeMo CI nemo-rl profile bootstrap: all ten writable paths plus the /opt/nemo-rl/datasets directory link: ok. Before this change it failed with PermissionError.
  • import nemo_rl from /opt/nemo_rl_venv: ok.
  • 2-GPU python -m torch.distributed.run NCCL all-reduce: rank 0 uid 65532 allreduce 3.0, rank 1 uid 65532 allreduce 3.0.
  • tests/unit/L0_Unit_Tests_Algorithms.sh stops at uv run rebuilding the editable nemo-rl offline (setuptools not in the empty caller-selected UV_CACHE_DIR). A root control with the same environment fails identically, so that is not a UID effect and is outside this PR.
  • Pending: the CI:L0 container build for this commit.

🤖 Generated with Claude Code

Install uv into /usr/local/bin and uv's managed Python into /opt/uv/python so an
unprivileged runtime UID (for example 65532) can run the image's toolchain. /root
is not traversable by other users, and the project venv's python is a symlink into
the managed-Python directory, so both were unusable for a non-root caller.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: oliver könig <[email protected]>
@ko3n1g ko3n1g added the CI:L0 Run doctests and unit tests label Sep 24, 2026
@copy-pr-bot

copy-pr-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@ko3n1g

ko3n1g commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ad38e2b

@ko3n1g

ko3n1g commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found. Installing uv in /usr/local/bin and its managed Python under /opt/uv/python removes the /root traversal dependency while preserving existing build-stage discovery and cache behavior.

Review generated by codex

Create the nemo-runtime user (65532) and its home, pre-create the
writable runtime paths a non-root caller needs, and hand it the three
prebuilt environment roots (/opt/nemo-rl, the project venv, the Ray
actor venvs) so it can create entries there. Only the directories change
owner, so no venv file is copied into the layer. A build-time probe runs
as that UID; the image stays root by default.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: oliver könig <[email protected]>
@ko3n1g

ko3n1g commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1f112c0

@ko3n1g

ko3n1g commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d149d39

@ko3n1g

ko3n1g commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d8b65a2

@kajalj22 kajalj22 assigned kajalj22 and unassigned kajalj22 Sep 28, 2026
@kajalj22
kajalj22 self-requested a review September 28, 2026 17:32
@ko3n1g
ko3n1g merged commit 4f4f351 into main Sep 28, 2026
121 of 123 checks passed
@ko3n1g
ko3n1g deleted the ko3n1g/build/non-root-runtime branch September 28, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L0 Run doctests and unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants