Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions charts/common/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
.project
.idea/
*.tmproj

temp.yaml
1 change: 1 addition & 0 deletions charts/common/templates/_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ env:
{{ include "common.healthcheck.startup" . }}
{{- end }}
{{ include "common.resources" . }}
{{ include "common.security.containerContext" . }}
{{- if .Values.volumeMounts }}
volumeMounts:
{{- toYaml .Values.volumeMounts | nindent 2 }}
Expand Down
50 changes: 49 additions & 1 deletion charts/common/templates/_security_context.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{- define "common.security.context" -}}
{{/*
Pod-level security context - called at spec.securityContext
*/}}

{{- define "common.security.podContext" -}}
{{- $context := default (dict) .Values.securityContext -}}
{{- $runAsUser := ternary $context.runAsUser 1001 (hasKey $context "runAsUser") -}}
{{- $runAsGroup := ternary $context.runAsGroup $runAsUser (hasKey $context "runAsGroup") -}}
Expand All @@ -9,4 +13,48 @@ securityContext:
runAsGroup: {{ $runAsGroup }}
fsGroup: {{ $fsGroup }}
runAsNonRoot: {{ $runAsNonRoot }}
{{- if hasKey $context "seccompProfile" }}
seccompProfile:
type: {{ $context.seccompProfile.type }}
Comment on lines +16 to +18
{{- end }}
{{- end -}}

{{- define "common.security.containerContext" -}}
{{- $pod := default (dict) .Values.securityContext -}}
{{- $ctr := default (dict) .Values.containerSecurityContext -}}

{{/*
Cascade each field: use container value if explicitly set,
otherwise fall back to pod value, otherwise use secure default.
*/}}
{{- $runAsNonRoot := ternary $ctr.runAsNonRoot (ternary $pod.runAsNonRoot true (hasKey $pod "runAsNonRoot")) (hasKey $ctr "runAsNonRoot") -}}
{{- $runAsUser := ternary $ctr.runAsUser (ternary $pod.runAsUser 1001 (hasKey $pod "runAsUser")) (hasKey $ctr "runAsUser") -}}
{{- $seccomp := ternary $ctr.seccompProfile (ternary $pod.seccompProfile nil (hasKey $pod "seccompProfile")) (hasKey $ctr "seccompProfile") -}}

{{/*
Container-only fields — no pod-level equivalent to cascade from,
so fall back directly to CIS-compliant secure defaults.
*/}}

{{- $allowPrivEsc := ternary $ctr.allowPrivilegeEscalation false (hasKey $ctr "allowPrivilegeEscalation") -}}
{{- $readOnlyRoot := ternary $ctr.readOnlyRootFilesystem true (hasKey $ctr "readOnlyRootFilesystem") -}}

securityContext:
runAsNonRoot: {{ $runAsNonRoot }}
runAsUser: {{ $runAsUser }}
allowPrivilegeEscalation: {{ $allowPrivEsc }}
readOnlyRootFilesystem: {{ $readOnlyRoot }}
{{- if and .Values.containerSecurityContext (hasKey $ctr "capabilities") }}
capabilities:
{{- toYaml $ctr.capabilities | nindent 4 }}
{{- end }}
Comment on lines +41 to +50
{{- if $seccomp }}
seccompProfile:
type: {{ $seccomp.type }}
{{- end }}
{{- end -}}

{{- define "common.security.context" -}}
{{- include "common.security.podContext" . -}}
{{- end -}}

Loading