Skip to content

Commit ccf3ba6

Browse files
burtonralexellis
authored andcommitted
Non-root users for all templates
Update all python-flask templates to use a non-root user Signed-off-by: Burton Rheutan <[email protected]>
1 parent f016955 commit ccf3ba6

File tree

3 files changed

+60
-18
lines changed

3 files changed

+60
-18
lines changed

template/python27-flask/Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,34 @@ ARG ADDITIONAL_PACKAGE
88
# Alternatively use ADD https:// (which will not be cached by Docker builder)
99
RUN apk --no-cache add ${ADDITIONAL_PACKAGE}
1010

11-
WORKDIR /root/
11+
# Add non root user
12+
RUN addgroup -S app && adduser app -S -G app
13+
RUN chown app /home/app
1214

15+
USER app
16+
17+
ENV PATH=$PATH:/home/app/.local/bin
18+
19+
WORKDIR /home/app/
20+
21+
COPY index.py .
1322
COPY requirements.txt .
23+
USER root
1424
RUN pip install -r requirements.txt
15-
COPY index.py .
25+
USER app
1626

1727
RUN mkdir -p function
1828
RUN touch ./function/__init__.py
19-
WORKDIR /root/function/
29+
WORKDIR /home/app/function/
2030
COPY function/requirements.txt .
21-
RUN pip install -r requirements.txt
31+
RUN pip install --user -r requirements.txt
32+
33+
WORKDIR /home/app/
2234

23-
WORKDIR /root/
24-
COPY function function
35+
USER root
36+
COPY function function
37+
RUN chown -R app:app ./
38+
USER app
2539

2640
ENV fprocess="python index.py"
2741
ENV cgi_headers="true"

template/python3-flask-armhf/Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,34 @@ RUN apk --no-cache add curl \
99

1010
RUN apk --no-cache add musl-dev gcc make openssl-dev libffi-dev
1111

12-
WORKDIR /root/
12+
# Add non root user
13+
RUN addgroup -S app && adduser app -S -G app
14+
RUN chown app /home/app
1315

16+
USER app
17+
18+
ENV PATH=$PATH:/home/app/.local/bin
19+
20+
WORKDIR /home/app/
21+
22+
COPY index.py .
1423
COPY requirements.txt .
24+
USER root
1525
RUN pip install -r requirements.txt
16-
COPY index.py .
26+
USER app
1727

1828
RUN mkdir -p function
1929
RUN touch ./function/__init__.py
20-
WORKDIR /root/function/
30+
WORKDIR /home/app/function/
2131
COPY function/requirements.txt .
22-
RUN pip install -r requirements.txt
32+
RUN pip install --user -r requirements.txt
33+
34+
WORKDIR /home/app/
2335

24-
WORKDIR /root/
25-
COPY function function
36+
USER root
37+
COPY function function
38+
RUN chown -R app:app ./
39+
USER app
2640

2741
ENV fprocess="python index.py"
2842

template/python3-flask/Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,34 @@ RUN chmod +x /usr/bin/fwatchdog
77
ARG ADDITIONAL_PACKAGE
88
RUN apk --no-cache add musl-dev gcc make ${ADDITIONAL_PACKAGE}
99

10-
WORKDIR /root/
10+
# Add non root user
11+
RUN addgroup -S app && adduser app -S -G app
12+
RUN chown app /home/app
1113

14+
USER app
15+
16+
ENV PATH=$PATH:/home/app/.local/bin
17+
18+
WORKDIR /home/app/
19+
20+
COPY index.py .
1221
COPY requirements.txt .
22+
USER root
1323
RUN pip install -r requirements.txt
14-
COPY index.py .
24+
USER app
1525

1626
RUN mkdir -p function
1727
RUN touch ./function/__init__.py
18-
WORKDIR /root/function/
28+
WORKDIR /home/app/function/
1929
COPY function/requirements.txt .
20-
RUN pip install -r requirements.txt
30+
RUN pip install --user -r requirements.txt
31+
32+
WORKDIR /home/app/
2133

22-
WORKDIR /root/
23-
COPY function function
34+
USER root
35+
COPY function function
36+
RUN chown -R app:app ./
37+
USER app
2438

2539
ENV fprocess="python index.py"
2640

0 commit comments

Comments
 (0)