Skip to content

WPB-29578: migrate session cookies to PostGreSQL - #5644

Open
blackheaven wants to merge 8 commits into
developfrom
gdifolco/WPB-29578-migration-postgres-session-store
Open

blackheaven wants to merge 8 commits into
developfrom
gdifolco/WPB-29578-migration-postgres-session-store

Conversation

@blackheaven

@blackheaven blackheaven commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

https://wearezeta.atlassian.net/browse/WPB-29578

Checklist

  • Add a new entry in an appropriate subdirectory of changelog.d
  • Read and follow the PR guidelines

@blackheaven
blackheaven requested review from a team as code owners October 22, 2026 20:58
@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Oct 22, 2026
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29578-migration-postgres-session-store branch 2 times, most recently from 55712b3 to 1145bd0 Compare October 29, 2026 17:43
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29578-migration-postgres-session-store branch from b61ab0a to 4b831a0 Compare November 4, 2026 14:53
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29578-migration-postgres-session-store branch from 4b831a0 to e8ca66a Compare November 5, 2026 13:47
@VeryMilkyJoe
VeryMilkyJoe requested a balanced review from Copilot November 6, 2026 16:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The session backfill cannot decode its Cassandra scan and can resurrect revoked cookies or extend cookie validity, creating critical migration and authentication risks.

6 open issues
What changed in this PR

Adds PostgreSQL storage for session cookies, with dual writes and a background backfill worker to support migration from Cassandra.

Changes:

  • Adds the session schema, PostgreSQL interpreter, dual-write mode, and migration worker.
  • Wires storage selection and migration controls into Brig, deployment configuration, and operator documentation.
  • Adds cookie marshalling checks and an integration test covering migration phases.
File Description
services/​galley/​galley.integration.yaml Selects PostgreSQL session storage for integration environments.
services/​brig/​src/​Brig/​CanonicalInterpreter.hs Selects the configured session-store interpreter.
services/​brig/​src/​Brig/​App.hs Supports PostgreSQL in the ad hoc session-store runner.
services/​brig/​brig.integration.yaml Enables PostgreSQL session storage.
services/​background-worker/​test/​Test/​Wire/​Util.hs Adds session storage to test configuration.
services/​background-worker/​test/​Test/​Wire/​BackendNotificationPusherSpec.hs Updates configuration fixtures with the sessions field.
services/​background-worker/​src/​Wire/​PostgresMigrations.hs Starts session backfill with metrics and cleanup.
services/​background-worker/​src/​Wire/​BackgroundWorker/​Options.hs Adds the session migration flag.
services/​background-worker/​src/​Wire/​BackgroundWorker.hs Wires migration startup and shutdown.
services/​background-worker/​background-worker.integration.yaml Configures session storage and migration defaults.
postgres-schema.sql Records the cookie table, primary key, and index.
libs/​wire-subsystems/​wire-subsystems.cabal Exposes the new session-store modules.
libs/​wire-subsystems/​src/​Wire/​SessionStore/​Postgres.hs Implements PostgreSQL cookie storage and validity filtering.
libs/​wire-subsystems/​src/​Wire/​SessionStore/​Migration.hs Implements Cassandra-to-PostgreSQL session backfill.
libs/​wire-subsystems/​src/​Wire/​SessionStore/​DualWrite.hs Mirrors mutations while retaining Cassandra reads.
libs/​wire-subsystems/​src/​Wire/​SessionStore/​Cassandra.hs Adds the session scan used by backfill.
libs/​wire-subsystems/​src/​Wire/​PostgresMigrationOpts.hs Adds session storage selection.
libs/​wire-subsystems/​postgres-migrations/​20261022090000-user-cookies.sql Creates the PostgreSQL session schema.
libs/​wire-api/​test/​unit/​Test/​Wire/​API/​Roundtrip/​PostgresMarshall.hs Adds cookie marshalling round-trip checks.
libs/​wire-api/​src/​Wire/​API/​User/​Auth.hs Adds PostgreSQL conversions for cookie types.
integration/​test/​Test/​Migration/​Sessions.hs Adds phased session migration coverage.
integration/​integration.cabal Registers the migration test module.
hack/​helm_vars/​wire-server/​values.yaml.gotmpl Passes session storage selection into Helm values.
hack/​helm_vars/​common.yaml.gotmpl Defines the preferred session store.
docs/​src/​developer/​reference/​config-options.md Documents session migration settings and metrics.
charts/​wire-server/​values.yaml Adds session storage and worker defaults.
charts/​wire-server/​templates/​background-worker/​configmap.yaml Renders the session migration flag.
changelog.d/​gdifolco-WPB-29578-migration-postgres-session-store Adds a session migration changelog fragment.

Review effort: Balanced

@blackheaven
blackheaven force-pushed the gdifolco/WPB-29578-migration-postgres-session-store branch from e8ca66a to 9ac86a5 Compare November 10, 2026 08:36
…er-cookies pg_cron job (ADR-0005)

- DualWrite mutations hold a shared per-user migration lock so they serialize
  against the backfill's exclusive lock: a revoke racing the copy loop either
  lands before the lock (row skipped) or after (Postgres row deleted), never
  resurrecting a cookie (5685 connections pattern). The backfill re-reads the
  Cassandra row inside the locked section.
- Backfill stamps an absolute validity deadline computed from the row's
  remaining Cassandra TTL at page-fetch time (never now()+TTL at insert, which
  would restart and extend the cookie's validity); expired rows are skipped.
- Backfill insert is ON CONFLICT DO NOTHING (insertCookieWithDeadline); the
  runtime renew path keeps DO UPDATE.
- Reads filter expired rows; inserts purge expired rows in-statement.
- New guarded migration 20261110121000-user-cookies-ttl-cleanup.sql schedules
  cron job expire-user-cookies (hourly) and adds user_cookies_expires_at_idx
  (hand-merged into postgres-schema.sql; the shared backendA database does not
  carry this PR's tables, so the full pg_dump regen shows only unrelated
  blocks).
- Changelog renamed to changelog.d/5-internal/WPB-29578.
@blackheaven
blackheaven force-pushed the gdifolco/WPB-29578-migration-postgres-session-store branch from 9ac86a5 to 036ce60 Compare November 13, 2026 11:12

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

easy-to-review ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants