fix(matrix): read MATRIX_RECOVERY_KEY from the active profile secret scope (#69090) - #69133
Closed
PRATHAMESH75 wants to merge 1 commit into
Closed
Conversation
…scope (NousResearch#69090) In a multiplexed gateway (gateway.multiplex_profiles) every profile's Matrix adapter connects inside _profile_runtime_scope, which installs the routed profile's .env as the active secret scope. The E2EE cross-signing bootstrap read MATRIX_RECOVERY_KEY via os.getenv, so every secondary profile verified with the DEFAULT profile's recovery key and failed with 'recovery key verification failed: Key MAC does not match'. Resolve the key via get_secret(), which honors the active profile scope and falls back to os.environ when no scope is installed (single-profile gateways — behavior unchanged). Fixes NousResearch#69090
1 task
Collaborator
Contributor
Author
|
Closing in favor of #69110 by @sergioperezcheco, which was opened first and is the more complete fix for the same bug (#69090):
No reason to keep a narrower, partly-overlapping duplicate open. Full credit to @sergioperezcheco for #69110. |
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.
Problem
In a multiplexed gateway (
gateway.multiplex_profiles = true), sending an encrypted Matrix message through a secondary profile fails E2EE cross-signing with:Direct API sends and
hermes -p <profile> sendwork; only the multiplexed gateway path is affected. Fixes #69090.Root cause
Each profile's Matrix adapter is connected inside
_profile_runtime_scope(gateway/run.py:9532), which installs that profile's.envas the active secret scope soget_secret(...)resolves the routed profile's credentials. The adapter already threads the per-profile access token and homeserver through itsconfigobject, but the E2EE cross-signing bootstrap read the recovery key straight from the process environment:os.getenvignores the profile scope, so every secondary profile verified cross-signing with the default profile's recovery key — hence the MAC mismatch.Fix
Resolve the recovery key via
get_secret, the same profile-scope-aware primitive the Slack adapter already uses:get_secretreads the active profile's secret scope when one is installed (the multiplexed connect path) and falls back toos.environwhen none is — so single-profile gateways are behavior-identical to the oldos.getenv. The read sits insideconnect()'s existingtry/except, so an unscoped multiplex read (fail-closedUnscopedSecretError) degrades to "E2EE bootstrap skipped" rather than crashing.Scope note
I intentionally left the
recovery_key_configuredread inget_diagnostics()(adapter.py:1740) onos.getenv. That is a non-authoritative diagnostic boolean, andget_diagnosticshas no gateway caller that guarantees it runs inside a profile scope — switching it toget_secretwould risk a fail-closed raise on an unscoped status read for no correctness benefit. The reported failure is entirely the connect-time verification path fixed above.Test
tests/gateway/test_matrix.py::TestMatrixAccessTokenAuth::test_connect_reads_recovery_key_from_active_profile_scopedrives the realconnect()E2EE path with a secret scope holding the profile's key whileos.environholds a different (default-profile) key, and assertsOlmMachine.verify_with_recovery_keyis awaited with the scoped key. It fails against the oldos.getenvline and passes with the fix.The arm64 fork-Docker job is expected to fail on fork PRs and is unrelated to this change.