From 57c5271d9d6265a34a9d9cceb93365f685074f96 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 14 Nov 2024 16:30:09 +0200 Subject: [PATCH] Enable (Traefik compression middleware)-assisted compression for synapse-reverse-proxy-companion This likely breaks QR code login for Synapse-worker setups. See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/3749 --- group_vars/matrix_servers | 3 ++ .../defaults/main.yml | 5 +++ .../tasks/validate_config.yml | 2 + .../templates/labels.j2 | 40 +++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index dd4905958..480680729 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -4869,6 +4869,9 @@ matrix_synapse_reverse_proxy_companion_container_labels_traefik_entrypoints: "{{ matrix_synapse_reverse_proxy_companion_container_labels_traefik_tls_certResolver: "{{ traefik_certResolver_primary }}" matrix_synapse_reverse_proxy_companion_container_labels_traefik_hostname: "{{ matrix_server_fqn_matrix }}" +matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_enabled: "{{ matrix_playbook_reverse_proxy_traefik_middleware_compession_enabled }}" +matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_name: "{{ matrix_playbook_reverse_proxy_traefik_middleware_compession_name if matrix_playbook_reverse_proxy_traefik_middleware_compession_enabled else '' }}" + matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_client_api_enabled: "{{ matrix_synapse_container_labels_public_client_synapse_client_api_enabled }}" matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_admin_api_enabled: "{{ matrix_synapse_container_labels_public_client_synapse_admin_api_enabled }}" diff --git a/roles/custom/matrix-synapse-reverse-proxy-companion/defaults/main.yml b/roles/custom/matrix-synapse-reverse-proxy-companion/defaults/main.yml index 2f2cca4e4..3d9173bd3 100644 --- a/roles/custom/matrix-synapse-reverse-proxy-companion/defaults/main.yml +++ b/roles/custom/matrix-synapse-reverse-proxy-companion/defaults/main.yml @@ -61,6 +61,11 @@ matrix_synapse_reverse_proxy_companion_container_labels_traefik_entrypoints: web matrix_synapse_reverse_proxy_companion_container_labels_traefik_tls_certResolver: default # noqa var-naming matrix_synapse_reverse_proxy_companion_container_labels_traefik_hostname: '' +# Controls whether a compression middleware will be injected into the middlewares list. +# This compression middleware is supposed to be defined elsewhere (using labels or a File provider, etc.) and is merely referenced by this router. +matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_enabled: false +matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_name: "" + # Controls whether labels will be added that expose the Client-Server API on a public Traefik entrypoint. matrix_synapse_reverse_proxy_companion_container_labels_public_client_api_enabled: true matrix_synapse_reverse_proxy_companion_container_labels_public_client_api_traefik_hostname: "{{ matrix_synapse_reverse_proxy_companion_container_labels_traefik_hostname }}" diff --git a/roles/custom/matrix-synapse-reverse-proxy-companion/tasks/validate_config.yml b/roles/custom/matrix-synapse-reverse-proxy-companion/tasks/validate_config.yml index 92d89b57a..4da323182 100644 --- a/roles/custom/matrix-synapse-reverse-proxy-companion/tasks/validate_config.yml +++ b/roles/custom/matrix-synapse-reverse-proxy-companion/tasks/validate_config.yml @@ -17,3 +17,5 @@ - {'name': 'matrix_synapse_reverse_proxy_companion_container_labels_public_federation_api_traefik_entrypoints', when: "{{ matrix_synapse_reverse_proxy_companion_container_labels_public_federation_api_enabled }}"} - {'name': 'matrix_synapse_reverse_proxy_companion_container_labels_internal_client_api_traefik_entrypoints', when: "{{ matrix_synapse_reverse_proxy_companion_container_labels_internal_client_api_enabled }}"} + + - {'name': 'matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_name', when: "{{ matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_enabled }}"} diff --git a/roles/custom/matrix-synapse-reverse-proxy-companion/templates/labels.j2 b/roles/custom/matrix-synapse-reverse-proxy-companion/templates/labels.j2 index 44c7e7a82..8b8bd7cdb 100644 --- a/roles/custom/matrix-synapse-reverse-proxy-companion/templates/labels.j2 +++ b/roles/custom/matrix-synapse-reverse-proxy-companion/templates/labels.j2 @@ -16,8 +16,18 @@ traefik.http.services.matrix-synapse-reverse-proxy-companion-federation-api.load # # ############################################################ +{% set client_api_middlewares = [] %} + +{% if matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_enabled %} +{% set client_api_middlewares = client_api_middlewares + [matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_name] %} +{% endif %} + traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-api.rule={{ matrix_synapse_reverse_proxy_companion_container_labels_public_client_api_traefik_rule }} +{% if client_api_middlewares | length > 0 %} +traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-api.middlewares={{ client_api_middlewares | join(',') }} +{% endif %} + {% if matrix_synapse_reverse_proxy_companion_container_labels_public_client_api_traefik_priority | int > 0 %} traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-api.priority={{ matrix_synapse_reverse_proxy_companion_container_labels_public_client_api_traefik_priority }} {% endif %} @@ -69,8 +79,18 @@ traefik.http.routers.matrix-synapse-reverse-proxy-companion-internal-client-api. # # ############################################################ +{% set synapse_client_api_middlewares = [] %} + +{% if matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_enabled %} +{% set synapse_client_api_middlewares = synapse_client_api_middlewares + [matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_name] %} +{% endif %} + traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synapse-client-api.rule={{ matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_client_api_traefik_rule }} +{% if synapse_client_api_middlewares | length > 0 %} +traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synapse-client-api.middlewares={{ synapse_client_api_middlewares | join(',') }} +{% endif %} + {% if matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_client_api_traefik_priority | int > 0 %} traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synapse-client-api.priority={{ matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_client_api_traefik_priority }} {% endif %} @@ -98,8 +118,18 @@ traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synaps # # ############################################################ +{% set synapse_admin_api_middlewares = [] %} + +{% if matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_enabled %} +{% set synapse_admin_api_middlewares = synapse_admin_api_middlewares + [matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_name] %} +{% endif %} + traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synapse-admin-api.rule={{ matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_admin_api_traefik_rule }} +{% if synapse_admin_api_middlewares | length > 0 %} +traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synapse-admin-api.middlewares={{ synapse_admin_api_middlewares | join(',') }} +{% endif %} + {% if matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_admin_api_traefik_priority | int > 0 %} traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synapse-admin-api.priority={{ matrix_synapse_reverse_proxy_companion_container_labels_public_client_synapse_admin_api_traefik_priority }} {% endif %} @@ -127,8 +157,18 @@ traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-client-synaps # # ############################################################ +{% set federation_api_middlewares = [] %} + +{% if matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_enabled %} +{% set federation_api_middlewares = federation_api_middlewares + [matrix_synapse_reverse_proxy_companion_container_labels_traefik_compression_middleware_name] %} +{% endif %} + traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-federation-api.rule={{ matrix_synapse_reverse_proxy_companion_container_labels_public_federation_api_traefik_rule }} +{% if federation_api_middlewares | length > 0 %} +traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-federation-api.middlewares={{ federation_api_middlewares | join(',') }} +{% endif %} + {% if matrix_synapse_reverse_proxy_companion_container_labels_public_federation_api_traefik_priority | int > 0 %} traefik.http.routers.matrix-synapse-reverse-proxy-companion-public-federation-api.priority={{ matrix_synapse_reverse_proxy_companion_container_labels_public_federation_api_traefik_priority }} {% endif %}