fix(caddy): end the forgejo session on keycloak front-channel logout #760

Sammanfogat
supernaut sammanfogade 1 incheckning från fix/756-logout in i main 2026-10-17 09:59:30 +00:00
Ägare

Signing out on the portal now also signs the browser out of Forgejo, through Keycloak front-channel logout. Refs #756.

What

  • Keycloak (opentofu/keycloak/clients.tofu): the forgejo client gets frontchannel_logout_url = <forgejo_url>/user/frontchannel-logout. The other clients keep their current setting (null).
  • Caddy on git.*: a GET /user/frontchannel-logout with Sec-Fetch-Dest: iframe, Sec-Fetch-Site: same-site and the realm's iss is rewritten to Forgejo's own POST /user/logout. Forgejo then deletes the server-side session and expires the session and persistent cookies. That response drops X-Frame-Options and sends frame-ancestors https://<keycloak_domain>. Any other request to the path reaches Forgejo unchanged and gets a 404.
  • Test: ansible/roles/caddy/files/test_frontchannel_logout.sh runs the real template blocks in Caddy against a stub upstream. It covers the #646 control, the Keycloak frame, a cross-site frame, a top-level navigation, a wrong iss and missing fetch metadata. It is wired into CI.
  • Runbook: one paragraph next to the #646 sign-out paragraph.

Limits

  • Only a logout through Keycloak's page in the browser signs out of Forgejo. A Keycloak session that times out or is ended in the admin console does not.
  • Any same-site page can frame the URL and sign a user out of Forgejo. Other sites, links and fetches cannot.
  • Browsers without Fetch Metadata never match, so the Forgejo session stays open there.

Before merge

  • Staging apply: Keycloak plan shows one in-place update of keycloak_openid_client.sign_in["forgejo"] only; Caddy --check --diff shows only the new block.
  • Browser test on staging: portal sign-out ends the Forgejo session; opening the URL directly gives 404; #646 sign-out still works.

The bitborg-web FAQ change (accounts-signout) follows in its own PR after the test.

Signing out on the portal now also signs the browser out of Forgejo, through Keycloak front-channel logout. Refs #756. ## What - **Keycloak** (`opentofu/keycloak/clients.tofu`): the `forgejo` client gets `frontchannel_logout_url = <forgejo_url>/user/frontchannel-logout`. The other clients keep their current setting (`null`). - **Caddy on `git.*`**: a `GET /user/frontchannel-logout` with `Sec-Fetch-Dest: iframe`, `Sec-Fetch-Site: same-site` and the realm's `iss` is rewritten to Forgejo's own `POST /user/logout`. Forgejo then deletes the server-side session and expires the `session` and `persistent` cookies. That response drops `X-Frame-Options` and sends `frame-ancestors https://<keycloak_domain>`. Any other request to the path reaches Forgejo unchanged and gets a 404. - **Test**: `ansible/roles/caddy/files/test_frontchannel_logout.sh` runs the real template blocks in Caddy against a stub upstream. It covers the #646 control, the Keycloak frame, a cross-site frame, a top-level navigation, a wrong `iss` and missing fetch metadata. It is wired into CI. - **Runbook**: one paragraph next to the #646 sign-out paragraph. ## Limits - Only a logout through Keycloak's page in the browser signs out of Forgejo. A Keycloak session that times out or is ended in the admin console does not. - Any same-site page can frame the URL and sign a user out of Forgejo. Other sites, links and fetches cannot. - Browsers without Fetch Metadata never match, so the Forgejo session stays open there. ## Before merge - [x] Staging apply: Keycloak plan shows one in-place update of `keycloak_openid_client.sign_in["forgejo"]` only; Caddy `--check --diff` shows only the new block. - [x] Browser test on staging: portal sign-out ends the Forgejo session; opening the URL directly gives 404; #646 sign-out still works. The bitborg-web FAQ change (`accounts-signout`) follows in its own PR after the test.
supernaut lade till 1 incheckning 2026-10-17 09:54:49 +00:00
fix(caddy): end the forgejo session on keycloak front-channel logout
Alla kontroller lyckades
ci / ci (pull_request) Successful in 3m5s
2c5a2dc4da
Signing out of Bitborg-id from the portal now also signs the browser out of Forgejo.

- Keycloak: the forgejo client gets front-channel logout with frontchannel_logout_url https://<git>/user/frontchannel-logout. Other clients keep their current setting.
- Caddy on git.*: a GET to that path with Sec-Fetch-Dest iframe, Sec-Fetch-Site same-site and the realm's iss becomes Forgejo's own POST /user/logout. Forgejo deletes the server-side session and expires the session and persistent cookies. The response may be framed by the Keycloak host only.
- Any other request to the path reaches Forgejo unchanged (404).
- New test ansible/roles/caddy/files/test_frontchannel_logout.sh runs the real blocks against a stub upstream. It is wired into CI.

Refs #756
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-17 09:59:10 +00:00
supernaut sammanfogade incheckning be2f5d30dd till main 2026-10-17 09:59:30 +00:00
supernaut tog bort grenen fix/756-logout 2026-10-17 09:59:31 +00:00
Upphovsperson
Ägare

Prod apply, 2026-10-17, from main (be2f5d3):

  • OpenTofu opentofu/keycloak, workspace prod: 0 added, 1 changed, 0 destroyed. Only keycloak_openid_client.sign_in["forgejo"]: frontchannel_logout_enabled true, frontchannel_logout_url https://git.bitborg.se/user/frontchannel-logout.
  • Ansible --tags caddy on bitborg-prod: --check --diff showed only the @forgejo_frontchannel_logout block; apply changed=2, failed=0.

Curl checks on git.bitborg.se: bare URL 404 with X-Frame-Options: DENY; iframe-shaped GET with the realm's iss 200, frame-ancestors https://id.bitborg.se, persistent and redirect_to expired. X-Frame-Options: DENY also on the 200, as on staging (#761).

Prod apply, 2026-10-17, from `main` (be2f5d3): - OpenTofu `opentofu/keycloak`, workspace `prod`: 0 added, 1 changed, 0 destroyed. Only `keycloak_openid_client.sign_in["forgejo"]`: `frontchannel_logout_enabled` true, `frontchannel_logout_url` `https://git.bitborg.se/user/frontchannel-logout`. - Ansible `--tags caddy` on `bitborg-prod`: `--check --diff` showed only the `@forgejo_frontchannel_logout` block; apply `changed=2`, `failed=0`. Curl checks on `git.bitborg.se`: bare URL `404` with `X-Frame-Options: DENY`; iframe-shaped `GET` with the realm's `iss` `200`, `frame-ancestors https://id.bitborg.se`, `persistent` and `redirect_to` expired. `X-Frame-Options: DENY` also on the `200`, as on staging (#761).
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-infra!760
Ingen beskrivning angiven.