diff --git a/docs/configuring-playbook-bridge-mautrix-wsproxy.md b/docs/configuring-playbook-bridge-mautrix-wsproxy.md index ac11ce8d3..3c3324d52 100644 --- a/docs/configuring-playbook-bridge-mautrix-wsproxy.md +++ b/docs/configuring-playbook-bridge-mautrix-wsproxy.md @@ -8,23 +8,15 @@ Use the following playbook configuration: ```yaml matrix_mautrix_wsproxy_enabled: true -matrix_mautrix_wsproxy_appservice_token: 'random string' -matrix_mautrix_wsproxy_homeserver_token: 'random string' +matrix_mautrix_androidsms_appservice_token: 'random string' +matrix_mautrix_androidsms_homeserver_token: 'random string' +matrix_mautrix_imessage_appservice_token: 'random string' +matrix_mautrix_imessage_homeserver_token: 'random string' matrix_mautrix_wsproxy_syncproxy_shared_secret: 'random string' ``` - -## Set up Double Puppeting - -If you'd like to use [Double Puppeting](https://github.com/tulir/mautrix-hangouts/wiki/Authentication#double-puppeting) (hint: you most likely do), you have 1 way of going about it. - -### Method 1: automatically, by enabling Shared Secret Auth - -The bridge will automatically perform Double Puppeting if you enable [Shared Secret Auth](configuring-playbook-shared-secret-auth.md) for this playbook. - -This is the recommended way of setting up Double Puppeting, as it's easier to accomplish, works for all your users automatically, and has less of a chance of breaking in the future. +Note that the tokens must match what is compiled into the `mautrix-imessage` bridge running on Mac and Android. ## Usage -Follow the [matrix-imessage documenation](https://docs.mau.fi/bridges/go/imessage/index.html) for running `android-sms` or `matrix-imessage` on your device. -The name of the bridge bot is androidsms, but the bridge works for either iMessage or Android SMS, though not both at the same time. +Follow the [matrix-imessage documenation](https://docs.mau.fi/bridges/go/imessage/index.html) for running `android-sms` and/or `matrix-imessage` on your device(s). diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 4df8d7147..85e2d6113 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -725,14 +725,6 @@ matrix_mautrix_wsproxy_homeserver_domain: '{{ matrix_domain }}' matrix_mautrix_wsproxy_homeserver_address: "{{ 'http://matrix-synapse:8008' if matrix_synapse_enabled else '' }}" -matrix_mautrix_wsproxy_homeserver_token: "{{ matrix_homeserver_generic_secret_key | password_hash('sha512', 'wsproxy.hs.token') | to_uuid }}" - -matrix_mautrix_wsproxy_appservice_token: "{{ matrix_homeserver_generic_secret_key | password_hash('sha512', 'wsproxy.as.token') | to_uuid }}" - -matrix_mautrix_wsproxy_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" - -# Postgres is the default, except if not using `matrix_postgres` (internal postgres) - ###################################################################### # # /matrix-bridge-mautrix-wsproxy diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml index 54434c2a5..986f35d3b 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/defaults/main.yml @@ -30,10 +30,14 @@ matrix_mautrix_wsproxy_systemd_required_services_list: ['docker.service'] # List of systemd services that matrix-mautrix-wsproxy.service wants matrix_mautrix_wsproxy_systemd_wanted_services_list: [] -matrix_mautrix_wsproxy_appservice_token: '' -matrix_mautrix_wsproxy_homeserver_token: '' +matrix_mautrix_androidsms_appservice_token: '' +matrix_mautrix_androidsms_homeserver_token: '' -matrix_mautrix_wsproxy_appservice_bot_username: androidsmsbot +matrix_mautrix_imessage_appservice_token: '' +matrix_mautrix_imessage_homeserver_token: '' + +matrix_mautrix_androidsms_appservice_bot_username: androidsmsbot +matrix_mautrix_imessage_appservice_bot_username: imessagebot # Default mautrix-wsproxy configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. @@ -57,21 +61,37 @@ matrix_mautrix_wsproxy_configuration_extension: "{{ matrix_mautrix_wsproxy_confi # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_wsproxy_configuration_yaml`. matrix_mautrix_wsproxy_configuration: "{{ matrix_mautrix_wsproxy_configuration_yaml|from_yaml|combine(matrix_mautrix_wsproxy_configuration_extension, recursive=True) }}" -matrix_mautrix_wsproxy_registration_yaml: | +matrix_mautrix_androidsms_registration_yaml: | id: androidsms url: {{ matrix_mautrix_wsproxy_appservice_address }} - as_token: "{{ matrix_mautrix_wsproxy_appservice_token }}" - hs_token: "{{ matrix_mautrix_wsproxy_homeserver_token }}" - sender_localpart: _bot_{{ matrix_mautrix_wsproxy_appservice_bot_username }} + as_token: "{{ matrix_mautrix_androidsms_appservice_token }}" + hs_token: "{{ matrix_mautrix_androidsms_homeserver_token }}" + sender_localpart: _bot_{{ matrix_mautrix_androidsms_appservice_bot_username }} rate_limited: false namespaces: users: - regex: '@androidsms_.+:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' exclusive: true - exclusive: true - regex: '^@{{ matrix_mautrix_wsproxy_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_androidsms_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' + +matrix_mautrix_androidsms_registration: "{{ matrix_mautrix_androidsms_registration_yaml|from_yaml }}" + +matrix_mautrix_imessage_registration_yaml: | + id: imessage + url: {{ matrix_mautrix_wsproxy_appservice_address }} + as_token: "{{ matrix_mautrix_imessage_appservice_token }}" + hs_token: "{{ matrix_mautrix_imessage_homeserver_token }}" + sender_localpart: _bot_{{ matrix_mautrix_imessage_appservice_bot_username }} + rate_limited: false + namespaces: + users: + - regex: '@imessage_.+:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' + exclusive: true + - exclusive: true + regex: '^@{{ matrix_mautrix_imessage_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_wsproxy_homeserver_domain|regex_escape }}$' -matrix_mautrix_wsproxy_registration: "{{ matrix_mautrix_wsproxy_registration_yaml|from_yaml }}" +matrix_mautrix_imessage_registration: "{{ matrix_mautrix_imessage_registration_yaml|from_yaml }}" # Syncproxy-related configuration fields matrix_mautrix_wsproxy_syncproxy_version: latest diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/init.yml b/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/init.yml index 819c3b041..dcb1617a4 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/init.yml +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/init.yml @@ -9,14 +9,18 @@ {{ matrix_synapse_container_extra_arguments | default([]) + - ["--mount type=bind,src={{ matrix_mautrix_wsproxy_config_path }}/registration.yaml,dst=/matrix-mautrix-wsproxy-registration.yaml,ro"] + ["--mount type=bind,src={{ matrix_mautrix_wsproxy_config_path }}/androidsms-registration.yaml,dst=/matrix-mautrix-androidsms-registration.yaml,ro"] + + + ["--mount type=bind,src={{ matrix_mautrix_wsproxy_config_path }}/imessage-registration.yaml,dst=/matrix-mautrix-imessage-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ matrix_synapse_app_service_config_files | default([]) + - ["/matrix-mautrix-wsproxy-registration.yaml"] + ["/matrix-mautrix-androidsms-registration.yaml"] + + + ["/matrix-mautrix-imessage-registration.yaml"] }} when: matrix_mautrix_wsproxy_enabled|bool diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml b/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml index 1eec6411a..1f47e9edf 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml @@ -53,10 +53,18 @@ owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" -- name: Ensure mautrix-wsproxy registration.yaml installed +- name: Ensure mautrix-androidsms registration.yaml installed ansible.builtin.copy: - content: "{{ matrix_mautrix_wsproxy_registration|to_nice_yaml }}" - dest: "{{ matrix_mautrix_wsproxy_config_path }}/registration.yaml" + content: "{{ matrix_mautrix_androidsms_registration|to_nice_yaml }}" + dest: "{{ matrix_mautrix_wsproxy_config_path }}/androidsms-registration.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure mautrix-imessage registration.yaml installed + ansible.builtin.copy: + content: "{{ matrix_mautrix_imessage_registration|to_nice_yaml }}" + dest: "{{ matrix_mautrix_wsproxy_config_path }}/imessage-registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml b/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml index 1a4ba894c..0db36f959 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml @@ -6,6 +6,8 @@ You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" with_items: - - "matrix_mautrix_wsproxy_appservice_token" - - "matrix_mautrix_wsproxy_homeserver_token" + - "matrix_mautrix_androidsms_appservice_token" + - "matrix_mautrix_androidsms_homeserver_token" + - "matrix_mautrix_imessage_appservice_token" + - "matrix_mautrix_imessage_homeserver_token" - "matrix_mautrix_wsproxy_syncproxy_shared_secret" diff --git a/roles/custom/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 b/roles/custom/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 index 873832fb6..2c7932614 100644 --- a/roles/custom/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 +++ b/roles/custom/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 @@ -1,11 +1,14 @@ listen_address: 0.0.0.0:29331 appservices: - id: androidsms - as: "{{ matrix_mautrix_wsproxy_appservice_token }}" - hs: "{{ matrix_mautrix_wsproxy_homeserver_token }}" + as: {{ matrix_mautrix_androidsms_appservice_token | to_json }} + hs: {{ matrix_mautrix_androidsms_homeserver_token | to_json }} + - id: imessage + as: {{ matrix_mautrix_imessage_appservice_token | to_json }} + hs: {{ matrix_mautrix_imessage_homeserver_token | to_json }} sync_proxy: # The URL that mautrix-wsproxy can use to reach mautrix-syncproxy - url: "{{ matrix_mautrix_wsproxy_syncproxy_appservice_address }}" + url: {{ matrix_mautrix_wsproxy_syncproxy_appservice_address | to_json }} # The URL that mautrix-syncproxy can use to reach mautrix-wsproxy - wsproxy_url: "{{ matrix_mautrix_wsproxy_appservice_address }}" - shared_secret: "{{ matrix_mautrix_wsproxy_syncproxy_shared_secret }}" + wsproxy_url: {{ matrix_mautrix_wsproxy_appservice_address | to_json }} + shared_secret: {{ matrix_mautrix_wsproxy_syncproxy_shared_secret | to_json }}