Skip to content

WPB-22966: migrate oauth auth-code to PostGreSQL - #5622

Open
blackheaven wants to merge 7 commits into
developfrom
gdifolco/WPB-22966-migration-postgres-oauth-auth-code
Open

blackheaven wants to merge 7 commits into
developfrom
gdifolco/WPB-22966-migration-postgres-oauth-auth-code

Conversation

@blackheaven

Copy link
Copy Markdown
Contributor

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

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 20, 2026 23:35
@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Oct 20, 2026
@blackheaven
blackheaven force-pushed the gdifolco/WPB-22966-migration-postgres-oauth-auth-code branch from 0cde656 to 6f14a1c Compare October 20, 2026 23:58
@blackheaven
blackheaven force-pushed the gdifolco/WPB-22966-migration-postgres-oauth-auth-code branch 2 times, most recently from c5bab57 to de55a54 Compare November 4, 2026 12:50
@blackheaven
blackheaven force-pushed the gdifolco/WPB-22966-migration-postgres-oauth-auth-code branch from de55a54 to 7ccf775 Compare November 5, 2026 12:53
@VeryMilkyJoe
VeryMilkyJoe requested a balanced review from Copilot November 6, 2026 16:33

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

Critical schema and backfill defects invalidate the SQL dump, block migration completion, and risk reactivating redeemed or expired authorization codes.

7 open issues
What changed in this PR

This PR adds PostgreSQL storage for OAuth authorization codes, moving Brig’s persistence logic behind a shared store abstraction with Cassandra, dual-write, and PostgreSQL modes.

Changes:

  • Adds the authorization-code store, PostgreSQL schema, and serialization support.
  • Wires background migration, metrics, configuration, and deployment settings.
  • Adds migration lifecycle and serialization tests, documentation, and a changelog entry.
File Description
services/​galley/​galley.integration.yaml Adds the authorization-code storage setting.
services/​brig/​src/​Brig/​CanonicalInterpreter.hs Selects the configured store interpreter.
services/​brig/​src/​Brig/​API/​Public.hs Adds the store effect requirement.
services/​brig/​src/​Brig/​API/​OAuth.hs Routes authorization-code operations through the store.
services/​brig/​brig.integration.yaml Selects PostgreSQL for integration testing.
services/​background-worker/​test/​Test/​Wire/​Util.hs Updates test migration options.
services/​background-worker/​test/​Test/​Wire/​BackendNotificationPusherSpec.hs Updates migration-option fixtures.
services/​background-worker/​src/​Wire/​PostgresMigrations.hs Adds migration startup and metrics.
services/​background-worker/​src/​Wire/​BackgroundWorker/​Options.hs Adds the migration enablement flag.
services/​background-worker/​src/​Wire/​BackgroundWorker.hs Wires migration startup and cleanup.
services/​background-worker/​background-worker.integration.yaml Adds integration migration settings.
postgres-schema.sql Updates the schema snapshot.
libs/​wire-subsystems/​wire-subsystems.cabal Exposes the new store modules.
libs/​wire-subsystems/​src/​Wire/​PostgresMigrationOpts.hs Adds storage-mode configuration.
libs/​wire-subsystems/​src/​Wire/​OAuthAuthCodeStore/​Postgres.hs Implements PostgreSQL insertion and atomic consumption.
libs/​wire-subsystems/​src/​Wire/​OAuthAuthCodeStore/​Migration.hs Implements Cassandra-to-PostgreSQL backfill.
libs/​wire-subsystems/​src/​Wire/​OAuthAuthCodeStore/​DualWrite.hs Mirrors writes and consumption during migration.
libs/​wire-subsystems/​src/​Wire/​OAuthAuthCodeStore/​Cassandra.hs Extracts existing Cassandra persistence.
libs/​wire-subsystems/​src/​Wire/​OAuthAuthCodeStore.hs Defines the authorization-code store effect.
libs/​wire-subsystems/​postgres-migrations/​20261020120000-oauth-auth-code.sql Creates the table and expiration index.
libs/​wire-api/​test/​unit/​Test/​Wire/​API/​Roundtrip/​PostgresMarshall.hs Adds OAuth serialization round-trip tests.
libs/​wire-api/​src/​Wire/​API/​OAuth.hs Adds PostgreSQL serialization instances.
integration/​test/​Test/​Migration/​OAuthAuthCode.hs Adds migration lifecycle and replay assertions.
integration/​integration.cabal Registers the migration test module.
hack/​helm_vars/​wire-server/​values.yaml.gotmpl Passes the selected storage mode into Helm values.
hack/​helm_vars/​common.yaml.gotmpl Defines the preferred authorization-code store.
docs/​src/​developer/​reference/​config-options.md Documents configuration and migration controls.
charts/​wire-server/​values.yaml Adds default storage and migration settings.
charts/​wire-server/​templates/​background-worker/​configmap.yaml Renders the migration flag.
changelog.d/​5-internal/​WPB-22966 Records the storage migration.

Review effort: Balanced

Comment thread postgres-schema.sql Resolved
@blackheaven
blackheaven force-pushed the gdifolco/WPB-22966-migration-postgres-oauth-auth-code branch from af078e2 to 638f9fb Compare November 10, 2026 08:54
- Backfill: read ttl(client) instead of ttl(code) (Cassandra rejects
  ttl() on key columns); capture one absolute deadline per page so
  buffered rows cannot outlive their source TTL; skip rows whose
  deadline already passed; probe Cassandra liveness before inserting so
  codes consumed while buffered are not resurrected in Postgres.
- insertOAuthAuthCodePg takes an absolute expires_at and inserts with
  ON CONFLICT (code) DO NOTHING; interpreter computes now + ttl.
- postgres-schema.sql: repair the oauth_auth_code splice that broke the
  nonce table block (missing expires_at, terminator, OWNER ordering).
- Integration test: route users to the dynamic backend domain; use the
  real brig config key settings.setOAuthAuthorizationCodeExpirationTimeSecs.
Adds the guarded cron.schedule migration for the short-lived
oauth_auth_code rows (daily sweep; reads already filter on expires_at),
mirroring the mls-proposal-refs TTL-cleanup template. Also restores the
opening '--' comment line for the oauth_auth_code_pkey constraint block
in postgres-schema.sql.
@blackheaven
blackheaven force-pushed the gdifolco/WPB-22966-migration-postgres-oauth-auth-code branch from 638f9fb to 90a0296 Compare November 13, 2026 19:02

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