diff --git a/roles/custom/matrix-synapse/defaults/main.yml b/roles/custom/matrix-synapse/defaults/main.yml index 71dee6cda..21234f1ae 100644 --- a/roles/custom/matrix-synapse/defaults/main.yml +++ b/roles/custom/matrix-synapse/defaults/main.yml @@ -1555,7 +1555,8 @@ matrix_synapse_max_event_delay_duration: 24h # Controls whether to enable the MSC4143 experimental feature (RTC transports). # -# This is used by MatrixRTC clients to discover the unstable RTC transports API. +# This only gates the unstable RTC transports API, which older MatrixRTC clients use. +# The stable API (`/_matrix/client/v1/rtc/transports`) is always served. # # This follows `matrix_synapse_matrix_rtc_transports`, because serving the RTC transports API without any transports configured # breaks MatrixRTC (Element Call) for clients which consult this API. @@ -1566,15 +1567,28 @@ matrix_synapse_experimental_features_msc4143_enabled: "{{ matrix_synapse_matrix_ # Controls the `matrix_rtc.transports` setting - the list of MatrixRTC transports advertised via the RTC transports API (MSC4143). # -# The API serving this list is only enabled when `matrix_synapse_experimental_features_msc4143_enabled` is set to `true`. -# Otherwise, this setting is parsed by Synapse, but remains unused. +# The stable API always serves this list. +# The unstable API serving it is only enabled when `matrix_synapse_experimental_features_msc4143_enabled` is set to `true`. matrix_synapse_matrix_rtc_transports: "{{ matrix_synapse_matrix_rtc_transports_default + matrix_synapse_matrix_rtc_transports_auto + matrix_synapse_matrix_rtc_transports_custom }}" -# Holds the default MatrixRTC transports list, driven by `matrix_synapse_matrix_rtc_transports_livekit_url`. +# Holds the default MatrixRTC transports list, driven by `matrix_synapse_matrix_rtc_transports_livekit_sfu_url` and `matrix_synapse_matrix_rtc_transports_livekit_url`. +# +# The stable `m.livekit` transport is advertised when an SFU URL is set. +# The deprecated `livekit` transport is advertised for clients which don't support the stable one yet. +# As recommended by upstream, it also carries the SFU URL, so that clients supporting it use the Client-Server API too. +# +# See: https://element-hq.github.io/synapse/latest/upgrade.html#stable-matrixrtc-transport-discovery matrix_synapse_matrix_rtc_transports_default: |- {{ ( - [{'type': 'livekit', 'livekit_service_url': matrix_synapse_matrix_rtc_transports_livekit_url}] if matrix_synapse_matrix_rtc_transports_livekit_url != '' else [] + [{'type': 'm.livekit', 'url': matrix_synapse_matrix_rtc_transports_livekit_sfu_url}] if matrix_synapse_matrix_rtc_transports_livekit_sfu_url != '' else [] + ) + + + ( + [ + {'type': 'livekit', 'livekit_service_url': matrix_synapse_matrix_rtc_transports_livekit_url} + | combine({'url': matrix_synapse_matrix_rtc_transports_livekit_sfu_url} if matrix_synapse_matrix_rtc_transports_livekit_sfu_url != '' else {}) + ] if matrix_synapse_matrix_rtc_transports_livekit_url != '' else [] ) }} @@ -1587,11 +1601,37 @@ matrix_synapse_matrix_rtc_transports_auto: [] # Holds additional MatrixRTC transports entries that you may wish to inject. matrix_synapse_matrix_rtc_transports_custom: [] -# Controls the MatrixRTC LiveKit URL auto-added to `matrix_synapse_matrix_rtc_transports`. +# Controls the MatrixRTC LiveKit authorization service URL (`livekit_service_url`) auto-added to `matrix_synapse_matrix_rtc_transports`. +# +# Clients using the deprecated `livekit` transport talk to this service directly. # # This is set automatically if you are using the playbook's MatrixRTC stack. matrix_synapse_matrix_rtc_transports_livekit_url: '' +# Controls the WebSocket URL of the LiveKit SFU auto-added to `matrix_synapse_matrix_rtc_transports`. +# +# Setting this advertises the stable `m.livekit` transport. +# Clients using it reach the LiveKit authorization service through this homeserver. +# This requires the authorization service to be registered as an application service (see `matrix_synapse_app_service_config_files`), +# as well as the MSC4502 and MSC4512 experimental features (see `matrix_synapse_experimental_features_msc4502_enabled` and `matrix_synapse_experimental_features_msc4512_enabled`). +# +# A playbook may set this automatically, based on the state of other services. +matrix_synapse_matrix_rtc_transports_livekit_sfu_url: '' + +# Controls whether to enable the MSC4502 experimental feature (room membership lookups by application services). +# +# The LiveKit authorization service (lk-jwt-service) uses this to verify that MatrixRTC callers are joined to the room. +# +# See https://github.com/matrix-org/matrix-spec-proposals/pull/4502 +matrix_synapse_experimental_features_msc4502_enabled: false + +# Controls whether to enable the MSC4512 experimental feature (proxying Client-Server and Server-Server API requests to application services). +# +# The LiveKit authorization service (lk-jwt-service) uses this to serve the stable `m.livekit` MatrixRTC transport. +# +# See https://github.com/matrix-org/matrix-spec-proposals/pull/4512 +matrix_synapse_experimental_features_msc4512_enabled: false + # Controls whether to enable the MSC4306 experimental feature ("thread subscriptions"). # # In current Synapse, this also enables the MSC4308 thread-subscriptions extension @@ -1627,6 +1667,8 @@ matrix_synapse_experimental_features_default: | 'msc4108_enabled': matrix_synapse_experimental_features_msc4108_enabled | bool, 'msc4143_enabled': matrix_synapse_experimental_features_msc4143_enabled | bool, 'msc4306_enabled': matrix_synapse_experimental_features_msc4306_enabled | bool, + 'msc4502_enabled': matrix_synapse_experimental_features_msc4502_enabled | bool, + 'msc4512_enabled': matrix_synapse_experimental_features_msc4512_enabled | bool, 'msc4354_enabled': matrix_synapse_experimental_features_msc4354_enabled | bool, } | dict2items diff --git a/roles/custom/matrix-synapse/molecule/default/molecule.yml b/roles/custom/matrix-synapse/molecule/default/molecule.yml index 9e76918d8..e74f4c1bb 100644 --- a/roles/custom/matrix-synapse/molecule/default/molecule.yml +++ b/roles/custom/matrix-synapse/molecule/default/molecule.yml @@ -88,6 +88,18 @@ provisioner: matrix_s3_media_store_enabled: false matrix_playbook_ssl_enabled: false + # Stable MatrixRTC (`m.livekit`) next to the deprecated transport, plus what the LiveKit + # authorization service needs as an application service. prepare.yml writes a registration + # shaped like the one the matrix-livekit-jwt-service role renders, so that Synapse must accept it. + matrix_synapse_matrix_rtc_transports_livekit_url: https://matrix.molecule.local/livekit-jwt-service + matrix_synapse_matrix_rtc_transports_livekit_sfu_url: wss://matrix.molecule.local/livekit-server + matrix_synapse_experimental_features_msc4502_enabled: true + matrix_synapse_experimental_features_msc4512_enabled: true + matrix_synapse_container_extra_arguments: + - --mount type=bind,src=/matrix/molecule-livekit-registration.yaml,dst=/livekit-registration.yaml,ro + matrix_synapse_app_service_config_files: + - /livekit-registration.yaml + # verify.yml is a separate play, so pin paths that otherwise come from role defaults. # The component version is deliberately loaded from defaults/main.yml instead. matrix_synapse_base_path: /matrix/synapse diff --git a/roles/custom/matrix-synapse/molecule/default/prepare.yml b/roles/custom/matrix-synapse/molecule/default/prepare.yml index b5a48dfef..eaa9d819a 100644 --- a/roles/custom/matrix-synapse/molecule/default/prepare.yml +++ b/roles/custom/matrix-synapse/molecule/default/prepare.yml @@ -64,6 +64,25 @@ group: "{{ matrix_group_name }}" mode: '0750' + - name: Ensure the LiveKit authorization service registration exists + ansible.builtin.copy: + dest: /matrix/molecule-livekit-registration.yaml + mode: '0644' + content: | + id: livekit-jwt-service + url: ~ + as_token: molecule-synapse-livekit-as-token-3f9a + hs_token: molecule-synapse-livekit-hs-token-71c2 + sender_localpart: _lk_jwt_service + namespaces: + users: + - regex: '@.*:molecule\.local' + exclusive: false + io.element.msc4502.scopes: + - urn:matrix:client:io.element.msc4502:rooms:is_joined + io.element.msc4512.proxy_prefix: rtc/livekit + io.element.msc4512.proxy_url: http://matrix-livekit-jwt-service:8080 + # Postgres must attach before the role creates this network during converge. - name: Ensure the Synapse container network exists ansible.builtin.command: diff --git a/roles/custom/matrix-synapse/molecule/default/verify.yml b/roles/custom/matrix-synapse/molecule/default/verify.yml index b8232ef60..9a841fd21 100644 --- a/roles/custom/matrix-synapse/molecule/default/verify.yml +++ b/roles/custom/matrix-synapse/molecule/default/verify.yml @@ -142,6 +142,92 @@ fail_msg: "The versions endpoint did not return a Matrix versions document" success_msg: "The versions endpoint returns a Matrix versions document" + - name: Request MatrixRTC endpoints as the LiveKit authorization service + ansible.builtin.command: + argv: + - docker + - run + - --rm + - --network={{ matrix_synapse_container_network }} + - "{{ molecule_shared_image_curl }}" + - --silent + - --show-error + - --header + - "Authorization: Bearer molecule-synapse-livekit-as-token-3f9a" + - --write-out + - "\nHTTP_STATUS=%{http_code}" + - http://matrix-synapse:{{ matrix_synapse_container_client_api_port }}{{ item.path }} + register: matrix_synapse_rtc_responses + changed_when: false + failed_when: false + loop: + - name: stable transports + path: /_matrix/client/v1/rtc/transports + - name: unstable transports + path: /_matrix/client/unstable/org.matrix.msc4143/rtc/transports + - name: room membership + path: /_matrix/client/unstable/io.element.msc4502/rooms/%21unknown%3Amolecule.local/is_joined?mxid=%40alice%3Amolecule.local + loop_control: + label: "{{ item.name }}" + + - name: Assert Synapse serves MatrixRTC discovery and membership lookups to the application service + ansible.builtin.assert: + that: + - matrix_synapse_rtc_responses.results | map(attribute='rc') | unique | list == [0] + - matrix_synapse_rtc_responses.results | map(attribute='stdout_lines') | map('last') | unique | list == ['HTTP_STATUS=200'] + - matrix_synapse_rtc_stable.transports == matrix_synapse_rtc_expected_transports + - matrix_synapse_rtc_unstable.rtc_transports == matrix_synapse_rtc_expected_transports + - matrix_synapse_rtc_is_joined.joined is sameas false + fail_msg: "Synapse did not serve the expected MatrixRTC transports or membership lookup" + success_msg: "Synapse advertises stable and legacy LiveKit transports and serves MSC4502 lookups" + vars: + matrix_synapse_rtc_documents: >- + {{ matrix_synapse_rtc_responses.results | map(attribute='stdout') + | map('regex_replace', '(?s)\s*HTTP_STATUS=[0-9]+\s*$', '') | map('from_json') | list }} + matrix_synapse_rtc_stable: "{{ matrix_synapse_rtc_documents[0] }}" + matrix_synapse_rtc_unstable: "{{ matrix_synapse_rtc_documents[1] }}" + matrix_synapse_rtc_is_joined: "{{ matrix_synapse_rtc_documents[2] }}" + matrix_synapse_rtc_expected_transports: + - type: m.livekit + url: wss://matrix.molecule.local/livekit-server + - type: livekit + livekit_service_url: https://matrix.molecule.local/livekit-jwt-service + url: wss://matrix.molecule.local/livekit-server + + # The registration points the proxy at a container which doesn't exist here, so the proxied + # request fails upstream. Without MSC4512, Synapse would not know the route at all (404). + - name: Request a proxied LiveKit authorization service endpoint + ansible.builtin.command: + argv: + - docker + - run + - --rm + - --network={{ matrix_synapse_container_network }} + - "{{ molecule_shared_image_curl }}" + - --silent + - --show-error + - --request + - POST + - --header + - "Authorization: Bearer molecule-synapse-livekit-as-token-3f9a" + - --data-binary + - "{}" + - --write-out + - "\nHTTP_STATUS=%{http_code}" + - http://matrix-synapse:{{ matrix_synapse_container_client_api_port }}/_matrix/client/unstable/io.element.msc4195/rtc/livekit/get_token + register: matrix_synapse_rtc_proxy_response + changed_when: false + failed_when: false + + - name: Assert Synapse proxies the LiveKit authorization service route (MSC4512) + ansible.builtin.assert: + that: + - matrix_synapse_rtc_proxy_response.rc == 0 + - matrix_synapse_rtc_proxy_response.stdout_lines[-1] is match('HTTP_STATUS=5[0-9][0-9]$') + - "'M_UNRECOGNIZED' not in matrix_synapse_rtc_proxy_response.stdout" + fail_msg: "Synapse does not route the proxy prefix to the application service: {{ matrix_synapse_rtc_proxy_response.stdout }}" + success_msg: "Synapse routes the proxy prefix to the application service" + # The role moved the listener away from 8008. Refusing the upstream default port proves # the successful requests above did not accidentally hit an unchanged default listener. - name: Request the upstream-default Synapse port