feat(deploy): split non-secret chart config into ConfigMap and password into Secret
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qu4xuNCkFLDByYWUrjanny
This commit is contained in:
parent
46541ba221
commit
9b64b8d117
8 changed files with 52 additions and 37 deletions
13
README.md
13
README.md
|
|
@ -47,7 +47,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. Für Produktion besser `secrets.existingSecret` mit den Schlüsseln `APP_JWT_SECRET` und `DB_DSN` verwenden.
|
||||
- **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.
|
||||
|
||||
## CI
|
||||
|
|
@ -79,10 +79,15 @@ pnpm dev # Vite leitet /api an :8080 weiter
|
|||
| `APP_JWT_TTL_HOURS` | `24` | Gültigkeit des Tokens |
|
||||
| `APP_LOG_LEVEL` | `info` | `debug`, `info`, `warn` oder `error` |
|
||||
| `DB_DRIVER` | `sqlite` | `sqlite`, `mariadb` oder `postgres` |
|
||||
| `DB_DSN` | `timetracker.db` | Verbindungsstring der gewählten Datenbank |
|
||||
| `DB_NAME` | `timetracker.db` (sqlite) / `timetracker` | sqlite: Dateipfad; mariadb/postgres: Datenbankname |
|
||||
| `DB_HOST` | – | Host für mariadb und postgres (Pflicht dort) |
|
||||
| `DB_PORT` | `3306` / `5432` | Port; leer = Standard des Treibers |
|
||||
| `DB_USER` | `timetracker` | Benutzer für mariadb und postgres |
|
||||
| `DB_PASSWORD` | – | Passwort für mariadb und postgres (Geheimnis) |
|
||||
| `DB_SSLMODE` | `disable` | nur postgres |
|
||||
|
||||
Beispiele für `DB_DSN` stehen in [backend/.env.example](backend/.env.example).
|
||||
Für MariaDB und PostgreSQL in Docker: `docker compose --profile postgres up` bzw. `--profile mariadb`, danach `DB_DRIVER` und `DB_DSN` entsprechend setzen.
|
||||
Die Verbindung wird aus diesen Feldern zusammengesetzt, es gibt keinen Verbindungsstring mehr. Beispiele stehen in [backend/.env.example](backend/.env.example).
|
||||
Für MariaDB und PostgreSQL in Docker: `docker compose --profile postgres up` bzw. `--profile mariadb`, danach `DB_DRIVER`, `DB_HOST`, `DB_USER` und `DB_PASSWORD` entsprechend setzen.
|
||||
|
||||
## Tests
|
||||
|
||||
|
|
|
|||
|
|
@ -41,15 +41,6 @@ app.kubernetes.io/component: {{ .component }}
|
|||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "timetracker.dsn" -}}
|
||||
{{- $db := .Values.config.database -}}
|
||||
{{- if eq $db.driver "postgres" -}}
|
||||
host={{ $db.host }} port={{ default 5432 $db.port }} user={{ $db.user }} password={{ .Values.secrets.inline.dbPassword }} dbname={{ $db.name }} sslmode={{ $db.sslmode }} TimeZone=Europe/Berlin
|
||||
{{- else -}}
|
||||
{{ $db.user }}:{{ .Values.secrets.inline.dbPassword }}@tcp({{ $db.host }}:{{ default 3306 $db.port }})/{{ $db.name }}?parseTime=true&loc=Europe%2FBerlin&charset=utf8mb4
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Fails the render early for configurations that cannot work. */}}
|
||||
{{- define "timetracker.validate" -}}
|
||||
{{- $driver := .Values.config.database.driver -}}
|
||||
|
|
|
|||
21
deploy/helm/timetracker/templates/configmap.yaml
Normal file
21
deploy/helm/timetracker/templates/configmap.yaml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Non-secret settings. The password and JWT secret live in the Secret.
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" . }}-config
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
data:
|
||||
APP_PORT: "8080"
|
||||
APP_LOG_LEVEL: {{ .Values.config.logLevel | quote }}
|
||||
APP_JWT_TTL_HOURS: {{ .Values.config.jwtTtlHours | quote }}
|
||||
DB_DRIVER: {{ .Values.config.database.driver | quote }}
|
||||
{{- if eq .Values.config.database.driver "sqlite" }}
|
||||
DB_NAME: "/data/timetracker.db"
|
||||
{{- else }}
|
||||
DB_HOST: {{ .Values.config.database.host | quote }}
|
||||
DB_PORT: {{ toString (default "" .Values.config.database.port) | quote }}
|
||||
DB_NAME: {{ .Values.config.database.name | quote }}
|
||||
DB_USER: {{ .Values.config.database.user | quote }}
|
||||
DB_SSLMODE: {{ .Values.config.database.sslmode | quote }}
|
||||
{{- end }}
|
||||
|
|
@ -34,30 +34,22 @@ spec:
|
|||
- name: http
|
||||
containerPort: 8080
|
||||
protocol: TCP
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: {{ include "timetracker.fullname" . }}-config
|
||||
env:
|
||||
- name: APP_PORT
|
||||
value: "8080"
|
||||
- name: APP_LOG_LEVEL
|
||||
value: {{ .Values.config.logLevel | quote }}
|
||||
- name: APP_JWT_TTL_HOURS
|
||||
value: {{ .Values.config.jwtTtlHours | quote }}
|
||||
- name: DB_DRIVER
|
||||
value: {{ .Values.config.database.driver | quote }}
|
||||
{{- if eq .Values.config.database.driver "sqlite" }}
|
||||
- name: DB_DSN
|
||||
value: "/data/timetracker.db"
|
||||
{{- else }}
|
||||
- name: DB_DSN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "timetracker.secretName" . }}
|
||||
key: DB_DSN
|
||||
{{- end }}
|
||||
- name: APP_JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "timetracker.secretName" . }}
|
||||
key: APP_JWT_SECRET
|
||||
{{- if ne .Values.config.database.driver "sqlite" }}
|
||||
- name: DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "timetracker.secretName" . }}
|
||||
key: DB_PASSWORD
|
||||
{{- end }}
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
allowPrivilegeEscalation: false
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ type: Opaque
|
|||
stringData:
|
||||
APP_JWT_SECRET: {{ .Values.secrets.inline.jwtSecret | quote }}
|
||||
{{- if ne .Values.config.database.driver "sqlite" }}
|
||||
DB_DSN: {{ include "timetracker.dsn" . | quote }}
|
||||
DB_PASSWORD: {{ .Values.secrets.inline.dbPassword | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ config:
|
|||
sslmode: disable
|
||||
|
||||
secrets:
|
||||
# Use an existing secret with the keys APP_JWT_SECRET and, for postgres/mariadb, DB_DSN.
|
||||
# Use an existing secret with the keys APP_JWT_SECRET and, for postgres/mariadb, DB_PASSWORD.
|
||||
# When set, inline values below are ignored.
|
||||
existingSecret: ""
|
||||
inline:
|
||||
jwtSecret: ""
|
||||
# postgres/mariadb only; the DSN is assembled from this value and config.database.*
|
||||
# postgres/mariadb only, stored as DB_PASSWORD
|
||||
dbPassword: ""
|
||||
|
||||
persistence:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Default: SQLite in a volume. Run with a database profile to use MariaDB or PostgreSQL:
|
||||
# docker compose --profile postgres up --build
|
||||
# docker compose --profile mariadb up --build
|
||||
# Then set DB_DRIVER and DB_DSN for the backend accordingly (see README).
|
||||
# Then set DB_DRIVER, DB_HOST, DB_USER and DB_PASSWORD for the backend accordingly (see README).
|
||||
services:
|
||||
backend:
|
||||
build: ./backend
|
||||
|
|
@ -9,7 +9,12 @@ services:
|
|||
APP_JWT_SECRET: ${APP_JWT_SECRET:?set APP_JWT_SECRET in .env}
|
||||
APP_LOG_LEVEL: info
|
||||
DB_DRIVER: ${DB_DRIVER:-sqlite}
|
||||
DB_DSN: ${DB_DSN:-/data/timetracker.db}
|
||||
DB_HOST: ${DB_HOST:-}
|
||||
DB_PORT: ${DB_PORT:-}
|
||||
DB_NAME: ${DB_NAME:-/data/timetracker.db}
|
||||
DB_USER: ${DB_USER:-timetracker}
|
||||
DB_PASSWORD: ${DB_PASSWORD:-}
|
||||
DB_SSLMODE: ${DB_SSLMODE:-disable}
|
||||
volumes:
|
||||
- sqlite-data:/data
|
||||
expose:
|
||||
|
|
|
|||
|
|
@ -68,4 +68,5 @@ docs/plan/ diese Dateien
|
|||
| `APP_JWT_TTL_HOURS` | `24` | Gültigkeit des Tokens |
|
||||
| `APP_LOG_LEVEL` | `info` | Logrus-Level |
|
||||
| `DB_DRIVER` | `sqlite` | `sqlite`, `mariadb` oder `postgres` |
|
||||
| `DB_DSN` | `timetracker.db` | Verbindungsstring für die gewählte DB |
|
||||
| `DB_NAME` | `timetracker.db` | Dateipfad (sqlite) bzw. Datenbankname |
|
||||
| `DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASSWORD`, `DB_SSLMODE` | – | Verbindungsfelder für mariadb/postgres; die DSN wird im Backend zusammengesetzt |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue