mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 12:16:03 +09:00
feat(platform): make the Keycloak public host configurable (#5112)
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list — pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `kind/backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does The Keycloak chart already accepts `ingress.host`, but every OIDC consumer rebuilds the issuer as `https://keycloak.<root-host>/realms/<realm>` on its own: the dashboard and linstor-gui gatekeepers (`--oidc-issuer-url`, `--login-url`, `--whitelist-domain`, external logout URL), Grafana SSO (`auth_url`, `token_url`, `api_url`), the info kubeconfig (`--oidc-issuer-url`) and tenant Kubernetes clusters in `oidc.mode: System` (AuthenticationConfiguration issuer). Serving Keycloak on any other hostname (for example `auth.example.org`) therefore changes the `iss` of every token while those consumers keep expecting the old one, and SSO breaks across the platform. This adds `authentication.oidc.keycloakHost` to the platform values. The platform resolves it once (empty means `keycloak.<root-host>`), validates it as a bare lowercase hostname (no scheme, port or path, since it is spliced into URLs and `--whitelist-domain`), and publishes it as `_cluster.keycloak-host`. The Keycloak chart (Ingress, HTTPRoute, `KC_HOSTNAME`) and the five consumers read that key, each falling back to `keycloak.<root-host>` when it is absent so a chart rendered without the platform Secret behaves as before. `ingress.host` on the Keycloak chart keeps working and still wins, and its comment now points at the platform value. Existing clusters render unchanged: with `keycloakHost` empty, every URL is byte-identical to today's. Changing the value on a live cluster is an issuer change, so sessions and refresh tokens minted under the old host stop being accepted and the management apiserver (configured out of band via talm `oidcIssuerUrl`) must trust the new issuer first; the values comment says so. Tests: one new suite each for the platform wiring and validation and for the Keycloak chart, plus a custom-host case in the dashboard, linstor-gui, info, monitoring and kubernetes suites. Reverting the templates makes every new case fail; `helm unittest` passes on all seven touched charts. ### Screenshots <!-- REQUIRED for UI changes: attach screenshots or screen recordings demonstrating the visual impact of your changes. PRs with UI changes without screenshots will not be merged. --> ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM TO FILL IN: 1. Walk the trigger map against the actual diff of this PR, file by file. Do not decide from the PR title or from your memory of what you changed. 2. For every repository you tick, open the follow-up PR there and link it on the same line. A ticked box with no link claims work that does not exist, which is worse than an empty box. Search that repository for an open PR or issue covering it first, and link that instead of filing a duplicate. 3. When the follow-up is out of scope, or needs a decision that is not yours to make, open an issue in that repository instead, link that, and say so in the PR body. Do not push a speculative PR into another repository just to fill a line here. 4. Do not tick "No downstream repository is affected" to make the checklist go away. If you are unsure, leave every box empty and say so in the PR body, so a human decides. --> - [ ] No downstream repository is affected by this change - [x] [cozystack/website](https://github.com/cozystack/website) - follow-up: https://github.com/cozystack/website/issues/778 (issue rather than PR: the table row should land once this PR merges) - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same `type(scope):` prefix as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note feat(platform): add authentication.oidc.keycloakHost to serve Keycloak on a custom public hostname; the Keycloak Ingress, KC_HOSTNAME, the dashboard and linstor-gui gatekeepers, Grafana SSO, the info kubeconfig and tenant Kubernetes clusters in oidc.mode System all follow it. Empty keeps keycloak.<root-host>. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added an optional public Keycloak hostname, defaulting to `keycloak.<cluster-root-domain>` when unset. * The configured hostname is used for Keycloak access, OIDC issuer and login URLs, and related browser-facing authentication settings across supported services and kubeconfig. * Existing Keycloak hostname overrides remain supported when compatible with the platform hostname. * **Bug Fixes** * Invalid configured hostnames—including values with schemes, paths, ports, or invalid DNS lengths—and conflicting explicit Keycloak and platform hostnames now prevent rendering. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
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"'
|
||||
@@ -546,6 +546,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