mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-05 14:42:05 +09:00
fix(linstor-gui): keep concurrent and slow sign-ins from failing on CSRF (#5538)
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, security (a fix that comes through a security advisory), docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list — pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer, a `fix` included. What counts as breaking: https://github.com/cozystack/cozystack/blob/main/docs/agents/contributing.md#what-counts-as-breaking - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Fixes merged to `main` reach the release lines the backport batch runs for automatically, so do not open backport PRs by hand: https://github.com/cozystack/cozystack/blob/main/docs/release/backports.md --> ## What this PR does The linstor-gui gatekeeper runs oauth2-proxy with the same CSRF cookie setup that #5536 and #5537 change for the dashboard: one shared `kc-access_csrf` cookie with a 15-minute lifetime. Once the session ends, for example after a logout from the dashboard, every linstor-gui tab that gets reloaded starts its own sign-in and overwrites the CSRF cookie of the others. Finishing the login in any tab but the last one ends on a `403 Forbidden` with `CSRF token mismatch, potential attack` in the log. 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. The gatekeeper now runs with `--cookie-csrf-per-request=true`, `--cookie-csrf-per-request-limit=10` and `--cookie-csrf-expire=1h`: one CSRF cookie per sign-in, a cap on how many can pile up in the request headers, and a lifetime that outlives Keycloak's 30-minute login lifespan. The lifetime stays well below `--cookie-expire` (168h), because a CSRF cookie with an older signature fails validation and the limit skips it instead of deleting it. Verified on a test cluster with oauth2-proxy v7.12.0 run on the chart-rendered gatekeeper arguments against the 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. The lifetime change was measured on the dashboard gatekeeper, which shares the mechanism: a login page left open for 16 minutes fails on the default lifetime and signs in once the cookie outlives the wait (#5537). The realm used for the test has no `linstor-gui` client, so the run used another confidential client and left out `--allowed-group`, which oauth2-proxy checks only after the CSRF state. A helm-unittest case pins all three flags. <!-- Uncomment the next line when this PR adds or changes a downstream patch: https://github.com/cozystack/cozystack/blob/main/CONTRIBUTING.md#patches-to-other-projects-code --> <!-- Upstream: link to the upstream pull request, or to the issue or thread where the change was raised --> ### Screenshots No visual change: only the gatekeeper's oauth2-proxy flags change. ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM TO FILL IN: 1. Walk the trigger map against the actual diff of this PR, file by file. Do not decide from the PR title or from your memory of what you changed. 2. For every repository you tick, open the follow-up PR there and link it on the same line. A ticked box with no link claims work that does not exist, which is worse than an empty box. Search that repository for an open PR or issue covering it first, and link that instead of filing a duplicate. 3. When the follow-up is out of scope, or needs a decision that is not yours to make, open an issue in that repository instead, link that, and say so in the PR body. Do not push a speculative PR into another repository just to fill a line here. 4. Do not tick "No downstream repository is affected" to make the checklist go away. If you are unsure, leave every box empty and say so in the PR body, so a human decides. --> - [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: ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same `type(scope):` prefix as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note fix(linstor-gui): signing in no longer fails with a 403 "CSRF token mismatch" when several linstor-gui tabs sign in at once, or when the Keycloak login page was left open for more than 15 minutes. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved sign-in CSRF cookie handling by limiting concurrent per-request cookies to 10 and setting them to expire after one hour. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
2 files changed
+34
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user