diff --git a/Dockerfile b/Dockerfile index 67e39ce..5851aef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -68,7 +68,14 @@ RUN corepack pnpm build \ # --------------------------------------------------------------------------- # runtime # --------------------------------------------------------------------------- -FROM nginx@sha256:65645c7bb6a0661892a8b03b89d0743208a18dd2f3f17a54ef4b76fb8e2f2a10 AS runtime +# Unprivileged NGINX 1.27.5 on Alpine, the same release and distribution as the +# previous nginx base: the master runs as uid 101 and listens on 8080, so the +# container needs no root and no capability. Kubernetes runs it with +# runAsNonRoot and capabilities drop ALL (deploy/production/frontend-nonroot). +FROM nginxinc/nginx-unprivileged@sha256:65e3e85dbaed8ba248841d9d58a899b6197106c23cb0ff1a132b7bfe0547e4c0 AS runtime + +# The file edits below need root; the image drops back to uid 101 at the end. +USER root # Replaces the packaged default server block; the generated file is the whole # server definition, including the BFF proxy locations. @@ -81,16 +88,18 @@ COPY --from=build /src/dist/ /usr/share/nginx/html/ # not a page either. RUN rm -f /usr/share/nginx/html/nginx.conf /usr/share/nginx/html/server.mjs \ && rm -rf /usr/share/nginx/html/.vite \ - # The build writes config.json 0600, which nginx (running as `nginx`) cannot + # The build writes config.json 0600, which nginx (running as uid 101) cannot # read — the container came up healthy and answered 403 for the one file the # SPA needs before it can boot. Normalise what is served to world-readable. && chmod -R a+rX /usr/share/nginx/html -EXPOSE 80 +USER 101 + +EXPOSE 8080 # No `nginx -t` here: proxy_pass names are resolved when the config loads, and # `backend`/`keycloak` only exist on the compose network. The container's own # startup is the check, and it fails loudly. HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://127.0.0.1${VITE_ROUTER_BASE_PATH:-/}config.json || exit 1 + CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8080${VITE_ROUTER_BASE_PATH:-/}config.json || exit 1 diff --git a/docker-compose.dev-stack.yml b/docker-compose.dev-stack.yml index 9e11040..780dd53 100644 --- a/docker-compose.dev-stack.yml +++ b/docker-compose.dev-stack.yml @@ -163,7 +163,7 @@ services: - "cp /etc/nginx/tls/server.crt /tls-public/server.crt && exec nginx -g 'daemon off;'" ports: - - "${PUBLIC_HTTP_PORT:-8088}:80" + - "${PUBLIC_HTTP_PORT:-8088}:8080" - "${PUBLIC_PORT:-8443}:443" depends_on: backend: { condition: service_started } diff --git a/scripts/generate-nginx-config.ts b/scripts/generate-nginx-config.ts index f17cd89..3b27e2d 100644 --- a/scripts/generate-nginx-config.ts +++ b/scripts/generate-nginx-config.ts @@ -136,10 +136,11 @@ ${secure} # config/hosting/cache-policy.json # # Plain HTTP on purpose: the edge terminates TLS and this container is only ever -# reached from inside the deployment network. +# reached from inside the deployment network. 8080, not 80: the runtime image is +# unprivileged NGINX, which cannot bind a port below 1024 without a capability. server { - listen 80; + listen 8080; server_name _; root /usr/share/nginx/html; index index.html;