Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backport): Use non-root default user for Docker image #2287

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nox
.*cache
33 changes: 32 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,43 @@ RUN apt-get -qq -y update && \
python -m pip list

FROM base

USER root

SHELL [ "/bin/bash", "-c" ]
ENV PATH=/usr/local/venv/bin:"${PATH}"

RUN apt-get -qq -y update && \
apt-get -qq -y install --no-install-recommends \
curl && \
apt-get -y autoclean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/venv /usr/local/venv

# Create non-root user "moby" with uid 1000
RUN adduser \
--shell /bin/bash \
--gecos "default user" \
--uid 1000 \
--disabled-password \
moby && \
chown -R moby /home/moby && \
mkdir /work && \
chown -R moby /work && \
echo -e "\nexport PATH=/usr/local/venv/bin:${PATH}\n" >> /home/moby/.bashrc

COPY --from=builder --chown=moby /usr/local/venv /usr/local/venv/

USER moby

ENV USER ${USER}
ENV HOME /home/moby
WORKDIR ${HOME}/work

# Use C.UTF-8 locale to avoid issues with ASCII encoding
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

ENV PATH=${HOME}/.local/bin:${PATH}

ENTRYPOINT ["/usr/local/venv/bin/pyhf"]
Loading