diff --git a/hack/dashboard-gatekeeper-login.bats b/hack/dashboard-gatekeeper-login.bats new file mode 100644 index 000000000..03a22e2f0 --- /dev/null +++ b/hack/dashboard-gatekeeper-login.bats @@ -0,0 +1,162 @@ +#!/usr/bin/env bats +# ----------------------------------------------------------------------------- +# The dashboard gatekeeper's login redirect, checked against the oauth2-proxy +# binary the chart ships rather than against the rendered config text: the +# chart is rendered for a non-default realm, the auth-proxy container runs with +# the image, args and alpha config from that render, and /oauth2/start must +# redirect to that realm with an allowed kc_idp_hint passed through. The image +# comes from the render, so bumping it re-runs these cases on the new binary. +# ----------------------------------------------------------------------------- + +load test_helper + +REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)" +STUB_IMAGE="python:3.13-alpine@sha256:9ef1a599f863231c3d91e941389bfdc4a2d6070557243d54df1a4e57015b960e" +HOST=example.org +REALM=acme + +setup() { + strict_setup + docker info >/dev/null 2>&1 || { + echo "docker is required to run the gatekeeper image" >&2 + return 1 + } + work=$(mktemp -d) + mkdir -p "$work/config" "$work/client" + printf 'unused' > "$work/client/client-secret" +} + +teardown() { + [ -n "${work:-}" ] || return 0 + for f in "$work"/cid-*; do + if [ -e "$f" ]; then docker rm -f "$(cat "$f")" >/dev/null 2>&1 || true; fi + done + if [ -e "$work/network" ]; then docker network rm "$(cat "$work/network")" >/dev/null 2>&1 || true; fi + rm -rf "$work" +} + +# render +render() { + helm template dashboard "$REPO_ROOT/packages/system/dashboard" --namespace cozy-dashboard \ + --set-string "_cluster.root-host=$HOST" \ + --set-string '_cluster.oidc-enabled=true' \ + --set-string "_cluster.oidc-realm-name=$REALM" \ + --set-string "_cluster.keycloak-internal-url=$1" > "$work/rendered.yaml" + yq 'select(.kind == "ConfigMap" and .metadata.name == "incloud-web-gatekeeper-config") | .data["alpha-config.yaml"]' \ + "$work/rendered.yaml" > "$work/config/alpha-config.yaml" + yq 'select(.kind == "Deployment" and .metadata.name == "incloud-web-gatekeeper") | .spec.template.spec.containers[] | select(.name == "auth-proxy") | .image' \ + "$work/rendered.yaml" > "$work/image" + yq 'select(.kind == "Deployment" and .metadata.name == "incloud-web-gatekeeper") | .spec.template.spec.containers[] | select(.name == "auth-proxy") | .args[]' \ + "$work/rendered.yaml" > "$work/args" + [ -s "$work/config/alpha-config.yaml" ] + [ -s "$work/image" ] +} + +# start_proxy [docker run options...]; prints the published host:port +start_proxy() { + local cookie_secret args=() a + cookie_secret=$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n') + while IFS= read -r a; do + args+=("${a/\$(OAUTH2_PROXY_COOKIE_SECRET)/$cookie_secret}") + done < "$work/args" + docker run -d "$@" -p 127.0.0.1::8000 \ + -v "$work/config:/etc/oauth2-proxy/config:ro" \ + -v "$work/client:/etc/oauth2-proxy/client:ro" \ + "$(cat "$work/image")" "${args[@]}" > "$work/cid-proxy" + local addr + addr=$(docker port "$(cat "$work/cid-proxy")" 8000/tcp | head -n1) + timeout 60 sh -c "until curl -sf -o /dev/null http://$addr/ping; do sleep 0.5; done" || { + echo "gatekeeper did not become ready; its log:" >&2 + docker logs "$(cat "$work/cid-proxy")" >&2 || true + return 1 + } + echo "$addr" +} + +# login_redirect +login_redirect() { + curl -sS -o /dev/null -w '%{redirect_url}' "http://$1/oauth2/start?$2" +} + +auth_url="https://keycloak.$HOST/realms/$REALM/protocol/openid-connect/auth" + +# expect_redirect ... ; a leading "!" means must not +# contain. A function, not [[ ]]: a failing [[ ]] mid-test does not stop the +# test under bash 3.2. +expect_redirect() { + local location=$1 want + shift + case "$location" in + "$auth_url?"*) ;; + *) echo "expected a redirect to $auth_url, got: ${location:-}" >&2; return 1 ;; + esac + for want in "$@"; do + case "$want" in + !*) + case "$location" in + *"${want#!}"*) echo "unexpected ${want#!} in: $location" >&2; return 1 ;; + esac + ;; + *) + case "$location" in + *"$want"*) ;; + *) echo "expected $want in: $location" >&2; return 1 ;; + esac + ;; + esac + done +} + +@test "in-cluster Keycloak URL: login redirects to the configured realm and passes an allowed kc_idp_hint" { + render "http://keycloak-http.cozy-keycloak.svc:8080/realms/$REALM" + addr=$(start_proxy --network bridge) + + expect_redirect "$(login_redirect "$addr" 'kc_idp_hint=portal')" '&kc_idp_hint=portal&' + expect_redirect "$(login_redirect "$addr" 'kc_idp_hint=x%26prompt%3Dnone')" '!kc_idp_hint' '!prompt=none' + expect_redirect "$(login_redirect "$addr" '')" '!kc_idp_hint' +} + +@test "OIDC discovery: the gatekeeper discovers the configured realm and passes an allowed kc_idp_hint" { + render "" + issuer="https://keycloak.$HOST/realms/$REALM" + + mkdir -p "$work/stub/realms/$REALM/.well-known" + cat > "$work/stub/realms/$REALM/.well-known/openid-configuration" </dev/null + + network="gatekeeper-login-$(basename "$work" | tr -cd 'a-zA-Z0-9')" + docker network create "$network" >/dev/null + echo "$network" > "$work/network" + docker run -d --network "$network" --network-alias "keycloak.$HOST" \ + -v "$work/stub:/stub:ro" -w /stub "$STUB_IMAGE" python3 -c ' +import http.server, ssl +server = http.server.ThreadingHTTPServer(("", 443), http.server.SimpleHTTPRequestHandler) +ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) +ctx.load_cert_chain("tls.crt", "tls.key") +server.socket = ctx.wrap_socket(server.socket, server_side=True) +server.serve_forever() +' > "$work/cid-stub" + # Discovery runs once at startup and the gatekeeper exits if it fails. + timeout 60 sh -c "until docker exec $(cat "$work/cid-stub") python3 -c 'import socket; socket.create_connection((\"127.0.0.1\", 443), 1)' 2>/dev/null; do sleep 0.5; done" || { + docker logs "$(cat "$work/cid-stub")" >&2 || true + false + } + + addr=$(start_proxy --network "$network" -v "$work/stub/tls.crt:/stub-ca.crt:ro" -e SSL_CERT_FILE=/stub-ca.crt) + + expect_redirect "$(login_redirect "$addr" 'kc_idp_hint=portal')" '&kc_idp_hint=portal&' +} diff --git a/hack/e2e-install-cozystack.bats b/hack/e2e-install-cozystack.bats index 500fe68ee..f7dda2d7b 100644 --- a/hack/e2e-install-cozystack.bats +++ b/hack/e2e-install-cozystack.bats @@ -367,6 +367,48 @@ # has necessarily been re-reconciled, so Ready here means the whole upgrade # converged -- not just the one Deployment this test watched. kubectl wait hr/dashboard -n cozy-dashboard --timeout=10m --for=condition=ready + + # The login redirect oauth2-proxy builds from the alpha config: the realm path + # must reach the browser-facing auth URL, an allowed kc_idp_hint must be passed + # through to Keycloak, and a value outside the allow pattern must be dropped. + # Asserted after the port-forward is gone: on failure set -e would skip a kill + # placed after the assertion, and a trap would hide the TAP line. + pf_log=$(mktemp) + kubectl -n cozy-dashboard port-forward deploy/incloud-web-gatekeeper 18000:8000 >"$pf_log" 2>&1 & + pf_pid=$! + hinted="" + rejected="" + if timeout 30 sh -ec 'until nc -z localhost 18000; do sleep 0.2; done'; then + hinted=$(curl -sS -o /dev/null -w '%{redirect_url}' 'http://localhost:18000/oauth2/start?kc_idp_hint=e2e-idp') || true + rejected=$(curl -sS -o /dev/null -w '%{redirect_url}' 'http://localhost:18000/oauth2/start?kc_idp_hint=e2e%26prompt%3Dnone') || true + fi + kill "$pf_pid" 2>/dev/null || true + wait "$pf_pid" 2>/dev/null || true + + case "$hinted" in + https://keycloak.example.org/realms/cozy/protocol/openid-connect/auth\?*\&kc_idp_hint=e2e-idp\&*|https://keycloak.example.org/realms/cozy/protocol/openid-connect/auth\?*\&kc_idp_hint=e2e-idp) ;; + *) + echo "=== /oauth2/start?kc_idp_hint=e2e-idp did not redirect to the cozy realm with the hint ===" + echo "Location: ${hinted:-}" + cat "$pf_log" + false + ;; + esac + case "$rejected" in + https://keycloak.example.org/realms/cozy/protocol/openid-connect/auth\?*kc_idp_hint*|https://keycloak.example.org/realms/cozy/protocol/openid-connect/auth\?*prompt=none*) + echo "=== a kc_idp_hint outside the allow pattern reached the Keycloak URL ===" + echo "Location: $rejected" + false + ;; + https://keycloak.example.org/realms/cozy/protocol/openid-connect/auth\?*) ;; + *) + echo "=== /oauth2/start with a rejected kc_idp_hint did not redirect to Keycloak ===" + echo "Location: ${rejected:-}" + cat "$pf_log" + false + ;; + esac + rm -f "$pf_log" } @test "Aggregated API rejects Tenant name with dashes" { diff --git a/packages/system/dashboard/templates/gatekeeper-config.yaml b/packages/system/dashboard/templates/gatekeeper-config.yaml new file mode 100644 index 000000000..19e1624e9 --- /dev/null +++ b/packages/system/dashboard/templates/gatekeeper-config.yaml @@ -0,0 +1,79 @@ +{{- $host := index .Values._cluster "root-host" }} +{{- $realm := index .Values._cluster "oidc-realm-name" | default "cozy" }} +{{- $oidcEnabled := index .Values._cluster "oidc-enabled" }} +{{- $keycloakInternalUrl := index .Values._cluster "keycloak-internal-url" | default "" }} +{{- if eq $oidcEnabled "true" }} +# oauth2-proxy alpha configuration for the OIDC gatekeeper. Provider, upstream, +# server and header injection live here because only the alpha configuration +# can pass a query parameter from /oauth2/start through to the IdP login URL. +apiVersion: v1 +kind: ConfigMap +metadata: + name: incloud-web-gatekeeper-config +data: + alpha-config.yaml: | + server: + BindAddress: 0.0.0.0:8000 + upstreamConfig: + upstreams: + - id: / + path: / + uri: http://cozy-dashboard-console.{{ .Release.Namespace }}.svc:8080 + passHostHeader: true + proxyWebSockets: true + flushInterval: 1s + timeout: 30s + injectRequestHeaders: + - name: X-Forwarded-Groups + values: [{claim: groups}] + - name: X-Forwarded-User + values: [{claim: user}] + - name: X-Forwarded-Email + values: [{claim: email}] + - name: X-Forwarded-Preferred-Username + values: [{claim: preferred_username}] + - name: X-Forwarded-Access-Token + values: [{claim: access_token}] + - name: Authorization + values: [{claim: id_token, prefix: "Bearer "}] + providers: + - id: oidc=dashboard + provider: oidc + clientID: dashboard + clientSecretFile: /etc/oauth2-proxy/client/client-secret + # No offline_access: that scope makes Keycloak issue an *offline* + # refresh token, which is decoupled from the SSO session and is NOT + # revoked by logout (end_session). Since oauth2-proxy keeps the + # refresh token in the kc-access cookie and silently refreshes it, + # a copied cookie would stay valid for the whole offline-session + # lifetime (~30d) even after the user logs out. An online refresh + # token is bound to the SSO session and is revoked on logout. + scope: openid email profile + loginURLParameters: + - name: approval_prompt + default: [force] + # A link to /oauth2/start?kc_idp_hint= sends the user straight + # to that Keycloak identity provider instead of the realm login page. + - name: kc_idp_hint + allow: + - pattern: '^[A-Za-z0-9._-]+$' + {{- if $keycloakInternalUrl }} + loginURL: https://keycloak.{{ $host }}/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} + {{- end }} + oidcConfig: + issuerURL: https://keycloak.{{ $host }}/realms/{{ $realm }} + {{- if $keycloakInternalUrl }} + skipDiscovery: true + jwksURL: {{ $keycloakInternalUrl }}/protocol/openid-connect/certs + {{- end }} + emailClaim: email + groupsClaim: groups + userIDClaim: email + audienceClaims: [aud] + insecureSkipNonce: true +{{- end }} diff --git a/packages/system/dashboard/templates/gatekeeper.yaml b/packages/system/dashboard/templates/gatekeeper.yaml index dce5dcd84..9e231e9e8 100644 --- a/packages/system/dashboard/templates/gatekeeper.yaml +++ b/packages/system/dashboard/templates/gatekeeper.yaml @@ -21,6 +21,10 @@ spec: maxUnavailable: 25% template: metadata: + {{- if eq $oidcEnabled "true" }} + annotations: + checksum/gatekeeper-config: {{ include (print $.Template.BasePath "/gatekeeper-config.yaml") . | sha256sum }} + {{- end }} labels: app.kubernetes.io/instance: incloud-web app.kubernetes.io/name: gatekeeper @@ -51,52 +55,32 @@ spec: - name: auth-proxy image: quay.io/oauth2-proxy/oauth2-proxy:v7.12.0 imagePullPolicy: IfNotPresent + # Provider, upstream, listen address and injected headers are in + # gatekeeper-config.yaml; oauth2-proxy refuses them as flags next to + # --alpha-config. args: - - --provider=oidc - - --upstream=http://cozy-dashboard-console.{{ .Release.Namespace }}.svc:8080 - - --http-address=0.0.0.0:8000 + - --alpha-config=/etc/oauth2-proxy/config/alpha-config.yaml - --redirect-url=https://dashboard.{{ $host }}/oauth2/callback - - --oidc-issuer-url=https://keycloak.{{ $host }}/realms/{{ $realm }} - {{- if $keycloakInternalUrl }} - - --skip-oidc-discovery - - --login-url=https://keycloak.{{ $host }}/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} - {{- end }} - --whitelist-domain=keycloak.{{ $host }} - --email-domain=* - --api-route=^/api(/|$) - --api-route=^/apis(/|$) - - --pass-access-token=true - - --pass-authorization-header=true - --cookie-refresh=3m - --cookie-name=kc-access - --cookie-secure=true - --cookie-secret=$(OAUTH2_PROXY_COOKIE_SECRET) - --skip-provider-button - # No offline_access: that scope makes Keycloak issue an *offline* - # refresh token, which is decoupled from the SSO session and is NOT - # revoked by logout (end_session). Since oauth2-proxy keeps the - # refresh token in the kc-access cookie and silently refreshes it, - # a copied cookie would stay valid for the whole offline-session - # lifetime (~30d) even after the user logs out. An online refresh - # token is bound to the SSO session and is revoked on logout. - - --scope=openid email profile {{- if eq $oidcInsecureSkipVerify "true" }} - --ssl-insecure-skip-verify=true {{- end }} + volumeMounts: + - name: gatekeeper-config + mountPath: /etc/oauth2-proxy/config + readOnly: true + - name: client-secret + mountPath: /etc/oauth2-proxy/client + readOnly: true env: - - name: OAUTH2_PROXY_CLIENT_ID - value: dashboard - - name: OAUTH2_PROXY_CLIENT_SECRET - valueFrom: - secretKeyRef: - name: dashboard-client - key: client-secret-key - name: OAUTH2_PROXY_COOKIE_SECRET valueFrom: secretKeyRef: @@ -212,8 +196,18 @@ spec: type: RuntimeDefault terminationMessagePath: /dev/termination-log terminationMessagePolicy: File - {{- if ne $oidcEnabled "true" }} volumes: + {{- if eq $oidcEnabled "true" }} + - name: gatekeeper-config + configMap: + name: incloud-web-gatekeeper-config + - name: client-secret + secret: + secretName: dashboard-client + items: + - key: client-secret-key + path: client-secret + {{- else }} # optional: the login page degrades to its unbranded default if the # ConfigMap is missing, so a start-up dependency is not worth failing on. - name: branding diff --git a/packages/system/dashboard/tests/gatekeeper_test.yaml b/packages/system/dashboard/tests/gatekeeper_test.yaml index 3b8efd7ed..e5735e9b8 100644 --- a/packages/system/dashboard/tests/gatekeeper_test.yaml +++ b/packages/system/dashboard/tests/gatekeeper_test.yaml @@ -1,6 +1,7 @@ suite: gatekeeper container and probes per OIDC mode templates: - templates/gatekeeper.yaml + - templates/gatekeeper-config.yaml release: name: dashboard @@ -19,6 +20,7 @@ release: tests: - it: oidc-enabled=false renders token-proxy with /healthz probes + template: templates/gatekeeper.yaml set: _cluster: root-host: example.org @@ -76,15 +78,25 @@ tests: # there — pin its absence so a refactor that hoists the volume out of the # non-OIDC guard is a test failure. - it: oidc-enabled=true does not mount the branding config + template: templates/gatekeeper.yaml set: _cluster: root-host: example.org oidc-enabled: "true" asserts: - - notExists: + - notContains: path: spec.template.spec.volumes - - notExists: + content: + name: branding + configMap: + name: cozy-dashboard-console-config + optional: true + - notContains: path: spec.template.spec.containers[0].volumeMounts + content: + name: branding + mountPath: /etc/cozystack/branding + readOnly: true # authentication.oidc.enabled defaults to false while keycloakInternalUrl now # defaults to the in-cluster Service, so THIS pair — OIDC off, internal URL @@ -93,6 +105,7 @@ tests: # token-proxy branch today; pin that, because a refactor which hoists the # block out would otherwise ship silently. - it: oidc-enabled=false ignores a set keycloak-internal-url + template: templates/gatekeeper.yaml set: _cluster: root-host: example.org @@ -115,6 +128,7 @@ tests: content: --oidc-jwks-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/certs - it: oidc-enabled=true renders auth-proxy with /ping probes and no startupProbe + template: templates/gatekeeper.yaml set: _cluster: root-host: example.org @@ -137,151 +151,3 @@ tests: - equal: path: spec.template.spec.containers[0].ports[0].containerPort value: 8000 - - # keycloak-internal-url arrives on the _cluster channel from - # authentication.oidc.keycloakInternalUrl in packages/core/platform. Its - # default is the in-cluster Keycloak Service, so the value asserted below is - # what a stock cluster ships: oauth2-proxy skips OIDC discovery and talks to - # the Service for token/jwks/userinfo/logout, which keeps the dashboard - # independent of the root ingress serving keycloak. at startup. The - # browser-facing URLs (redirect, login) must stay on the external host — - # routing them to a cluster-internal address would send the user's browser to - # an unreachable URL. - - it: default in-cluster keycloak URL skips discovery and keeps browser URLs external - set: - _cluster: - root-host: example.org - oidc-enabled: "true" - keycloak-internal-url: http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy - asserts: - - contains: - path: spec.template.spec.containers[0].args - content: --skip-oidc-discovery - - contains: - path: spec.template.spec.containers[0].args - content: --redeem-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/token - - contains: - path: spec.template.spec.containers[0].args - content: --oidc-jwks-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/certs - - contains: - path: spec.template.spec.containers[0].args - content: --validate-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/userinfo - - contains: - path: spec.template.spec.containers[0].args - content: --backend-logout-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/logout?id_token_hint={id_token} - - contains: - path: spec.template.spec.containers[0].args - content: --redirect-url=https://dashboard.example.org/oauth2/callback - - contains: - path: spec.template.spec.containers[0].args - content: --login-url=https://keycloak.example.org/realms/cozy/protocol/openid-connect/auth - - contains: - path: spec.template.spec.containers[0].args - content: --oidc-issuer-url=https://keycloak.example.org/realms/cozy - - - it: an explicit keycloak-internal-url override wins over the default - set: - _cluster: - root-host: example.org - oidc-enabled: "true" - keycloak-internal-url: http://keycloak.example.test:8080/realms/other - asserts: - - contains: - path: spec.template.spec.containers[0].args - content: --skip-oidc-discovery - - contains: - path: spec.template.spec.containers[0].args - content: --redeem-url=http://keycloak.example.test:8080/realms/other/protocol/openid-connect/token - - contains: - path: spec.template.spec.containers[0].args - content: --oidc-jwks-url=http://keycloak.example.test:8080/realms/other/protocol/openid-connect/certs - - contains: - path: spec.template.spec.containers[0].args - content: --validate-url=http://keycloak.example.test:8080/realms/other/protocol/openid-connect/userinfo - - notContains: - path: spec.template.spec.containers[0].args - content: --redeem-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/token - - # The escape hatch: an operator who sets keycloakInternalUrl back to "" gets - # the historical shape — full OIDC discovery against the external issuer, no - # backend URLs pinned. It must keep working, so pin it. - # - # --skip-oidc-discovery carries the whole meaning here. All five in-cluster - # args live inside one {{- if $keycloakInternalUrl }} block in the template, - # so its absence structurally guarantees the absence of the other four; the - # notContains assertions below then pin the regression that actually threatens - # this branch — the in-cluster default leaking back in. Asserting an arg count - # instead would couple this OIDC test to every unrelated gatekeeper flag. - - it: empty keycloak-internal-url restores external OIDC discovery - set: - _cluster: - root-host: example.org - oidc-enabled: "true" - keycloak-internal-url: "" - asserts: - - notContains: - path: spec.template.spec.containers[0].args - content: --skip-oidc-discovery - - contains: - path: spec.template.spec.containers[0].args - content: --oidc-issuer-url=https://keycloak.example.org/realms/cozy - - contains: - 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} - - notContains: - path: spec.template.spec.containers[0].args - content: --redeem-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/token - - notContains: - path: spec.template.spec.containers[0].args - content: --oidc-jwks-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/certs - - notContains: - path: spec.template.spec.containers[0].args - content: --validate-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/userinfo - - notContains: - path: spec.template.spec.containers[0].args - content: --backend-logout-url=http://keycloak-http.cozy-keycloak.svc:8080/realms/cozy/protocol/openid-connect/logout?id_token_hint={id_token} - - # The realm segment of the browser-facing issuer/login/logout URLs is driven - # by _cluster.oidc-realm-name (authentication.oidc.realmName in the platform). - # A renamed realm must reach every one of them; a URL left on the literal - # "cozy" would send the browser to a realm the apiserver OIDC issuer no longer - # matches, silently breaking SSO. - - it: threads a custom realm name through the browser-facing OIDC URLs - set: - _cluster: - root-host: example.org - oidc-enabled: "true" - oidc-realm-name: acme - keycloak-internal-url: http://keycloak-http.cozy-keycloak.svc:8080/realms/acme - asserts: - - contains: - path: spec.template.spec.containers[0].args - content: --oidc-issuer-url=https://keycloak.example.org/realms/acme - - contains: - path: spec.template.spec.containers[0].args - content: --login-url=https://keycloak.example.org/realms/acme/protocol/openid-connect/auth - - notContains: - path: spec.template.spec.containers[0].args - content: --oidc-issuer-url=https://keycloak.example.org/realms/cozy - - # The external-discovery branch (empty internal URL) builds its own - # backend-logout-url on the browser host, so the realm segment there must - # follow oidc-realm-name too; reverting $realm in that branch alone would - # otherwise survive the suite. - - it: threads a custom realm into the external-discovery logout URL - set: - _cluster: - root-host: example.org - oidc-enabled: "true" - oidc-realm-name: acme - keycloak-internal-url: "" - asserts: - - notContains: - path: spec.template.spec.containers[0].args - content: --skip-oidc-discovery - - contains: - path: spec.template.spec.containers[0].args - content: --backend-logout-url=https://keycloak.example.org/realms/acme/protocol/openid-connect/logout?id_token_hint={id_token} - - 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}