Add inbound Matrix routing by hs_token (Phase 2) - #31
Closed
fmartingr wants to merge 1 commit into
Closed
Conversation
Route inbound Application Service traffic to the correct homeserver by matching the presented hs_token against each server's HSToken, resolving a serverID, and scoping all lookups to that server's KV namespace. - api.go: MatrixAuthorizationRequired matches the bearer token against every server's hs_token (constant-time), injects the resolved serverID into the request context, and enforces the per-server Enabled flag on top of the global enable_sync switch. - matrix_webhook.go: dedup transactions per (serverID, txnID); thread serverID through processMatrixEvent, room-mapping lookup, ghost-user detection, and Matrix-initiated DM handling. - plugin.go/bridge_utils.go/sync_to_mattermost.go: construct inbound bridges scoped to the originating server; resolve the per-server domain for the matrix_event_id_<domain> post property. - kvstore: add SetAtomicWithRetries for concurrency-safe upserts of the shared channel_mapping value across servers. Also adds an admin-only /matrix server command group and backing registry mutation API for local multi-server testing until the System Console UI lands.
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.
Summary
Phase 2 of multi-Matrix-server support (MM-64622): route inbound Matrix Application Service traffic to the correct server. Each managed homeserver has its own
hs_token; the presented bearer token is matched against every server's token to resolve theserverID, and all lookups/persistence happen in that server's KV namespace.Builds on Phase 1 (config/client registry, namespaced KV). Single-server installs behave exactly as before.
Changes
server/api.go): match the presentedBearertoken against every server'sHSToken(constant-time, full scan), resolveserverID, and inject it into the request context. Keeps the globalenable_synccheck plus a per-serverEnabledcheck; unknown/invalid token → 401.server/matrix_webhook.go): keyprocessedTransactionsby(serverID, txnID)instead oftxnIDalone — MatrixtxnIDs are only unique per homeserver, so colliding IDs across servers no longer dedupe against each other.server/matrix_webhook.go): threadserverIDthroughprocessMatrixEvent; room-mapping and fallback room-state lookups use the resolved server's namespace and client from the registry.server/sync_to_mattermost.go,server/bridge_utils.go): allmatrix_user_,mattermost_user_,matrix_event_post_,matrix_reaction_reads/writes are namespaced byserverID; post property stored asmatrix_event_id_<serverDomain>./matrix servercommand (server/command/command.go): admin-only subcommands (list/add/remove/map) to register additional servers directly for local multi-server testing, since the System Console UI can't yet manage more than one server.docker-compose.yml(+ configs), and adocs/local-development.mdguide.(serverID, txnID)dedup, unchanged single-server behavior, and unknown-token 401.Acceptance criteria
(serverID, txnID).