Optimized matrix domain mapping

This commit is contained in:
Kevin Veen-Birkenbach 2025-05-17 11:53:49 +02:00
parent a3d5bb3277
commit ca5c3c6e8a
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
17 changed files with 38 additions and 37 deletions

View File

@ -21,8 +21,7 @@ defaults_domains: >-
| add_domain_if_group('mailu', 'mail.' ~ primary_domain, group_names) | add_domain_if_group('mailu', 'mail.' ~ primary_domain, group_names)
| add_domain_if_group('mastodon', ['microblog.' ~ primary_domain], group_names) | add_domain_if_group('mastodon', ['microblog.' ~ primary_domain], group_names)
| add_domain_if_group('matomo', 'matomo.' ~ primary_domain, group_names) | add_domain_if_group('matomo', 'matomo.' ~ primary_domain, group_names)
| add_domain_if_group('matrix', 'matrix.' ~ primary_domain, group_names) | add_domain_if_group('matrix', {'synapse': 'matrix.' ~ primary_domain, 'element':'element.' ~ primary_domain}, group_names)
| add_domain_if_group('matrix', 'element.' ~ primary_domain, group_names)
| add_domain_if_group('moodle', 'academy.' ~ primary_domain, group_names) | add_domain_if_group('moodle', 'academy.' ~ primary_domain, group_names)
| add_domain_if_group('mediawiki', 'wiki.' ~ primary_domain, group_names) | add_domain_if_group('mediawiki', 'wiki.' ~ primary_domain, group_names)
| add_domain_if_group('nextcloud', 'cloud.' ~ primary_domain, group_names) | add_domain_if_group('nextcloud', 'cloud.' ~ primary_domain, group_names)

View File

@ -16,10 +16,12 @@ defaults_service_provider:
logo: "{{applications.assets_server.url}}/img/logo.png" logo: "{{applications.assets_server.url}}/img/logo.png"
favicon: "{{applications.assets_server.url}}/img/favicon.ico" favicon: "{{applications.assets_server.url}}/img/favicon.ico"
contact: contact:
bluesky: "{{ '@' ~ users.administrator.username ~ '.' ~ domains.[application_id].api if 'bluesky' in group_names else '' }}" bluesky: >-
{{ ('@' ~ users.administrator.username ~ '.' ~ domains[application_id]['api'])
if 'bluesky' in group_names else '' }}
email: "contact@{{ primary_domain }}" email: "contact@{{ primary_domain }}"
mastodon: "{{ '@' ~ users.administrator.username ~ '@' ~ domains.mastodon if 'mastodon' in group_names else '' }}" mastodon: "{{ '@' ~ users.administrator.username ~ '@' ~ domains.mastodon if 'mastodon' in group_names else '' }}"
matrix: "{{ '@' ~ users.administrator.username ~ ':' ~ domains.synapse if 'matrix' in group_names else '' }}" matrix: "{{ '@' ~ users.administrator.username ~ ':' ~ domains.matrix.synapse if 'matrix' in group_names else '' }}"
peertube: "{{ '@' ~ users.administrator.username ~ '@' ~ domains.peertube[0] if 'peertube' in group_names else '' }}" peertube: "{{ '@' ~ users.administrator.username ~ '@' ~ domains.peertube[0] if 'peertube' in group_names else '' }}"
pixelfed: "{{ '@' ~ users.administrator.username ~ '@' ~ domains.pixelfed if 'pixelfed' in group_names else '' }}" pixelfed: "{{ '@' ~ users.administrator.username ~ '@' ~ domains.pixelfed if 'pixelfed' in group_names else '' }}"
phone: "+0 000 000 404" phone: "+0 000 000 404"

View File

@ -3,8 +3,8 @@
include_role: include_role:
name: nginx-domain-setup name: nginx-domain-setup
loop: loop:
- "{{domains.element}}" - "{{domains.matrix.element}}"
- "{{domains.synapse}}" - "{{domains.matrix.synapse}}"
loop_control: loop_control:
loop_var: domain loop_var: domain
@ -129,13 +129,13 @@
#- name: add log.config #- name: add log.config
# template: # template:
# src: "log.config.j2" # src: "log.config.j2"
# dest: "{{docker_compose.directories.instance}}{{domains.synapse}}.log.config" # dest: "{{docker_compose.directories.instance}}{{domains.matrix.synapse}}.log.config"
# notify: recreate matrix # notify: recreate matrix
# #
## https://github.com/matrix-org/synapse/issues/6303 ## https://github.com/matrix-org/synapse/issues/6303
#- name: set correct folder permissions #- name: set correct folder permissions
# command: # command:
# cmd: "docker run --rm --mount type=volume,src=matrix_synapse_data,dst=/data -e SYNAPSE_SERVER_NAME={{domains.synapse}} -e SYNAPSE_REPORT_STATS=no --entrypoint /bin/sh matrixdotorg/synapse:latest -c 'chown -vR 991:991 /data'" # cmd: "docker run --rm --mount type=volume,src=matrix_synapse_data,dst=/data -e SYNAPSE_SERVER_NAME={{domains.matrix.synapse}} -e SYNAPSE_REPORT_STATS=no --entrypoint /bin/sh matrixdotorg/synapse:latest -c 'chown -vR 991:991 /data'"
# #
#- name: add docker-compose.yml #- name: add docker-compose.yml
# template: # template:

View File

@ -8,7 +8,7 @@
# because you can't change the Domain after deployment. # because you can't change the Domain after deployment.
# #
# Example value: example.com # Example value: example.com
matrix_domain: "{{domains.synapse}}" matrix_domain: "{{domains.matrix.synapse}}"
# The Matrix homeserver software to install. # The Matrix homeserver software to install.
# See: # See:

View File

@ -16,7 +16,7 @@
include_role: include_role:
name: nginx-https-get-cert-modify-all name: nginx-https-get-cert-modify-all
vars: vars:
domain: "{{domains.synapse}}" domain: "{{domains.matrix.synapse}}"
http_port: "{{ports.localhost.http.synapse}}" http_port: "{{ports.localhost.http.synapse}}"
- name: create {{well_known_directory}} - name: create {{well_known_directory}}
@ -30,12 +30,12 @@
src: "well-known.j2" src: "well-known.j2"
dest: "{{well_known_directory}}server" dest: "{{well_known_directory}}server"
- name: create {{domains.synapse}}.conf - name: create {{domains.matrix.synapse}}.conf
template: template:
src: "templates/nginx.conf.j2" src: "templates/nginx.conf.j2"
dest: "{{nginx.directories.http.servers}}{{domains.synapse}}.conf" dest: "{{nginx.directories.http.servers}}{{domains.matrix.synapse}}.conf"
vars: vars:
domain: "{{domains.synapse}}" # Didn't work in the past. May it works now. This does not seem to work @todo Check how to solve without declaring set_fact, seems a bug at templates domain: "{{domains.matrix.synapse}}" # Didn't work in the past. May it works now. This does not seem to work @todo Check how to solve without declaring set_fact, seems a bug at templates
http_port: "{{ports.localhost.http.synapse}}" http_port: "{{ports.localhost.http.synapse}}"
notify: restart nginx notify: restart nginx
@ -43,7 +43,7 @@
include_role: include_role:
name: nginx-domain-setup name: nginx-domain-setup
vars: vars:
domain: "{{domains.element}}" domain: "{{domains.matrix.element}}"
http_port: "{{ports.localhost.http.element}}" http_port: "{{ports.localhost.http.element}}"
- name: include create-and-seed-database.yml for multiple bridges - name: include create-and-seed-database.yml for multiple bridges
@ -94,13 +94,13 @@
- name: add synapse log configuration - name: add synapse log configuration
template: template:
src: "synapse/log.config.j2" src: "synapse/log.config.j2"
dest: "{{docker_compose.directories.instance}}{{domains.synapse}}.log.config" dest: "{{docker_compose.directories.instance}}{{domains.matrix.synapse}}.log.config"
notify: docker compose project setup notify: docker compose project setup
# https://github.com/matrix-org/synapse/issues/6303 # https://github.com/matrix-org/synapse/issues/6303
- name: set correct folder permissions - name: set correct folder permissions
command: command:
cmd: "docker run --rm --mount type=volume,src=matrix_synapse_data,dst=/data -e SYNAPSE_SERVER_NAME={{domains.synapse}} -e SYNAPSE_REPORT_STATS=no --entrypoint /bin/sh matrixdotorg/synapse:latest -c 'chown -vR 991:991 /data'" cmd: "docker run --rm --mount type=volume,src=matrix_synapse_data,dst=/data -e SYNAPSE_SERVER_NAME={{domains.matrix.synapse}} -e SYNAPSE_REPORT_STATS=no --entrypoint /bin/sh matrixdotorg/synapse:latest -c 'chown -vR 991:991 /data'"
- name: add docker-compose.yml - name: add docker-compose.yml
template: template:

View File

@ -11,12 +11,12 @@ services:
volumes: volumes:
- synapse_data:/data - synapse_data:/data
- ./homeserver.yaml:/data/homeserver.yaml:ro - ./homeserver.yaml:/data/homeserver.yaml:ro
- ./{{domains.synapse}}.log.config:/data/{{domains.synapse}}.log.config:ro - ./{{domains.matrix.synapse}}.log.config:/data/{{domains.matrix.synapse}}.log.config:ro
{% for item in bridges %} {% for item in bridges %}
- {{docker_compose.directories.instance}}mautrix/{{item.bridge_name}}/registration.yaml:{{registration_file_folder}}{{item.bridge_name}}.registration.yaml:ro - {{docker_compose.directories.instance}}mautrix/{{item.bridge_name}}/registration.yaml:{{registration_file_folder}}{{item.bridge_name}}.registration.yaml:ro
{% endfor %} {% endfor %}
environment: environment:
- SYNAPSE_SERVER_NAME={{domains.synapse}} - SYNAPSE_SERVER_NAME={{domains.matrix.synapse}}
- SYNAPSE_REPORT_STATS=no - SYNAPSE_REPORT_STATS=no
ports: ports:
- "127.0.0.1:{{ports.localhost.http.synapse}}:8008" - "127.0.0.1:{{ports.localhost.http.synapse}}:8008"
@ -91,7 +91,7 @@ services:
KEYV_URL: '' KEYV_URL: ''
KEYV_BOT_ENCRYPTION: 'false' KEYV_BOT_ENCRYPTION: 'false'
KEYV_BOT_STORAGE: 'true' KEYV_BOT_STORAGE: 'true'
MATRIX_HOMESERVER_URL: 'https://{{domains.synapse}}' MATRIX_HOMESERVER_URL: 'https://{{domains.matrix.synapse}}'
MATRIX_BOT_USERNAME: '@chatgptbot:{{applications[application_id].server_name}}' MATRIX_BOT_USERNAME: '@chatgptbot:{{applications[application_id].server_name}}'
MATRIX_ACCESS_TOKEN: '{{ applications[application_id].credentials.chatgpt_bridge_access_token | default('') }}' MATRIX_ACCESS_TOKEN: '{{ applications[application_id].credentials.chatgpt_bridge_access_token | default('') }}'
MATRIX_BOT_PASSWORD: '{{applications[application_id].credentials.chatgpt_bridge_user_password}}' MATRIX_BOT_PASSWORD: '{{applications[application_id].credentials.chatgpt_bridge_user_password}}'

View File

@ -1,8 +1,8 @@
{ {
"default_server_config": { "default_server_config": {
"m.homeserver": { "m.homeserver": {
"base_url": "{{ web_protocol }}://{{domains.synapse}}", "base_url": "{{ web_protocol }}://{{domains.matrix.synapse}}",
"server_name": "{{domains.synapse}}" "server_name": "{{domains.matrix.synapse}}"
}, },
"m.identity_server": { "m.identity_server": {
"base_url": "{{ web_protocol }}://{{primary_domain}}" "base_url": "{{ web_protocol }}://{{primary_domain}}"

View File

@ -143,7 +143,7 @@ bridge:
sync_direct_chat_list: false sync_direct_chat_list: false
# Servers to always allow double puppeting from # Servers to always allow double puppeting from
double_puppet_server_map: double_puppet_server_map:
{{applications[application_id].server_name}}: {{domains.synapse}} {{applications[application_id].server_name}}: {{domains.matrix.synapse}}
# Allow using double puppeting from any server with a valid client .well-known file. # Allow using double puppeting from any server with a valid client .well-known file.
double_puppet_allow_discovery: false double_puppet_allow_discovery: false
# Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth

View File

@ -134,7 +134,7 @@ bridge:
double_puppet_allow_discovery: false double_puppet_allow_discovery: false
# Servers to allow double puppeting from, even if double_puppet_allow_discovery is false. # Servers to allow double puppeting from, even if double_puppet_allow_discovery is false.
double_puppet_server_map: double_puppet_server_map:
{{applications[application_id].server_name}}: https://{{domains.synapse}} {{applications[application_id].server_name}}: https://{{domains.matrix.synapse}}
# Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth # Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth
# #
# If set, custom puppets will be enabled automatically for local users # If set, custom puppets will be enabled automatically for local users

View File

@ -141,7 +141,7 @@ bridge:
federate_rooms: true federate_rooms: true
# Servers to always allow double puppeting from # Servers to always allow double puppeting from
double_puppet_server_map: double_puppet_server_map:
{{applications[application_id].server_name}}: https://{{domains.synapse}} {{applications[application_id].server_name}}: https://{{domains.matrix.synapse}}
# Allow using double puppeting from any server with a valid client .well-known file. # Allow using double puppeting from any server with a valid client .well-known file.
double_puppet_allow_discovery: false double_puppet_allow_discovery: false
# Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth

View File

@ -118,7 +118,7 @@ bridge:
# Servers to always allow double puppeting from # Servers to always allow double puppeting from
double_puppet_server_map: double_puppet_server_map:
{{applications[application_id].server_name}}: https://{{domains.synapse}} {{applications[application_id].server_name}}: https://{{domains.matrix.synapse}}
# Allow using double puppeting from any server with a valid client .well-known file. # Allow using double puppeting from any server with a valid client .well-known file.
double_puppet_allow_discovery: false double_puppet_allow_discovery: false
# Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth

View File

@ -198,7 +198,7 @@ bridge:
sync_direct_chat_list: false sync_direct_chat_list: false
# Servers to always allow double puppeting from # Servers to always allow double puppeting from
double_puppet_server_map: double_puppet_server_map:
{{applications[application_id].server_name}}: https://{{domains.synapse}} {{applications[application_id].server_name}}: https://{{domains.matrix.synapse}}
# Allow using double puppeting from any server with a valid client .well-known file. # Allow using double puppeting from any server with a valid client .well-known file.
double_puppet_allow_discovery: false double_puppet_allow_discovery: false
# Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth

View File

@ -236,7 +236,7 @@ bridge:
force_active_delivery_receipts: false force_active_delivery_receipts: false
# Servers to always allow double puppeting from # Servers to always allow double puppeting from
double_puppet_server_map: double_puppet_server_map:
{{applications[application_id].server_name}}: https://{{domains.synapse}} {{applications[application_id].server_name}}: https://{{domains.matrix.synapse}}
# Allow using double puppeting from any server with a valid client .well-known file. # Allow using double puppeting from any server with a valid client .well-known file.
double_puppet_allow_discovery: false double_puppet_allow_discovery: false
# Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth # Shared secrets for https://github.com/devture/matrix-synapse-shared-secret-auth

View File

@ -1,10 +1,10 @@
server { server {
{# Somehow .j2 doesn't interpretate the passed variable right. For this reasons this redeclaration is necessary #} {# Somehow .j2 doesn't interpretate the passed variable right. For this reasons this redeclaration is necessary #}
{# Could be that this is related to the set_fact use #} {# Could be that this is related to the set_fact use #}
{% set domain = domains.synapse %} {% set domain = domains.matrix.synapse %}
{% set http_port = ports.localhost.http.synapse %} {% set http_port = ports.localhost.http.synapse %}
server_name {{domains.synapse}}; server_name {{domains.matrix.synapse}};
{% include 'roles/letsencrypt/templates/ssl_header.j2' %} {% include 'roles/letsencrypt/templates/ssl_header.j2' %}
# For the federation port # For the federation port

View File

@ -17,15 +17,15 @@ database:
host: "{{database_host}}" host: "{{database_host}}"
cp_min: 5 cp_min: 5
cp_max: 10 cp_max: 10
log_config: "/data/{{domains.synapse}}.log.config" log_config: "/data/{{domains.matrix.synapse}}.log.config"
media_store_path: "/data/media_store" media_store_path: "/data/media_store"
registration_shared_secret: "{{applications[application_id].credentials.registration_shared_secret}}" registration_shared_secret: "{{applications[application_id].credentials.registration_shared_secret}}"
report_stats: true report_stats: true
macaroon_secret_key: "{{applications[application_id].credentials.macaroon_secret_key}}" macaroon_secret_key: "{{applications[application_id].credentials.macaroon_secret_key}}"
form_secret: "{{applications[application_id].credentials.form_secret}}" form_secret: "{{applications[application_id].credentials.form_secret}}"
signing_key_path: "/data/{{domains.synapse}}.signing.key" signing_key_path: "/data/{{domains.matrix.synapse}}.signing.key"
web_client_location: "{{ web_protocol }}://{{domains.element}}" web_client_location: "{{ web_protocol }}://{{domains.matrix.element}}"
public_baseurl: "{{ web_protocol }}://{{domains.synapse}}" public_baseurl: "{{ web_protocol }}://{{domains.matrix.synapse}}"
trusted_key_servers: trusted_key_servers:
- server_name: "matrix.org" - server_name: "matrix.org"
admin_contact: 'mailto:{{users.administrator.email}}' admin_contact: 'mailto:{{users.administrator.email}}'
@ -39,10 +39,10 @@ email:
#require_transport_security: true #require_transport_security: true
enable_tls: "{{ system_email.tls | upper }}" enable_tls: "{{ system_email.tls | upper }}"
notif_from: "Your Friendly %(app)s homeserver <{{ users['no-reply'].email }}>" notif_from: "Your Friendly %(app)s homeserver <{{ users['no-reply'].email }}>"
app_name: "Matrix on {{domains.synapse}}" app_name: "Matrix on {{domains.matrix.synapse}}"
enable_notifs: true enable_notifs: true
notif_for_new_users: false notif_for_new_users: false
client_base_url: "{{domains.synapse}}" client_base_url: "{{domains.matrix.synapse}}"
validation_token_lifetime: 15m validation_token_lifetime: 15m
{% if applications | is_feature_enabled('oidc',application_id) %} {% if applications | is_feature_enabled('oidc',application_id) %}

View File

@ -8,7 +8,7 @@ handlers:
file: file:
class: logging.handlers.RotatingFileHandler class: logging.handlers.RotatingFileHandler
formatter: precise formatter: precise
filename: /data/{{domains.synapse}}.homeserver.log filename: /data/{{domains.matrix.synapse}}.homeserver.log
maxBytes: 10485760 maxBytes: 10485760
backupCount: 3 backupCount: 3
console: console:

View File

@ -1,3 +1,3 @@
{ {
"m.server": "{{domains.synapse}}:443" "m.server": "{{domains.matrix.synapse}}:443"
} }