ozontech / ozontech/file.d

Bug: Container Runs as Root User in Dockerfile

Open
#987 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
504
Forks
263
Avg merge
4d 2h
Merged PRs (30d)
5

Description

Location:
ozontech/file.d/blob/master/build/package/Dockerfile
ozontech/file.d/blob/master/build/package/Dockerfile.scratch
ozontech/file.d/blob/master/build/package/Dockerfile_dev
ozontech/file.d/blob/master/build/package/Dockerfile_playground

Description:
All four Dockerfiles lack the USER instruction, causing the container to run as root (UID 0) by default. This violates the principle of least privilege (CWE-250). Even if a non-root user was created in previous build stages, it is not carried over to the final image; the USER instruction must be explicitly defined in the runtime stage.

Risk:

  • If any vulnerability leading to code execution is exploited (RCE, SSRF with command execution capabilities, writeable path traversal, etc.), an attacker gains full control over the container.
  • Root access within the container often allows an attacker to:
    • Install additional packages or malware,
    • Modify the host filesystem (if sensitive directories are mounted),
    • Bypass security restrictions in orchestrators (e.g., Kubernetes PodSecurityPolicies / Pod Security Admission).
  • Direct violation of security standards and benchmarks:
    • CIS Docker Benchmark 4.1,
    • OWASP Docker Security,
    • Kubernetes Pod Security Standards (Restricted profile).

Screenshot

Image

Empty value - run as root

Recommendations:

Add user creation and switch to the non-root user in the final stage of each Dockerfile:

# Example for Alpine-based images
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

For the scratch-based image:

ARG APP_IMAGE=ubuntu:latest

# Build
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build

RUN addgroup -S appgroup && adduser -S appuser -G appgroup

ARG VERSION
ARG BUILD_TIME
ARG TARGETARCH

WORKDIR /file.d

COPY go.mod go.sum ./

RUN go mod download

COPY . .

ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOARCH ${TARGETARCH:-amd64}

RUN go build -trimpath \
    -pgo default.pgo \
    -ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION}" \
    -o file.d ./cmd/file.d

# Deploy
FROM scratch

COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
USER appuser

WORKDIR /file.d

COPY --from=build /file.d/file.d /file.d/file.d

CMD [ "./file.d" ]
Image

In Kubernetes manifests, enforce this by adding the securityContext:

securityContext:
  runAsNonRoot: true
  runAsUser: 1001

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with build/package/Dockerfile, Dockerfile.scratch, Dockerfile_dev, and Dockerfile_playground, inspecting each final image stage and its existing user setup. Build the images and verify their configured UID is non-root, including the scratch-based image. Done means all four Dockerfiles explicitly run the application as a non-root user without breaking startup.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, dockerfile, go
Domain
devops, infrastructure, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.