diff --git a/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl b/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl index 3bcd753d4..4500a0adb 100644 --- a/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl +++ b/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl @@ -50,12 +50,34 @@ values: | etcd: hosts: default: etcd + # NOTE (portdirect): if the stanza, or a portion of it, under `pod` is not + # specififed then the following will be used as defaults: + # pod: + # security_context: + # kubernetes_entrypoint: + # container: + # kubernetes_entrypoint: + # runAsUser: 65534 + # readOnlyRootFilesystem: true + # allowPrivilegeEscalation: false + pod: + security_context: + kubernetes_entrypoint: + container: + kubernetes_entrypoint: + runAsUser: 0 + readOnlyRootFilesystem: false usage: | {{ tuple . "calico_node" list | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" }} return: | - name: init image: "quay.io/stackanetes/kubernetes-entrypoint:v0.3.1" imagePullPolicy: IfNotPresent + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: false + runAsUser: 0 + env: - name: POD_NAME valueFrom: @@ -89,6 +111,18 @@ return: | [] */}} +{{- define "helm-toolkit.snippets.kubernetes_entrypoint_init_container._default_security_context" -}} +Values: + pod: + security_context: + kubernetes_entrypoint: + container: + kubernetes_entrypoint: + runAsUser: 65534 + readOnlyRootFilesystem: true + allowPrivilegeEscalation: false +{{- end -}} + {{- define "helm-toolkit.snippets.kubernetes_entrypoint_init_container" -}} {{- $envAll := index . 0 -}} {{- $component := index . 1 -}} @@ -110,9 +144,11 @@ return: | {{- end -}} {{- end -}} {{- $deps := $envAll.Values.__kubernetes_entrypoint_init_container.deps }} - +{{- $default_security_context := include "helm-toolkit.snippets.kubernetes_entrypoint_init_container._default_security_context" . | fromYaml }} +{{- $patchedEnvAll := mergeOverwrite $default_security_context $envAll }} - name: init {{ tuple $envAll "dep_check" | include "helm-toolkit.snippets.image" | indent 2 }} +{{- dict "envAll" $patchedEnvAll "application" "kubernetes_entrypoint" "container" "kubernetes_entrypoint" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 2 }} env: - name: POD_NAME valueFrom: