From b9d692a91cb06c3554a18f109f567a8e85e47ca8 Mon Sep 17 00:00:00 2001 From: Ken Schiano Date: Sat, 21 Nov 2026 20:49:45 -0500 Subject: [PATCH] Build the site image on Red Hat's hardened images Node build on hi/nodejs:22-builder, the nginx config checked with `nginx -t` on hi/nginx:latest-builder, served by the distroless hi/nginx runtime (UID 65532, no shell). nginx keeps temp files in /tmp so the pod can run with a read-only root filesystem; adds nosniff/referrer headers and hides the nginx version. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 23 +++++++++++++++++------ deploy/nginx.conf | 28 ++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6fee316..82c2bb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,24 @@ -# The published Atlas page as a container: build the static site (npm run build -> dist/), then serve it with an -# unprivileged nginx on port 8080. .gitea/workflows/image.yml builds this on every push to main and pushes it to -# harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment (kubefiles, -# web/threshing-atlas) when that digest changes. -FROM node:22-alpine AS build +# The published Atlas page as a container, on Red Hat's hardened images: build the static site with Node, check +# the nginx config with the nginx builder (it has a shell), then serve with the distroless nginx runtime (no shell +# or package manager, UID 65532, port 8080). .gitea/workflows/image.yml builds this on every push to main and +# pushes it to harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment +# (kubefiles, web/threshing-atlas) when that digest changes. +ARG NODE_TAG=22 +ARG NGINX_TAG=latest + +FROM registry.access.redhat.com/hi/nodejs:${NODE_TAG}-builder AS build +# Only /site leaves this stage, so build as root +USER root WORKDIR /src COPY . . RUN node site/build.js /site -FROM nginxinc/nginx-unprivileged:1.28-alpine +# Fail the build on a bad config, since the runtime image can't run `nginx -t` for us +FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}-builder AS nginx-check COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf +RUN nginx -t -e /dev/stderr + +FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG} +COPY --from=nginx-check /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf COPY --from=build /site /usr/share/nginx/html EXPOSE 8080 diff --git a/deploy/nginx.conf b/deploy/nginx.conf index 954f614..2aaed44 100644 --- a/deploy/nginx.conf +++ b/deploy/nginx.conf @@ -1,20 +1,36 @@ # The Atlas is plain static files. The data changes daily, so browsers revalidate rather than cache blindly. +# Replaces the image's conf.d/default.conf (it listens on 8080 and runs as UID 65532). + +# Temp files under /tmp (an emptyDir in the pod), so the root filesystem can be read-only +client_body_temp_path /tmp/client_body; +proxy_temp_path /tmp/proxy; +fastcgi_temp_path /tmp/fastcgi; +uwsgi_temp_path /tmp/uwsgi; +scgi_temp_path /tmp/scgi; + server { listen 8080; root /usr/share/nginx/html; index index.html; charset utf-8; + server_tokens off; - types { - text/plain yaml py csv; - } + # The image logs to files under /var/log/nginx; send access logs to the pod log instead + access_log /dev/stdout main; + + # Show the page's data and source files as text (in server context this replaces the inherited types) include /etc/nginx/mime.types; + types { + text/plain yaml py; + } gzip on; - gzip_types text/plain text/css application/javascript application/json text/csv; + gzip_types text/plain text/css text/csv text/javascript application/javascript application/json; - add_header Cache-Control "no-cache"; + add_header Cache-Control "no-cache" always; + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "strict-origin-when-cross-origin" always; - location = /healthz { access_log off; return 200 "ok\n"; } + location = /healthz { access_log off; default_type text/plain; return 200 "ok\n"; } location / { try_files $uri $uri/ =404; } }