keycloak: end the forgejo session on portal sign-out #756

Stängd
öppnade 2026-10-15 11:02:13 +00:00 av supernaut · 10 kommentarer
Ägare

What

Signing out on the portal ends the portal session and the Bitborg ID (Keycloak) session. The Forgejo session at git.bitborg.se stays open until the person signs out there or it expires. On a shared computer the next person can still use git.bitborg.se as them.

The other direction works since #646: Forgejo sign-out also ends the Bitborg ID session.

Options to evaluate

  • Keycloak back-channel logout to Forgejo: Forgejo v16 has no back-channel logout endpoint.
  • Front-channel logout: Keycloak loads a Forgejo URL in the browser on logout. Forgejo's sign-out is a same-origin POST, so this needs a Caddy-side endpoint that ends the Forgejo session, much like the #646 approach.
  • Shorter Forgejo session lifetime as a mitigation only.
  • Wait for upstream Forgejo OIDC logout support.

Done when

  • Signing out on the portal also ends the Forgejo session, tested on staging in a browser.
  • The FAQ accounts-signout (bitborg-web, English and Swedish) no longer advises signing out in both places.
## What Signing out on the portal ends the portal session and the Bitborg ID (Keycloak) session. The Forgejo session at git.bitborg.se stays open until the person signs out there or it expires. On a shared computer the next person can still use git.bitborg.se as them. The other direction works since #646: Forgejo sign-out also ends the Bitborg ID session. ## Options to evaluate - Keycloak back-channel logout to Forgejo: Forgejo v16 has no back-channel logout endpoint. - Front-channel logout: Keycloak loads a Forgejo URL in the browser on logout. Forgejo's sign-out is a same-origin POST, so this needs a Caddy-side endpoint that ends the Forgejo session, much like the #646 approach. - Shorter Forgejo session lifetime as a mitigation only. - Wait for upstream Forgejo OIDC logout support. ## Done when - Signing out on the portal also ends the Forgejo session, tested on staging in a browser. - The FAQ `accounts-signout` (bitborg-web, English and Swedish) no longer advises signing out in both places.
Upphovsperson
Ägare

Next step: reproduce on staging in a browser. Sign in through the portal, open Forgejo, sign out on the portal, then reload Forgejo. Then check whether a front-channel logout URL on the Keycloak forgejo client, served through Caddy as in #646, ends the Forgejo session. Curl cannot show this, because the race in #646 happens only in a browser.

Next step: reproduce on staging in a browser. Sign in through the portal, open Forgejo, sign out on the portal, then reload Forgejo. Then check whether a front-channel logout URL on the Keycloak `forgejo` client, served through Caddy as in #646, ends the Forgejo session. Curl cannot show this, because the race in #646 happens only in a browser.
Upphovsperson
Ägare

Not started yet. Reproducing this needs a signed-in staging browser session, and the SAQ A checkout check on staging uses the same session, so that check goes first. Next step: reproduce on stg in a browser, then test a front-channel logout URL on the Keycloak forgejo client, served through Caddy as in #646.

Not started yet. Reproducing this needs a signed-in staging browser session, and the SAQ A checkout check on staging uses the same session, so that check goes first. Next step: reproduce on stg in a browser, then test a front-channel logout URL on the Keycloak `forgejo` client, served through Caddy as in #646.
Upphovsperson
Ägare

Reproduced on staging in a browser, 2026-10-17.

  1. Signed in through the portal, then on git.stg.bitborg.se.
  2. Portal sign-out went to the Keycloak logout endpoint (client_id=bitborg-web, with id_token_hint). Keycloak showed a "Do you want to log out?" confirmation page. Confirmed.
  3. The Keycloak session ended: the account console asked for sign-in.
  4. git.stg.bitborg.se still showed the user signed in after a reload.

Cause: the portal sign-out ends only the portal and Keycloak sessions. Nothing tells Forgejo, and Forgejo v16 has no OIDC logout endpoint.

Triage: go with front-channel logout on the Keycloak forgejo client. The URL is a Caddy endpoint on the Forgejo host that expires the Forgejo session cookies, in the style of #646. Open questions for the change: framing (the global X-Frame-Options), the server-side session, and limiting who can trigger the endpoint. Side finding: the confirmation page appears despite id_token_hint. Looking into it with the change.

Reproduced on staging in a browser, 2026-10-17. 1. Signed in through the portal, then on git.stg.bitborg.se. 2. Portal sign-out went to the Keycloak logout endpoint (`client_id=bitborg-web`, with `id_token_hint`). Keycloak showed a "Do you want to log out?" confirmation page. Confirmed. 3. The Keycloak session ended: the account console asked for sign-in. 4. git.stg.bitborg.se still showed the user signed in after a reload. Cause: the portal sign-out ends only the portal and Keycloak sessions. Nothing tells Forgejo, and Forgejo v16 has no OIDC logout endpoint. Triage: go with front-channel logout on the Keycloak `forgejo` client. The URL is a Caddy endpoint on the Forgejo host that expires the Forgejo session cookies, in the style of #646. Open questions for the change: framing (the global `X-Frame-Options`), the server-side session, and limiting who can trigger the endpoint. Side finding: the confirmation page appears despite `id_token_hint`. Looking into it with the change.
Upphovsperson
Ägare

Change is in PR #760. Merge after the staging apply and browser test listed there.

Change is in PR #760. Merge after the staging apply and browser test listed there.
Upphovsperson
Ägare

Staging apply of #760, 2026-10-17, from main at be2f5d3 (the PR was already merged; tree equal to 2c5a2dc).

  • OpenTofu opentofu/keycloak, workspace staging: 0 added, 1 changed, 0 destroyed. Only keycloak_openid_client.sign_in["forgejo"]: frontchannel_logout_enabled true, frontchannel_logout_url https://git.stg.bitborg.se/user/frontchannel-logout.
  • Ansible --tags caddy on bitborg-staging: changed=2 (Caddyfile, restart), failed=0. Diff was only the @forgejo_frontchannel_logout block.

Curl checks:

  • Bare URL: 404, X-Frame-Options: DENY. As expected.
  • GET with Sec-Fetch-Dest: iframe, Sec-Fetch-Site: same-site and the iss query: 200, Content-Security-Policy: frame-ancestors https://id.stg.bitborg.se, persistent and redirect_to cookies expired (Max-Age=0).
  • Deviation: X-Frame-Options: DENY is still on the 200 response. The site-wide security_headers snippet sets it after the inner -X-Frame-Options runs. Browsers ignore X-Frame-Options when the CSP has frame-ancestors, so the browser test decides whether this needs a fix.
  • A HEAD request does not match (method GET) and gets 404. Expected.

Browser test next.

Staging apply of #760, 2026-10-17, from `main` at be2f5d3 (the PR was already merged; tree equal to `2c5a2dc`). - OpenTofu `opentofu/keycloak`, workspace `staging`: 0 added, 1 changed, 0 destroyed. Only `keycloak_openid_client.sign_in["forgejo"]`: `frontchannel_logout_enabled` true, `frontchannel_logout_url` `https://git.stg.bitborg.se/user/frontchannel-logout`. - Ansible `--tags caddy` on `bitborg-staging`: `changed=2` (Caddyfile, restart), `failed=0`. Diff was only the `@forgejo_frontchannel_logout` block. Curl checks: - Bare URL: `404`, `X-Frame-Options: DENY`. As expected. - `GET` with `Sec-Fetch-Dest: iframe`, `Sec-Fetch-Site: same-site` and the `iss` query: `200`, `Content-Security-Policy: frame-ancestors https://id.stg.bitborg.se`, `persistent` and `redirect_to` cookies expired (`Max-Age=0`). - Deviation: `X-Frame-Options: DENY` is still on the `200` response. The site-wide `security_headers` snippet sets it after the inner `-X-Frame-Options` runs. Browsers ignore `X-Frame-Options` when the CSP has `frame-ancestors`, so the browser test decides whether this needs a fix. - A `HEAD` request does not match (`method GET`) and gets `404`. Expected. Browser test next.
Upphovsperson
Ägare

Browser test on staging, 2026-10-17, Chrome, account signup-test-free. All four steps pass.

  1. Portal "Logga ut": Keycloak showed its confirm page (side finding, see below), then logged out. Staging Caddy log, 10:08:34Z: GET git.stg.bitborg.se/user/frontchannel-logout?iss=…&sid=…, 200, Sec-Fetch-Dest: iframe, Sec-Fetch-Site: same-site.
  2. Reload git.stg.bitborg.se: signed out. "Sign in" showed the Keycloak login form.
  3. Abuse check, after a fresh sign-in: the URL with a valid iss in the address bar gives 404, and the user stays signed in.
  4. #646 regression: Forgejo "Sign out" goes to the Keycloak confirm page (client_id=forgejo), then back to Forgejo signed out. The next "Sign in" shows the login form.

The extra X-Frame-Options: DENY on the 200 did not stop the sign-out. Follow-up to drop the dead -X-Frame-Options line and its test assertion is open for decision.

Left for this issue: the bitborg-web FAQ accounts-signout PR.

Browser test on staging, 2026-10-17, Chrome, account `signup-test-free`. All four steps pass. 1. Portal "Logga ut": Keycloak showed its confirm page (side finding, see below), then logged out. Staging Caddy log, 10:08:34Z: `GET git.stg.bitborg.se/user/frontchannel-logout?iss=…&sid=…`, `200`, `Sec-Fetch-Dest: iframe`, `Sec-Fetch-Site: same-site`. 2. Reload `git.stg.bitborg.se`: signed out. "Sign in" showed the Keycloak login form. 3. Abuse check, after a fresh sign-in: the URL with a valid `iss` in the address bar gives `404`, and the user stays signed in. 4. #646 regression: Forgejo "Sign out" goes to the Keycloak confirm page (`client_id=forgejo`), then back to Forgejo signed out. The next "Sign in" shows the login form. The extra `X-Frame-Options: DENY` on the `200` did not stop the sign-out. Follow-up to drop the dead `-X-Frame-Options` line and its test assertion is open for decision. Left for this issue: the bitborg-web FAQ `accounts-signout` PR.
Upphovsperson
Ägare

FAQ PR: bitborg/bitborg-web#399. Merge it only after #760 is applied on prod.

FAQ PR: bitborg/bitborg-web#399. Merge it only after #760 is applied on prod.
Upphovsperson
Ägare

Follow-up PR #761 drops the no-op -X-Frame-Options from the front-channel handle, its test assertion and the runbook claim. After merge: --tags caddy on staging and prod.

Follow-up PR #761 drops the no-op `-X-Frame-Options` from the front-channel handle, its test assertion and the runbook claim. After merge: `--tags caddy` on staging and prod.
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).
Upphovsperson
Ägare

Done: #760 and #761 merged and applied on staging and prod (operator ran --tags caddy on both after #761), FAQ bitborg/bitborg-web#399 merged. Front-channel URL re-checked on both envs: iframe-shaped GET 200, bare URL 404. Side finding tracked in bitborg/bitborg-web#398.

Done: #760 and #761 merged and applied on staging and prod (operator ran `--tags caddy` on both after #761), FAQ bitborg/bitborg-web#399 merged. Front-channel URL re-checked on both envs: iframe-shaped GET 200, bare URL 404. Side finding tracked in bitborg/bitborg-web#398.
supernaut refererade till detta ärende från en incheckning 2026-10-17 15:18:36 +00:00
Logga in för att delta i denna konversation.
Ingen milstolpe
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#756
Ingen beskrivning angiven.