Skip to content

Commit 4a0dfe3

Browse files
author
Frederic Spiers
committed
feat(helm): prepare certificate refactor
1 parent 802735c commit 4a0dfe3

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

helm/ggbridge/templates/_helpers.tpl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,17 @@ Returns cert-manager issuer spec for TLS config
566566
{{- $fullname := include "ggbridge.fullname" . -}}
567567
{{- $spec := dict -}}
568568
{{- if hasKey .Values.tls.certManager.issuer.spec "vault" -}}
569-
{{- $spec = dict "vault" (dict "auth" (dict "kubernetes" (dict "secretRef" (dict "name" (printf "%s-issuer-token" $fullname) "key" "token")))) -}}
569+
{{- $userKubernetesAuth := dig "vault" "auth" "kubernetes" dict .Values.tls.certManager.issuer.spec -}}
570+
{{- $kubernetesAuth := dict -}}
571+
572+
{{/* Only add secretRef if user hasn't provided secretRef OR serviceAccountRef */}}
573+
{{- if and (not (hasKey $userKubernetesAuth "secretRef")) (not (hasKey $userKubernetesAuth "serviceAccountRef")) -}}
574+
{{- $_ := set $kubernetesAuth "secretRef" (dict "name" (printf "%s-issuer-token" $fullname) "key" "token") -}}
575+
{{- end -}}
576+
577+
{{- $spec = dict "vault" (dict "auth" (dict "kubernetes" $kubernetesAuth)) -}}
570578
{{- end -}}
571-
{{- $spec = include "ggbridge.tplvalues.merge" ( dict "values" ( list .Values.tls.certManager.issuer.spec $spec ) "context" . ) | fromYaml -}}
579+
{{- $spec = include "ggbridge.tplvalues.merge" ( dict "values" ( list $spec .Values.tls.certManager.issuer.spec ) "context" . ) | fromYaml -}}
572580
{{ include "ggbridge.tplvalues.render" ( dict "value" $spec "context" .) }}
573581
{{- end -}}
574582

helm/ggbridge/templates/cert-manager.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{{- if .Values.tls.certManager.enabled -}}
2-
{{- $fullname := include "ggbridge.fullname" . -}}
3-
{{- $namespace := ternary (default .Release.Namespace .Values.server.istio.gateway.namespace) .Release.Namespace .Values.server.istio.enabled -}}
1+
{{- $fullname := include "ggbridge.fullname" . -}}
2+
{{- $namespace := ternary (default .Release.Namespace .Values.server.istio.gateway.namespace) .Release.Namespace .Values.server.istio.enabled -}}
3+
{{- if and .Values.tls.certManager.enabled (not (hasKey .Values.tls.certManager.issuer.spec "vault")) -}}
44
{{- if .Values.tls.certManager.issuer.spec }}
55
{{- if hasKey .Values.tls.certManager.issuer.spec "selfSigned" -}}
66
---
@@ -69,3 +69,18 @@ spec:
6969
{{- end }}
7070
{{- end }}
7171
{{- end }}
72+
{{- if hasKey .Values.tls.certManager.issuer.spec "vault" }}
73+
---
74+
apiVersion: cert-manager.io/v1
75+
kind: Issuer
76+
metadata:
77+
name: {{ printf "%s-issuer" $fullname }}
78+
namespace: {{ $namespace }}
79+
labels:
80+
{{- include "ggbridge.labels" $ | nindent 4 }}
81+
{{- if .Values.commonAnnotations }}
82+
annotations: {{- include "ggbridge.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" . ) | nindent 4 }}
83+
{{- end }}
84+
spec:
85+
{{- include "ggbridge.certManager.issuer.spec" . | nindent 2 }}
86+
{{- end }}

helm/ggbridge/templates/client/cert-manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.tls.certManager.enabled -}}
1+
{{- if and .Values.tls.certManager.enabled (and (not (empty .Values.tls.certManager.issuer.spec)) (not (hasKey .Values.tls.certManager.issuer.spec "vault"))) -}}
22
{{- $fullname := include "ggbridge.fullname" . -}}
33
{{- $namespace := ternary (default .Release.Namespace .Values.server.istio.gateway.namespace) .Release.Namespace .Values.server.istio.enabled -}}
44
{{- $clientFullname := include "ggbridge.client.fullname" $ -}}

helm/ggbridge/templates/rbac.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,21 @@ metadata:
4545
annotations:
4646
kubernetes.io/service-account.name: {{ printf "%s-issuer" $fullname }}
4747
type: kubernetes.io/service-account-token
48+
---
49+
apiVersion: rbac.authorization.k8s.io/v1
50+
kind: ClusterRoleBinding
51+
metadata:
52+
name: {{ printf "%s-issuer" $fullname }}-token-reviewer
53+
roleRef:
54+
apiGroup: rbac.authorization.k8s.io
55+
kind: ClusterRole
56+
name: system:auth-delegator
57+
subjects:
58+
- kind: ServiceAccount
59+
name: {{ printf "%s-issuer" $fullname }}
60+
namespace: {{ .Release.Namespace }}
4861
{{- end }}
62+
{{- if .Values.tls.certManager.rbac.subjects }}
4963
---
5064
apiVersion: rbac.authorization.k8s.io/v1
5165
kind: Role
@@ -79,7 +93,6 @@ rules:
7993
- 'list'
8094
- 'watch'
8195
- 'create'
82-
{{- if .Values.tls.certManager.rbac.subjects }}
8396
---
8497
apiVersion: rbac.authorization.k8s.io/v1
8598
kind: RoleBinding

0 commit comments

Comments
 (0)