From d8e478a104cb5bda59fd645b88da05671f3c8608 Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Sun, 12 Jul 2026 03:46:59 +0200 Subject: [PATCH] fix(docker): run container fully as non-root nginx user semgrep HIGH: no USER directive before ENTRYPOINT (container ran as root). Runtime dirs, conf.d and html dir chowned to nginx so the entrypoint (env.js write + PORT envsubst) and nginx master both run as uid 101. Verified: docker build + run, HTTP 200, SPA fallback, env override OK, ps shows master+workers as nginx. CONSTRAINT: PORT env var must now be >=1024 (default 8080 unaffected). --- Dockerfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b580612..34afefa3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,10 +25,16 @@ COPY --from=builder /app/dist /usr/share/nginx/html COPY docker/nginx.conf /etc/nginx/conf.d/default.conf COPY docker/entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh +# Run fully as non-root (port 8080 is unprivileged). nginx needs to own: +# its runtime dirs, the config it rewrites at startup (PORT envsubst), +# and the html dir (entrypoint writes env.js there). +RUN chmod +x /entrypoint.sh \ + && touch /var/run/nginx.pid \ + && chown -R nginx:nginx /var/cache/nginx /var/run/nginx.pid \ + /etc/nginx/conf.d /usr/share/nginx/html + +USER nginx -# Drop root: nginx master runs as root for port binding, workers as nginx -# The entrypoint writes env.js before exec-ing nginx EXPOSE 8080 ENTRYPOINT ["/entrypoint.sh"]