Run production frontend Nginx unprivileged under dropped caps

This commit is contained in:
2026-03-02 16:41:20 -03:00
parent d50169b883
commit 8f2c357bfc
3 changed files with 31 additions and 2 deletions

View File

@@ -141,8 +141,9 @@ Recommended LIVE pattern:
- Frontend no longer consumes `VITE_API_TOKEN`. - Frontend no longer consumes `VITE_API_TOKEN`.
- Frontend image target is environment-driven: - Frontend image target is environment-driven:
- `APP_ENV=development` builds the `development` target and runs Vite dev server - `APP_ENV=development` builds the `development` target and runs Vite dev server
- `APP_ENV=production` builds the `production` target and serves static assets through Nginx - `APP_ENV=production` builds the `production` target and serves static assets through unprivileged Nginx
- Frontend Docker targets are selected from `APP_ENV`, so use `development` or `production` values. - Frontend Docker targets are selected from `APP_ENV`, so use `development` or `production` values.
- Production frontend Nginx uses non-root runtime plus `/tmp` temp-path configuration so it can run with container capability dropping enabled.
- Vite dev server host allowlist uses the union of: - Vite dev server host allowlist uses the union of:
- hostnames extracted from `CORS_ORIGINS` - hostnames extracted from `CORS_ORIGINS`
- optional explicit hostnames from `VITE_ALLOWED_HOSTS` - optional explicit hostnames from `VITE_ALLOWED_HOSTS`

View File

@@ -41,9 +41,15 @@ RUN npm run build
FROM nginx:1.27-alpine AS production FROM nginx:1.27-alpine AS production
COPY nginx-main.conf /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html COPY --from=build /app/dist /usr/share/nginx/html
RUN mkdir -p /tmp/client_temp /tmp/proxy_temp /tmp/fastcgi_temp /tmp/uwsgi_temp /tmp/scgi_temp \
&& chown -R 101:101 /tmp /var/log/nginx /usr/share/nginx/html
EXPOSE 5173 EXPOSE 5173
CMD ["nginx", "-g", "daemon off;"] USER 101:101
ENTRYPOINT ["nginx"]
CMD ["-g", "daemon off;"]

22
frontend/nginx-main.conf Normal file
View File

@@ -0,0 +1,22 @@
worker_processes auto;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_body_temp_path /tmp/client_temp;
proxy_temp_path /tmp/proxy_temp;
fastcgi_temp_path /tmp/fastcgi_temp;
uwsgi_temp_path /tmp/uwsgi_temp;
scgi_temp_path /tmp/scgi_temp;
include /etc/nginx/conf.d/*.conf;
}