mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-05 14:42:05 +09:00
fix(dashboard): keep a slow re-login from failing on an expired CSRF cookie
After a logout the console lands straight on the Keycloak login page. If that page stays open for more than 15 minutes before the password is entered, the callback fails with a 403 and the gatekeeper logs unable to obtain CSRF cookie: ... CSRF cookie with name 'kc-access_<state>_csrf' was not found oauth2-proxy gives the CSRF cookie a fixed Max-Age of --cookie-csrf-expire (15m by default), while Keycloak keeps a login page usable for 30 minutes and then restarts the flow with the original state, so the browser drops the cookie while the login it belongs to is still alive. The lifetime becomes 1h, which outlives Keycloak's login lifespan. It stays finite and well below --cookie-expire (168h) on purpose: a CSRF cookie with an older signature fails validation, and the per-request limit skips such cookies instead of deleting them, so a cookie the browser keeps longer than that would stay in the request headers. Tested by running the chart-rendered oauth2-proxy v7.12.0 config against a live Keycloak, waiting in real time: after a logout, a login page left open for 16 minutes fails with the 403 above on the default lifetime and signs in once the cookie outlives the wait; at 31 minutes Keycloak asks for the password again and the login then completes. The same binary sets Max-Age=3600 on the CSRF cookie with this flag. Assisted-by: LLM Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
This commit is contained in:
1 parent
06c2be9745
commit
777721f5f7
2 files changed
+23
No files matched your search
@@ -76,6 +76,12 @@ spec:
|
||||
# abandoned flows from piling up in the request headers.
|
||||
- --cookie-csrf-per-request=true
|
||||
- --cookie-csrf-per-request-limit=10
|
||||
# Keycloak accepts a login page for 30m and then restarts it with the
|
||||
# original state, so the default 15m fails the callback of a login
|
||||
# page left open longer. Keep it finite and below the 168h
|
||||
# --cookie-expire: older CSRF cookies fail signature checks, and
|
||||
# the per-request limit skips them instead of deleting them.
|
||||
- --cookie-csrf-expire=1h
|
||||
- --skip-provider-button
|
||||
{{- if eq $oidcInsecureSkipVerify "true" }}
|
||||
- --ssl-insecure-skip-verify=true
|
||||
|
||||
@@ -221,3 +221,20 @@ tests:
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --cookie-csrf-per-request-limit=10
|
||||
|
||||
# The CSRF cookie has to outlive Keycloak's 30m login lifespan, or a login page
|
||||
# left open that long fails its callback, and stay finite and below the 168h
|
||||
# signature lifetime, past which oauth2-proxy can neither read nor prune it.
|
||||
- it: keeps the CSRF cookie for an hour
|
||||
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-expire=1h
|
||||
- notContains:
|
||||
path: spec.template.spec.containers[0].args
|
||||
content: --cookie-csrf-expire=0
|
||||
Reference in new issue
Block a user