From 4ad4a4401405091a2b7a78f20f80722f261ea801 Mon Sep 17 00:00:00 2001 From: Alexey Artamonov Date: Tue, 1 Dec 2026 16:07:22 +0300 Subject: [PATCH] fix(dashboard): keep re-login working across tabs after logout With OIDC enabled, signing out of the dashboard and signing back in often ends on the oauth2-proxy 403 page even though Keycloak accepted the password. The gatekeeper log shows Invalid authentication via OAuth2: CSRF token mismatch, potential attack oauth2-proxy keeps the state of a pending login in a single kc-access_csrf cookie. After a logout every other open console tab gets a 401 on its next API call or watch reconnect and starts its own sign-in, which overwrites that cookie, so the callback of the tab the user is typing into no longer matches. Giving each flow its own CSRF cookie keeps concurrent sign-ins independent; the limit caps how many abandoned flows can accumulate in the request headers. Tested by running the chart-rendered oauth2-proxy v7.12.0 config against a live Keycloak with two tabs signing in after a logout: without the flags the first tab gets the 403 above, with them both sign-ins complete. Assisted-by: LLM Signed-off-by: Alexey Artamonov --- .../system/dashboard/templates/gatekeeper.yaml | 6 ++++++ .../system/dashboard/tests/gatekeeper_test.yaml | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/system/dashboard/templates/gatekeeper.yaml b/packages/system/dashboard/templates/gatekeeper.yaml index 0f90dd039..aa4a6b2a8 100644 --- a/packages/system/dashboard/templates/gatekeeper.yaml +++ b/packages/system/dashboard/templates/gatekeeper.yaml @@ -70,6 +70,12 @@ spec: - --cookie-name=kc-access - --cookie-secure=true - --cookie-secret=$(OAUTH2_PROXY_COOKIE_SECRET) + # After a logout every open console tab starts its own sign-in; with + # a single shared CSRF cookie the newest flow overwrites the others + # and the callback of any other tab fails with a 403. The limit keeps + # abandoned flows from piling up in the request headers. + - --cookie-csrf-per-request=true + - --cookie-csrf-per-request-limit=10 - --skip-provider-button {{- if eq $oidcInsecureSkipVerify "true" }} - --ssl-insecure-skip-verify=true diff --git a/packages/system/dashboard/tests/gatekeeper_test.yaml b/packages/system/dashboard/tests/gatekeeper_test.yaml index 4ac7d5ab9..ff2ad9d2d 100644 --- a/packages/system/dashboard/tests/gatekeeper_test.yaml +++ b/packages/system/dashboard/tests/gatekeeper_test.yaml @@ -205,3 +205,19 @@ tests: - notContains: path: spec.template.spec.containers[0].args content: --whitelist-domain=keycloak.example.org + + # A shared CSRF cookie fails the re-login callback of every console tab but the + # last one to start a sign-in after a logout ("CSRF token mismatch", 403). + - it: keeps one CSRF cookie per sign-in flow + template: templates/gatekeeper.yaml + set: + _cluster: + root-host: example.org + oidc-enabled: "true" + asserts: + - contains: + path: spec.template.spec.containers[0].args + content: --cookie-csrf-per-request=true + - contains: + path: spec.template.spec.containers[0].args + content: --cookie-csrf-per-request-limit=10