From ce5486a8d625580fa694af83062a1fb794bc3c12 Mon Sep 17 00:00:00 2001 From: John Murret Date: Mon, 7 Feb 2022 20:19:04 -0700 Subject: [PATCH] Extracting ip_sans and alt_names code intohelper functions. --- charts/consul/templates/_helpers.tpl | 14 +++++++++++--- charts/consul/test/unit/server-statefulset.bats | 8 ++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/charts/consul/templates/_helpers.tpl b/charts/consul/templates/_helpers.tpl index 5f4c52d570..277f744d08 100644 --- a/charts/consul/templates/_helpers.tpl +++ b/charts/consul/templates/_helpers.tpl @@ -32,7 +32,7 @@ as well as the global.name setting. {{- define "consul.serverTLSCertTemplate" -}} | {{ "{{" }}- with secret "{{ .Values.server.serverCert.secretName }}" "{{ printf "common_name=server.%s.%s" .Values.global.datacenter .Values.global.domain }}" - "ttl=1h" "alt_names={{ include "consul.serverTLSAltNames" . }}{{- if .Values.server.tls -}}{{- if .Values.server.tls.serverAdditionalDNSSANs -}}{{- range $san := .Values.server.tls.serverAdditionalDNSSANs }},{{ $san }} {{- end -}}{{- end -}}{{- end -}}" "ip_sans=127.0.0.1{{- if .Values.server.tls -}}{{- if .Values.server.tls.serverAdditionalIPSANs -}}{{- range $ipsan := .Values.server.tls.serverAdditionalIPSANs }},{{ $ipsan }} {{- end -}}{{- end -}}{{- end -}}" -{{ "}}" }} + "ttl=1h" "alt_names={{ include "consul.serverTLSAltNames" . }}" "ip_sans=127.0.0.1{{ include "consul.serverAdditionalIPSANs" . }}" -{{ "}}" }} {{ "{{" }}- .Data.certificate -{{ "}}" }} {{ "{{" }}- end -{{ "}}" }} {{- end -}} @@ -40,7 +40,7 @@ as well as the global.name setting. {{- define "consul.serverTLSKeyTemplate" -}} | {{ "{{" }}- with secret "{{ .Values.server.serverCert.secretName }}" "{{ printf "common_name=server.%s.%s" .Values.global.datacenter .Values.global.domain }}" - "ttl=1h" "alt_names={{ include "consul.serverTLSAltNames" . }}{{- if .Values.server.tls -}}{{- if .Values.server.tls.serverAdditionalDNSSANs -}}{{- range $san := .Values.server.tls.serverAdditionalDNSSANs }},{{ $san }} {{- end -}}{{- end -}}{{- end -}}" "ip_sans=127.0.0.1{{- if .Values.server.tls -}}{{- if .Values.server.tls.serverAdditionalIPSANs -}}{{- range $ipsan := .Values.server.tls.serverAdditionalIPSANs }},{{ $ipsan }} {{- end -}}{{- end -}}{{- end -}}" -{{ "}}" }} + "ttl=1h" "alt_names={{ include "consul.serverTLSAltNames" . }}" "ip_sans=127.0.0.1{{ include "consul.serverAdditionalIPSANs" . }}" -{{ "}}" }} {{ "{{" }}- .Data.private_key -{{ "}}" }} {{ "{{" }}- end -{{ "}}" }} {{- end -}} @@ -48,7 +48,15 @@ as well as the global.name setting. {{- define "consul.serverTLSAltNames" -}} {{- $name := include "consul.fullname" . -}} {{- $ns := .Release.Namespace -}} -{{ printf "localhost,%s-server,*.%s-server,*.%s-server.%s,*.%s-server.%s.svc,*.server.%s.%s" $name $name $name $ns $name $ns (.Values.global.datacenter ) (.Values.global.domain) }} +{{ printf "localhost,%s-server,*.%s-server,*.%s-server.%s,*.%s-server.%s.svc,*.server.%s.%s" $name $name $name $ns $name $ns (.Values.global.datacenter ) (.Values.global.domain) }}{{ include "consul.serverAdditionalDNSSANs" . }} +{{- end -}} + +{{- define "consul.serverAdditionalDNSSANs" -}} +{{- if .Values.global.tls -}}{{- if .Values.global.tls.serverAdditionalDNSSANs -}}{{- range $san := .Values.global.tls.serverAdditionalDNSSANs }},{{ $san }} {{- end -}}{{- end -}}{{- end -}} +{{- end -}} + +{{- define "consul.serverAdditionalIPSANs" -}} +{{- if .Values.global.tls -}}{{- if .Values.global.tls.serverAdditionalIPSANs -}}{{- range $ipsan := .Values.global.tls.serverAdditionalIPSANs }},{{ $ipsan }} {{- end -}}{{- end -}}{{- end -}} {{- end -}} {{/* diff --git a/charts/consul/test/unit/server-statefulset.bats b/charts/consul/test/unit/server-statefulset.bats index 7da8dc068e..65e3abe511 100755 --- a/charts/consul/test/unit/server-statefulset.bats +++ b/charts/consul/test/unit/server-statefulset.bats @@ -1799,8 +1799,8 @@ load _helpers --set 'global.secretsBackend.vault.consulCARole=test' \ --set 'global.tls.caCert.secretName=pki_int/cert/ca' \ --set 'server.serverCert.secretName=pki_int/issue/test' \ - --set 'server.tls.serverAdditionalDNSSANs[0]=*.foo.com' \ - --set 'server.tls.serverAdditionalDNSSANs[1]=*.bar.com' \ + --set 'global.tls.serverAdditionalDNSSANs[0]=*.foo.com' \ + --set 'global.tls.serverAdditionalDNSSANs[1]=*.bar.com' \ . | tee /dev/stderr | yq -r '.spec.template' | tee /dev/stderr) @@ -1828,8 +1828,8 @@ load _helpers --set 'global.secretsBackend.vault.consulCARole=test' \ --set 'global.tls.caCert.secretName=pki_int/cert/ca' \ --set 'server.serverCert.secretName=pki_int/issue/test' \ - --set 'server.tls.serverAdditionalIPSANs[0]=1.1.1.1' \ - --set 'server.tls.serverAdditionalIPSANs[1]=2.2.2.2' \ + --set 'global.tls.serverAdditionalIPSANs[0]=1.1.1.1' \ + --set 'global.tls.serverAdditionalIPSANs[1]=2.2.2.2' \ . | tee /dev/stderr | yq -r '.spec.template' | tee /dev/stderr)