Allow resigning of events with a new signing key#19668
Merged
Conversation
73940ac to
c6cde8d
Compare
Add `resign_event` and `event_needs_resigning` utility functions to `event_signing.py`, and a `_resign_events` background update handler that iterates through locally-sent events and re-signs any that aren't signed with the current signing key. Co-Authored-By: Kegan Dougall <kegan@element.io> Co-Authored-By: Erik Johnston <erikj@element.io>
Allow admins to trigger the event re-signing background update via POST /_synapse/admin/v1/background_updates/start_job with job_name "event_resign".
Add unit tests for `resign_event` and `event_needs_resigning` in test_event_signing.py, and an integration test for the event_resign background update in test_events_bg_updates.py.
c6cde8d to
4a6e6d5
Compare
erikjohnston
requested changes
Apr 8, 2026
Use -(1 << 31) as the initial stream position instead of 0, matching the precedent set by POPULATE_STREAM_ORDERING2. This ensures events with negative stream orderings (from backfill) are also covered.
Allow filtering which events to re-sign: - old_key_id: only re-sign events signed with a specific key (filtered in Python since signatures are stored as JSON) - before_ts: only re-sign events with received_ts < value (filtered in SQL alongside the existing stream_ordering scan) These parameters are passed through the admin API POST body and preserved in the background update progress across batches.
erikjohnston
reviewed
Apr 8, 2026
Instead of matching on the key ID string, accept the full public key (format: "algorithm:key_id base64key") and verify the event signature against it. This is more secure as it ensures we only re-sign events genuinely signed by the specified key. Events without a signature for the key ID are fast-path skipped. A warning is logged if a signature exists but fails verification.
Co-authored-by: Erik Johnston <erikj@element.io>
4f9eade to
7521e11
Compare
erikjohnston
approved these changes
Apr 9, 2026
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.
This adds a way to re-sign all locally-created events with a new signing key, which is useful when rotating server signing keys.
This doesn't trigger automatically, instead needs to be triggered when needed via the admin API.
c.f. https://github.com/matrix-org/internal-config/issues/1670#issuecomment-4206020126 for internal discussion.