From 0b429d3fdd863ddeeb3a6f1c0826f90989085583 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 29 Jan 2026 11:50:21 +0200 Subject: [PATCH] matrix-appservice-irc: derive Traefik path prefix from publicUrl pathPrefix Instead of hardcoding '/irc' in two places, the Traefik path prefix is now derived from the mediaProxy publicUrl_pathPrefix variable by stripping the trailing slash (Traefik paths must not end with a slash, except for '/'). Added validation to ensure: - publicUrl_pathPrefix starts and ends with a slash (required by the service) - Traefik path prefix doesn't end with a slash (consistent with other roles) --- .../defaults/main.yml | 3 ++- .../tasks/validate_config.yml | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml b/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml index 631138533..d36c46e18 100644 --- a/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml +++ b/roles/custom/matrix-bridge-appservice-irc/defaults/main.yml @@ -497,7 +497,8 @@ matrix_appservice_irc_container_labels_traefik_tls_certResolver: default # noqa # Controls whether Traefik labels for the media proxy will be applied matrix_appservice_irc_container_labels_media_proxy_enabled: true -matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix: "/irc" +# Derived from publicUrl_pathPrefix, stripping any trailing slash (unless it's just "/") +matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix: "{{ '/' if matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix == '/' else matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix.rstrip('/') }}" matrix_appservice_irc_container_labels_media_proxy_traefik_rule: "Host(`{{ matrix_appservice_irc_ircService_mediaProxy_publicUrl_hostname }}`) && PathPrefix(`{{ matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix }}`)" matrix_appservice_irc_container_labels_media_proxy_traefik_priority: 2000 matrix_appservice_irc_container_labels_media_proxy_traefik_entrypoints: "{{ matrix_appservice_irc_container_labels_traefik_entrypoints }}" diff --git a/roles/custom/matrix-bridge-appservice-irc/tasks/validate_config.yml b/roles/custom/matrix-bridge-appservice-irc/tasks/validate_config.yml index 00124dc40..c1697a6ae 100644 --- a/roles/custom/matrix-bridge-appservice-irc/tasks/validate_config.yml +++ b/roles/custom/matrix-bridge-appservice-irc/tasks/validate_config.yml @@ -44,3 +44,26 @@ - {'old': 'matrix_appservice_irc_container_expose_client_server_api_port', 'new': ''} - {'old': 'matrix_appservice_irc_container_self_build', 'new': 'matrix_appservice_irc_container_image_self_build'} - {'old': 'matrix_appservice_irc_docker_image_name_prefix', 'new': 'matrix_appservice_irc_docker_image_registry_prefix'} + +- name: Fail if matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix does not start with a slash + ansible.builtin.fail: + msg: >- + matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix (`{{ matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix }}`) must start with a slash (e.g. `/` or `/irc/`). + when: "matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix[0] != '/'" + +- name: Fail if matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix does not end with a slash + ansible.builtin.fail: + msg: >- + matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix (`{{ matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix }}`) must end with a slash (e.g. `/` or `/irc/`). + when: "matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix[-1] != '/'" + +- when: matrix_appservice_irc_container_labels_traefik_enabled | bool + block: + # We ensure it doesn't end with a slash, because we handle both (slash and no-slash). + # Knowing that the path_prefix does not end with a slash ensures we know how to set these routes up + # without having to do "does it end with a slash" checks elsewhere. + - name: Fail if matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix ends with a slash + ansible.builtin.fail: + msg: >- + matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix (`{{ matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix }}`) must either be `/` or not end with a slash (e.g. `/irc`). + when: "matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix != '/' and matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix[-1] == '/'"