Skip to content

Commit ec8a7a4

Browse files
committed
Stabilize Matrix Authentication Service integration for Synapse
Related to element-hq/synapse#18759 Currently problematic (leading to failures to start for Synapse) because of: element-hq/synapse#18759 (comment)
1 parent 1c09eda commit ec8a7a4

File tree

6 files changed

+67
-95
lines changed

6 files changed

+67
-95
lines changed

group_vars/matrix_servers

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -669,17 +669,6 @@ matrix_authentication_service_config_passwords_schemes:
669669
- version: 2
670670
algorithm: argon2id
671671

672-
matrix_authentication_service_config_clients_auto: |-
673-
{{
674-
([
675-
{
676-
'client_id': matrix_synapse_experimental_features_msc3861_client_id,
677-
'client_auth_method': matrix_synapse_experimental_features_msc3861_client_auth_method,
678-
'client_secret': matrix_synapse_experimental_features_msc3861_client_secret,
679-
}
680-
] if matrix_synapse_experimental_features_msc3861_enabled else [])
681-
}}
682-
683672
matrix_authentication_service_config_email_transport: "{{ 'smtp' if exim_relay_enabled else 'blackhole' }}"
684673
matrix_authentication_service_config_email_hostname: "{{ exim_relay_identifier if exim_relay_enabled else '' }}"
685674
matrix_authentication_service_config_email_port: "{{ 8025 if exim_relay_enabled else 587 }}"
@@ -4911,7 +4900,7 @@ matrix_synapse_systemd_required_services_list_auto: |
49114900
+
49124901
(['matrix-goofys.service'] if matrix_s3_media_store_enabled else [])
49134902
+
4914-
(['matrix-authentication-service.service'] if (matrix_authentication_service_enabled and matrix_synapse_experimental_features_msc3861_enabled) else [])
4903+
(['matrix-authentication-service.service'] if (matrix_synapse_matrix_authentication_service_enabled and matrix_synapse_matrix_authentication_service_endpoint == matrix_authentication_service_http_base_container_url) else [])
49154904
}}
49164905

49174906
matrix_synapse_systemd_wanted_services_list_auto: |
@@ -4945,11 +4934,9 @@ matrix_synapse_report_stats_endpoint: "{{ (('http://' + matrix_synapse_usage_exp
49454934

49464935
matrix_synapse_experimental_features_msc3266_enabled: "{{ matrix_rtc_enabled }}"
49474936

4948-
matrix_synapse_experimental_features_msc3861_enabled: "{{ matrix_authentication_service_enabled and not matrix_authentication_service_migration_in_progress }}"
4949-
matrix_synapse_experimental_features_msc3861_issuer: "{{ matrix_authentication_service_http_base_container_url if matrix_authentication_service_enabled else '' }}"
4950-
matrix_synapse_experimental_features_msc3861_client_secret: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'syn.ngauth.cs', rounds=655555) | to_uuid }}"
4951-
matrix_synapse_experimental_features_msc3861_admin_token: "{{ matrix_authentication_service_config_matrix_secret if matrix_authentication_service_enabled else '' }}"
4952-
matrix_synapse_experimental_features_msc3861_account_management_url: "{{ matrix_authentication_service_account_management_url if matrix_authentication_service_enabled else '' }}"
4937+
matrix_synapse_matrix_authentication_service_enabled: "{{ matrix_authentication_service_enabled }}"
4938+
matrix_synapse_matrix_authentication_service_endpoint: "{{ matrix_authentication_service_http_base_container_url if matrix_authentication_service_enabled else '' }}"
4939+
matrix_synapse_matrix_authentication_service_secret: "{{ matrix_authentication_service_config_matrix_secret if matrix_authentication_service_enabled else '' }}"
49534940

49544941
matrix_synapse_experimental_features_msc4108_enabled: "{{ matrix_authentication_service_enabled and not matrix_authentication_service_migration_in_progress }}"
49554942

@@ -4961,7 +4948,7 @@ matrix_synapse_experimental_features_msc4222_enabled: "{{ matrix_rtc_enabled }}"
49614948
# Unless this is done, Synapse fails on startup with:
49624949
# > Error in configuration at 'password_config.enabled':
49634950
# > Password auth cannot be enabled when OAuth delegation is enabled
4964-
matrix_synapse_password_config_enabled: "{{ not matrix_synapse_experimental_features_msc3861_enabled }}"
4951+
matrix_synapse_password_config_enabled: "{{ not matrix_synapse_matrix_authentication_service_enabled }}"
49654952

49664953
matrix_synapse_register_user_script_matrix_authentication_service_path: "{{ matrix_authentication_service_bin_path }}/register-user"
49674954

roles/custom/matrix-synapse/defaults/main.yml

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,13 +1220,6 @@ matrix_synapse_email_app_name: Matrix
12201220
matrix_synapse_email_client_base_url: "{{ 'https' if matrix_playbook_ssl_enabled else 'http' }}://{{ matrix_server_fqn_element }}"
12211221
matrix_synapse_email_invite_client_location: "https://app.element.io"
12221222

1223-
1224-
################################################################################
1225-
#
1226-
# Next-generation auth for Matrix, based on OAuth 2.0/OIDC
1227-
#
1228-
################################################################################
1229-
12301223
# Controls whether to enable the "send typing, presence and receipts to appservices" experimental feature.
12311224
#
12321225
# See:
@@ -1248,50 +1241,29 @@ matrix_synapse_experimental_features_msc3202_device_masquerading_enabled: false
12481241
# - https://matrix-org.github.io/matrix-hookshot/latest/advanced/encryption.html#running-with-synapse
12491242
matrix_synapse_experimental_features_msc3202_transaction_extensions_enabled: false
12501243

1251-
# Controls whether to enable the "Next-generation auth for Matrix, based on OAuth 2.0/OIDC" experimental feature.
1244+
################################################################################
1245+
#
1246+
# Next-generation auth for Matrix, based on OAuth 2.0/OIDC
12521247
#
1248+
################################################################################
1249+
1250+
# Controls whether to enable "Matrix Authentication Service" integration ("Next-generation auth for Matrix, based on OAuth 2.0/OIDC").
12531251
# See:
1252+
# - https://github.com/element-hq/matrix-authentication-service
12541253
# - https://matrix.org/blog/2023/09/better-auth/
12551254
# - https://github.com/matrix-org/matrix-spec-proposals/pull/3861
1256-
matrix_synapse_experimental_features_msc3861_enabled: false
1257-
1258-
# Specifies the issuer URL for the OAuth 2.0/OIDC authentication provider.
1259-
#
1260-
# This can be set to a private (container) URL.
1261-
#
1262-
# Example: https://matrix.example.com/auth/
1263-
matrix_synapse_experimental_features_msc3861_issuer: ''
1264-
1265-
# Specifies the introspection endpoint URL for the OAuth 2.0/OIDC authentication provider.
1266-
#
1267-
# This can be set to a private (container) URL.
1268-
#
1269-
# If this is left empty, `{issuer}/.well-known/openid-configuration` will be fetched and the `introspection_endpoint` will be extracted from there.
1270-
# We define it explicitly, because this allows us to override it and use an internal (container network) URL instead of using the public one.
1271-
# Avoiding public addresses is an optimization that decreases overhead due to public networking and SSL termination.
1272-
#
1273-
# Example: https://matrix.example.com/auth/oauth2/introspect
1274-
matrix_synapse_experimental_features_msc3861_introspection_endpoint: "{{ matrix_synapse_experimental_features_msc3861_issuer + 'oauth2/introspect' }}"
1275-
1276-
# A unique identifier for the client.
1277-
#
1278-
# It must be a valid ULID (https://github.com/ulid/spec),
1279-
# and it happens that 0000000000000000000SYNAPSE is a valid ULID.
1280-
matrix_synapse_experimental_features_msc3861_client_id: '0000000000000000000SYNAPSE'
1281-
1282-
matrix_synapse_experimental_features_msc3861_client_auth_method: client_secret_basic
1283-
1284-
matrix_synapse_experimental_features_msc3861_client_secret: ''
1255+
matrix_synapse_matrix_authentication_service_enabled: false
12851256

1286-
# A token that can be used to make admin API calls.
1287-
# Matches `matrix.secret` in the matrix-authentication-service config
1288-
matrix_synapse_experimental_features_msc3861_admin_token: ''
1257+
# Specifies the base URL where the Matrix Authentication Service is running.
1258+
matrix_synapse_matrix_authentication_service_endpoint: ""
12891259

1290-
# URL to advertise to clients where users can self-manage their account.
1291-
matrix_synapse_experimental_features_msc3861_account_management_url: ''
1260+
# Specifies the shared secret used to authenticate Matrix Authentication Service requests.
1261+
# Must be the same as `matrix.secret` in the Matrix Authentication Service configuration.
1262+
# See https://element-hq.github.io/matrix-authentication-service/reference/configuration.html#matrix
1263+
matrix_synapse_matrix_authentication_service_secret: ""
12921264

12931265
# Controls whether to enable the "QR code login" experimental feature.
1294-
# Enabling this requires that MSC3861 (see `matrix_synapse_experimental_features_msc3861_enabled`) is also enabled.
1266+
# Enabling this requires that Matrix Authentication Service integration (see `matrix_synapse_matrix_authentication_service_enabled`) is also enabled.
12951267
matrix_synapse_experimental_features_msc4108_enabled: false
12961268

12971269
################################################################################

roles/custom/matrix-synapse/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
- tags:
6363
- register-user
6464
block:
65-
- when: matrix_synapse_enabled and not matrix_synapse_experimental_features_msc3861_enabled
65+
- when: matrix_synapse_enabled and not matrix_synapse_matrix_authentication_service_enabled
6666
ansible.builtin.include_tasks: "{{ role_path }}/tasks/register_user.yml"
6767

6868
- tags:

roles/custom/matrix-synapse/tasks/validate_config.yml

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,11 @@
3939
- {'name': 'matrix_synapse_metrics_proxying_hostname', when: "{{ matrix_synapse_metrics_proxying_enabled }}"}
4040
- {'name': 'matrix_synapse_metrics_proxying_path_prefix', when: "{{ matrix_synapse_metrics_proxying_enabled }}"}
4141

42-
- {'name': 'matrix_synapse_experimental_features_msc3861_issuer', when: "{{ matrix_synapse_experimental_features_msc3861_enabled }}"}
43-
- {'name': 'matrix_synapse_experimental_features_msc3861_client_id', when: "{{ matrix_synapse_experimental_features_msc3861_enabled }}"}
44-
- {'name': 'matrix_synapse_experimental_features_msc3861_client_auth_method', when: "{{ matrix_synapse_experimental_features_msc3861_enabled }}"}
45-
- {'name': 'matrix_synapse_experimental_features_msc3861_client_secret', when: "{{ matrix_synapse_experimental_features_msc3861_enabled }}"}
46-
- {'name': 'matrix_synapse_experimental_features_msc3861_admin_token', when: "{{ matrix_synapse_experimental_features_msc3861_enabled }}"}
47-
- {'name': 'matrix_synapse_experimental_features_msc3861_account_management_url', when: "{{ matrix_synapse_experimental_features_msc3861_enabled }}"}
42+
- {'name': 'matrix_synapse_matrix_authentication_service_endpoint', when: "{{ matrix_synapse_matrix_authentication_service_enabled }}"}
43+
- {'name': 'matrix_synapse_matrix_authentication_service_secret', when: "{{ matrix_synapse_matrix_authentication_service_enabled }}"}
4844

4945
- {'name': 'matrix_synapse_container_labels_traefik_compression_middleware_name', when: "{{ matrix_synapse_container_labels_traefik_compression_middleware_enabled }}"}
5046

51-
# If only MSC 4108 is enabled, Synapse fails with: "MSC4108 requires MSC3861 to be enabled"
52-
- name: Fail if Synapse experimental feature QR code login (MSC4108) is enabled while Next-Gen Auth (MSC3861) is not
53-
ansible.builtin.fail:
54-
msg: >-
55-
QR code login (MSC4108) requires Next-Gen Auth (MSC3861) to be enabled or Synapse will fail to start.
56-
Enable `matrix_synapse_experimental_features_msc3861_enabled` when using `matrix_synapse_experimental_features_msc4108_enabled`.
57-
when: "matrix_synapse_experimental_features_msc4108_enabled and not matrix_synapse_experimental_features_msc3861_enabled"
58-
5947
- name: Fail if asking for more than 1 instance of single-instance workers
6048
ansible.builtin.fail:
6149
msg: >-
@@ -121,6 +109,14 @@
121109
- {'old': 'matrix_s3_goofys_docker_image_name_prefix', 'new': 'matrix_s3_goofys_docker_image_registry_prefix'}
122110
- {'old': 'matrix_synapse_rust_synapse_compress_state_docker_image_name_prefix', 'new': 'matrix_synapse_rust_synapse_compress_state_docker_image_registry_prefix'}
123111

112+
- {'old': 'matrix_synapse_experimental_features_msc3861_enabled', 'new': 'matrix_synapse_matrix_authentication_service_enabled'}
113+
- {'old': 'matrix_synapse_experimental_features_msc3861_issuer', 'new': '<superseded by matrix_synapse_matrix_authentication_service_endpoint>'}
114+
- {'old': 'matrix_synapse_experimental_features_msc3861_client_id', 'new': '<removed>'}
115+
- {'old': 'matrix_synapse_experimental_features_msc3861_client_auth_method', 'new': '<removed>'}
116+
- {'old': 'matrix_synapse_experimental_features_msc3861_client_secret', 'new': '<removed>'}
117+
- {'old': 'matrix_synapse_experimental_features_msc3861_admin_token', 'new': '<removed>'}
118+
- {'old': 'matrix_synapse_experimental_features_msc3861_account_management_url', 'new': '<removed>'}
119+
124120
- name: (Deprecation) Catch and report renamed settings in matrix_synapse_configuration_extension_yaml
125121
ansible.builtin.fail:
126122
msg: >-
@@ -163,19 +159,39 @@
163159

164160
- name: Fail if known Synapse password provider modules are enabled when auth is delegated to Matrix Authentication Service
165161
ansible.builtin.fail:
166-
msg: "When Synapse is delegating authentication to Matrix Authentication Service, it does not make sense to enable password provider modules, because it is not Synapse that is handling authentication. Please disable {{ item }} before enabling Matrix Authentication Service integration for Synapse. Synapse will refuse to start otherwise."
167-
when: matrix_synapse_experimental_features_msc3861_enabled and vars[item] | bool
162+
msg: "When Synapse is delegating authentication to Matrix Authentication Service (`matrix_synapse_matrix_authentication_service_enabled: true`), it does not make sense to enable password provider modules, because it is not Synapse that is handling authentication. Please disable {{ item }} before enabling Matrix Authentication Service integration for Synapse. Synapse will refuse to start otherwise."
163+
when: matrix_synapse_matrix_authentication_service_enabled and vars[item] | bool
168164
with_items:
169165
- matrix_synapse_ext_password_provider_rest_auth_enabled
170166
- matrix_synapse_ext_password_provider_shared_secret_auth_enabled
171167
- matrix_synapse_ext_password_provider_ldap_enabled
172168

173169
- name: Fail if password config is enabled for Synapse when auth is delegated to Matrix Authentication Service
174170
ansible.builtin.fail:
175-
msg: "When Synapse is delegating authentication to Matrix Authentication Service, it doesn't make sense to enable the password config (`matrix_synapse_password_config_enabled: true`), because it is not Synapse that is handling authentication. Please remove your `matrix_synapse_password_config_enabled: true` setting before enabling Matrix Authentication Service integration for Synapse. Synapse will refuse to start otherwise."
176-
when: matrix_synapse_experimental_features_msc3861_enabled and matrix_synapse_password_config_enabled
171+
msg: "When Synapse is delegating authentication to Matrix Authentication Service (`matrix_synapse_matrix_authentication_service_enabled: true`), it doesn't make sense to enable the password config (`matrix_synapse_password_config_enabled: true`), because it is not Synapse that is handling authentication. Please remove your `matrix_synapse_password_config_enabled: true` setting before enabling Matrix Authentication Service integration for Synapse. Synapse will refuse to start otherwise."
172+
when: matrix_synapse_matrix_authentication_service_enabled and matrix_synapse_password_config_enabled
173+
174+
- name: Fail if registration is enabled for Synapse when auth is delegated to Matrix Authentication Service
175+
ansible.builtin.fail:
176+
msg: "When Synapse is delegating authentication to Matrix Authentication Service (`matrix_synapse_matrix_authentication_service_enabled: true`), it doesn't make sense to enable registration (`matrix_synapse_enable_registration: true`), because it is not Synapse that is handling authentication. Synapse will refuse to start otherwise."
177+
when: matrix_synapse_matrix_authentication_service_enabled and matrix_synapse_enable_registration
178+
179+
- name: Fail if registration CAPTCHA is enabled for Synapse when auth is delegated to Matrix Authentication Service
180+
ansible.builtin.fail:
181+
msg: "When Synapse is delegating authentication to Matrix Authentication Service (`matrix_synapse_matrix_authentication_service_enabled: true`), it doesn't make sense to enable registration CAPTCHA (`matrix_synapse_enable_registration_captcha: true`), because it is not Synapse that is handling authentication. Synapse will refuse to start otherwise."
182+
when: matrix_synapse_matrix_authentication_service_enabled and matrix_synapse_enable_registration_captcha
183+
184+
- name: Fail if OpenID Connect is enabled for Synapse when auth is delegated to Matrix Authentication Service
185+
ansible.builtin.fail:
186+
msg: "When Synapse is delegating authentication to Matrix Authentication Service (`matrix_synapse_matrix_authentication_service_enabled: true`), it doesn't make sense to enable OpenID Connect (`matrix_synapse_oidc_enabled: true`), because it is not Synapse that is handling authentication. Synapse will refuse to start otherwise."
187+
when: matrix_synapse_matrix_authentication_service_enabled and matrix_synapse_oidc_enabled
188+
189+
- name: Fail if CAS config is enabled for Synapse when auth is delegated to Matrix Authentication Service
190+
ansible.builtin.fail:
191+
msg: "When Synapse is delegating authentication to Matrix Authentication Service (`matrix_synapse_matrix_authentication_service_enabled: true`), it doesn't make sense to enable CAS config (`matrix_synapse_cas_config_enabled: true`), because it is not Synapse that is handling authentication. Synapse will refuse to start otherwise."
192+
when: matrix_synapse_matrix_authentication_service_enabled and matrix_synapse_cas_config_enabled
177193

178-
- name: Fail if QR code login (MSC4108) is enabled while Next-Gen Auth (MSC3861) is not
194+
- name: Fail if QR code login (MSC4108) is enabled while Matrix Authentication Service is not
179195
ansible.builtin.fail:
180-
msg: "When Synapse QR code login is enabled (MSC4108 via `matrix_synapse_experimental_features_msc4108_enabled`), Next-Gen auth (MSC3861 via `matrix_synapse_experimental_features_msc3861_enabled`) must also be enabled."
181-
when: matrix_synapse_experimental_features_msc4108_enabled and not matrix_synapse_experimental_features_msc3861_enabled
196+
msg: "When Synapse QR code login is enabled (MSC4108 via `matrix_synapse_experimental_features_msc4108_enabled`), Matrix Authentication Service integration (`matrix_synapse_matrix_authentication_service_enabled`) must also be enabled."
197+
when: matrix_synapse_experimental_features_msc4108_enabled and not matrix_synapse_matrix_authentication_service_enabled

roles/custom/matrix-synapse/templates/synapse/bin/register-user.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#jinja2: lstrip_blocks: True
22
#!/bin/bash
33

4-
{% if matrix_synapse_experimental_features_msc3861_enabled %}
4+
{% if matrix_synapse_matrix_authentication_service_enabled %}
55
echo "Registering users is handled by the Matrix Authentication Service, so you cannot use this script anymore."
66
echo "Consider using the {{ matrix_synapse_register_user_script_matrix_authentication_service_path }} script instead."
77
exit 2

roles/custom/matrix-synapse/templates/synapse/homeserver.yaml.j2

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,6 +2971,14 @@ background_updates:
29712971
#
29722972
#default_batch_size: 50
29732973

2974+
2975+
{% if matrix_synapse_matrix_authentication_service_enabled %}
2976+
matrix_authentication_service:
2977+
enabled: true
2978+
endpoint: {{ matrix_synapse_matrix_authentication_service_endpoint | to_json }}
2979+
secret: {{ matrix_synapse_matrix_authentication_service_secret | to_json }}
2980+
{% endif %}
2981+
29742982
experimental_features:
29752983
{% if matrix_synapse_experimental_features_msc2409_to_device_messages_enabled %}
29762984
msc2409_to_device_messages_enabled: true
@@ -2984,17 +2992,6 @@ experimental_features:
29842992
{% if matrix_synapse_experimental_features_msc3266_enabled %}
29852993
msc3266_enabled: true
29862994
{% endif %}
2987-
{% if matrix_synapse_experimental_features_msc3861_enabled %}
2988-
msc3861:
2989-
enabled: true
2990-
issuer: {{ matrix_synapse_experimental_features_msc3861_issuer | to_json }}
2991-
introspection_endpoint: {{ matrix_synapse_experimental_features_msc3861_introspection_endpoint | to_json }}
2992-
client_id: {{ matrix_synapse_experimental_features_msc3861_client_id | to_json }}
2993-
client_auth_method: {{ matrix_synapse_experimental_features_msc3861_client_auth_method | to_json }}
2994-
client_secret: {{ matrix_synapse_experimental_features_msc3861_client_secret | to_json }}
2995-
admin_token: {{ matrix_synapse_experimental_features_msc3861_admin_token | to_json }}
2996-
account_management_url: {{ matrix_synapse_experimental_features_msc3861_account_management_url | to_json }}
2997-
{% endif %}
29982995
{% if matrix_synapse_experimental_features_msc4108_enabled %}
29992996
msc4108_enabled: true
30002997
{% endif %}

0 commit comments

Comments
 (0)