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).
This commit is contained in:
1 parent
187dfb5371
commit
d8e478a104
1 file changed
+9
-3
+9
-3
@@ -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"]
|
||||
Reference in new issue
Block a user