Skip to content

Commit 13d0251

Browse files
committed
Fix non-root user definition to improve security
**What** - Fix a bug where the non-root user that is defined does not have the required permissions to use the `root` dir or conda. This should improve function security by not running as root by default Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
1 parent 747a0a6 commit 13d0251

2 files changed

Lines changed: 34 additions & 26 deletions

File tree

template/pydatatscience-web/Dockerfile

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
21
FROM python:3-slim
32

43
# Allows you to add additional packages via build-arg
54
ARG ADDITIONAL_PACKAGE
65
ARG CHANNEL=pytorch
76

7+
RUN addgroup app && adduser app --system --ingroup app \
8+
&& mkdir -p /opt/conda && chown -R app /opt/conda \
9+
&& chown -R app /root && chmod -R go+rX /root
10+
11+
ENV HOME /home/app
12+
ENV PATH=$HOME/conda/bin:$PATH
13+
814
RUN apt-get update \
915
&& apt-get -y install curl bzip2 ${ADDITIONAL_PACKAGE} \
10-
&& curl -sSL https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o /tmp/miniconda.sh \
1116
&& curl -sSL https://github.com/openfaas-incubator/of-watchdog/releases/download/0.5.1/of-watchdog > /usr/bin/fwatchdog \
12-
&& bash /tmp/miniconda.sh -bfp /usr/local \
13-
&& rm -rf /tmp/miniconda.sh \
14-
&& conda install -y python=3 \
15-
&& conda update conda \
16-
&& apt-get -qq -y remove curl bzip2 \
17+
&& curl -sSL https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o /tmp/miniconda.sh \
18+
&& chown app /tmp/miniconda.sh \
19+
&& apt-get -qq -y remove curl \
1720
&& apt-get -qq -y autoremove \
1821
&& apt-get autoclean \
1922
&& rm -rf /var/lib/apt/lists/* /var/log/dpkg.log \
20-
&& conda clean --all --yes \
2123
&& chmod +x /usr/bin/fwatchdog
2224

23-
ENV PATH /opt/conda/bin:$PATH
24-
2525
# Add non root user
26-
RUN addgroup app && adduser app --system --ingroup app
27-
28-
USER app
2926
WORKDIR /root/
27+
USER app
28+
29+
RUN bash /tmp/miniconda.sh -bfp $HOME/conda \
30+
&& conda install -y python=3 \
31+
&& conda update conda \
32+
&& conda clean --all --yes \
33+
&& rm -rf /tmp/miniconda.sh
3034

3135
COPY requirements.txt .
3236
RUN conda install --file requirements.txt -c ${CHANNEL}

template/pydatatscience/Dockerfile

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
21
FROM python:3-slim
32

43
# Allows you to add additional packages via build-arg
54
ARG ADDITIONAL_PACKAGE
65
ARG CHANNEL=pytorch
76

7+
RUN addgroup app && adduser app --system --ingroup app \
8+
&& mkdir -p /opt/conda && chown -R app /opt/conda \
9+
&& chown -R app /root && chmod -R go+rX /root
10+
11+
ENV HOME /home/app
12+
ENV PATH=$HOME/conda/bin:$PATH
13+
814
RUN apt-get update \
915
&& apt-get -y install curl bzip2 ${ADDITIONAL_PACKAGE} \
10-
&& curl -sSL https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o /tmp/miniconda.sh \
1116
&& curl -sSL https://github.com/openfaas-incubator/of-watchdog/releases/download/0.5.1/of-watchdog > /usr/bin/fwatchdog \
12-
&& bash /tmp/miniconda.sh -bfp /usr/local \
13-
&& rm -rf /tmp/miniconda.sh \
14-
&& conda install -y python=3 \
15-
&& conda update conda \
16-
&& apt-get -qq -y remove curl bzip2 \
17+
&& curl -sSL https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o /tmp/miniconda.sh \
18+
&& chown app /tmp/miniconda.sh \
19+
&& apt-get -qq -y remove curl \
1720
&& apt-get -qq -y autoremove \
1821
&& apt-get autoclean \
1922
&& rm -rf /var/lib/apt/lists/* /var/log/dpkg.log \
20-
&& conda clean --all --yes \
2123
&& chmod +x /usr/bin/fwatchdog
2224

23-
ENV PATH /opt/conda/bin:$PATH
24-
2525
# Add non root user
26-
RUN addgroup app && adduser app --system --ingroup app
27-
28-
USER app
2926
WORKDIR /root/
27+
USER app
28+
29+
RUN bash /tmp/miniconda.sh -bfp $HOME/conda \
30+
&& conda install -y python=3 \
31+
&& conda update conda \
32+
&& conda clean --all --yes \
33+
&& rm -rf /tmp/miniconda.sh
3034

3135
COPY requirements.txt .
3236
RUN conda install --file requirements.txt -c ${CHANNEL}

0 commit comments

Comments
 (0)