From 564b3cf1696c9af187a679d0c207b8ac98bccd1a Mon Sep 17 00:00:00 2001 From: Paul ALNET Date: Sun, 20 Oct 2024 21:41:08 +0200 Subject: [PATCH] feat: serve mautrix bridgev2 wellknown file --- group_vars/matrix_servers | 9 +++ .../matrix-static-files/defaults/main.yml | 59 +++++++++++++++++++ .../matrix-static-files/tasks/install.yml | 10 ++++ .../tasks/self_check_well_known.yml | 15 +++++ .../public/.well-known/matrix/mautrix.j2 | 4 ++ 5 files changed, 97 insertions(+) create mode 100644 roles/custom/matrix-static-files/templates/public/.well-known/matrix/mautrix.j2 diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 64224e5e4..59a88414a 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -5581,6 +5581,15 @@ matrix_static_files_file_matrix_client_property_m_tile_server_map_style_url: "{{ matrix_static_files_file_matrix_server_property_m_server: "{{ matrix_server_fqn_matrix_federation }}:{{ matrix_federation_public_port }}" +# mautrix-manager auto-configuration disabled by default +matrix_static_files_file_matrix_mautrix_enabled: false +matrix_static_files_file_matrix_mautrix_property_fi_mau_bridges: + - "https://bridges.example.com/signal" + # TODO populate with enabled bridges + +matrix_static_files_file_matrix_mautrix_property_fi_mau_external_bridge_servers: + [] + matrix_static_files_scheme: "{{ 'https' if matrix_playbook_ssl_enabled else 'http' }}" matrix_static_files_self_check_hostname_matrix: "{{ matrix_server_fqn_matrix }}" diff --git a/roles/custom/matrix-static-files/defaults/main.yml b/roles/custom/matrix-static-files/defaults/main.yml index 51a996dc0..137480511 100644 --- a/roles/custom/matrix-static-files/defaults/main.yml +++ b/roles/custom/matrix-static-files/defaults/main.yml @@ -332,6 +332,65 @@ matrix_static_files_file_matrix_support_configuration: "{{ matrix_static_files_f # # ######################################################################## +######################################################################## +# # +# Related to /.well-known/matrix/mautrix # +# # +######################################################################## + +# Controls whether a `/.well-known/matrix/mautrix` file is generated and used at all. +# For details about this file, see mautrix/manager auto-configuration section : https://github.com/mautrix/manager#auto-configuration +# +# This is not enabled by default, as for it to be useful, other information is necessary. +# See `matrix_static_files_file_matrix_mautrix_property_fi_mau_bridges`, `matrix_static_files_file_matrix_mautrix_property_fi_mau_external_bridge_servers`, etc. +matrix_static_files_file_matrix_mautrix_enabled: false + +# Controls the fi.mau.bridges property in the /.well-known/matrix/mautrix file +# It indexes local bridges implementing the bridgev2 API +# Example entry : https://bridges.example.com/signal +matrix_static_files_file_matrix_mautrix_property_fi_mau_bridges: [] + +# Controls the fi.mau.external_bridge_servers property in the /.well-known/matrix/mautrix file +# It indexes remote servers with bridges implementing the bridgev2 API +# Example entry : anotherserver.example.org +matrix_static_files_file_matrix_mautrix_property_fi_mau_external_bridge_servers: + [] + +# Default /.well-known/matrix/mautrix configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_static_files_file_matrix_mautrix_configuration_extension_json`) +# or completely replace this variable with your own template. +matrix_static_files_file_matrix_mautrix_configuration_json: "{{ lookup('template', 'templates/public/.well-known/matrix/mautrix.j2') }}" + +# Your custom JSON configuration for /.well-known/matrix/mautrix should go to `matrix_static_files_file_matrix_mautrix_configuration_extension_json`. +# This configuration extends the default starting configuration (`matrix_static_files_file_matrix_mautrix_configuration_extension_json`). +# +# You can override individual variables from the default configuration, or introduce new ones. +# +# If you need something more special, you can take full control by +# completely redefining `matrix_static_files_file_matrix_mautrix_configuration_json`. +# +# Example configuration extension follows: +# +# matrix_static_files_file_matrix_mautrix_configuration_extension_json: | +# { +# "m.another": "value", +# "m.yet_another": 3 +# } +matrix_static_files_file_matrix_mautrix_configuration_extension_json: "{}" + +matrix_static_files_file_matrix_mautrix_configuration_extension: "{{ matrix_static_files_file_matrix_mautrix_configuration_extension_json | from_json if matrix_static_files_file_matrix_mautrix_configuration_extension_json | from_json is mapping else {} }}" + +# Holds the final /.well-known/matrix/mautrix configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_static_files_file_matrix_mautrix_configuration_json` or `matrix_static_files_file_matrix_mautrix_configuration_extension_json`. +matrix_static_files_file_matrix_mautrix_configuration: "{{ matrix_static_files_file_matrix_mautrix_configuration_json | combine(matrix_static_files_file_matrix_mautrix_configuration_extension, recursive=True) }}" + +######################################################################## +# # +# /Related to /.well-known/matrix/mautrix # +# # +######################################################################## ######################################################################## # # diff --git a/roles/custom/matrix-static-files/tasks/install.yml b/roles/custom/matrix-static-files/tasks/install.yml index 3cbd9d4c6..4c9345ccc 100644 --- a/roles/custom/matrix-static-files/tasks/install.yml +++ b/roles/custom/matrix-static-files/tasks/install.yml @@ -52,6 +52,10 @@ dest: "{{ matrix_static_files_public_well_known_matrix_path }}/support" when: "{{ matrix_static_files_file_matrix_support_enabled }}" + - content: "{{ matrix_static_files_file_matrix_mautrix_configuration | to_nice_json }}" + dest: "{{ matrix_static_files_public_well_known_matrix_path }}/mautrix" + when: "{{ matrix_static_files_file_matrix_mautrix_enabled }}" + # This one will not be deleted if `matrix_static_files_file_index_html_enabled` flips to `false`. # See the comment for `matrix_static_files_file_index_html_enabled` to learn why. - content: "{{ matrix_static_files_file_index_html_template }}" @@ -70,6 +74,12 @@ state: absent when: "not matrix_static_files_file_matrix_support_enabled | bool" +- name: Ensure /.well-known/matrix/mautrix file deleted if not enabled + ansible.builtin.file: + path: "{{ matrix_static_files_public_well_known_matrix_path }}/mautrix" + state: absent + when: "not matrix_static_files_file_matrix_mautrix_enabled | bool" + - name: Ensure matrix-static-files container image is pulled community.docker.docker_image: name: "{{ matrix_static_files_container_image }}" diff --git a/roles/custom/matrix-static-files/tasks/self_check_well_known.yml b/roles/custom/matrix-static-files/tasks/self_check_well_known.yml index b6b8f5494..2248c7e65 100644 --- a/roles/custom/matrix-static-files/tasks/self_check_well_known.yml +++ b/roles/custom/matrix-static-files/tasks/self_check_well_known.yml @@ -24,6 +24,21 @@ ansible.builtin.set_fact: well_known_file_checks: "{{ well_known_file_checks + [well_known_file_check_matrix_server] }}" +- when: matrix_static_files_file_matrix_mautrix_enabled | bool + block: + - name: Prepare /.well-known/matrix/mautrix to well-known files to check, if enabled + ansible.builtin.set_fact: + well_known_file_check_matrix_mautrix: + path: /.well-known/matrix/mautrix + purpose: Mautrix bridge discovery + cors: true + follow_redirects: safe + validate_certs: "{{ matrix_static_files_self_check_validate_certificates }}" + + - name: Inject /.well-known/matrix/mautrix to well-known files to check, if enabled + ansible.builtin.set_fact: + well_known_file_checks: "{{ well_known_file_checks + [well_known_file_check_matrix_mautrix] }}" + - name: Perform well-known checks ansible.builtin.include_tasks: "{{ role_path }}/tasks/self_check_well_known_file.yml" with_items: "{{ well_known_file_checks }}" diff --git a/roles/custom/matrix-static-files/templates/public/.well-known/matrix/mautrix.j2 b/roles/custom/matrix-static-files/templates/public/.well-known/matrix/mautrix.j2 new file mode 100644 index 000000000..291d3711a --- /dev/null +++ b/roles/custom/matrix-static-files/templates/public/.well-known/matrix/mautrix.j2 @@ -0,0 +1,4 @@ +{ + "fi.mau.bridges": {{ matrix_static_files_file_matrix_mautrix_property_fi_mau_bridges|to_json }}, + "fi.mau.external_bridge_servers": {{ matrix_static_files_file_matrix_mautrix_property_fi_mau_external_bridge_servers|to_json }} +}