feat(dashboard): let a login link pick the Keycloak identity provider (#5286)

## What this PR does

A login link into the dashboard can now name the Keycloak identity
provider, so a user who comes from a portal brokered into Keycloak skips
the realm login page:

```
https://dashboard.<host>/oauth2/start?kc_idp_hint=<idp-alias>&rd=/admin/tenants
```

The motivating case is a billing portal registered in the realm as an
OIDC identity provider. Its "Open dashboard" button today lands every
client on "Sign in to <realm>", where they must pick the portal's
provider by hand on every new browser or session. Keycloak skips that
page when the auth request carries `kc_idp_hint`. The gatekeeper,
however, builds the request from a fixed `--login-url`, and
oauth2-proxy's flags forward only `acr_values`, `prompt` and
`approval_prompt` from `/oauth2/start`. Putting the hint into
`--login-url` would force every dashboard login, administrators
included, through that one provider.

oauth2-proxy can forward an allowed parameter through
`providers[].loginURLParameters`, but only in its alpha configuration.
The OIDC gatekeeper therefore now runs from one:

- `templates/gatekeeper-config.yaml` (new, OIDC only) holds the
provider, upstream, listen address and injected headers. The values are
exactly what `oauth2-proxy --convert-config-to-alpha` (v7.12.0) produces
for the previous flags, both the in-cluster Keycloak branch and the
external-discovery branch. On top of those, `kc_idp_hint` is allowed
when it matches `^[A-Za-z0-9._-]+$`. That rule and `clientSecretFile` in
place of the inline `clientSecret` are the only hand-written lines;
everything else, `scope`, `approval_prompt`, `insecureSkipNonce`,
`flushInterval` and `timeout` included, is the converter output
unchanged.
- `templates/gatekeeper.yaml` keeps the flags the alpha configuration
does not own (redirect URL, whitelist domain, email domain, API routes,
cookie options, `--skip-provider-button`, `--ssl-insecure-skip-verify`).
It mounts the config and the `dashboard-client` secret as files
(`clientSecretFile`). A checksum annotation restarts the pod when the
config changes.
- The token-proxy branch (OIDC disabled) is unchanged.

A login without the parameter behaves as before. oauth2-proxy logs a
warning on start that the alpha configuration format may change between
releases.

Tests:
- **Chart suite.** The gatekeeper suite loads the config template as
well, because the deployment checksums it. The "no branding volume" test
now asserts the branding volume is absent, not that the pod has no
volumes. The five tests that read Keycloak URLs from the container args
are removed: those values now sit in the alpha configuration. `helm
unittest .` passes, 23 tests.
- **E2E.** After the gatekeeper rolls out with OIDC enabled, the in-tree
install suite requests `/oauth2/start` through a port-forward and checks
the redirect: `kc_idp_hint=e2e-idp` reaches the `cozy` realm's auth URL,
and a value outside the allow pattern (`e2e%26prompt%3Dnone`) is
dropped. This covers the realm path and the allow rule that the removed
chart tests no longer pin.
- **Gatekeeper login (`hack/dashboard-gatekeeper-login.bats`).** Renders
the chart for a realm other than `cozy`, starts the auth-proxy image
with the rendered args and alpha config, and checks the `/oauth2/start`
redirect: on the in-cluster Keycloak branch the hint reaches that
realm's auth URL, a value outside the allow pattern is dropped, and a
login without it carries none; on the external-discovery branch the
gatekeeper discovers that realm from a local Keycloak stub and passes
the hint. The image is read from the render, so an oauth2-proxy bump
re-checks the alpha configuration. Needs docker, like
`hack/etcd-grpc-alerts.bats`.
- **Real oauth2-proxy v7.12.0 on the rendered config.** Ran with the
rendered args and checked:
  - `/ping` answers OK;
- `/oauth2/start?kc_idp_hint=whmcs` puts `kc_idp_hint=whmcs` into the
Keycloak auth URL;
- `/oauth2/start` without the parameter, or with a value outside the
pattern, does not;
  - a protected path redirects without it;
  - `/apis/*` stays 401;
  - `--ssl-insecure-skip-verify` starts fine alongside `--alpha-config`.
- **Live cluster.** Swapped in the rendered gatekeeper with the
HelmRelease suspended, then reverted:
- a brokered user who was already signed in at the portal went from the
hinted link straight to the dashboard;
  - a plain visit still showed the realm login page;
- a hinted visit without a portal session went straight to the portal's
own login;
- API calls from the console worked, so the `Authorization` header
injection is intact.

### Screenshots

N/A — no console UI changes. The change removes the Keycloak login page
from the hinted flow.

### Downstream repositories

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[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:

The diff touches only the dashboard gatekeeper templates and their
tests. It adds no value, schema, package or platform component. I walked
the trigger map against it, and no entry matches.

### Release note

```release-note
feat(dashboard): a dashboard login link can name the Keycloak identity provider with `/oauth2/start?kc_idp_hint=<alias>`, so users coming from a brokered portal skip the realm login page. The OIDC gatekeeper now runs oauth2-proxy from an alpha configuration kept in a ConfigMap; logins without the parameter are unchanged.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* OIDC-enabled clusters now use updated dashboard sign-in settings,
forwarding identity and token information to the dashboard.
* Authentication requests use Keycloak’s internal URL when configured;
otherwise, logout uses the public Keycloak URL.
  * Sign-in requests include the OpenID, email, and profile scopes.
* Supported identity-provider hints are preserved in sign-in redirects,
while invalid hints are excluded.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Andrey Kolkov authored and GitHub committed 2026-11-20 17:05:43 +07:00
commit f4330867ea
5 files changed
+325 -182

No files matched your search

+162
View File
@@ -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 <keycloak-internal-url>
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 <host:port> <query>
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 <location> <must contain>... ; 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:-<none>}" >&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" <<EOF
{
"issuer": "$issuer",
"authorization_endpoint": "$auth_url",
"token_endpoint": "$issuer/protocol/openid-connect/token",
"userinfo_endpoint": "$issuer/protocol/openid-connect/userinfo",
"jwks_uri": "$issuer/protocol/openid-connect/certs",
"end_session_endpoint": "$issuer/protocol/openid-connect/logout",
"response_types_supported": ["code"],
"subject_types_supported": ["public"],
"id_token_signing_alg_values_supported": ["RS256"]
}
EOF
openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj "/CN=keycloak.$HOST" \
-addext "subjectAltName=DNS:keycloak.$HOST" \
-keyout "$work/stub/tls.key" -out "$work/stub/tls.crt" 2>/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&'
}
+42
View File
@@ -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:-<none>}"
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:-<none>}"
cat "$pf_log"
false
;;
esac
rm -f "$pf_log"
}
@test "Aggregated API rejects Tenant name with dashes" {
@@ -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=<alias> 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 }}
@@ -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
@@ -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.<host> 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}