Skip to content

Allow resigning of events with a new signing key#19668

Merged
sandhose merged 13 commits intodevelopfrom
quenting/resign-background-update
Apr 14, 2026
Merged

Allow resigning of events with a new signing key#19668
sandhose merged 13 commits intodevelopfrom
quenting/resign-background-update

Conversation

@sandhose
Copy link
Copy Markdown
Member

@sandhose sandhose commented Apr 8, 2026

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.

@sandhose sandhose requested a review from a team as a code owner April 8, 2026 11:41
@sandhose sandhose force-pushed the quenting/resign-background-update branch from 73940ac to c6cde8d Compare April 8, 2026 11:44
sandhose and others added 4 commits April 8, 2026 13:46
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.
@sandhose sandhose force-pushed the quenting/resign-background-update branch from c6cde8d to 4a6e6d5 Compare April 8, 2026 11:49
Comment thread synapse/storage/databases/main/events_bg_updates.py Outdated
Comment thread synapse/crypto/event_signing.py
sandhose added 3 commits April 8, 2026 15:58
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.
Comment thread synapse/storage/databases/main/events_bg_updates.py
sandhose and others added 2 commits April 8, 2026 16:54
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>
@sandhose sandhose force-pushed the quenting/resign-background-update branch from 4f9eade to 7521e11 Compare April 8, 2026 15:00
@sandhose sandhose requested a review from erikjohnston April 8, 2026 15:02
Comment thread synapse/storage/databases/main/events_bg_updates.py Outdated
@sandhose sandhose enabled auto-merge (squash) April 13, 2026 13:56
@reivilibre reivilibre self-assigned this Apr 14, 2026
@sandhose sandhose merged commit bed00bb into develop Apr 14, 2026
82 of 84 checks passed
@sandhose sandhose deleted the quenting/resign-background-update branch April 14, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants