mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-03-25 22:17:25 +00:00
matrix-authentication-service: add UNIX socket support for playbook-managed Postgres
MAS now connects to the playbook-managed Postgres via a UNIX socket by default (when available), matching the approach already used by Synapse. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,3 +1,19 @@
|
||||
# 2026-03-19
|
||||
|
||||
## Matrix Authentication Service now prefers UNIX sockets for playbook-managed Postgres
|
||||
|
||||
When [Matrix Authentication Service](docs/configuring-playbook-matrix-authentication-service.md) (MAS) uses the playbook-managed Postgres service, it now connects to it via a [UNIX socket](https://en.wikipedia.org/wiki/Unix_domain_socket) by default instead of TCP.
|
||||
|
||||
This follows the same approach [applied to Synapse](#synapse-now-prefers-unix-sockets-for-playbook-managed-postgres-and-valkey) and reduces unnecessary container-network wiring, keeping local IPC off the network stack.
|
||||
|
||||
If you use an external Postgres server for MAS, this does not change your setup.
|
||||
|
||||
If you'd like to keep the previous TCP-based behavior, add the following configuration to your `vars.yml`:
|
||||
|
||||
```yaml
|
||||
matrix_authentication_service_config_database_socket_enabled: false
|
||||
```
|
||||
|
||||
# 2026-03-17
|
||||
|
||||
## Synapse now prefers UNIX sockets for playbook-managed Postgres and Valkey
|
||||
|
||||
@@ -1079,9 +1079,18 @@ matrix_authentication_service_enabled: false
|
||||
matrix_authentication_service_hostname: "{{ matrix_server_fqn_matrix }}"
|
||||
matrix_authentication_service_path_prefix: /auth
|
||||
|
||||
matrix_authentication_service_config_database_host: "{{ postgres_connection_hostname if postgres_enabled else '' }}"
|
||||
matrix_playbook_matrix_authentication_service_uses_managed_postgres: "{{ postgres_enabled }}"
|
||||
|
||||
matrix_authentication_service_config_database_host: "{{ matrix_authentication_service_config_database_socket_path if matrix_authentication_service_config_database_socket_enabled else (postgres_connection_hostname if matrix_playbook_matrix_authentication_service_uses_managed_postgres else '') }}"
|
||||
matrix_authentication_service_config_database_password: "{{ (matrix_homeserver_generic_secret_key + ':mas.db') | hash('sha512') | to_uuid }}"
|
||||
|
||||
# unix socket connection
|
||||
matrix_authentication_service_config_database_socket_enabled: "{{ matrix_playbook_matrix_authentication_service_uses_managed_postgres and postgres_container_unix_socket_enabled }}"
|
||||
# path to the Postgres socket's parent dir inside the MAS container
|
||||
matrix_authentication_service_config_database_socket_path: "{{ '/run-postgres' if matrix_playbook_matrix_authentication_service_uses_managed_postgres else '' }}"
|
||||
# path to the Postgres socket on the host
|
||||
matrix_authentication_service_config_database_socket_path_host: "{{ postgres_run_path if matrix_playbook_matrix_authentication_service_uses_managed_postgres else '' }}"
|
||||
|
||||
matrix_authentication_service_config_matrix_homeserver: "{{ matrix_domain }}"
|
||||
matrix_authentication_service_config_matrix_secret: "{{ (matrix_homeserver_generic_secret_key + ':mas.hs.secret') | hash('sha512') | to_uuid }}"
|
||||
matrix_authentication_service_config_matrix_endpoint: "{{ matrix_homeserver_container_url }}"
|
||||
@@ -1114,7 +1123,7 @@ matrix_authentication_service_container_network: "{{ matrix_homeserver_container
|
||||
matrix_authentication_service_container_additional_networks_auto: |-
|
||||
{{
|
||||
(
|
||||
([postgres_container_network] if postgres_enabled and matrix_authentication_service_config_database_host == postgres_connection_hostname else [])
|
||||
([postgres_container_network] if (matrix_playbook_matrix_authentication_service_uses_managed_postgres and not matrix_authentication_service_config_database_socket_enabled) else [])
|
||||
+
|
||||
([exim_relay_container_network] if (exim_relay_enabled and matrix_authentication_service_config_email_transport == 'smtp' and matrix_authentication_service_config_email_hostname == exim_relay_identifier and matrix_authentication_service_container_network != exim_relay_container_network) else [])
|
||||
+
|
||||
@@ -1139,7 +1148,7 @@ matrix_authentication_service_container_labels_internal_compatibility_layer_entr
|
||||
# We'll put our dependency on the homeserver as a "want", rather than a requirement.
|
||||
matrix_authentication_service_systemd_required_services_list_auto: |
|
||||
{{
|
||||
([postgres_identifier ~ '.service'] if postgres_enabled and matrix_authentication_service_config_database_host == postgres_connection_hostname else [])
|
||||
([postgres_identifier ~ '.service'] if matrix_playbook_matrix_authentication_service_uses_managed_postgres else [])
|
||||
}}
|
||||
|
||||
# See more information about this homeserver "want" in the comment for `matrix_authentication_service_systemd_required_services_list_auto` above.
|
||||
@@ -1150,7 +1159,7 @@ matrix_authentication_service_systemd_wanted_services_list_auto: |
|
||||
([exim_relay_identifier ~ '.service'] if (exim_relay_enabled and matrix_authentication_service_config_email_transport == 'smtp' and matrix_authentication_service_config_email_hostname == exim_relay_identifier and matrix_authentication_service_container_network != exim_relay_container_network) else [])
|
||||
}}
|
||||
|
||||
matrix_authentication_service_syn2mas_container_network: "{{ postgres_container_network if postgres_enabled and matrix_authentication_service_config_database_host == postgres_connection_hostname else matrix_authentication_service_container_network }}"
|
||||
matrix_authentication_service_syn2mas_container_network: "{{ postgres_container_network if (matrix_playbook_matrix_authentication_service_uses_managed_postgres and not matrix_authentication_service_config_database_socket_enabled) else matrix_authentication_service_container_network }}"
|
||||
|
||||
matrix_authentication_service_syn2mas_synapse_homeserver_config_path: "{{ matrix_synapse_config_dir_path + '/homeserver.yaml' if matrix_synapse_enabled else '' }}"
|
||||
matrix_authentication_service_syn2mas_synapse_database_socket_enabled: "{{ matrix_synapse_database_socket_enabled if matrix_synapse_enabled else false }}"
|
||||
@@ -4047,7 +4056,7 @@ postgres_managed_databases_auto: |
|
||||
'name': matrix_authentication_service_config_database_database,
|
||||
'username': matrix_authentication_service_config_database_username,
|
||||
'password': matrix_authentication_service_config_database_password,
|
||||
}] if (matrix_authentication_service_enabled and matrix_authentication_service_config_database_host == postgres_connection_hostname) else [])
|
||||
}] if (matrix_authentication_service_enabled and matrix_playbook_matrix_authentication_service_uses_managed_postgres) else [])
|
||||
+
|
||||
([{
|
||||
'name': matrix_bot_matrix_reminder_bot_database_name,
|
||||
|
||||
@@ -300,6 +300,15 @@ matrix_authentication_service_config_database_idle_timeout: 600
|
||||
# Controls the `database.max_lifetime` configuration setting.
|
||||
matrix_authentication_service_config_database_max_lifetime: 1800
|
||||
|
||||
# Controls whether the database connection is made via a UNIX socket.
|
||||
matrix_authentication_service_config_database_socket_enabled: false
|
||||
|
||||
# The path to the Postgres socket's parent directory inside the MAS container.
|
||||
matrix_authentication_service_config_database_socket_path: "/run-postgres"
|
||||
|
||||
# The path to the Postgres socket directory on the host (bind-mount source).
|
||||
matrix_authentication_service_config_database_socket_path_host: ""
|
||||
|
||||
########################################################################################
|
||||
# #
|
||||
# /Database configuration #
|
||||
|
||||
@@ -71,7 +71,10 @@
|
||||
--mount type=bind,src={{ matrix_authentication_service_config_path }}/config.yaml,dst=/config.yaml,ro
|
||||
--mount type=bind,src={{ matrix_authentication_service_data_keys_path }},dst=/keys,ro
|
||||
--mount type=bind,src={{ matrix_authentication_service_syn2mas_synapse_homeserver_config_path }},dst=/homeserver.yaml,ro
|
||||
{% if matrix_authentication_service_syn2mas_synapse_database_socket_enabled %}
|
||||
{% if matrix_authentication_service_config_database_socket_enabled %}
|
||||
--mount type=bind,src={{ matrix_authentication_service_config_database_socket_path_host }},dst={{ matrix_authentication_service_config_database_socket_path }}
|
||||
{% endif %}
|
||||
{% if matrix_authentication_service_syn2mas_synapse_database_socket_enabled and (not matrix_authentication_service_config_database_socket_enabled or matrix_authentication_service_syn2mas_synapse_database_socket_path != matrix_authentication_service_config_database_socket_path) %}
|
||||
--mount type=bind,src={{ matrix_authentication_service_syn2mas_synapse_database_socket_path_host }},dst={{ matrix_authentication_service_syn2mas_synapse_database_socket_path }}
|
||||
{% endif %}
|
||||
{{ matrix_authentication_service_container_image }}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
- {'name': 'matrix_authentication_service_hostname', when: true}
|
||||
- {'name': 'matrix_authentication_service_config_database_username', when: true}
|
||||
- {'name': 'matrix_authentication_service_config_database_password', when: true}
|
||||
- {'name': 'matrix_authentication_service_config_database_host', when: true}
|
||||
- {'name': 'matrix_authentication_service_config_database_host', when: "{{ not matrix_authentication_service_config_database_socket_enabled }}"}
|
||||
- {'name': 'matrix_authentication_service_config_database_socket_path_host', when: "{{ matrix_authentication_service_config_database_socket_enabled }}"}
|
||||
- {'name': 'matrix_authentication_service_config_database_database', when: true}
|
||||
- {'name': 'matrix_authentication_service_config_secrets_encryption', when: true}
|
||||
- {'name': 'matrix_authentication_service_config_matrix_homeserver', when: true}
|
||||
|
||||
@@ -28,6 +28,9 @@ ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
|
||||
--label-file={{ matrix_authentication_service_config_path }}/labels \
|
||||
--mount type=bind,src={{ matrix_authentication_service_config_path }}/config.yaml,dst=/config.yaml,ro \
|
||||
--mount type=bind,src={{ matrix_authentication_service_data_keys_path }},dst=/keys,ro \
|
||||
{% if matrix_authentication_service_config_database_socket_enabled %}
|
||||
--mount type=bind,src={{ matrix_authentication_service_config_database_socket_path_host }},dst={{ matrix_authentication_service_config_database_socket_path }} \
|
||||
{% endif %}
|
||||
{% for arg in matrix_authentication_service_container_extra_arguments %}
|
||||
{{ arg }} \
|
||||
{% endfor %}
|
||||
|
||||
@@ -254,6 +254,13 @@ matrix_playbook_synapse_uses_managed_postgres: false
|
||||
matrix_playbook_synapse_uses_managed_valkey: false
|
||||
matrix_playbook_synapse_auto_compressor_uses_managed_postgres: false
|
||||
|
||||
# This playbook-level helper describes whether Matrix Authentication Service should be wired
|
||||
# to the playbook-managed Postgres instance.
|
||||
# It is meant for orchestration concerns like container networking, systemd ordering, and database creation,
|
||||
# while `matrix_authentication_service_*` variables stay focused on actual connection parameters.
|
||||
# This likely gets overridden elsewhere.
|
||||
matrix_playbook_matrix_authentication_service_uses_managed_postgres: false
|
||||
|
||||
# Controls whether various services should expose metrics publicly.
|
||||
# If Prometheus is operating on the same machine, exposing metrics publicly is not necessary.
|
||||
matrix_metrics_exposure_enabled: false
|
||||
|
||||
Reference in New Issue
Block a user