mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
feat(platform): make the Keycloak public host configurable
Keycloak's own chart already accepts ingress.host, but the OIDC consumers rebuild the issuer as keycloak.<root-host> on their own. Moving Keycloak to another hostname therefore changed the issuer of every token while the dashboard and linstor-gui gatekeepers, Grafana, the info kubeconfig and tenant clusters in oidc.mode System kept expecting the old one, and SSO broke everywhere at once. authentication.oidc.keycloakHost resolves the host once in the platform and publishes it as _cluster.keycloak-host, which Keycloak (Ingress, HTTPRoute, KC_HOSTNAME) and every consumer read. Left empty it resolves to keycloak.<root-host>, so existing clusters render unchanged. The kind is checked before any default, since `default` treats false and 0 as unset and would silently fall back to the derived host. An explicit host must also respect the RFC 1123 label and total length limits. Setting the chart's ingress.host and a different non-default keycloakHost is refused, as KC_HOSTNAME and the consumers' issuer would disagree; a legacy ingress.host alone keeps working. Any valid DNS name is accepted, including all-digit labels and words such as true, so the host is quoted wherever it is rendered; unquoted it turns into a YAML number or bool and the Ingress no longer decodes. The Gateway path's whole-apex cert modes render listeners for the apex only, and the Keycloak chart cannot see the TenantGateway cert mode to refuse an out-of-apex host, so that constraint is documented next to the setting. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
This commit is contained in:
20 files changed
+456
-24
No files matched your search
@@ -120,12 +120,14 @@ scope from packages/system/keycloak-configure.
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Issuer URL for `mode: System`. Resolves to the platform Keycloak realm
|
||||
`cozy`, served at the root host published in the per-namespace bundle by
|
||||
cozystack-basics.
|
||||
Issuer URL for `mode: System`. Resolves to the platform Keycloak realm,
|
||||
served at the keycloak-host published in the per-namespace bundle by
|
||||
cozystack-basics (keycloak.<root-host> when the platform does not set one).
|
||||
*/}}
|
||||
{{- define "kubernetes.oidc.systemIssuerURL" -}}
|
||||
{{- printf "https://keycloak.%s/realms/%s" (dig "root-host" "" (.Values._cluster | default dict)) (dig "oidc-realm-name" "cozy" (.Values._cluster | default dict) | toString) }}
|
||||
{{- $cluster := .Values._cluster | default dict }}
|
||||
{{- $keycloakHost := dig "keycloak-host" "" $cluster | default (printf "keycloak.%s" (dig "root-host" "" $cluster)) }}
|
||||
{{- printf "https://%s/realms/%s" $keycloakHost (dig "oidc-realm-name" "cozy" $cluster | toString) }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
|
||||
@@ -2929,3 +2929,23 @@ tests:
|
||||
- notMatchRegex:
|
||||
path: stringData["config.yaml"]
|
||||
pattern: "group in the cozy realm"
|
||||
|
||||
# The guest apiserver must trust the issuer Keycloak actually signs with,
|
||||
# which is https://<_cluster.keycloak-host>/realms/<realm>.
|
||||
- it: System mode points the issuer at a custom keycloak-host
|
||||
release:
|
||||
name: kubernetes-app
|
||||
namespace: tenant-foo
|
||||
template: templates/oidc-authn-config.yaml
|
||||
set:
|
||||
_cluster.oidc-enabled: "true"
|
||||
_cluster.root-host: example.org
|
||||
_cluster.keycloak-host: auth.example.org
|
||||
oidc.mode: System
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData["config.yaml"]
|
||||
pattern: "url: https://auth.example.org/realms/cozy"
|
||||
- notMatchRegex:
|
||||
path: stringData["config.yaml"]
|
||||
pattern: "keycloak.example.org"
|
||||
@@ -146,6 +146,27 @@ stringData:
|
||||
{{- fail "authentication.oidc.realmName must not be master: that realm holds the Keycloak super-admin, so platform clients and end users would share it. Pick any other name, e.g. realmName: \"cozy\"" }}
|
||||
{{- end }}
|
||||
oidc-realm-name: {{ $realmName | quote }}
|
||||
{{- /* Resolved here so every consumer reads one ready-made value instead
|
||||
of re-deriving keycloak.<root-host>. An explicit value is spliced
|
||||
into URLs and an oauth2-proxy --whitelist-domain flag, so only a
|
||||
bare lowercase DNS name within the RFC 1123 length limits is
|
||||
accepted: a scheme, port or path would yield an issuer that
|
||||
matches nothing. The kind is checked before `default`, which would
|
||||
otherwise launder false or 0 into the derived host. The derived
|
||||
keycloak.<root-host> is not validated, so clusters that never set
|
||||
this key render exactly as before. */}}
|
||||
{{- $keycloakHost := .Values.authentication.oidc.keycloakHost }}
|
||||
{{- if not (or (kindIs "invalid" $keycloakHost) (kindIs "string" $keycloakHost)) }}
|
||||
{{- fail (printf "authentication.oidc.keycloakHost must be a string (got %s)" (kindOf $keycloakHost)) }}
|
||||
{{- end }}
|
||||
{{- if $keycloakHost }}
|
||||
{{- if or (gt (len $keycloakHost) 253) (not (regexMatch "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$" $keycloakHost)) }}
|
||||
{{- fail (printf "authentication.oidc.keycloakHost %q is invalid: give a bare lowercase hostname such as auth.example.org, without scheme, port or path, with labels of at most 63 characters and 253 in total" $keycloakHost) }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- $keycloakHost = printf "keycloak.%s" $rootHost }}
|
||||
{{- end }}
|
||||
keycloak-host: {{ $keycloakHost | quote }}
|
||||
{{- /* null keycloakInternalUrl derives the in-cluster Service URL for the
|
||||
configured realm; "" is the external-discovery escape hatch and an
|
||||
explicit value is passed through, so distinguish null from "" with
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
suite: apps.yaml OIDC keycloak-host platform → tenant value wiring
|
||||
templates:
|
||||
- templates/apps.yaml
|
||||
|
||||
release:
|
||||
name: cozy-platform
|
||||
namespace: cozy-system
|
||||
|
||||
# authentication.oidc.keycloakHost is the single source for the host of the
|
||||
# Keycloak issuer. It rides the _cluster channel as keycloak-host, already
|
||||
# resolved, so the Keycloak chart and every OIDC consumer agree on it without
|
||||
# each re-deriving keycloak.<root-host>.
|
||||
|
||||
tests:
|
||||
- it: defaults the keycloak host to keycloak.<publishing.host>
|
||||
set:
|
||||
publishing.host: example.org
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData["values.yaml"]
|
||||
pattern: 'keycloak-host:\s*"keycloak\.example\.org"'
|
||||
|
||||
- it: propagates a custom keycloak host onto the _cluster channel
|
||||
set:
|
||||
publishing.host: example.org
|
||||
authentication.oidc.keycloakHost: auth.example.org
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData["values.yaml"]
|
||||
pattern: 'keycloak-host:\s*"auth\.example\.org"'
|
||||
|
||||
# The host is spliced after "https://" and into --whitelist-domain, so a
|
||||
# scheme would yield https://https://... and a path would shift the realm.
|
||||
- it: rejects a keycloak host carrying a scheme
|
||||
set:
|
||||
authentication.oidc.keycloakHost: https://auth.example.org
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: 'authentication.oidc.keycloakHost "https://auth.example.org" is invalid'
|
||||
|
||||
- it: rejects a keycloak host carrying a path
|
||||
set:
|
||||
authentication.oidc.keycloakHost: auth.example.org/realms
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: 'authentication.oidc.keycloakHost "auth.example.org/realms" is invalid'
|
||||
|
||||
- it: rejects a keycloak host carrying a port
|
||||
set:
|
||||
authentication.oidc.keycloakHost: auth.example.org:8443
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: 'authentication.oidc.keycloakHost "auth.example.org:8443" is invalid'
|
||||
|
||||
# `default` treats false and 0 as unset; checking the kind first keeps a
|
||||
# mistyped value from silently falling back to keycloak.<root-host>.
|
||||
- it: rejects a non-string keycloak host instead of falling back to the default
|
||||
set:
|
||||
authentication.oidc.keycloakHost: false
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: 'authentication.oidc.keycloakHost must be a string (got bool)'
|
||||
|
||||
- it: rejects a DNS label longer than 63 characters
|
||||
set:
|
||||
authentication.oidc.keycloakHost: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.example.org
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: 'authentication.oidc.keycloakHost ".*" is invalid'
|
||||
|
||||
- it: rejects a hostname longer than 253 characters
|
||||
set:
|
||||
authentication.oidc.keycloakHost: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.org
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: 'authentication.oidc.keycloakHost ".*" is invalid'
|
||||
|
||||
- it: accepts a 63-character label
|
||||
set:
|
||||
authentication.oidc.keycloakHost: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.example.org
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData["values.yaml"]
|
||||
pattern: 'keycloak-host:\s*"a{63}\.example\.org"'
|
||||
|
||||
# Both are valid DNS labels, so they must survive validation and reach the
|
||||
# _cluster channel as strings.
|
||||
- it: accepts an all-digit keycloak host
|
||||
set:
|
||||
authentication.oidc.keycloakHost: "123"
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData["values.yaml"]
|
||||
pattern: 'keycloak-host:\s*"123"'
|
||||
|
||||
- it: accepts a boolean-looking keycloak host
|
||||
set:
|
||||
authentication.oidc.keycloakHost: "true"
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData["values.yaml"]
|
||||
pattern: 'keycloak-host:\s*"true"'
|
||||
@@ -528,6 +528,27 @@ authentication:
|
||||
# it here would put the platform clients, the cluster-admin roles and every
|
||||
# end user inside it.
|
||||
realmName: "cozy"
|
||||
# Public hostname Keycloak is served on, without scheme or path. Empty means
|
||||
# keycloak.<publishing.host>. It is the host of the OIDC issuer
|
||||
# (https://<keycloakHost>/realms/<realmName>), so the Keycloak Ingress and
|
||||
# KC_HOSTNAME, the dashboard and linstor-gui gatekeepers, Grafana SSO, the
|
||||
# info kubeconfig and tenant Kubernetes clusters in oidc.mode System all
|
||||
# follow it. As with realmName, the apiserver OIDC issuer is set out-of-band
|
||||
# via talm oidcIssuerUrl and must name the same host.
|
||||
#
|
||||
# Changing it on a running cluster changes the issuer of every token minted
|
||||
# afterwards: sessions and refresh tokens issued under the old host stop
|
||||
# being accepted, and the apiserver must trust the new issuer first.
|
||||
#
|
||||
# Certificates that cover the whole apex do not stretch to a host outside
|
||||
# it. In wildcard mode (publishing.certificates.wildcard or
|
||||
# wildcardSecretName) the Keycloak Ingress relies on the wildcard
|
||||
# certificate, which covers *.<publishing.host> only; on the Gateway path
|
||||
# the dns01, existingSecret and edge cert modes render listeners for the
|
||||
# apex alone, so the Keycloak HTTPRoute finds no listener. Pick a host one
|
||||
# label under publishing.host, or provide a certificate and listener that
|
||||
# cover it.
|
||||
keycloakHost: ""
|
||||
# In-cluster URL of the KeyCloak realm, used for backend-to-backend requests. oauth2-proxy runs
|
||||
# with --skip-oidc-discovery and sends every backend call (token, jwks, userinfo, logout) to this
|
||||
# URL, while browser-facing redirects keep pointing at the external host.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{{- $host := index .Values._cluster "root-host" }}
|
||||
{{- $realm := index .Values._cluster "oidc-realm-name" | default "cozy" }}
|
||||
{{- $keycloakHost := index .Values._cluster "keycloak-host" | default (printf "keycloak.%s" $host) }}
|
||||
{{- $oidcEnabled := index .Values._cluster "oidc-enabled" }}
|
||||
{{- if $oidcEnabled }}
|
||||
{{- $apiServerEndpoint := index .Values._cluster "api-server-endpoint" }}
|
||||
@@ -36,7 +37,7 @@ stringData:
|
||||
args:
|
||||
- oidc-login
|
||||
- get-token
|
||||
- --oidc-issuer-url=https://keycloak.{{ $host }}/realms/{{ $realm }}
|
||||
- --oidc-issuer-url=https://{{ $keycloakHost }}/realms/{{ $realm }}
|
||||
- --oidc-client-id=kubernetes
|
||||
- --skip-open-browser
|
||||
command: kubectl
|
||||
|
||||
@@ -41,3 +41,19 @@ tests:
|
||||
- notMatchRegex:
|
||||
path: stringData.kubeconfig
|
||||
pattern: '/realms/cozy'
|
||||
|
||||
- it: points the issuer at a custom keycloak-host
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.org
|
||||
oidc-enabled: "true"
|
||||
keycloak-host: auth.example.org
|
||||
api-server-endpoint: https://api.example.org:6443
|
||||
kube-root-ca: dGVzdA==
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData.kubeconfig
|
||||
pattern: '--oidc-issuer-url=https://auth\.example\.org/realms/cozy'
|
||||
- notMatchRegex:
|
||||
path: stringData.kubeconfig
|
||||
pattern: 'keycloak\.example\.org'
|
||||
@@ -1,5 +1,6 @@
|
||||
{{- $host := index .Values._cluster "root-host" }}
|
||||
{{- $realm := index .Values._cluster "oidc-realm-name" | default "cozy" }}
|
||||
{{- $keycloakHost := index .Values._cluster "keycloak-host" | default (printf "keycloak.%s" $host) }}
|
||||
{{- $oidcEnabled := index .Values._cluster "oidc-enabled" }}
|
||||
{{- $keycloakInternalUrl := index .Values._cluster "keycloak-internal-url" | default "" }}
|
||||
{{- if eq $oidcEnabled "true" }}
|
||||
@@ -58,15 +59,15 @@ data:
|
||||
allow:
|
||||
- pattern: '^[A-Za-z0-9._-]+$'
|
||||
{{- if $keycloakInternalUrl }}
|
||||
loginURL: https://keycloak.{{ $host }}/realms/{{ $realm }}/protocol/openid-connect/auth
|
||||
loginURL: https://{{ $keycloakHost }}/realms/{{ $realm }}/protocol/openid-connect/auth
|
||||
redeemURL: {{ $keycloakInternalUrl }}/protocol/openid-connect/token
|
||||
validateURL: {{ $keycloakInternalUrl }}/protocol/openid-connect/userinfo
|
||||
backendLogoutURL: {{ $keycloakInternalUrl }}/protocol/openid-connect/logout?id_token_hint={id_token}
|
||||
{{- else }}
|
||||
backendLogoutURL: https://keycloak.{{ $host }}/realms/{{ $realm }}/protocol/openid-connect/logout?id_token_hint={id_token}
|
||||
backendLogoutURL: https://{{ $keycloakHost }}/realms/{{ $realm }}/protocol/openid-connect/logout?id_token_hint={id_token}
|
||||
{{- end }}
|
||||
oidcConfig:
|
||||
issuerURL: https://keycloak.{{ $host }}/realms/{{ $realm }}
|
||||
issuerURL: https://{{ $keycloakHost }}/realms/{{ $realm }}
|
||||
{{- if $keycloakInternalUrl }}
|
||||
skipDiscovery: true
|
||||
jwksURL: {{ $keycloakInternalUrl }}/protocol/openid-connect/certs
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{{- $host := index .Values._cluster "root-host" }}
|
||||
{{- $realm := index .Values._cluster "oidc-realm-name" | default "cozy" }}
|
||||
{{- $keycloakHost := index .Values._cluster "keycloak-host" | default (printf "keycloak.%s" $host) }}
|
||||
{{- $oidcEnabled := index .Values._cluster "oidc-enabled" }}
|
||||
{{- $oidcInsecureSkipVerify := index .Values._cluster "oidc-insecure-skip-verify" }}
|
||||
{{- $keycloakInternalUrl := index .Values._cluster "keycloak-internal-url" | default "" }}
|
||||
@@ -61,7 +62,7 @@ spec:
|
||||
args:
|
||||
- --alpha-config=/etc/oauth2-proxy/config/alpha-config.yaml
|
||||
- --redirect-url=https://dashboard.{{ $host }}/oauth2/callback
|
||||
- --whitelist-domain=keycloak.{{ $host }}
|
||||
- --whitelist-domain={{ $keycloakHost }}
|
||||
- --email-domain=*
|
||||
- --api-route=^/api(/|$)
|
||||
- --api-route=^/apis(/|$)
|
||||
|
||||
@@ -151,3 +151,57 @@ tests:
|
||||
- equal:
|
||||
path: spec.template.spec.containers[0].ports[0].containerPort
|
||||
value: 8000
|
||||
|
||||
# The browser-facing issuer, login URL, logout URL and redirect whitelist
|
||||
# follow _cluster.keycloak-host (authentication.oidc.keycloakHost in the
|
||||
# platform), so moving Keycloak off keycloak.<root-host> keeps dashboard SSO
|
||||
# working.
|
||||
- it: builds the browser-facing OIDC URLs on a custom keycloak-host
|
||||
template: templates/gatekeeper-config.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.org
|
||||
oidc-enabled: "true"
|
||||
keycloak-host: auth.example.org
|
||||
keycloak-internal-url: http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: data["alpha-config.yaml"]
|
||||
pattern: 'issuerURL: https://auth\.example\.org/realms/cozy\n'
|
||||
- matchRegex:
|
||||
path: data["alpha-config.yaml"]
|
||||
pattern: 'loginURL: https://auth\.example\.org/realms/cozy/protocol/openid-connect/auth\n'
|
||||
- notMatchRegex:
|
||||
path: data["alpha-config.yaml"]
|
||||
pattern: 'keycloak\.example\.org'
|
||||
|
||||
- it: builds the external-discovery logout URL on a custom keycloak-host
|
||||
template: templates/gatekeeper-config.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.org
|
||||
oidc-enabled: "true"
|
||||
keycloak-host: auth.example.org
|
||||
keycloak-internal-url: ""
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: data["alpha-config.yaml"]
|
||||
pattern: 'backendLogoutURL: https://auth\.example\.org/realms/cozy/protocol/openid-connect/logout\?id_token_hint=\{id_token\}\n'
|
||||
- notMatchRegex:
|
||||
path: data["alpha-config.yaml"]
|
||||
pattern: 'keycloak\.example\.org'
|
||||
|
||||
- it: whitelists the custom keycloak-host for the post-logout redirect
|
||||
template: templates/gatekeeper.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.org
|
||||
oidc-enabled: "true"
|
||||
keycloak-host: auth.example.org
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --whitelist-domain=auth.example.org
|
||||
- notContains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --whitelist-domain=keycloak.example.org
|
||||
@@ -1,3 +1,22 @@
|
||||
{{- /* Public hostname Keycloak serves on and issues tokens for.
|
||||
ingress.host keeps precedence for deployments that set it before the
|
||||
platform-wide authentication.oidc.keycloakHost existed. Setting both to
|
||||
different hosts is refused: KC_HOSTNAME would follow ingress.host while
|
||||
every OIDC consumer builds its issuer from _cluster.keycloak-host, so
|
||||
every login would fail issuer validation. A keycloak-host equal to the
|
||||
derived keycloak.<root-host> is the platform default, not a choice, and
|
||||
does not conflict. */}}
|
||||
{{- define "keycloak.host" -}}
|
||||
{{- $cluster := .Values._cluster | default dict }}
|
||||
{{- $derived := printf "keycloak.%s" (dig "root-host" "" $cluster) }}
|
||||
{{- $platformHost := dig "keycloak-host" "" $cluster }}
|
||||
{{- $override := .Values.ingress.host }}
|
||||
{{- if and $override $platformHost (ne $platformHost $derived) (ne $platformHost $override) }}
|
||||
{{- fail (printf "ingress.host %q conflicts with the platform authentication.oidc.keycloakHost %q: OIDC consumers would expect an issuer Keycloak does not sign with. Drop ingress.host and keep only the platform value" $override $platformHost) }}
|
||||
{{- end }}
|
||||
{{- $override | default $platformHost | default $derived }}
|
||||
{{- end }}
|
||||
|
||||
{{- /* Realms published on the login host in the narrowed (ingress.adminHost)
|
||||
mode, as a YAML list — callers parse it with fromYamlArray.
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{{- $host := index .Values._cluster "root-host" }}
|
||||
{{- $ingressHost := .Values.ingress.host | default (printf "keycloak.%s" $host) }}
|
||||
{{- $ingressHost := include "keycloak.host" . }}
|
||||
{{- $exposeIngress := (index .Values._cluster "expose-ingress") | default "tenant-root" }}
|
||||
{{- $adminExposeIngress := (index .Values._cluster "expose-ingress-admin") | default $exposeIngress }}
|
||||
{{- $gatewayEnabled := (index .Values._cluster "gateway-enabled") | default "false" }}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- $host := index .Values._cluster "root-host" }}
|
||||
{{- $ingressHost := .Values.ingress.host | default (printf "keycloak.%s" $host) }}
|
||||
{{- $ingressHost := include "keycloak.host" . }}
|
||||
{{- $solver := (index .Values._cluster "solver") | default "http01" }}
|
||||
{{- $clusterIssuer := (index .Values._cluster "issuer-name") | default "letsencrypt-prod" }}
|
||||
{{- $exposeIngress := (index .Values._cluster "expose-ingress") | default "tenant-root" }}
|
||||
@@ -35,7 +35,7 @@ spec:
|
||||
ingressClassName: {{ $exposeIngress }}
|
||||
tls:
|
||||
- hosts:
|
||||
- {{ $ingressHost }}
|
||||
- {{ $ingressHost | quote }}
|
||||
{{- /* Operator wildcard mode: no per-host secret — ingress-nginx falls
|
||||
back to the default SSL certificate while the tls section keeps
|
||||
the HTTP-to-HTTPS redirect enforced. */}}
|
||||
@@ -43,7 +43,7 @@ spec:
|
||||
secretName: web-tls
|
||||
{{- end }}
|
||||
rules:
|
||||
- host: {{ $ingressHost }}
|
||||
- host: {{ $ingressHost | quote }}
|
||||
http:
|
||||
paths:
|
||||
{{- if $adminHost }}
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
{{- include "keycloak.truststores.validate" . -}}
|
||||
|
||||
{{- $host := index .Values._cluster "root-host" }}
|
||||
{{- $ingressHost := .Values.ingress.host | default (printf "keycloak.%s" $host) }}
|
||||
{{- $ingressHost := include "keycloak.host" . }}
|
||||
{{- $clusterDomain := (index .Values._cluster "cluster-domain") | default "cozy.local" }}
|
||||
|
||||
{{- /*
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
suite: keycloak hostname from the platform keycloak-host
|
||||
|
||||
release:
|
||||
name: keycloak
|
||||
namespace: cozy-keycloak
|
||||
|
||||
# KC_HOSTNAME fixes the issuer of every token Keycloak mints, so it must follow
|
||||
# the same _cluster.keycloak-host the OIDC consumers build their issuer from.
|
||||
# ingress.host stays as a per-chart override and wins when set.
|
||||
tests:
|
||||
- it: serves and issues on the platform keycloak-host
|
||||
template: templates/sts.yaml
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: StatefulSet
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: auth.example.com
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].env
|
||||
content:
|
||||
name: KC_HOSTNAME
|
||||
value: https://auth.example.com
|
||||
|
||||
- it: routes the Ingress to the platform keycloak-host
|
||||
template: templates/ingress.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: auth.example.com
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.rules[0].host
|
||||
value: auth.example.com
|
||||
- equal:
|
||||
path: spec.tls[0].hosts
|
||||
value: [auth.example.com]
|
||||
|
||||
- it: routes the HTTPRoute to the platform keycloak-host
|
||||
template: templates/httproute.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: auth.example.com
|
||||
gateway-enabled: "true"
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.hostnames
|
||||
content: auth.example.com
|
||||
|
||||
# Legacy deployments set only ingress.host; the platform then publishes the
|
||||
# derived keycloak.<root-host>, which is not a competing choice.
|
||||
- it: keeps a legacy ingress.host when the platform host is the derived default
|
||||
template: templates/sts.yaml
|
||||
documentSelector:
|
||||
path: kind
|
||||
value: StatefulSet
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: keycloak.example.com
|
||||
ingress:
|
||||
host: sso.example.com
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].env
|
||||
content:
|
||||
name: KC_HOSTNAME
|
||||
value: https://sso.example.com
|
||||
|
||||
- it: refuses an ingress.host that conflicts with an explicit platform host
|
||||
template: templates/sts.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: auth.example.com
|
||||
ingress:
|
||||
host: sso.example.com
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: 'ingress.host "sso.example.com" conflicts with the platform authentication.oidc.keycloakHost "auth.example.com"'
|
||||
|
||||
# Platform validation accepts all-digit labels and words YAML would read as
|
||||
# booleans. Unquoted, "123" and "true" render as a number and a bool, and the
|
||||
# Ingress no longer decodes as networking.k8s.io/v1.
|
||||
- it: keeps an all-digit host a string in the Ingress
|
||||
template: templates/ingress.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: "123"
|
||||
asserts:
|
||||
- isAPIVersion:
|
||||
of: networking.k8s.io/v1
|
||||
- equal:
|
||||
path: spec.rules[0].host
|
||||
value: "123"
|
||||
- equal:
|
||||
path: spec.tls[0].hosts
|
||||
value: ["123"]
|
||||
|
||||
- it: keeps a boolean-looking host a string in the Ingress
|
||||
template: templates/ingress.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: "true"
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.rules[0].host
|
||||
value: "true"
|
||||
- equal:
|
||||
path: spec.tls[0].hosts
|
||||
value: ["true"]
|
||||
|
||||
- it: keeps a boolean-looking host a string in the HTTPRoute
|
||||
template: templates/httproute.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.com
|
||||
keycloak-host: "true"
|
||||
gateway-enabled: "true"
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.hostnames
|
||||
value: ["true"]
|
||||
@@ -5,9 +5,12 @@ _cluster: {}
|
||||
image: quay.io/keycloak/keycloak:26.8.2-3
|
||||
|
||||
ingress:
|
||||
# Custom hostname for the Keycloak Ingress.
|
||||
# If set, this value will be used as the Ingress hostname (e.g., "auth.example.com").
|
||||
# If left empty, defaults to "keycloak.<root-host>" based on the cluster root-host setting.
|
||||
# Custom hostname for the Keycloak Ingress (e.g., "auth.example.com").
|
||||
# Prefer the platform-wide authentication.oidc.keycloakHost: it moves the
|
||||
# Keycloak Ingress and KC_HOSTNAME together with every OIDC consumer
|
||||
# (dashboard, linstor-gui, Grafana, info kubeconfig, tenant Kubernetes).
|
||||
# This value moves Keycloak alone, so those consumers keep the old issuer.
|
||||
# If left empty, the platform keycloak-host is used, then "keycloak.<root-host>".
|
||||
host: ""
|
||||
# Optional separate hostname for the Keycloak admin console (opt-in).
|
||||
# When set (e.g., "keycloak-admin.example.com"):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{{- $host := index .Values._cluster "root-host" }}
|
||||
{{- $realm := index .Values._cluster "oidc-realm-name" | default "cozy" }}
|
||||
{{- $keycloakHost := index .Values._cluster "keycloak-host" | default (printf "keycloak.%s" $host) }}
|
||||
{{- $oidcEnabled := index .Values._cluster "oidc-enabled" }}
|
||||
{{- $oidcInsecureSkipVerify := index .Values._cluster "oidc-insecure-skip-verify" }}
|
||||
{{- $keycloakInternalUrl := index .Values._cluster "keycloak-internal-url" | default "" }}
|
||||
@@ -70,18 +71,18 @@ spec:
|
||||
- --upstream=http://linstor-gui.{{ .Release.Namespace }}.svc:80
|
||||
- --http-address=0.0.0.0:8000
|
||||
- --redirect-url=https://linstor-gui.{{ $host }}/oauth2/callback
|
||||
- --oidc-issuer-url=https://keycloak.{{ $host }}/realms/{{ $realm }}
|
||||
- --oidc-issuer-url=https://{{ $keycloakHost }}/realms/{{ $realm }}
|
||||
{{- if $keycloakInternalUrl }}
|
||||
- --skip-oidc-discovery
|
||||
- --login-url=https://keycloak.{{ $host }}/realms/{{ $realm }}/protocol/openid-connect/auth
|
||||
- --login-url=https://{{ $keycloakHost }}/realms/{{ $realm }}/protocol/openid-connect/auth
|
||||
- --redeem-url={{ $keycloakInternalUrl }}/protocol/openid-connect/token
|
||||
- --oidc-jwks-url={{ $keycloakInternalUrl }}/protocol/openid-connect/certs
|
||||
- --validate-url={{ $keycloakInternalUrl }}/protocol/openid-connect/userinfo
|
||||
- --backend-logout-url={{ $keycloakInternalUrl }}/protocol/openid-connect/logout?id_token_hint={id_token}
|
||||
{{- else }}
|
||||
- --backend-logout-url=https://keycloak.{{ $host }}/realms/{{ $realm }}/protocol/openid-connect/logout?id_token_hint={id_token}
|
||||
- --backend-logout-url=https://{{ $keycloakHost }}/realms/{{ $realm }}/protocol/openid-connect/logout?id_token_hint={id_token}
|
||||
{{- end }}
|
||||
- --whitelist-domain=keycloak.{{ $host }}
|
||||
- --whitelist-domain={{ $keycloakHost }}
|
||||
- --email-domain=*
|
||||
- --pass-access-token=true
|
||||
- --pass-authorization-header=true
|
||||
|
||||
@@ -345,3 +345,24 @@ tests:
|
||||
- notContains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --backend-logout-url=https://keycloak.example.org/realms/cozy/protocol/openid-connect/logout?id_token_hint={id_token}
|
||||
|
||||
# Same issuer host as the dashboard: _cluster.keycloak-host.
|
||||
- it: builds the browser-facing OIDC URLs on a custom keycloak-host
|
||||
template: templates/gatekeeper.yaml
|
||||
set:
|
||||
_cluster:
|
||||
root-host: example.org
|
||||
oidc-enabled: "true"
|
||||
keycloak-host: auth.example.org
|
||||
keycloak-internal-url: http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy
|
||||
expose-services: "linstor-gui"
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --oidc-issuer-url=https://auth.example.org/realms/cozy
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --login-url=https://auth.example.org/realms/cozy/protocol/openid-connect/auth
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --whitelist-domain=auth.example.org
|
||||
@@ -45,7 +45,8 @@
|
||||
{{- define "monitoring.oidc.systemIssuerURL" -}}
|
||||
{{- $host := index .Values._cluster "root-host" -}}
|
||||
{{- $realm := index .Values._cluster "oidc-realm-name" | default "cozy" | toString -}}
|
||||
{{- printf "https://keycloak.%s/realms/%s" $host $realm -}}
|
||||
{{- $keycloakHost := index .Values._cluster "keycloak-host" | default (printf "keycloak.%s" $host) -}}
|
||||
{{- printf "https://%s/realms/%s" $keycloakHost $realm -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /*
|
||||
|
||||
@@ -800,3 +800,25 @@ tests:
|
||||
- equal:
|
||||
path: spec.config["auth.generic_oauth"].auth_url
|
||||
value: "https://keycloak.example.org/realms/acme/protocol/openid-connect/auth"
|
||||
|
||||
# Grafana calls the token and userinfo endpoints on the public host, so all
|
||||
# three URLs must move with _cluster.keycloak-host.
|
||||
- it: mode=System grafana.yaml builds the OIDC URLs on a custom keycloak-host
|
||||
template: templates/grafana/grafana.yaml
|
||||
set:
|
||||
oidc.mode: System
|
||||
_cluster.oidc-enabled: "true"
|
||||
_cluster.keycloak-host: auth.example.org
|
||||
oidc.users:
|
||||
- email: alice@example.com
|
||||
role: Admin
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.config["auth.generic_oauth"].auth_url
|
||||
value: "https://auth.example.org/realms/cozy/protocol/openid-connect/auth"
|
||||
- equal:
|
||||
path: spec.config["auth.generic_oauth"].token_url
|
||||
value: "https://auth.example.org/realms/cozy/protocol/openid-connect/token"
|
||||
- equal:
|
||||
path: spec.config["auth.generic_oauth"].api_url
|
||||
value: "https://auth.example.org/realms/cozy/protocol/openid-connect/userinfo"
|
||||
Reference in new issue
Block a user