diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 6b9abdab2..34bbc0da2 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -6118,6 +6118,7 @@ matrix_static_files_container_labels_traefik_entrypoints: "{{ traefik_entrypoint matrix_static_files_container_labels_traefik_tls_certResolver: "{{ traefik_certResolver_primary }}" matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_hostname: "{{ matrix_server_fqn_matrix }}" +matrix_static_files_container_labels_well_known_element_endpoint_traefik_hostname: "{{ matrix_server_fqn_matrix }}" # Base domain serving is not enabled by default (see `matrix_static_files_container_labels_base_domain_enabled`), # but we pass the hostname, so that enabling it is easy. diff --git a/roles/custom/matrix-static-files/defaults/main.yml b/roles/custom/matrix-static-files/defaults/main.yml index 53c461dcc..cbd8ab79d 100644 --- a/roles/custom/matrix-static-files/defaults/main.yml +++ b/roles/custom/matrix-static-files/defaults/main.yml @@ -57,7 +57,7 @@ matrix_static_files_container_labels_traefik_docker_network: "{{ matrix_static_f matrix_static_files_container_labels_traefik_entrypoints: web-secure matrix_static_files_container_labels_traefik_tls_certResolver: default # noqa var-naming -# Controls whether labels will be added that expose the well-known public endpoint on the Matrix domain. +# Controls whether labels will be added that expose the `/.well-known/matrix` endpoint on the Matrix domain. matrix_static_files_container_labels_well_known_matrix_endpoint_enabled: true matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_hostname: '' matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_path_prefix: /.well-known/matrix @@ -72,6 +72,21 @@ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls_cert matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_enabled: true matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_minResponseBodyBytes: 100 # noqa var-naming +# Controls whether labels will be added that expose the `/.well-known/element` endpoint on the Matrix domain. +matrix_static_files_container_labels_well_known_element_endpoint_enabled: true +matrix_static_files_container_labels_well_known_element_endpoint_traefik_hostname: '' +matrix_static_files_container_labels_well_known_element_endpoint_traefik_path_prefix: /.well-known/element +matrix_static_files_container_labels_well_known_element_endpoint_traefik_rule: "Host(`{{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_hostname }}`) && PathPrefix(`{{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_path_prefix }}`)" +matrix_static_files_container_labels_well_known_element_endpoint_traefik_priority: 0 +matrix_static_files_container_labels_well_known_element_endpoint_traefik_entrypoints: "{{ matrix_static_files_container_labels_traefik_entrypoints }}" +matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls: "{{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_entrypoints != 'web' }}" +matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls_certResolver: "{{ matrix_static_files_container_labels_traefik_tls_certResolver }}" # noqa var-naming +# Controls whether the compress middleware (https://doc.traefik.io/traefik/middlewares/http/compress/) will be enabled for this router. +# The web-server only compresses known file types and our /.well-known/matrix/* files have no file extension. +# As such, they are not being compressed there and we compress them at the Traefik level. +matrix_static_files_container_labels_well_known_element_endpoint_middleware_compress_enabled: true +matrix_static_files_container_labels_well_known_element_endpoint_middleware_compress_minResponseBodyBytes: 100 # noqa var-naming + # Controls whether labels will be added that serve the base domain. # # This is similar to `matrix_static_files_container_labels_well_known_matrix_endpoint_*`, but does more. diff --git a/roles/custom/matrix-static-files/tasks/validate_config.yml b/roles/custom/matrix-static-files/tasks/validate_config.yml index 2697fa654..b76b8201e 100644 --- a/roles/custom/matrix-static-files/tasks/validate_config.yml +++ b/roles/custom/matrix-static-files/tasks/validate_config.yml @@ -13,6 +13,9 @@ - {'name': 'matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_hostname', when: "{{ matrix_static_files_container_labels_well_known_matrix_endpoint_enabled }}"} - {'name': 'matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_path_prefix', when: "{{ matrix_static_files_container_labels_well_known_matrix_endpoint_enabled }}"} + - {'name': 'matrix_static_files_container_labels_well_known_element_endpoint_traefik_hostname', when: "{{ matrix_static_files_container_labels_well_known_element_endpoint_enabled }}"} + - {'name': 'matrix_static_files_container_labels_well_known_element_endpoint_traefik_path_prefix', when: "{{ matrix_static_files_container_labels_well_known_element_endpoint_enabled }}"} + - {'name': 'matrix_static_files_container_labels_base_domain_traefik_hostname', when: "{{ matrix_static_files_container_labels_base_domain_enabled }}"} - {'name': 'matrix_static_files_container_labels_base_domain_traefik_path_prefix', when: "{{ matrix_static_files_container_labels_base_domain_enabled }}"} diff --git a/roles/custom/matrix-static-files/templates/labels.j2 b/roles/custom/matrix-static-files/templates/labels.j2 index 2d5be3895..26bd34036 100644 --- a/roles/custom/matrix-static-files/templates/labels.j2 +++ b/roles/custom/matrix-static-files/templates/labels.j2 @@ -25,27 +25,27 @@ traefik.http.services.{{ matrix_static_files_identifier }}.loadbalancer.server.p {% set well_known_matrix_endpoint_middlewares = [] %} {% if matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_enabled %} -traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-compress.compress=true -traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-compress.compress.minResponseBodyBytes={{ matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_minResponseBodyBytes }} -{% set well_known_matrix_endpoint_middlewares = well_known_matrix_endpoint_middlewares + [matrix_static_files_identifier + '-well-known-compress'] %} +traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-matrix-compress.compress=true +traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-matrix-compress.compress.minResponseBodyBytes={{ matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_minResponseBodyBytes }} +{% set well_known_matrix_endpoint_middlewares = well_known_matrix_endpoint_middlewares + [matrix_static_files_identifier + '-well-known-matrix-compress'] %} {% endif %} -traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.rule={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_rule }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.rule={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_rule }} {% if well_known_matrix_endpoint_middlewares | length > 0 %} -traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.middlewares={{ well_known_matrix_endpoint_middlewares | join(',') }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.middlewares={{ well_known_matrix_endpoint_middlewares | join(',') }} {% endif %} {% if matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority | int > 0 %} -traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.priority={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.priority={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority }} {% endif %} -traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.service={{ matrix_static_files_identifier }} -traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.entrypoints={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_entrypoints }} -traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.tls={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls | to_json }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.service={{ matrix_static_files_identifier }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.entrypoints={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_entrypoints }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.tls={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls | to_json }} {% if matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls %} -traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.tls.certResolver={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls_certResolver }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.tls.certResolver={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls_certResolver }} {% endif %} ############################################################ @@ -56,6 +56,47 @@ traefik.http.routers.{{ matrix_static_files_identifier }}-well-known.tls.certRes {% endif %} +{% if matrix_static_files_container_labels_well_known_element_endpoint_enabled %} +############################################################ +# # +# Related to /.well-known/element on the Matrix domain # +# # +############################################################ + +{% set well_known_element_endpoint_middlewares = [] %} + +{% if matrix_static_files_container_labels_well_known_element_endpoint_middleware_compress_enabled %} +traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-element-compress.compress=true +traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-element-compress.compress.minResponseBodyBytes={{ matrix_static_files_container_labels_well_known_element_endpoint_middleware_compress_minResponseBodyBytes }} +{% set well_known_element_endpoint_middlewares = well_known_element_endpoint_middlewares + [matrix_static_files_identifier + '-well-known-element-compress'] %} +{% endif %} + +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.rule={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_rule }} + +{% if well_known_element_endpoint_middlewares | length > 0 %} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.middlewares={{ well_known_element_endpoint_middlewares | join(',') }} +{% endif %} + +{% if matrix_static_files_container_labels_well_known_element_endpoint_traefik_priority | int > 0 %} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.priority={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_priority }} +{% endif %} + +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.service={{ matrix_static_files_identifier }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.entrypoints={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_entrypoints }} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.tls={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls | to_json }} + +{% if matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls %} +traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.tls.certResolver={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls_certResolver }} +{% endif %} + +############################################################ +# # +# /Related to /.well-known/element on the Matrix domain # +# # +############################################################ +{% endif %} + + {% if matrix_static_files_container_labels_base_domain_enabled %} ############################################################ # #