Missing User Instruction

  • Query id: fd54f200-402c-4333-a5a4-36ef6709af2f
  • Query name: Missing User Instruction
  • Platform: Dockerfile
  • Severity: High
  • Category: Build Process
  • URL: Github

Description

A user should be specified in the dockerfile, otherwise the image will run as root
Documentation

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - dockerfile file
FROM python:2.7
RUN pip install Flask==0.11.1
RUN useradd -ms /bin/bash patrick
COPY --chown=patrick:patrick app /app
WORKDIR /app
CMD ["python", "app.py"]

Code samples without security vulnerabilities

Negative test num. 1 - dockerfile file
FROM python:2.7
RUN pip install Flask==0.11.1
RUN useradd -ms /bin/bash patrick
COPY --chown=patrick:patrick app /app
WORKDIR /app
USER patrick
CMD ["python", "app.py"]

FROM scratch
RUN pip install Flask==0.11.1
RUN useradd -ms /bin/bash patrick
COPY --chown=patrick:patrick app /app
WORKDIR /app
CMD ["python", "app.py"]