Skip to content

Commit 63f9926

Browse files
authored
feat(keycloak): allow overriding the database host/port/properties (#2907)
## What this PR does Makes the Keycloak database connection target configurable, so the connection can be routed through an external endpoint (for example a connection proxy such as PgBouncer or another pgwire proxy) without forking the chart: - `db.host` / `db.port` — override the host/port otherwise read from the `keycloak-db-app` secret. - `db.urlProperties` — sets `KC_DB_URL_PROPERTIES` (previously never set), e.g. `?sslmode=verify-full&prepareThreshold=0&sslrootcert=/etc/keycloak-db-ca/ca.crt`. - `extraVolumes` / `extraVolumeMounts` — mount additional volumes on the Keycloak container (e.g. a CA for `sslrootcert`). All new values default to empty, so the rendered StatefulSet is byte-for-byte unchanged for existing installs (verified with `helm template`). Credentials and database name are still taken from the `keycloak-db-app` secret. ### Release note ```release-note feat(keycloak): allow overriding the database host/port/URL properties (db.host, db.port, db.urlProperties) and add extraVolumes/extraVolumeMounts, so the DB connection can be routed through an external proxy ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Keycloak database host and port are now configurable through deployment values * Added support for custom database connection properties * Enhanced container storage configuration with additional volume and mount options <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 4593b72 + bc52d81 commit 63f9926

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

‎packages/system/keycloak/templates/sts.yaml‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,23 @@ spec:
142142
- name: KC_DB
143143
value: "postgres"
144144
- name: KC_DB_URL_HOST
145+
{{- if .Values.db.host }}
146+
value: {{ .Values.db.host | quote }}
147+
{{- else }}
145148
valueFrom:
146149
secretKeyRef:
147150
name: keycloak-db-app
148151
key: "host"
152+
{{- end }}
149153
- name: KC_DB_URL_PORT
154+
{{- if .Values.db.port }}
155+
value: {{ .Values.db.port | quote }}
156+
{{- else }}
150157
valueFrom:
151158
secretKeyRef:
152159
name: keycloak-db-app
153160
key: "port"
161+
{{- end }}
154162
- name: KC_DB_USERNAME
155163
valueFrom:
156164
secretKeyRef:
@@ -166,6 +174,10 @@ spec:
166174
secretKeyRef:
167175
name: keycloak-db-app
168176
key: "dbname"
177+
{{- with .Values.db.urlProperties }}
178+
- name: KC_DB_URL_PROPERTIES
179+
value: {{ . | quote }}
180+
{{- end }}
169181
- name: KC_FEATURES
170182
value: "docker"
171183
- name: KC_HOSTNAME
@@ -175,10 +187,15 @@ spec:
175187
{{- with .Values.extraEnv }}
176188
{{- toYaml . | nindent 12 }}
177189
{{- end }}
178-
{{- if .Values.themes }}
190+
{{- if or .Values.themes .Values.extraVolumeMounts }}
179191
volumeMounts:
192+
{{- if .Values.themes }}
180193
- name: themes
181194
mountPath: /opt/keycloak/themes
195+
{{- end }}
196+
{{- with .Values.extraVolumeMounts }}
197+
{{- toYaml . | nindent 12 }}
198+
{{- end }}
182199
{{- end }}
183200
ports:
184201
- name: http
@@ -207,10 +224,15 @@ spec:
207224
periodSeconds: 10
208225
timeoutSeconds: 5
209226
failureThreshold: 3
210-
{{- if .Values.themes }}
227+
{{- if or .Values.themes .Values.extraVolumes }}
211228
volumes:
229+
{{- if .Values.themes }}
212230
- name: themes
213231
emptyDir:
214232
sizeLimit: 256Mi
233+
{{- end }}
234+
{{- with .Values.extraVolumes }}
235+
{{- toYaml . | nindent 8 }}
236+
{{- end }}
215237
{{- end }}
216238
terminationGracePeriodSeconds: 60

‎packages/system/keycloak/values.yaml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ extraEnv: []
3939
# secretKeyRef:
4040
# name: my-secret
4141
# key: my-key
42+
43+
# Database connection. By default Keycloak connects directly to the chart's
44+
# CNPG cluster using the keycloak-db-app secret. Override these to route the
45+
# connection through an external endpoint (e.g. a connection proxy such as
46+
# PgBouncer) without the chart needing to know about it.
47+
db:
48+
# DB host. Empty = use the keycloak-db-app secret's "host" key.
49+
host: ""
50+
# DB port. Empty = use the keycloak-db-app secret's "port" key.
51+
port: ""
52+
# Extra JDBC URL properties, appended verbatim as KC_DB_URL_PROPERTIES, e.g.
53+
# "?sslmode=verify-full&prepareThreshold=0&sslrootcert=/etc/keycloak-db-ca/ca.crt"
54+
# Empty = KC_DB_URL_PROPERTIES is not set.
55+
urlProperties: ""
56+
57+
# Extra volumes and volume mounts on the Keycloak container (in addition to
58+
# themes). Useful for mounting a CA so KC_DB_URL_PROPERTIES can reference an
59+
# sslrootcert when routing the DB connection through a proxy.
60+
extraVolumes: []
61+
# - name: keycloak-db-ca
62+
# secret:
63+
# secretName: keycloak-db-ca
64+
extraVolumeMounts: []
65+
# - name: keycloak-db-ca
66+
# mountPath: /etc/keycloak-db-ca
67+
# readOnly: true

0 commit comments

Comments
 (0)