Repository navigation
WPB-29582: migrate mls key packages to PostGreSQL - #5646
Open
blackheaven wants to merge 6 commits into
Open
blackheaven wants to merge 6 commits into
blackheaven wants to merge 6 commits into
Conversation
blackheaven
force-pushed
the
gdifolco/WPB-29582-migration-postgres-mls-key-packages
branch
2 times, most recently
from
October 23, 2026 12:30
20c88fe to
322caef
Compare
akshaymankar
requested changes
Oct 28, 2026
blackheaven
force-pushed
the
gdifolco/WPB-29582-migration-postgres-mls-key-packages
branch
from
November 4, 2026 11:26
fa20ba2 to
eaa5b43
Compare
blackheaven
force-pushed
the
gdifolco/WPB-29582-migration-postgres-mls-key-packages
branch
from
November 5, 2026 12:05
eaa5b43 to
ffbd9e8
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The review found an issue that should be addressed before approval.
10 open issues
OwnDomain resolves to the static env.domain1; startDynamicBackend does not change it. Consequently… · New Passing alice1 sends its Z-Client header. Because the target is Alice herself,… · New This self-claim sends alice1 as Z-Client, so Brig excludes the only client and consumes no package.… · New Brig skips the requesting client when claiming the same user's packages. Passing alice1 here… · New The delete endpoint returns HTTP 201 in both API versions (MLSKeyPackageAPI in… · New replaceKeyPackages calls the PUT endpoint whose successful response is HTTP 201, as specified by… · New This claim targets the requesting user's own client, which claimLocalKeyPackages excludes using the… · New An unmarked user keeps writing exclusively to Cassandra, but Wire.Migration.migrationLoop exits… · New This DISTINCT query is invalid for the existing Cassandra schema. V80_KeyPackageCiphersuite.hs… · New The Cassandra partition key is (user, client, cipher_suite), not user alone (see… · New
What changed in this PR
Adds PostgreSQL storage and migration support for MLS key packages, connecting Brig’s storage routing to a background-worker backfill.
Changes:
- Introduces PostgreSQL tables, serialization, and store operations.
- Adds per-user migration locking, routing, worker controls, and metrics.
- Updates deployment configuration, documentation, and migration tests.
| File | Description |
|---|---|
| services/galley/galley.integration.yaml | Updated as part of this pull request. |
| services/brig/src/Brig/CanonicalInterpreter.hs | Updated as part of this pull request. |
| services/brig/brig.integration.yaml | Updated as part of this pull request. |
| services/background-worker/test/Test/Wire/Util.hs | Updated as part of this pull request. |
| services/background-worker/test/Test/Wire/BackendNotificationPusherSpec.hs | Updated as part of this pull request. |
| services/background-worker/src/Wire/PostgresMigrations.hs | Updated as part of this pull request. |
| services/background-worker/src/Wire/BackgroundWorker/Options.hs | Updated as part of this pull request. |
| services/background-worker/src/Wire/BackgroundWorker.hs | Updated as part of this pull request. |
| services/background-worker/background-worker.integration.yaml | Updated as part of this pull request. |
| postgres-schema.sql | Updated as part of this pull request. |
| libs/wire-subsystems/wire-subsystems.cabal | Updated as part of this pull request. |
| libs/wire-subsystems/src/Wire/PostgresMigrationOpts.hs | Updated as part of this pull request. |
| libs/wire-subsystems/src/Wire/MlsKeyPackageStore/Postgres.hs | Updated as part of this pull request. |
| libs/wire-subsystems/src/Wire/MlsKeyPackageStore/Migration.hs | Updated as part of this pull request. |
| libs/wire-subsystems/src/Wire/MlsKeyPackageStore/Migrating.hs | Updated as part of this pull request. |
| libs/wire-subsystems/postgres-migrations/20261023072742-mls-key-packages.sql | Updated as part of this pull request. |
| libs/wire-api/test/unit/Test/Wire/API/Roundtrip/PostgresMarshall.hs | Updated as part of this pull request. |
| libs/wire-api/src/Wire/API/MLS/KeyPackage.hs | Updated as part of this pull request. |
| libs/wire-api/src/Wire/API/MLS/CipherSuite.hs | Updated as part of this pull request. |
| integration/test/Test/Migration/MlsKeyPackages.hs | Updated as part of this pull request. |
| integration/integration.cabal | Updated as part of this pull request. |
| hack/helm_vars/wire-server/values.yaml.gotmpl | Updated as part of this pull request. |
| hack/helm_vars/common.yaml.gotmpl | Updated as part of this pull request. |
| docs/src/developer/reference/config-options.md | Updated as part of this pull request. |
| charts/wire-server/values.yaml | Updated as part of this pull request. |
| charts/wire-server/templates/background-worker/configmap.yaml | Updated as part of this pull request. |
| changelog.d/5-internal/WPB-29582 | Updated as part of this pull request. |
Review effort: Balanced
- Rename mls_key_packages column "user" -> user_id (migration SQL, hasql statements, postgres-schema.sql hand-merged from pg_dump of the migration). - Drop Wire.MlsKeyPackageStore.DualWrite entirely: key packages are one-time-use security material (claiming deletes them), so an async delete-mirror failure could resurface a claimed key package in Postgres. migration-to-postgresql now serves Cassandra from brig while the background-worker copy loop backfills Postgres; cutover is the direct config flip cassandra -> postgresql, followed by an immediate reconciliation pass (documented in Migration.hs haddock). - Fix integration test imports (createMLSClient/ciphersuites from MLS.Util) so the test compiles.
…-user marker - insertKeyPackagesPg stored ref and data swapped; PG mode was functionally broken - migration: per-user exclusive lock + copy + marker (mls_key_packages_migrated_users); already-marked users are skipped so retry passes/restarts cannot resurrect claimed one-time-use key packages; no Cassandra deletes (users precedent) - brig migration mode: new Wire.MlsKeyPackageStore.Migrating routes per user by the marker under a shared migration lock (same strategy as the users store) - integration test: assert no failed migrations; pin claim path against ref/data swap
…-demand migration - The copier enumerated users with SELECT DISTINCT user FROM mls_key_packages, which is invalid CQL (user is not the only partition key); enumerate brig's clients table instead (partition key user alone) and fan out over (client, cipher suite) point queries restricted on the full (user, client, cipher_suite) partition key. - On-demand migration in the migration-mode interpreter: an unmarked user is copied + marked under the exclusive migration lock on first routed access, so users whose first key package lands after the worker's enumeration passed them cannot lose all packages at cutover (no reconciliation pass needed). - Test: Alice on the backend domain (OwnDomain is static env.domain1), client-less Bob claims (self-claim sends Z-Client and consumes nothing), delete/replace return 201 per the MLS routes, carol pins the worker's clients-table backfill; DO-UPDATE justification comment on insertStatement (marker-gated transaction).
…gs, migration tests)
blackheaven
force-pushed
the
gdifolco/WPB-29582-migration-postgres-mls-key-packages
branch
from
November 13, 2026 19:21
bd76606 to
731c461
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

https://wearezeta.atlassian.net/browse/WPB-29582
Checklist
changelog.d