Skip to content

use ubuntu user instead of root for uv docker images#3491

Merged
winglian merged 1 commit intomainfrom
docker-user
Mar 13, 2026
Merged

use ubuntu user instead of root for uv docker images#3491
winglian merged 1 commit intomainfrom
docker-user

Conversation

@winglian
Copy link
Collaborator

@winglian winglian commented Mar 12, 2026

Summary by CodeRabbit

Chores

  • Refactored user context and permission management for containerized deployments
  • Enhanced SSH key authentication handling and configuration
  • Improved system initialization with better privilege escalation support
  • Updated Jupyter startup configuration with password token support

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Docker and entrypoint script updates shift execution context from root to non-root ubuntu user. Includes path migrations to /home/ubuntu, ownership changes with chown ubuntu:ubuntu, creation of ubuntu user with sudo privileges, and script refactoring to conditionally use sudo for privileged operations.

Changes

Cohort / File(s) Summary
Docker Dockerfile Variants
docker/Dockerfile-cloud-uv, docker/Dockerfile-uv, docker/Dockerfile-uv-base
User context switched from root to ubuntu; paths updated to /home/ubuntu for SSH config, entrypoint, and BASHRC; ownership adjusted with chown ubuntu:ubuntu for /workspace and home directories; ubuntu user created with passwordless sudo privileges.
Entrypoint Script
scripts/cloud-entrypoint.sh
Added non-root detection with conditional SUDO prefix for privileged operations; refactored add_keys_to_authorized() to accept key_value parameter; updated SSH/Jupyter/SLURM initialization logic to support non-root execution; added JUPYTER_PASSWORD to JUPYTER_TOKEN export handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • add uv axolotl builds #3431: Directly modifies the same Dockerfile variants and cloud-entrypoint.sh with identical user context and path changes at the code level.
  • add support for base image with uv #2691: Updates docker/Dockerfile-uv-base, introducing foundational uv-based image changes that interact with the ubuntu user and sudo configuration additions.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: migrating Docker images from root user to ubuntu user for uv-based containers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docker-user
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/cloud-entrypoint.sh (1)

88-93: ⚠️ Potential issue | 🟠 Major

The mkdir and ln commands should use $SUDO for consistency with the entrypoint's permission handling logic.

The script detects non-root execution at the top (lines 3-8) and sets SUDO="" or SUDO="sudo" accordingly. However, lines 88-93 don't use $SUDO, unlike other privileged operations in the same script (e.g., line 12). This inconsistency means the code will fail if the entrypoint runs as a non-root user without proper /workspace ownership, even though the script already has the defensive mechanism in place.

Update lines 88-93 to use $SUDO:

Diff
if [ ! -d "/workspace/data/axolotl-artifacts" ]; then
    $SUDO mkdir -p /workspace/data/axolotl-artifacts
fi
if [ ! -L "/workspace/axolotl/outputs" ]; then
    $SUDO ln -sf /workspace/data/axolotl-artifacts /workspace/axolotl/outputs
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/cloud-entrypoint.sh` around lines 88 - 93, The mkdir/ln calls in the
entrypoint currently run without using the SUDO wrapper variable (SUDO) so they
may fail when the script detected non-root execution; update the block that
creates /workspace/data/axolotl-artifacts and the symlink
/workspace/axolotl/outputs to prefix both mkdir -p and ln -sf with $SUDO (i.e.,
change mkdir -p and ln -sf to $SUDO mkdir -p and $SUDO ln -sf) so permission
handling is consistent with the rest of the script and the SUDO variable set
earlier is honored.
🧹 Nitpick comments (2)
docker/Dockerfile-uv-base (1)

24-28: Passwordless sudo grants full root access to the ubuntu user.

The NOPASSWD:ALL configuration allows any process running as ubuntu to execute any command as root without authentication. This is a common pattern for container entrypoints but reduces the security benefit of running as non-root.

Consider restricting sudo to only the specific commands needed by the entrypoint:

🔒 Proposed restricted sudo configuration
 RUN useradd -m -s /bin/bash -u 1000 ubuntu 2>/dev/null; \
     usermod -aG sudo ubuntu && \
-    echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/ubuntu && \
+    echo 'ubuntu ALL=(ALL) NOPASSWD: /usr/sbin/service ssh start, /usr/bin/tee /etc/rp_environment, /bin/sed -i * /etc/ssh/sshd_config, /bin/bash /slurm-init.sh' > /etc/sudoers.d/ubuntu && \
     chmod 0440 /etc/sudoers.d/ubuntu

This limits the attack surface if the container is compromised, while still allowing the entrypoint to function.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docker/Dockerfile-uv-base` around lines 24 - 28, The Dockerfile currently
creates the ubuntu user and writes a full NOPASSWD:ALL sudoers entry
(useradd/usermod and /etc/sudoers.d/ubuntu) which grants full root access;
change the sudoers entry to restrict which commands the ubuntu user can run
without a password (replace the broad "NOPASSWD:ALL" entry with a limited list
or Cmnd_Alias of specific entrypoint-related commands such as the startup
script, servicectl, or package commands required by the container), ensure the
file written to /etc/sudoers.d/ubuntu is mode 0440 and owned by root, and test
that the entrypoint still functions with the narrowed sudo privileges.
docker/Dockerfile-cloud-uv (1)

27-28: Two entrypoint script locations are made executable.

Line 27 makes /workspace/axolotl/scripts/cloud-entrypoint.sh executable (from the git clone), while line 28 makes /home/ubuntu/cloud-entrypoint.sh executable (the copied version used by ENTRYPOINT). Both are needed but the workspace version appears unused at runtime.

Consider removing the chmod for the workspace version if it's not used:

🧹 Remove unused chmod
-    chmod +x /workspace/axolotl/scripts/cloud-entrypoint.sh && \
     chmod +x /home/ubuntu/cloud-entrypoint.sh && \
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docker/Dockerfile-cloud-uv` around lines 27 - 28, The Dockerfile runs two
chmod +x steps making the workspace entrypoint and the copied runtime entrypoint
executable; remove the chmod for the workspace copy (the git-cloned
cloud-entrypoint.sh) if it is not used at runtime, or alternatively keep both
but add a clarifying comment and/or a conditional copy so only the runtime
entrypoint (the one used by ENTRYPOINT) is made executable; locate the two lines
performing "chmod +x" on the workspace cloud-entrypoint.sh and the home/ubuntu
cloud-entrypoint.sh and remove or document the workspace chmod accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@scripts/cloud-entrypoint.sh`:
- Around line 88-93: The mkdir/ln calls in the entrypoint currently run without
using the SUDO wrapper variable (SUDO) so they may fail when the script detected
non-root execution; update the block that creates
/workspace/data/axolotl-artifacts and the symlink /workspace/axolotl/outputs to
prefix both mkdir -p and ln -sf with $SUDO (i.e., change mkdir -p and ln -sf to
$SUDO mkdir -p and $SUDO ln -sf) so permission handling is consistent with the
rest of the script and the SUDO variable set earlier is honored.

---

Nitpick comments:
In `@docker/Dockerfile-cloud-uv`:
- Around line 27-28: The Dockerfile runs two chmod +x steps making the workspace
entrypoint and the copied runtime entrypoint executable; remove the chmod for
the workspace copy (the git-cloned cloud-entrypoint.sh) if it is not used at
runtime, or alternatively keep both but add a clarifying comment and/or a
conditional copy so only the runtime entrypoint (the one used by ENTRYPOINT) is
made executable; locate the two lines performing "chmod +x" on the workspace
cloud-entrypoint.sh and the home/ubuntu cloud-entrypoint.sh and remove or
document the workspace chmod accordingly.

In `@docker/Dockerfile-uv-base`:
- Around line 24-28: The Dockerfile currently creates the ubuntu user and writes
a full NOPASSWD:ALL sudoers entry (useradd/usermod and /etc/sudoers.d/ubuntu)
which grants full root access; change the sudoers entry to restrict which
commands the ubuntu user can run without a password (replace the broad
"NOPASSWD:ALL" entry with a limited list or Cmnd_Alias of specific
entrypoint-related commands such as the startup script, servicectl, or package
commands required by the container), ensure the file written to
/etc/sudoers.d/ubuntu is mode 0440 and owned by root, and test that the
entrypoint still functions with the narrowed sudo privileges.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5a8753ec-fc32-4b9d-ab6f-55f0cec92a2a

📥 Commits

Reviewing files that changed from the base of the PR and between 819b157 and d588fe6.

📒 Files selected for processing (4)
  • docker/Dockerfile-cloud-uv
  • docker/Dockerfile-uv
  • docker/Dockerfile-uv-base
  • scripts/cloud-entrypoint.sh

@winglian winglian merged commit 79908b3 into main Mar 13, 2026
18 checks passed
@winglian winglian deleted the docker-user branch March 13, 2026 00:41
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