Skip to content

Commit 43cc019

Browse files
authored
Merge pull request #612 from pi-geosolutions/non-root-tomcat-user-master
Run tomcat as non-root user
2 parents a64b9b0 + 4dd778e commit 43cc019

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ RUN if [ "$TOMCAT_EXTRAS" = false ]; then \
1919
find "${CATALINA_BASE}/webapps/" -delete; \
2020
fi
2121

22+
# Create a non-privileged tomcat user
23+
ARG USER_GID=999
24+
ARG USER_UID=999
25+
RUN addgroup --gid ${USER_GID} tomcat && \
26+
adduser --system -u ${USER_UID} --gid ${USER_GID} --no-create-home tomcat && \
27+
chown -R tomcat:tomcat ${CATALINA_BASE}/ && \
28+
chown tomcat:tomcat /docker-entrypoint.d
29+
2230
# Add application from first stage
23-
COPY --from=extractwar /tmp/mapstore "${CATALINA_BASE}/webapps/mapstore"
24-
COPY georchestra-docker-scripts/ /
31+
COPY --chown=tomcat:tomcat --from=extractwar /tmp/mapstore "${CATALINA_BASE}/webapps/mapstore"
32+
COPY --chown=tomcat:tomcat georchestra-docker-scripts/ /
2533
# SHould be override in 2024.xx when a server.xml on 8080 will be available
26-
COPY docker/server.xml "${CATALINA_BASE}/conf/"
27-
34+
COPY --chown=tomcat:tomcat docker/server.xml "${CATALINA_BASE}/conf/"
35+
USER tomcat
2836

2937
# Geostore externalization template. Disabled by default
3038
# COPY docker/geostore-datasource-ovr.properties "${CATALINA_BASE}/conf/"
@@ -38,4 +46,5 @@ ENV TERM xterm
3846
# Necessary to execute tomcat and custom scripts
3947
ENTRYPOINT ["/docker-entrypoint.sh"]
4048
CMD ["catalina.sh", "run"]
49+
4150
EXPOSE 8080

0 commit comments

Comments
 (0)