From cabbb8faf00807fc3a3b2d4d466f61881a41a8d4 Mon Sep 17 00:00:00 2001 From: Alexey Artamonov Date: Tue, 1 Dec 2026 16:33:34 +0300 Subject: [PATCH] fix(linstor-gui): keep concurrent and slow sign-ins from failing on CSRF The linstor-gui gatekeeper runs oauth2-proxy with the same single, 15-minute CSRF cookie the dashboard had. Once the session ends, for example after a logout from the dashboard, every linstor-gui tab that is reloaded starts its own sign-in and overwrites the cookie of the others, so finishing the login in any tab but the last one fails with a 403 and "CSRF token mismatch, potential attack"; a login page left open for more than 15 minutes fails the same way with "CSRF cookie ... was not found", although Keycloak still accepts it. Give each sign-in its own CSRF cookie, cap how many can pile up in the request headers, and keep them for 1h instead of 15 minutes, which outlives Keycloak's 30-minute login lifespan. The lifetime stays finite and well inside --cookie-expire (168h): an older CSRF cookie fails signature validation and the per-request limit skips it instead of deleting it, so a longer-lived cookie would accumulate. Tested by running oauth2-proxy v7.12.0 with the chart-rendered gatekeeper arguments against a live Keycloak: with two tabs signing in after the session ended, the current arguments fail the first tab with the CSRF mismatch and the new ones sign both in. Assisted-by: LLM Signed-off-by: Alexey Artamonov --- .../linstor-gui/templates/gatekeeper.yaml | 9 +++++++ .../linstor-gui/tests/ingress_auth_test.yaml | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/system/linstor-gui/templates/gatekeeper.yaml b/packages/system/linstor-gui/templates/gatekeeper.yaml index 9f2c75732..aa34f8174 100644 --- a/packages/system/linstor-gui/templates/gatekeeper.yaml +++ b/packages/system/linstor-gui/templates/gatekeeper.yaml @@ -90,6 +90,15 @@ spec: - --cookie-name=kc-access - --cookie-secure=true - --cookie-secret=$(OAUTH2_PROXY_COOKIE_SECRET) + # One CSRF cookie per sign-in, kept for an hour: with a shared one, + # tabs signing in at once overwrite each other's state, and the + # default 15m fails a login page Keycloak still accepts for 30m. + # The limit keeps abandoned flows out of the headers; it cannot + # prune cookies older than the 168h --cookie-expire, so the + # lifetime stays finite and below that. + - --cookie-csrf-per-request=true + - --cookie-csrf-per-request-limit=10 + - --cookie-csrf-expire=1h - --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 diff --git a/packages/system/linstor-gui/tests/ingress_auth_test.yaml b/packages/system/linstor-gui/tests/ingress_auth_test.yaml index 1e2c9b80a..80bd53997 100644 --- a/packages/system/linstor-gui/tests/ingress_auth_test.yaml +++ b/packages/system/linstor-gui/tests/ingress_auth_test.yaml @@ -366,3 +366,28 @@ tests: - contains: path: spec.template.spec.containers[0].args content: --whitelist-domain=auth.example.org + + # One CSRF cookie per sign-in flow, kept for an hour: a shared cookie fails the + # callback of every tab but the last one to start a sign-in ("CSRF token + # mismatch"), the default 15m fails a login page Keycloak still accepts, and a + # lifetime past the 168h signature lifetime leaves cookies nothing can prune. + - it: keeps an hour-long CSRF cookie per sign-in flow + template: templates/gatekeeper.yaml + set: + _cluster: + root-host: example.org + oidc-enabled: "true" + expose-services: "linstor-gui" + 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 + - contains: + path: spec.template.spec.containers[0].args + content: --cookie-csrf-expire=1h + - notContains: + path: spec.template.spec.containers[0].args + content: --cookie-csrf-expire=0