From 9af2ef9f62a1510e945510539da64bcb3092b1c7 Mon Sep 17 00:00:00 2001 From: Pete Birley Date: Sat, 6 Apr 2019 14:07:42 -0400 Subject: [PATCH] HTK: Update k8s-entrypoint container macro to add security context This PS updates the htk k8s-entrypoint container macro to add security context, with a set of defaults to allow operation with existing charts. Change-Id: Ib41600e2e3c848ae0d62181ad7e01f3cf00a26a0 Signed-off-by: Pete Birley --- .../_kubernetes_entrypoint_init_container.tpl | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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: