feat(deploy): add timetracker helm chart with restricted pod security
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qu4xuNCkFLDByYWUrjanny
This commit is contained in:
parent
0483223c0d
commit
951ea9ccb4
11 changed files with 464 additions and 0 deletions
6
deploy/helm/timetracker/Chart.yaml
Normal file
6
deploy/helm/timetracker/Chart.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
apiVersion: v2
|
||||
name: timetracker
|
||||
description: Zeiterfassung mit Timer, manuellen Einträgen, Urlaub, Überstunden und Export
|
||||
type: application
|
||||
version: 0.1.0
|
||||
appVersion: "0.1.0"
|
||||
72
deploy/helm/timetracker/templates/_helpers.tpl
Normal file
72
deploy/helm/timetracker/templates/_helpers.tpl
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
{{- define "timetracker.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "timetracker.fullname" -}}
|
||||
{{- if .Values.fullnameOverride -}}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
|
||||
{{- else -}}
|
||||
{{- printf "%s-%s" .Release.Name (include "timetracker.name" .) | trunc 63 | trimSuffix "-" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "timetracker.labels" -}}
|
||||
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | quote }}
|
||||
app.kubernetes.io/name: {{ include "timetracker.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Selector for one component. Call with (dict "root" . "component" "backend"). */}}
|
||||
{{- define "timetracker.selector" -}}
|
||||
app.kubernetes.io/name: {{ include "timetracker.name" .root }}
|
||||
app.kubernetes.io/instance: {{ .root.Release.Name }}
|
||||
app.kubernetes.io/component: {{ .component }}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "timetracker.secretName" -}}
|
||||
{{- if .Values.secrets.existingSecret -}}
|
||||
{{- .Values.secrets.existingSecret -}}
|
||||
{{- else -}}
|
||||
{{- include "timetracker.fullname" . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "timetracker.pvcName" -}}
|
||||
{{- if .Values.persistence.existingClaim -}}
|
||||
{{- .Values.persistence.existingClaim -}}
|
||||
{{- else -}}
|
||||
{{- printf "%s-data" (include "timetracker.fullname" .) -}}
|
||||
{{- 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 -}}
|
||||
{{- if not (has $driver (list "sqlite" "postgres" "mariadb")) -}}
|
||||
{{- fail (printf "config.database.driver must be sqlite, postgres or mariadb, got %q" $driver) -}}
|
||||
{{- end -}}
|
||||
{{- if and (not .Values.secrets.existingSecret) (not .Values.secrets.inline.jwtSecret) -}}
|
||||
{{- fail "set secrets.existingSecret or secrets.inline.jwtSecret" -}}
|
||||
{{- end -}}
|
||||
{{- if ne $driver "sqlite" -}}
|
||||
{{- if not .Values.config.database.host -}}
|
||||
{{- fail "config.database.host is required for postgres and mariadb" -}}
|
||||
{{- end -}}
|
||||
{{- if and (not .Values.secrets.existingSecret) (not .Values.secrets.inline.dbPassword) -}}
|
||||
{{- fail "secrets.inline.dbPassword or secrets.existingSecret is required for postgres and mariadb" -}}
|
||||
{{- end -}}
|
||||
{{- else if gt (int .Values.replicaCount) 1 -}}
|
||||
{{- fail "sqlite supports a single replica; use postgres or mariadb for replicaCount > 1" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
92
deploy/helm/timetracker/templates/deployment-backend.yaml
Normal file
92
deploy/helm/timetracker/templates/deployment-backend.yaml
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
{{- include "timetracker.validate" . }}
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" . }}-backend
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
app.kubernetes.io/component: backend
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "timetracker.selector" (dict "root" . "component" "backend") | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 8 }}
|
||||
app.kubernetes.io/component: backend
|
||||
spec:
|
||||
serviceAccountName: {{ include "timetracker.fullname" . }}-backend
|
||||
automountServiceAccountToken: false
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65532
|
||||
runAsGroup: 65532
|
||||
fsGroup: 65532
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
containers:
|
||||
- name: backend
|
||||
image: "{{ .Values.image.backend.repository }}:{{ .Values.image.backend.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
protocol: TCP
|
||||
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
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
allowPrivilegeEscalation: false
|
||||
privileged: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/v1/health
|
||||
port: http
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 20
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api/v1/health
|
||||
port: http
|
||||
periodSeconds: 10
|
||||
resources:
|
||||
{{- toYaml .Values.resources.backend | nindent 12 }}
|
||||
{{- if eq .Values.config.database.driver "sqlite" }}
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
{{- end }}
|
||||
{{- if eq .Values.config.database.driver "sqlite" }}
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: {{ include "timetracker.pvcName" . }}
|
||||
{{- end }}
|
||||
70
deploy/helm/timetracker/templates/deployment-frontend.yaml
Normal file
70
deploy/helm/timetracker/templates/deployment-frontend.yaml
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" . }}-frontend
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
app.kubernetes.io/component: frontend
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "timetracker.selector" (dict "root" . "component" "frontend") | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 8 }}
|
||||
app.kubernetes.io/component: frontend
|
||||
spec:
|
||||
serviceAccountName: {{ include "timetracker.fullname" . }}-frontend
|
||||
automountServiceAccountToken: false
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65532
|
||||
runAsGroup: 65532
|
||||
fsGroup: 65532
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
containers:
|
||||
- name: frontend
|
||||
image: "{{ .Values.image.frontend.repository }}:{{ .Values.image.frontend.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
protocol: TCP
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
allowPrivilegeEscalation: false
|
||||
privileged: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
periodSeconds: 20
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
periodSeconds: 10
|
||||
resources:
|
||||
{{- toYaml .Values.resources.frontend | nindent 12 }}
|
||||
# nginx needs writable scratch space; everything else stays read-only.
|
||||
volumeMounts:
|
||||
- name: tmp
|
||||
mountPath: /tmp
|
||||
- name: nginx-cache
|
||||
mountPath: /var/cache/nginx
|
||||
- name: nginx-run
|
||||
mountPath: /var/run
|
||||
volumes:
|
||||
- name: tmp
|
||||
emptyDir: {}
|
||||
- name: nginx-cache
|
||||
emptyDir: {}
|
||||
- name: nginx-run
|
||||
emptyDir: {}
|
||||
33
deploy/helm/timetracker/templates/ingress.yaml
Normal file
33
deploy/helm/timetracker/templates/ingress.yaml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{{- if .Values.ingress.enabled }}
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" . }}
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
{{- with .Values.ingress.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- if .Values.ingress.className }}
|
||||
ingressClassName: {{ .Values.ingress.className }}
|
||||
{{- end }}
|
||||
{{- with .Values.ingress.tls }}
|
||||
tls:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
rules:
|
||||
{{- range .Values.ingress.hosts }}
|
||||
- host: {{ . | quote }}
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: frontend
|
||||
port:
|
||||
number: {{ $.Values.service.port }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
41
deploy/helm/timetracker/templates/networkpolicy.yaml
Normal file
41
deploy/helm/timetracker/templates/networkpolicy.yaml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{{- if .Values.networkPolicy.enabled }}
|
||||
# Only frontend pods may reach the backend API.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" . }}-backend
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
{{- include "timetracker.selector" (dict "root" . "component" "backend") | nindent 6 }}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
{{- include "timetracker.selector" (dict "root" . "component" "frontend") | nindent 14 }}
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: http
|
||||
---
|
||||
# The frontend serves the UI on its port to any source; the ingress controller is the usual client.
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" . }}-frontend
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
{{- include "timetracker.selector" (dict "root" . "component" "frontend") | nindent 6 }}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
ingress:
|
||||
- ports:
|
||||
- protocol: TCP
|
||||
port: http
|
||||
{{- end }}
|
||||
17
deploy/helm/timetracker/templates/pvc.yaml
Normal file
17
deploy/helm/timetracker/templates/pvc.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{{- if and (eq .Values.config.database.driver "sqlite") .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: {{ include "timetracker.pvcName" . }}
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
{{- if .Values.persistence.storageClass }}
|
||||
storageClassName: {{ .Values.persistence.storageClass | quote }}
|
||||
{{- end }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.persistence.size | quote }}
|
||||
{{- end }}
|
||||
14
deploy/helm/timetracker/templates/secret.yaml
Normal file
14
deploy/helm/timetracker/templates/secret.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{{- if not .Values.secrets.existingSecret }}
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" . }}
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
type: Opaque
|
||||
stringData:
|
||||
APP_JWT_SECRET: {{ .Values.secrets.inline.jwtSecret | quote }}
|
||||
{{- if ne .Values.config.database.driver "sqlite" }}
|
||||
DB_DSN: {{ include "timetracker.dsn" . | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
12
deploy/helm/timetracker/templates/serviceaccounts.yaml
Normal file
12
deploy/helm/timetracker/templates/serviceaccounts.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# One service account per component, without API token mounts: the pods never talk to the Kubernetes API.
|
||||
{{- range $component := list "backend" "frontend" }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: {{ include "timetracker.fullname" $ }}-{{ $component }}
|
||||
labels:
|
||||
{{- include "timetracker.labels" $ | nindent 4 }}
|
||||
app.kubernetes.io/component: {{ $component }}
|
||||
automountServiceAccountToken: false
|
||||
{{- end }}
|
||||
35
deploy/helm/timetracker/templates/services.yaml
Normal file
35
deploy/helm/timetracker/templates/services.yaml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# The frontend's nginx proxies /api to http://backend:8080, so the backend service name is fixed.
|
||||
# Run one release per namespace.
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
app.kubernetes.io/component: backend
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
{{- include "timetracker.selector" (dict "root" . "component" "backend") | nindent 4 }}
|
||||
ports:
|
||||
- name: http
|
||||
port: {{ .Values.service.port }}
|
||||
targetPort: http
|
||||
protocol: TCP
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: frontend
|
||||
labels:
|
||||
{{- include "timetracker.labels" . | nindent 4 }}
|
||||
app.kubernetes.io/component: frontend
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
{{- include "timetracker.selector" (dict "root" . "component" "frontend") | nindent 4 }}
|
||||
ports:
|
||||
- name: http
|
||||
port: {{ .Values.service.port }}
|
||||
targetPort: http
|
||||
protocol: TCP
|
||||
72
deploy/helm/timetracker/values.yaml
Normal file
72
deploy/helm/timetracker/values.yaml
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# Number of backend pods. SQLite supports only one; use postgres or mariadb for more.
|
||||
replicaCount: 1
|
||||
|
||||
image:
|
||||
backend:
|
||||
repository: __CI_REGISTRY_IMAGE__/backend
|
||||
tag: __GIT_COMMIT_SHA__
|
||||
frontend:
|
||||
repository: __CI_REGISTRY_IMAGE__/frontend
|
||||
tag: __GIT_COMMIT_SHA__
|
||||
pullPolicy: IfNotPresent
|
||||
|
||||
nameOverride: ""
|
||||
fullnameOverride: ""
|
||||
|
||||
config:
|
||||
logLevel: info
|
||||
jwtTtlHours: 24
|
||||
database:
|
||||
# sqlite | postgres | mariadb
|
||||
driver: sqlite
|
||||
host: ""
|
||||
port: ""
|
||||
name: timetracker
|
||||
user: timetracker
|
||||
# postgres only
|
||||
sslmode: disable
|
||||
|
||||
secrets:
|
||||
# Use an existing secret with the keys APP_JWT_SECRET and, for postgres/mariadb, DB_DSN.
|
||||
# When set, inline values below are ignored.
|
||||
existingSecret: ""
|
||||
inline:
|
||||
jwtSecret: ""
|
||||
# postgres/mariadb only; the DSN is assembled from this value and config.database.*
|
||||
dbPassword: ""
|
||||
|
||||
persistence:
|
||||
# sqlite database file lives in a PersistentVolumeClaim mounted at /data
|
||||
enabled: true
|
||||
existingClaim: ""
|
||||
storageClass: ""
|
||||
size: 1Gi
|
||||
|
||||
service:
|
||||
port: 8080
|
||||
|
||||
ingress:
|
||||
enabled: false
|
||||
className: ""
|
||||
annotations: {}
|
||||
# host names; all of them route / to the frontend
|
||||
hosts: []
|
||||
tls: []
|
||||
|
||||
networkPolicy:
|
||||
# backend accepts traffic only from frontend pods; frontend accepts it from anywhere on its port
|
||||
enabled: true
|
||||
|
||||
resources:
|
||||
backend:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
memory: 256Mi
|
||||
frontend:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 16Mi
|
||||
limits:
|
||||
memory: 64Mi
|
||||
Loading…
Add table
Add a link
Reference in a new issue