Add native Traefik support to Buscarron

This commit is contained in:
Slavi Pantaleev 2023-02-25 15:50:48 +02:00
parent 3852a740bc
commit 725b2beed7
9 changed files with 135 additions and 32 deletions

View File

@ -5,6 +5,31 @@ The playbook can install and configure [buscarron](https://gitlab.com/etke.cc/bu
Buscarron is bot that receives HTTP POST submissions of web forms and forwards them to a Matrix room. Buscarron is bot that receives HTTP POST submissions of web forms and forwards them to a Matrix room.
## Decide on a domain and path
By default, Rageshake is configured to use its own dedicated domain (`buscarron.DOMAIN`) and requires you to [adjust your DNS records](#adjusting-dns-records).
You can override the domain and path like this:
```yaml
# Switch to the domain used for Matrix services (`matrix.DOMAIN`),
# so we won't need to add additional DNS records for Rageshake.
matrix_bot_buscarron_hostname: "{{ matrix_server_fqn_matrix }}"
# Expose under the /buscarron subpath
matrix_bot_buscarron_path_prefix: /buscarron
```
**NOTE**: When using `matrix-nginx-proxy` instead of Traefik, you won't be able to override the path prefix. You can only override the domain, but that needs to happen using another variable: `matrix_server_fqn_buscarron` (e.g. `matrix_server_fqn_buscarron: "form.{{ matrix_domain }}"`).
## Adjusting DNS records
Once you've decided on the domain and path, **you may need to adjust your DNS** records to point the Buscarron domain to the Matrix server.
If you've decided to reuse the `matrix.` domain, you won't need to do any extra DNS configuration.
## Adjusting the playbook configuration ## Adjusting the playbook configuration
Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars.yml` file: Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars.yml` file:
@ -30,16 +55,6 @@ matrix_bot_buscarron_forms:
matrix_bot_buscarron_spamlist: [] # (optional) list of emails/domains/hosts (with wildcards support) that should be rejected automatically matrix_bot_buscarron_spamlist: [] # (optional) list of emails/domains/hosts (with wildcards support) that should be rejected automatically
``` ```
You will also need to add a DNS record so that buscarron can be accessed.
By default buscarron will use https://buscarron.DOMAIN so you will need to create an CNAME record for `buscarron`.
See [Configuring DNS](configuring-dns.md).
If you would like to use a different domain, add the following to your configuration file (changing it to use your preferred domain):
```yaml
matrix_server_fqn_buscarron: "form.{{ matrix_domain }}"
```
## Installing ## Installing

View File

@ -1685,7 +1685,25 @@ matrix_bot_buscarron_database_engine: "{{ 'postgres' if devture_postgres_enabled
matrix_bot_buscarron_database_hostname: "{{ devture_postgres_connection_hostname if devture_postgres_enabled else '' }}" matrix_bot_buscarron_database_hostname: "{{ devture_postgres_connection_hostname if devture_postgres_enabled else '' }}"
matrix_bot_buscarron_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'buscarron.bot.db', rounds=655555) | to_uuid }}" matrix_bot_buscarron_database_password: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'buscarron.bot.db', rounds=655555) | to_uuid }}"
matrix_bot_buscarron_container_network: "{{ matrix_docker_network }}" matrix_bot_buscarron_hostname: "{{ matrix_server_fqn_buscarron }}"
matrix_bot_buscarron_container_network: "{{ matrix_docker_network if matrix_playbook_reverse_proxy_type == 'playbook-managed-nginx' else 'matrix-bot-buscarron' }}"
# For now, we attach this to the matrix-nginx-proxy network (unless that's the same network as the main one for us),
# because that's where the homeserver is expected to be accessed from.
# In the future, this will need to be redone.
matrix_bot_buscarron_container_additional_networks: |
{{
(
([matrix_playbook_reverse_proxyable_services_additional_network] if matrix_playbook_reverse_proxyable_services_additional_network else [])
+
([matrix_nginx_proxy_container_network] if matrix_nginx_proxy_enabled and matrix_bot_buscarron_container_network != matrix_nginx_proxy_container_network else [])
) | unique
}}
matrix_bot_buscarron_container_labels_traefik_enabled: "{{ matrix_playbook_traefik_labels_enabled }}"
matrix_bot_buscarron_container_labels_traefik_docker_network: "{{ matrix_playbook_reverse_proxyable_services_additional_network }}"
matrix_bot_buscarron_container_labels_traefik_entrypoints: "{{ devture_traefik_entrypoint_primary }}"
###################################################################### ######################################################################
# #
@ -2415,7 +2433,7 @@ matrix_nginx_proxy_proxy_matrix_enabled: true
matrix_nginx_proxy_proxy_element_enabled: "{{ matrix_client_element_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}" matrix_nginx_proxy_proxy_element_enabled: "{{ matrix_client_element_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}"
matrix_nginx_proxy_proxy_hydrogen_enabled: "{{ matrix_client_hydrogen_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}" matrix_nginx_proxy_proxy_hydrogen_enabled: "{{ matrix_client_hydrogen_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}"
matrix_nginx_proxy_proxy_cinny_enabled: "{{ matrix_client_cinny_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}" matrix_nginx_proxy_proxy_cinny_enabled: "{{ matrix_client_cinny_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}"
matrix_nginx_proxy_proxy_buscarron_enabled: "{{ matrix_bot_buscarron_enabled }}" matrix_nginx_proxy_proxy_buscarron_enabled: "{{ matrix_bot_buscarron_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}"
matrix_nginx_proxy_proxy_dimension_enabled: "{{ matrix_dimension_enabled }}" matrix_nginx_proxy_proxy_dimension_enabled: "{{ matrix_dimension_enabled }}"
matrix_nginx_proxy_proxy_rageshake_enabled: "{{ matrix_rageshake_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}" matrix_nginx_proxy_proxy_rageshake_enabled: "{{ matrix_rageshake_enabled and matrix_playbook_reverse_proxy_type in ['playbook-managed-nginx', 'other-nginx-non-container'] }}"
matrix_nginx_proxy_proxy_etherpad_enabled: "{{ matrix_etherpad_enabled and matrix_etherpad_mode == 'standalone' }}" matrix_nginx_proxy_proxy_etherpad_enabled: "{{ matrix_etherpad_enabled and matrix_etherpad_mode == 'standalone' }}"
@ -2433,7 +2451,6 @@ matrix_nginx_proxy_container_labels_traefik_docker_network: "{{ matrix_playbook_
matrix_nginx_proxy_container_labels_traefik_entrypoints: "{{ devture_traefik_entrypoint_primary }}" matrix_nginx_proxy_container_labels_traefik_entrypoints: "{{ devture_traefik_entrypoint_primary }}"
matrix_nginx_proxy_container_labels_traefik_proxy_matrix_enabled: true matrix_nginx_proxy_container_labels_traefik_proxy_matrix_enabled: true
matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_enabled: "{{ matrix_bot_buscarron_enabled }}"
matrix_nginx_proxy_container_labels_traefik_proxy_dimension_enabled: "{{ matrix_dimension_enabled }}" matrix_nginx_proxy_container_labels_traefik_proxy_dimension_enabled: "{{ matrix_dimension_enabled }}"
matrix_nginx_proxy_container_labels_traefik_proxy_etherpad_enabled: "{{ matrix_etherpad_enabled and matrix_etherpad_mode == 'standalone' }}" matrix_nginx_proxy_container_labels_traefik_proxy_etherpad_enabled: "{{ matrix_etherpad_enabled and matrix_etherpad_mode == 'standalone' }}"
matrix_nginx_proxy_container_labels_traefik_proxy_bot_go_neb_enabled: "{{ matrix_bot_go_neb_enabled }}" matrix_nginx_proxy_container_labels_traefik_proxy_bot_go_neb_enabled: "{{ matrix_bot_go_neb_enabled }}"

View File

@ -7,6 +7,13 @@ matrix_bot_buscarron_enabled: true
matrix_bot_buscarron_version: v1.3.1 matrix_bot_buscarron_version: v1.3.1
# The hostname at which Buscarron is served.
matrix_bot_buscarron_hostname: ''
# The path at which Buscarron is exposed.
# This value must either be `/` or not end with a slash (e.g. `/buscarron`).
matrix_bot_buscarron_path_prefix: /
matrix_bot_buscarron_base_path: "{{ matrix_base_data_path }}/buscarron" matrix_bot_buscarron_base_path: "{{ matrix_base_data_path }}/buscarron"
matrix_bot_buscarron_config_path: "{{ matrix_bot_buscarron_base_path }}/config" matrix_bot_buscarron_config_path: "{{ matrix_bot_buscarron_base_path }}/config"
matrix_bot_buscarron_data_path: "{{ matrix_bot_buscarron_base_path }}/data" matrix_bot_buscarron_data_path: "{{ matrix_bot_buscarron_base_path }}/data"
@ -29,6 +36,36 @@ matrix_bot_buscarron_container_network: matrix-bot-buscarron
# Use this to expose this container to another reverse proxy, which runs in a different container network. # Use this to expose this container to another reverse proxy, which runs in a different container network.
matrix_bot_buscarron_container_additional_networks: [] matrix_bot_buscarron_container_additional_networks: []
# matrix_bot_buscarron_container_labels_traefik_enabled controls whether labels to assist a Traefik reverse-proxy will be attached to the container.
# See `../templates/labels.j2` for details.
#
# To inject your own other container labels, see `matrix_bot_buscarron_container_labels_additional_labels`.
matrix_bot_buscarron_container_labels_traefik_enabled: true
matrix_bot_buscarron_container_labels_traefik_docker_network: "{{ matrix_bot_buscarron_container_network }}"
matrix_bot_buscarron_container_labels_traefik_hostname: "{{ matrix_bot_buscarron_hostname }}"
# The path prefix must either be `/` or not end with a slash (e.g. `/buscarron`).
matrix_bot_buscarron_container_labels_traefik_path_prefix: "{{ matrix_bot_buscarron_path_prefix }}"
matrix_bot_buscarron_container_labels_traefik_rule: "Host(`{{ matrix_bot_buscarron_container_labels_traefik_hostname }}`){% if matrix_bot_buscarron_container_labels_traefik_path_prefix != '/' %} && PathPrefix(`{{ matrix_bot_buscarron_container_labels_traefik_path_prefix }}`){% endif %}"
matrix_bot_buscarron_container_labels_traefik_priority: 0
matrix_bot_buscarron_container_labels_traefik_entrypoints: web-secure
matrix_bot_buscarron_container_labels_traefik_tls: "{{ matrix_bot_buscarron_container_labels_traefik_entrypoints != 'web' }}"
matrix_bot_buscarron_container_labels_traefik_tls_certResolver: default # noqa var-naming
# Controls which additional headers to attach to all HTTP responses.
# To add your own headers, use `matrix_bot_buscarron_container_labels_traefik_additional_response_headers_custom`
matrix_bot_buscarron_container_labels_traefik_additional_response_headers: "{{ matrix_bot_buscarron_container_labels_traefik_additional_response_headers_auto | combine(matrix_bot_buscarron_container_labels_traefik_additional_response_headers_custom) }}"
matrix_bot_buscarron_container_labels_traefik_additional_response_headers_auto: {}
matrix_bot_buscarron_container_labels_traefik_additional_response_headers_custom: {}
# matrix_bot_buscarron_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file.
# See `../templates/labels.j2` for details.
#
# Example:
# matrix_bot_buscarron_container_labels_additional_labels: |
# my.label=1
# another.label="here"
matrix_bot_buscarron_container_labels_additional_labels: ''
# A list of extra arguments to pass to the container # A list of extra arguments to pass to the container
matrix_bot_buscarron_container_extra_arguments: [] matrix_bot_buscarron_container_extra_arguments: []

View File

@ -40,13 +40,16 @@
- {path: "{{ matrix_bot_buscarron_docker_src_files_path }}", when: true} - {path: "{{ matrix_bot_buscarron_docker_src_files_path }}", when: true}
when: "item.when | bool" when: "item.when | bool"
- name: Ensure buscarron environment variables file created - name: Ensure buscarron support files installed
ansible.builtin.template: ansible.builtin.template:
src: "{{ role_path }}/templates/env.j2" src: "{{ role_path }}/templates/{{ item }}.j2"
dest: "{{ matrix_bot_buscarron_config_path }}/env" dest: "{{ matrix_bot_buscarron_config_path }}/{{ item }}"
owner: "{{ matrix_user_username }}" owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}" group: "{{ matrix_user_groupname }}"
mode: 0640 mode: 0640
with_items:
- env
- labels
- name: Ensure buscarron image is pulled - name: Ensure buscarron image is pulled
community.docker.docker_image: community.docker.docker_image:

View File

@ -7,4 +7,5 @@
when: "item.when | bool and vars[item.name] == ''" when: "item.when | bool and vars[item.name] == ''"
with_items: with_items:
- {'name': 'matrix_bot_buscarron_password', when: true} - {'name': 'matrix_bot_buscarron_password', when: true}
- {'name': 'matrix_bot_buscarron_hostname', when: true}
- {'name': 'matrix_bot_buscarron_database_hostname', when: "{{ matrix_bot_buscarron_database_engine == 'postgres' }}"} - {'name': 'matrix_bot_buscarron_database_hostname', when: "{{ matrix_bot_buscarron_database_engine == 'postgres' }}"}

View File

@ -0,0 +1,45 @@
{% if matrix_bot_buscarron_container_labels_traefik_enabled %}
traefik.enable=true
{% if matrix_bot_buscarron_container_labels_traefik_docker_network %}
traefik.docker.network={{ matrix_bot_buscarron_container_labels_traefik_docker_network }}
{% endif %}
{% set middlewares = [] %}
{% if matrix_bot_buscarron_container_labels_traefik_path_prefix != '/' %}
traefik.http.middlewares.matrix-bot-buscarron-slashless-redirect.redirectregex.regex=({{ matrix_bot_buscarron_container_labels_traefik_path_prefix | quote }})$
traefik.http.middlewares.matrix-bot-buscarron-slashless-redirect.redirectregex.replacement=${1}/
{% set middlewares = middlewares + ['matrix-bot-buscarron-slashless-redirect'] %}
{% endif %}
{% if matrix_bot_buscarron_container_labels_traefik_path_prefix != '/' %}
traefik.http.middlewares.matrix-bot-buscarron-strip-prefix.stripprefix.prefixes={{ matrix_bot_buscarron_container_labels_traefik_path_prefix }}
{% set middlewares = middlewares + ['matrix-bot-buscarron-strip-prefix'] %}
{% endif %}
{% if matrix_bot_buscarron_container_labels_traefik_additional_response_headers.keys() | length > 0 %}
{% for name, value in matrix_bot_buscarron_container_labels_traefik_additional_response_headers.items() %}
traefik.http.middlewares.matrix-bot-buscarron-add-headers.headers.customresponseheaders.{{ name }}={{ value }}
{% endfor %}
{% set middlewares = middlewares + ['matrix-bot-buscarron-add-headers'] %}
{% endif %}
traefik.http.routers.matrix-bot-buscarron.rule={{ matrix_bot_buscarron_container_labels_traefik_rule }}
{% if matrix_bot_buscarron_container_labels_traefik_priority | int > 0 %}
traefik.http.routers.matrix-bot-buscarron.priority={{ matrix_bot_buscarron_container_labels_traefik_priority }}
{% endif %}
traefik.http.routers.matrix-bot-buscarron.service=matrix-bot-buscarron
{% if middlewares | length > 0 %}
traefik.http.routers.matrix-bot-buscarron.middlewares={{ middlewares | join(',') }}
{% endif %}
traefik.http.routers.matrix-bot-buscarron.entrypoints={{ matrix_bot_buscarron_container_labels_traefik_entrypoints }}
traefik.http.routers.matrix-bot-buscarron.tls={{ matrix_bot_buscarron_container_labels_traefik_tls | to_json }}
{% if matrix_bot_buscarron_container_labels_traefik_tls %}
traefik.http.routers.matrix-bot-buscarron.tls.certResolver={{ matrix_bot_buscarron_container_labels_traefik_tls_certResolver }}
{% endif %}
traefik.http.services.matrix-bot-buscarron.loadbalancer.server.port=8080
{% endif %}
{{ matrix_bot_buscarron_container_labels_additional_labels }}

View File

@ -25,6 +25,7 @@ ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
--read-only \ --read-only \
--network={{ matrix_bot_buscarron_container_network }} \ --network={{ matrix_bot_buscarron_container_network }} \
--env-file={{ matrix_bot_buscarron_config_path }}/env \ --env-file={{ matrix_bot_buscarron_config_path }}/env \
--label-file={{ matrix_bot_buscarron_config_path }}/labels \
--mount type=bind,src={{ matrix_bot_buscarron_data_path }},dst=/data \ --mount type=bind,src={{ matrix_bot_buscarron_data_path }},dst=/data \
{% for arg in matrix_bot_buscarron_container_extra_arguments %} {% for arg in matrix_bot_buscarron_container_extra_arguments %}
{{ arg }} \ {{ arg }} \

View File

@ -61,11 +61,6 @@ matrix_nginx_proxy_container_labels_traefik_proxy_matrix_rule: "Host(`{{ matrix_
matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoint: "{{ matrix_federation_traefik_entrypoint }}" matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoint: "{{ matrix_federation_traefik_entrypoint }}"
matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoints: "{{ matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoint }}" matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoints: "{{ matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoint }}"
matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_enabled: false
matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_hostname: "{{ matrix_server_fqn_buscarron }}"
matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_tls: "{{ matrix_nginx_proxy_container_labels_traefik_entrypoints != 'web' }}"
matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_rule: "Host(`{{ matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_hostname }}`)"
matrix_nginx_proxy_container_labels_traefik_proxy_dimension_enabled: false matrix_nginx_proxy_container_labels_traefik_proxy_dimension_enabled: false
matrix_nginx_proxy_container_labels_traefik_proxy_dimension_hostname: "{{ matrix_server_fqn_dimension }}" matrix_nginx_proxy_container_labels_traefik_proxy_dimension_hostname: "{{ matrix_server_fqn_dimension }}"
matrix_nginx_proxy_container_labels_traefik_proxy_dimension_tls: "{{ matrix_nginx_proxy_container_labels_traefik_entrypoints != 'web' }}" matrix_nginx_proxy_container_labels_traefik_proxy_dimension_tls: "{{ matrix_nginx_proxy_container_labels_traefik_entrypoints != 'web' }}"

View File

@ -38,17 +38,6 @@ traefik.http.routers.matrix-nginx-proxy-matrix-federation.tls.certResolver={{ ma
traefik.http.routers.matrix-nginx-proxy-matrix-federation.entrypoints={{ matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoints }} traefik.http.routers.matrix-nginx-proxy-matrix-federation.entrypoints={{ matrix_nginx_proxy_container_labels_traefik_proxy_matrix_federation_entrypoints }}
{% endif %} {% endif %}
{% if matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_enabled %}
# Buscarron
traefik.http.routers.matrix-nginx-proxy-buscarron.rule={{ matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_rule }}
traefik.http.routers.matrix-nginx-proxy-buscarron.service=matrix-nginx-proxy-web
traefik.http.routers.matrix-nginx-proxy-buscarron.tls={{ matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_tls | to_json }}
{% if matrix_nginx_proxy_container_labels_traefik_proxy_buscarron_tls %}
traefik.http.routers.matrix-nginx-proxy-buscarron.tls.certResolver={{ matrix_nginx_proxy_container_labels_traefik_tls_certResolver }}
{% endif %}
traefik.http.routers.matrix-nginx-proxy-buscarron.entrypoints={{ matrix_nginx_proxy_container_labels_traefik_entrypoints }}
{% endif %}
{% if matrix_nginx_proxy_container_labels_traefik_proxy_dimension_enabled %} {% if matrix_nginx_proxy_container_labels_traefik_proxy_dimension_enabled %}
# Dimension # Dimension