diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 1aed82081..dee9ee9a0 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -2403,6 +2403,7 @@ matrix_mautrix_whatsapp_appservice_token: "{{ (matrix_homeserver_generic_secret_ matrix_mautrix_whatsapp_homeserver_address: "{{ matrix_addons_homeserver_client_api_url }}" matrix_mautrix_whatsapp_homeserver_token: "{{ (matrix_homeserver_generic_secret_key + ':wa.hs.token') | hash('sha512') | to_uuid }}" +matrix_mautrix_whatsapp_provisioning_shared_secret: "{{ (matrix_homeserver_generic_secret_key + ':wa.prov') | hash('sha512') | to_uuid }}" matrix_mautrix_whatsapp_homeserver_async_media: "{{ matrix_homeserver_implementation in ['synapse'] }}" @@ -2421,6 +2422,11 @@ matrix_mautrix_whatsapp_metrics_proxying_enabled: "{{ matrix_mautrix_whatsapp_me matrix_mautrix_whatsapp_metrics_proxying_hostname: "{{ matrix_metrics_exposure_hostname }}" matrix_mautrix_whatsapp_metrics_proxying_path_prefix: "{{ matrix_metrics_exposure_path_prefix }}/mautrix-whatsapp" +matrix_mautrix_whatsapp_scheme: "{{ 'https' if matrix_playbook_ssl_enabled else 'http' }}" +matrix_mautrix_whatsapp_exposure_enabled: "{{ matrix_bridges_exposure_enabled }}" +matrix_mautrix_whatsapp_exposure_hostname: "{{ matrix_bridges_exposure_hostname }}" +matrix_mautrix_whatsapp_exposure_path_prefix: "{{ matrix_bridges_exposure_path_prefix }}/whatsapp" + # Postgres is the default, except if not using internal Postgres server matrix_mautrix_whatsapp_database_engine: "{{ 'postgres' if postgres_enabled else 'sqlite' }}" matrix_mautrix_whatsapp_database_hostname: "{{ postgres_connection_hostname if postgres_enabled else '' }}" diff --git a/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml index cc7fbdf06..a02707977 100644 --- a/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml @@ -48,6 +48,13 @@ matrix_mautrix_whatsapp_homeserver_domain: "{{ matrix_domain }}" matrix_mautrix_whatsapp_homeserver_async_media: false matrix_mautrix_whatsapp_appservice_address: "http://matrix-mautrix-whatsapp:8080" +# Scheme of the bridge's public address (see `matrix_mautrix_whatsapp_bridge_public_address`). +matrix_mautrix_whatsapp_scheme: https + +# The public base URL at which this bridge's HTTP API is reachable from outside (when exposed). +# Used for the provisioning API's external-server (OpenID) flow and for public media links. +matrix_mautrix_whatsapp_bridge_public_address: "{{ (matrix_mautrix_whatsapp_scheme + '://' + matrix_mautrix_whatsapp_exposure_hostname + matrix_mautrix_whatsapp_exposure_path_prefix) if matrix_mautrix_whatsapp_exposure_enabled else '' }}" + matrix_mautrix_whatsapp_msc4190_enabled: "{{ matrix_bridges_msc4190_enabled }}" matrix_mautrix_whatsapp_self_sign_enabled: "{{ matrix_bridges_self_sign_enabled }}" @@ -81,6 +88,15 @@ matrix_mautrix_whatsapp_container_labels_metrics_middleware_basic_auth_enabled: # See: https://doc.traefik.io/traefik/middlewares/http/basicauth/#users matrix_mautrix_whatsapp_container_labels_metrics_middleware_basic_auth_users: '' +# Controls whether labels will be added that expose mautrix-whatsapp's HTTP API +# (used by tools like mautrix-manager for bridge login) at `https://`. +matrix_mautrix_whatsapp_container_labels_exposure_enabled: "{{ matrix_mautrix_whatsapp_exposure_enabled }}" +matrix_mautrix_whatsapp_container_labels_exposure_traefik_rule: "Host(`{{ matrix_mautrix_whatsapp_exposure_hostname }}`) && PathPrefix(`{{ matrix_mautrix_whatsapp_exposure_path_prefix }}`)" +matrix_mautrix_whatsapp_container_labels_exposure_traefik_priority: 0 +matrix_mautrix_whatsapp_container_labels_exposure_traefik_entrypoints: "{{ matrix_mautrix_whatsapp_container_labels_traefik_entrypoints }}" +matrix_mautrix_whatsapp_container_labels_exposure_traefik_tls: "{{ matrix_mautrix_whatsapp_container_labels_exposure_traefik_entrypoints != 'web' }}" +matrix_mautrix_whatsapp_container_labels_exposure_traefik_tls_certResolver: "{{ matrix_mautrix_whatsapp_container_labels_traefik_tls_certResolver }}" # noqa var-naming + # matrix_mautrix_whatsapp_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file. # See `../templates/labels.j2` for details. # @@ -125,6 +141,11 @@ matrix_mautrix_whatsapp_metrics_proxying_enabled: false matrix_mautrix_whatsapp_metrics_proxying_hostname: '' matrix_mautrix_whatsapp_metrics_proxying_path_prefix: '' +# Controls whether mautrix-whatsapp's HTTP API is exposed publicly (used by tools like mautrix-manager for bridge login). +matrix_mautrix_whatsapp_exposure_enabled: false +matrix_mautrix_whatsapp_exposure_hostname: '' +matrix_mautrix_whatsapp_exposure_path_prefix: '' + # Database-related configuration fields. # # To use SQLite, stick to these defaults. diff --git a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 index 91b3e801e..24ae0cfdc 100644 --- a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 +++ b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/config.yaml.j2 @@ -269,7 +269,7 @@ appservice: # A public address that external services can use to reach this appservice. # This is only needed for things like public media. A reverse proxy is generally necessary when using this field. # This value doesn't affect the registration file. - public_address: "" + public_address: {{ matrix_mautrix_whatsapp_bridge_public_address | to_json }} # The hostname and port where this appservice should listen. # For Docker, you generally have to change the hostname to 0.0.0.0. diff --git a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/labels.j2 b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/labels.j2 index 74bd55954..060321bc2 100644 --- a/roles/custom/matrix-bridge-mautrix-whatsapp/templates/labels.j2 +++ b/roles/custom/matrix-bridge-mautrix-whatsapp/templates/labels.j2 @@ -46,6 +46,39 @@ traefik.http.routers.matrix-mautrix-whatsapp-metrics.tls.certResolver={{ matrix_ ############################################################ {% endif %} +{% if matrix_mautrix_whatsapp_container_labels_exposure_enabled %} +############################################################ +# # +# Bridge API exposure # +# # +############################################################ + +traefik.http.services.matrix-mautrix-whatsapp-exposure.loadbalancer.server.port=8080 + +traefik.http.middlewares.matrix-mautrix-whatsapp-exposure-strip-prefix.stripprefix.prefixes={{ matrix_mautrix_whatsapp_exposure_path_prefix }} +traefik.http.routers.matrix-mautrix-whatsapp-exposure.middlewares=matrix-mautrix-whatsapp-exposure-strip-prefix + +traefik.http.routers.matrix-mautrix-whatsapp-exposure.rule={{ matrix_mautrix_whatsapp_container_labels_exposure_traefik_rule }} + +{% if matrix_mautrix_whatsapp_container_labels_exposure_traefik_priority | int > 0 %} +traefik.http.routers.matrix-mautrix-whatsapp-exposure.priority={{ matrix_mautrix_whatsapp_container_labels_exposure_traefik_priority }} +{% endif %} + +traefik.http.routers.matrix-mautrix-whatsapp-exposure.service=matrix-mautrix-whatsapp-exposure +traefik.http.routers.matrix-mautrix-whatsapp-exposure.entrypoints={{ matrix_mautrix_whatsapp_container_labels_exposure_traefik_entrypoints }} + +traefik.http.routers.matrix-mautrix-whatsapp-exposure.tls={{ matrix_mautrix_whatsapp_container_labels_exposure_traefik_tls | to_json }} +{% if matrix_mautrix_whatsapp_container_labels_exposure_traefik_tls %} +traefik.http.routers.matrix-mautrix-whatsapp-exposure.tls.certResolver={{ matrix_mautrix_whatsapp_container_labels_exposure_traefik_tls_certResolver }} +{% endif %} + +############################################################ +# # +# /Bridge API exposure # +# # +############################################################ +{% endif %} + {% endif %}