Skip to content

Commit bd8ea31

Browse files
authored
DEVOPS-3030-added-support-custom-ca (#138)
1 parent 808f46b commit bd8ea31

File tree

6 files changed

+118
-4
lines changed

6 files changed

+118
-4
lines changed

.pipelines/helm-chart-validation.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ steps:
7070
password: test123
7171
redis:
7272
password: test123
73+
customCa:
74+
customCaCertificate: $(CUSTOM_CA_CERTIFICATE)
7375
defaults:
7476
dockerhub_config:
7577
configContent: $(DOCKERHUB_CONFIG)
@@ -181,6 +183,27 @@ steps:
181183
fi
182184
displayName: 'Validate Templates'
183185

186+
- script: |
187+
set -euo pipefail
188+
189+
echo "Verifying Keycloak custom CA volume mount in Helm template"
190+
191+
# Redirect output to file
192+
helm template $(RELEASE_NAME) $(CHART_PATH) -f values.yaml --namespace $(NAMESPACE) > template_output.yaml 2>&1
193+
194+
KEYCLOAK_CONTAINER="${RELEASE_NAME}-keycloak"
195+
196+
# Extract volume mounts for container $(RELEASE_NAME)-keycloak from the rendered template file
197+
VOLUME_MOUNTS=$(yq e ".spec.template.spec.containers[] | select(.name==\"$KEYCLOAK_CONTAINER\") | .volumeMounts[].name" template_output.yaml)
198+
199+
if echo "$VOLUME_MOUNTS" | grep -q "^custom-ca-certificate$"; then
200+
echo "Found 'custom-ca-certificate' volume mount in Helm template as expected"
201+
else
202+
echo "Missing 'custom-ca-certificate' volume mount in Helm template"
203+
exit 1
204+
fi
205+
displayName: 'Check Keycloak custom CA volume in Helm template'
206+
184207
- script: |
185208
set -euo pipefail
186209
kubectl create namespace $(NAMESPACE)

chart/templates/helpers/_helpers.tpl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ Usage:
460460
{{- end -}}
461461
{{- end -}}
462462

463-
464463
{{- define "secrets.certificate.name" -}}
465464
{{- if .Values.certificate.existing_cert -}}
466465
{{ .Values.certificate.existing_cert }}
@@ -510,6 +509,30 @@ Usage:
510509
{{- end -}}
511510

512511

512+
{{- define "secrets.custom_ca_certificate.enabled" -}}
513+
{{- if and .Values.secrets.customCa.customCaCertificate .Values.secrets.customCa.existingCaSecret }}
514+
{{- fail "You must set only one of secrets.customCa.customCaCertificate or secrets.customCa.existingCaSecret" }}
515+
{{- else if and (not (include "secrets.deploy_secrets" .)) .Values.secrets.customCa.customCaCertificate }}
516+
{{- fail "deploy_secrets must be true if customCaCertificate is defined" }}
517+
{{- else if and (include "secrets.deploy_secrets" .) .Values.secrets.customCa.customCaCertificate (not .Values.secrets.customCa.existingCaSecret) }}
518+
true
519+
{{- else if and .Values.secrets.customCa.existingCaSecret (not .Values.secrets.customCa.customCaCertificate) }}
520+
true
521+
{{- else -}}
522+
false
523+
{{- end -}}
524+
{{- end -}}
525+
526+
527+
{{- define "secrets.custom_ca_certificate.name" -}}
528+
{{- if .Values.secrets.customCa.existingCaSecret -}}
529+
{{ .Values.secrets.customCa.existingCaSecret }}
530+
{{- else -}}
531+
{{ include "lightrun.fullname" . }}-custom-ca-certificate
532+
{{- end -}}
533+
{{- end -}}
534+
535+
513536
{{/*
514537
#####################
515538
### JVM Heap size ###
@@ -898,5 +921,3 @@ Usage: {{ include "lightrun.datadogAnnotations" (dict "serviceName" "lightrun-be
898921
}
899922
{{- end }}
900923
{{- end }}
901-
902-

chart/templates/keycloak-statefulset.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ spec:
112112
.Values.general.internal_tls.enabled
113113
.Values.deployments.keycloak.extraVolumeMounts
114114
.Values.deployments.keycloak.asyncProfiler.enabled
115+
(include "secrets.custom_ca_certificate.enabled" . | trim | eq "true")
115116
}}
116117
volumeMounts:
117118
{{- include "lightrun-keycloak.volumeMounts.asyncProfiler" . | nindent 12 }}
@@ -127,6 +128,11 @@ spec:
127128
mountPath: /opt
128129
subPath: opt
129130
{{- end }}
131+
{{- if (include "secrets.custom_ca_certificate.enabled" . | trim | eq "true") }}
132+
- name: custom-ca-certificate
133+
mountPath: /opt/keycloak/conf/truststores
134+
readOnly: true
135+
{{- end }}
130136
{{- if .Values.general.internal_tls.enabled }}
131137
- name: internal-cert
132138
mountPath: /etc/x509/https/
@@ -356,6 +362,7 @@ spec:
356362
.Values.general.internal_tls.enabled
357363
.Values.deployments.keycloak.extraVolumes
358364
.Values.deployments.keycloak.asyncProfiler.enabled
365+
(include "secrets.custom_ca_certificate.enabled" . | trim | eq "true")
359366
}}
360367
volumes:
361368
{{- include "lightrun-keycloak.volumes.asyncProfiler" . | nindent 8 }}
@@ -368,6 +375,11 @@ spec:
368375
emptyDir:
369376
sizeLimit: {{ .Values.general.readOnlyRootFilesystem_tmpfs_sizeLimit }}
370377
{{ end }}
378+
{{- if (include "secrets.custom_ca_certificate.enabled" . | trim | eq "true") }}
379+
- name: custom-ca-certificate
380+
secret:
381+
secretName: {{ include "secrets.custom_ca_certificate.name" . }}
382+
{{ end }}
371383
{{- if .Values.general.internal_tls.enabled }}
372384
- name: internal-cert
373385
secret:

chart/templates/secrets.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,15 @@ stringData:
8989
KEYCLOAK_USER: admin
9090
KEYCLOAK_PASSWORD: {{ .Values.secrets.keycloak.password | quote }}
9191
DB_USER: {{ .Values.secrets.db.user | quote }}
92-
DB_PASSWORD: {{ .Values.secrets.db.password | quote}}
92+
DB_PASSWORD: {{ .Values.secrets.db.password | quote }}
93+
---
94+
{{- if and .Values.secrets.customCa.customCaCertificate (not .Values.secrets.customCa.existingCaSecret) }}
95+
apiVersion: v1
96+
kind: Secret
97+
metadata:
98+
name: {{ include "secrets.custom_ca_certificate.name" . }}
99+
type: Opaque
100+
data:
101+
custom-ca.pem: {{ .Values.secrets.customCa.customCaCertificate }}
102+
{{ end }}
93103
{{ end }}

chart/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ secrets:
478478
# redis authentication.
479479
# requires to enable auth in deployments.redis.auth.enabled by set to true
480480
password: ""
481+
customCa:
482+
# Optional | If empty, will not be used
483+
# Only *one* of `customCaCertificate` and `existingCaSecret` can be set at a time:
484+
# Setting both will cause Helm to fail during rendering.
485+
customCaCertificate: "" # Base64-encoded CA certificate content.
486+
existingCaSecret: "" # Name of an existing Kubernetes secret containing the CA certificate.
481487
license:
482488
content: ""
483489
signature: ""
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Custom CA Certificate
2+
3+
4+
The `customCa` block allows you to provide a custom Certificate Authority (CA) certificate to the application. This is optional — if no values are provided, no custom CA will be used.
5+
6+
> [!NOTE]
7+
> The certificate is loaded by Keycloak and required when using LDAP integration with a custom CA certificate.
8+
9+
10+
```yaml
11+
secrets:
12+
customCa:
13+
customCaCertificate: "" # Base64-encoded CA certificate content.
14+
existingCaSecret: "" # Name of an existing Kubernetes secret containing the CA certificate.
15+
```
16+
17+
### Option 1: Provide the CA certificate directly
18+
19+
Use `customCaCertificate` to provide the base64-encoded content of your CA certificate.
20+
A new Kubernetes Secret will be automatically created by the Helm chart.
21+
22+
`existingCaSecret` must not be set.
23+
24+
```yaml
25+
secrets:
26+
customCa:
27+
customCaCertificate: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t..."
28+
```
29+
30+
### Option 2: Use an existing Kubernetes Secret
31+
32+
Use `existingCaSecret` to reference an existing secret that contains your CA certificate. The secret key must be base64 encoded.
33+
34+
`customCaCertificate` must not be set.
35+
36+
37+
```yaml
38+
secrets:
39+
customCa:
40+
existingCaSecret: "<my-custom-ca-secret>"
41+
```
42+

0 commit comments

Comments
 (0)