fix(deploy): give the frontend pod the writable paths nginx needs

nginx failed at start with mkdir() /var/lib/nginx/tmp/client_body (13: Permission
denied) because the root file system is read-only. Mount emptyDirs on
/var/lib/nginx/tmp, /run (the pid file; /var/run is only a symlink to it) and /tmp,
drop the unused /var/cache/nginx mount, and make CI and make lint-chart fail if one
of them goes missing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qu4xuNCkFLDByYWUrjanny
This commit is contained in:
Jonas Leder 2026-11-04 15:28:58 +00:00
commit 0e1fdd8f8b
4 changed files with 25 additions and 9 deletions

View file

@ -81,6 +81,13 @@ HelmChart:
# Render with the common configurations so template failures show up in CI.
- helm template ci "$CHART_DIR" --set secrets.inline.jwtSecret=ci > /dev/null
- helm template ci "$CHART_DIR" --set config.database.driver=postgres --set config.database.host=db --set config.database.user=timetracker --set secrets.inline.dbPassword=ci --set secrets.inline.jwtSecret=ci --set replicaCount=2 --set ingress.enabled=true --set 'ingress.hosts={timetracker.example.com}' > /dev/null
- |
# The frontend pod runs with a read-only root file system. nginx writes only to these paths, so each
# needs an emptyDir mount; without /var/lib/nginx/tmp it fails at start with "mkdir() ... client_body".
RENDERED=$(helm template ci "$CHART_DIR" --set secrets.inline.jwtSecret=ci)
for path in /var/lib/nginx/tmp /run /tmp; do
echo "$RENDERED" | grep -q "mountPath: $path\$" || { echo "frontend pod has no writable $path"; exit 1; }
done
- |
# Flux picks the highest version, so versions must only grow. The patch number is the pipeline IID,
# which increases with every pipeline of the project. The major.minor part comes from Chart.yaml.

View file

@ -11,6 +11,11 @@ test-frontend:
lint-chart:
helm lint deploy/helm/timetracker --strict --set secrets.inline.jwtSecret=ci
helm template ci deploy/helm/timetracker --set secrets.inline.jwtSecret=ci > /dev/null
# nginx runs on a read-only root file system and writes only to these paths
for path in /var/lib/nginx/tmp /run /tmp; do \
helm template ci deploy/helm/timetracker --set secrets.inline.jwtSecret=ci | grep -q "mountPath: $$path$$" \
|| { echo "frontend pod has no writable $$path"; exit 1; }; \
done
swagger:
cd backend && go run github.com/swaggo/swag/cmd/swag@v1.16.6 init -g cmd/server/main.go -o docs --parseDependency --parseInternal

View file

@ -62,7 +62,7 @@ helm install timetracker deploy/helm/timetracker \
- **SQLite (Standard):** eine Datei in einem PersistentVolumeClaim unter `/data`. Nur ein Replica möglich, das Chart verweigert mehr.
- **PostgreSQL / MariaDB:** `config.database.driver`, `config.database.host`, `config.database.user`, `config.database.name` setzen und `secrets.inline.dbPassword` übergeben. Nicht geheime Werte liegen in einer ConfigMap, Passwort und JWT-Secret in einem Secret. Für Produktion besser `secrets.existingSecret` mit den Schlüsseln `APP_JWT_SECRET` und `DB_PASSWORD` verwenden.
- **Sicherheit:** Beide Pods laufen als Nutzer 65532 ohne Root-Rechte, mit read-only Root-Dateisystem, ohne Capabilities, ohne Privilege Escalation, mit `RuntimeDefault`-Seccomp und ohne ServiceAccount-Token. NetworkPolicies lassen nur Frontend-Pods zum Backend. Die Abschnitte `securityContext` in `values.yaml` bzw. den Templates sind die Stelle für Anpassungen.
- **Sicherheit:** Beide Pods laufen als Nutzer 65532 ohne Root-Rechte, mit read-only Root-Dateisystem (nginx schreibt nur nach `/tmp`, `/run` und `/var/lib/nginx/tmp`, jeweils ein `emptyDir`), ohne Capabilities, ohne Privilege Escalation, mit `RuntimeDefault`-Seccomp und ohne ServiceAccount-Token. NetworkPolicies lassen nur Frontend-Pods zum Backend. Die Abschnitte `securityContext` in `values.yaml` bzw. den Templates sind die Stelle für Anpassungen.
## CI

View file

@ -53,18 +53,22 @@ spec:
periodSeconds: 10
resources:
{{- toYaml .Values.resources.frontend | nindent 12 }}
# nginx needs writable scratch space; everything else stays read-only.
# The root file system is read-only. These are the only paths the chainguard/nginx image writes to:
# /var/lib/nginx/tmp request body and proxy buffers (compiled-in temp paths)
# /run nginx.pid (/var/run is a symlink to it)
# /tmp scratch space
# Access and error logs are symlinks to stdout and stderr and need no mount.
volumeMounts:
- name: nginx-tmp
mountPath: /var/lib/nginx/tmp
- name: nginx-run
mountPath: /run
- name: tmp
mountPath: /tmp
- name: nginx-cache
mountPath: /var/cache/nginx
- name: nginx-run
mountPath: /var/run
volumes:
- name: tmp
emptyDir: {}
- name: nginx-cache
- name: nginx-tmp
emptyDir: {}
- name: nginx-run
emptyDir: {}
- name: tmp
emptyDir: {}