Skip to content

Commit 39439cb

Browse files
committed
fix(docker): add --chmod to COPY instructions
Restrict write permissions on copied resources to satisfy Sonar rule docker:S6504. Refs: ATV-269
1 parent 21a5ca0 commit 39439cb

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN dnf --disableplugin subscription-manager -y --allowerasing update \
1111
&& dnf --disableplugin subscription-manager -y install pcre-devel nmap-ncat \
1212
&& dnf --disableplugin subscription-manager -y clean all
1313

14-
COPY scripts /scripts
14+
COPY --chmod=0550 --chown=1000:0 scripts /scripts
1515
ENV PATH="/scripts:${PATH}"
1616

1717
RUN setup_user.sh
@@ -26,13 +26,13 @@ RUN mkdir -p /usr/local/lib/uwsgi/plugins && chown -R 1000:0 /usr/local/lib/uwsg
2626

2727
WORKDIR /app
2828

29-
COPY --chown=1000:0 requirements.txt /app/requirements.txt
29+
COPY --chmod=0440 --chown=1000:0 requirements.txt /app/requirements.txt
3030

3131
RUN pip install -U pip setuptools wheel \
3232
&& pip install --no-cache-dir -r /app/requirements.txt
3333

3434
# Build and copy specific python-uwsgi-common files.
35-
ADD https://github.com/City-of-Helsinki/python-uwsgi-common/archive/${UWSGI_COMMON_REF}.tar.gz /usr/src/
35+
ADD --chmod=0440 https://github.com/City-of-Helsinki/python-uwsgi-common/archive/${UWSGI_COMMON_REF}.tar.gz /usr/src/
3636
RUN mkdir -p /usr/src/python-uwsgi-common && \
3737
tar --strip-components=1 -xzf /usr/src/${UWSGI_COMMON_REF}.tar.gz -C /usr/src/python-uwsgi-common && \
3838
cp /usr/src/python-uwsgi-common/uwsgi-base.ini /app && \
@@ -45,7 +45,7 @@ RUN mkdir -p /usr/src/python-uwsgi-common && \
4545

4646
USER 1000
4747

48-
COPY --chown=1000:0 docker-entrypoint.sh /entrypoint/docker-entrypoint.sh
48+
COPY --chmod=0555 --chown=1000:0 docker-entrypoint.sh /entrypoint/docker-entrypoint.sh
4949
ENTRYPOINT ["/entrypoint/docker-entrypoint.sh"]
5050

5151
EXPOSE 8000/tcp
@@ -54,19 +54,19 @@ EXPOSE 8000/tcp
5454
FROM appbase AS development
5555
# ==============================
5656

57-
COPY --chown=1000:0 requirements-dev.txt ./requirements-dev.txt
57+
COPY --chmod=0440 --chown=1000:0 requirements-dev.txt ./requirements-dev.txt
5858
RUN pip install --no-cache-dir -r ./requirements-dev.txt
5959

6060
ENV DEV_SERVER=1
6161

62-
COPY --chown=1000:0 . /app/
62+
COPY --chmod=0750 --chown=1000:0 . /app/
6363

6464
# ==============================
6565
FROM appbase AS staticbuilder
6666
# ==============================
6767

6868
ENV STATIC_ROOT=/var/static
69-
COPY --chown=1000:0 . /app/
69+
COPY --chmod=0555 --chown=1000:0 . /app/
7070
RUN SECRET_KEY="only-used-for-collectstatic" python manage.py collectstatic --noinput
7171

7272
# ==============================
@@ -76,5 +76,5 @@ FROM appbase AS production
7676
# fatal: detected dubious ownership in repository at '/app'
7777
RUN git config --global --add safe.directory /app
7878

79-
COPY --from=staticbuilder --chown=1000:0 /var/static /var/static
80-
COPY --chown=1000:0 . /app/
79+
COPY --from=staticbuilder --chmod=0555 --chown=1000:0 /var/static /var/static
80+
COPY --chmod=0555 --chown=1000:0 . /app/

0 commit comments

Comments
 (0)