Skip to content

fix: add non-root USER to Dockerfile#84

Merged
colindean merged 1 commit into
target:mainfrom
sydneylyon1:add-nonroot-user-to-dockerfile
Jun 29, 2026
Merged

fix: add non-root USER to Dockerfile#84
colindean merged 1 commit into
target:mainfrom
sydneylyon1:add-nonroot-user-to-dockerfile

Conversation

@sydneylyon1

Copy link
Copy Markdown

Closes #68

What changed

Run the container as a dedicated system user (diffpoetrylock) instead of root. This reduces the blast radius of any runtime compromise by removing root-level privileges from the container process.

RUN useradd --system --shell /usr/sbin/nologin diffpoetrylock
  • Creates a passwordless system account with no interactive login shell (/usr/sbin/nologin prevents interactive access even if the account is somehow targeted).
  • chown -R diffpoetrylock:diffpoetrylock /src — ensures runtime files are owned by the new user so the process can read/execute them.
  • USER diffpoetrylock — switches execution to the non-root account for the container's lifetime.

No home directory is created — the runtime path uses /tmp for temporary files and /src for app files, so no HOME-based paths are needed.

Validation

Built the image locally and confirmed non-root runtime:

$ docker run --entrypoint id diff-poetry-lock:test
uid=999(diffpoetrylock) gid=999(diffpoetrylock) groups=999(diffpoetrylock)

$ docker run --entrypoint /bin/sh diff-poetry-lock:test -c 'whoami && ls -l /src/entrypoint.sh'
diffpoetrylock
-rwxr-xr-x 1 diffpoetrylock diffpoetrylock 1042 Jun 26 18:23 /src/entrypoint.sh

Closes target#68

Run the container as a dedicated system user (diffpoetrylock) instead of
root. This reduces the blast radius of any runtime compromise by removing
root-level privileges from the container process.

Changes:
- RUN useradd --system --shell /usr/sbin/nologin diffpoetrylock
  Creates a passwordless system account with no interactive login shell.
- RUN chmod 0755 entrypoint.sh && chown -R diffpoetrylock:diffpoetrylock /src
  Ensures /src and entrypoint.sh are owned and executable by the new user.
- USER diffpoetrylock
  Switches runtime execution to the non-root account.

Validated locally by building the image and confirming:
  docker run --entrypoint id  => uid=999(diffpoetrylock) gid=999(diffpoetrylock)
  docker run --entrypoint /bin/sh -c 'whoami && ls -l /src/entrypoint.sh'
  => diffpoetrylock / -rwxr-xr-x 1 diffpoetrylock diffpoetrylock

Signed-off-by: Sydney Lyon <sydney.lyon@target.com>

@colindean colindean left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@sydneylyon1 Thank for this contribution! You're awesome for taking the time to improve this.

@colindean
colindean merged commit d9fd592 into target:main Jun 29, 2026
9 checks passed
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.

Add non-root USER to Dockerfile

2 participants