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: 1 addition & 1 deletion charts/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ maintainers:
- email: alex@kharkevich.org
name: Alexander Kharkevich
name: common
version: 2.3.0
version: 2.4.0
1 change: 1 addition & 0 deletions charts/common/templates/_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
name: app
image: "{{ default "ghcr.io/technicaldomain" .Values.image.registry }}/{{ .Values.image.name }}:{{ .Values.image.tag | default (include "common.chart.appVersion" .) }}"
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
{{ include "common.security.containerContext" . -}}
{{- with .Values.command }}
command:
{{- toYaml . | nindent 2 }}
Expand Down
34 changes: 34 additions & 0 deletions charts/common/templates/_security_context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,38 @@ securityContext:
runAsGroup: {{ $runAsGroup }}
fsGroup: {{ $fsGroup }}
runAsNonRoot: {{ $runAsNonRoot }}
{{- with $context.seccompProfile }}
seccompProfile:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}}

{{- /*
Container-level security context - rendered at containers[*].securityContext.
Rendered only when `.Values.containerSecurityContext` is set. Each field falls
back: container value -> pod-level value -> secure default.
*/ -}}
{{- define "common.security.containerContext" -}}
{{- $pod := default (dict) .Values.securityContext -}}
{{- $ctr := default (dict) .Values.containerSecurityContext -}}
{{- if $ctr -}}
{{- $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") -}}
{{- $allowPrivEsc := ternary $ctr.allowPrivilegeEscalation false (hasKey $ctr "allowPrivilegeEscalation") -}}
{{- $readOnlyRoot := ternary $ctr.readOnlyRootFilesystem true (hasKey $ctr "readOnlyRootFilesystem") -}}
{{- $seccomp := ternary $ctr.seccompProfile (ternary $pod.seccompProfile nil (hasKey $pod "seccompProfile")) (hasKey $ctr "seccompProfile") -}}
securityContext:
runAsNonRoot: {{ $runAsNonRoot }}
runAsUser: {{ $runAsUser }}
allowPrivilegeEscalation: {{ $allowPrivEsc }}
readOnlyRootFilesystem: {{ $readOnlyRoot }}
{{- if hasKey $ctr "capabilities" }}
capabilities:
{{- toYaml $ctr.capabilities | nindent 4 }}
{{- end }}
{{- if $seccomp }}
seccompProfile:
{{- toYaml $seccomp | nindent 4 }}
{{- end }}
{{- end -}}
{{- end -}}