chore(helm): enhance security context and volume handling

- [x] Add explicit security context with fsGroup and runAsUser to frontend deployment
- [x] Add initContainer to copy nginx static files and config to writable volumes
- [x] Add security context to initContainer with capability restrictions
- [x] Add runAsUser to frontend container security context
- [x] Add emptyDir volumes for nginx HTML and conf directories
- [x] Replace template includes with explicit volumeMounts in scanner deployment
- [x] Conditionally mount trivy cache volume in scanner deployment
- [x] Replace template includes with explicit volumeMounts in server deployment
This commit is contained in:
2026-01-03 00:52:59 +00:00
parent 6b037a92b4
commit 6afa55b5f5
3 changed files with 45 additions and 6 deletions
@@ -26,7 +26,30 @@ spec:
{{- end }} {{- end }}
serviceAccountName: {{ include "gohoarder.serviceAccountName" . }} serviceAccountName: {{ include "gohoarder.serviceAccountName" . }}
securityContext: securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }} fsGroup: 101
runAsNonRoot: true
runAsUser: 101
initContainers:
- name: copy-static-files
image: "{{ .Values.image.frontend.repository }}:{{ .Values.image.frontend.tag | default .Chart.AppVersion }}"
command: ['sh', '-c']
args:
- |
# Copy built frontend files to writable volume
cp -rp /usr/share/nginx/html/* /html/
# Copy nginx config to writable volume
cp -rp /etc/nginx/conf.d/* /conf/
volumeMounts:
- name: nginx-html
mountPath: /html
- name: nginx-conf
mountPath: /conf
securityContext:
runAsUser: 101
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
containers: containers:
- name: frontend - name: frontend
securityContext: securityContext:
@@ -35,6 +58,7 @@ spec:
drop: drop:
- ALL - ALL
readOnlyRootFilesystem: false readOnlyRootFilesystem: false
runAsUser: 101
image: "{{ .Values.image.frontend.repository }}:{{ .Values.image.frontend.tag | default .Chart.AppVersion }}" image: "{{ .Values.image.frontend.repository }}:{{ .Values.image.frontend.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.frontend.pullPolicy }} imagePullPolicy: {{ .Values.image.frontend.pullPolicy }}
ports: ports:
@@ -64,6 +88,10 @@ spec:
mountPath: /var/cache/nginx mountPath: /var/cache/nginx
- name: nginx-run - name: nginx-run
mountPath: /var/run mountPath: /var/run
- name: nginx-html
mountPath: /usr/share/nginx/html
- name: nginx-conf
mountPath: /etc/nginx/conf.d
volumes: volumes:
- name: tmp - name: tmp
emptyDir: {} emptyDir: {}
@@ -71,6 +99,10 @@ spec:
emptyDir: {} emptyDir: {}
- name: nginx-run - name: nginx-run
emptyDir: {} emptyDir: {}
- name: nginx-html
emptyDir: {}
- name: nginx-conf
emptyDir: {}
{{- with .Values.frontend.nodeSelector }} {{- with .Values.frontend.nodeSelector }}
nodeSelector: nodeSelector:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
@@ -42,9 +42,14 @@ spec:
chown -R 1000:1000 /var/cache/gohoarder /var/lib/gohoarder /tmp/gohoarder chown -R 1000:1000 /var/cache/gohoarder /var/lib/gohoarder /tmp/gohoarder
chmod 750 /var/cache/gohoarder /var/lib/gohoarder chmod 750 /var/cache/gohoarder /var/lib/gohoarder
volumeMounts: volumeMounts:
{{- include "gohoarder.storageVolume" . | nindent 8 }} - name: storage
{{- include "gohoarder.metadataVolume" . | nindent 8 }} mountPath: /var/cache/gohoarder
{{- include "gohoarder.trivyCacheVolume" . | nindent 8 }} - name: metadata
mountPath: /var/lib/gohoarder/metadata
{{- if .Values.security.scanners.trivy.enabled }}
- name: trivy-cache
mountPath: {{ .Values.security.scanners.trivy.cacheDb }}
{{- end }}
- name: tmp - name: tmp
mountPath: /tmp/gohoarder mountPath: /tmp/gohoarder
securityContext: securityContext:
@@ -39,8 +39,10 @@ spec:
chown -R 1000:1000 /var/cache/gohoarder /var/lib/gohoarder /tmp/gohoarder chown -R 1000:1000 /var/cache/gohoarder /var/lib/gohoarder /tmp/gohoarder
chmod 750 /var/cache/gohoarder /var/lib/gohoarder chmod 750 /var/cache/gohoarder /var/lib/gohoarder
volumeMounts: volumeMounts:
{{- include "gohoarder.storageVolume" . | nindent 8 }} - name: storage
{{- include "gohoarder.metadataVolume" . | nindent 8 }} mountPath: /var/cache/gohoarder
- name: metadata
mountPath: /var/lib/gohoarder/metadata
- name: tmp - name: tmp
mountPath: /tmp/gohoarder mountPath: /tmp/gohoarder
securityContext: securityContext: