From 905bdfc551669b3bdf06b211077c577af58f384c Mon Sep 17 00:00:00 2001 From: xvsun <80697688+xvsun@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:04:14 +0100 Subject: [PATCH] Add Synapse module auto accept invite to rooms and direct messages (#3195) * feat: auto-accept-invite module and docs * fix: name typos and some forgot to adjust variables * fix: accept only direct messages should work now and better wording * changed: only_direct_messages variable naming * feat: add logger, add synapse workers config * Fix typo and add details about synapse-auto-acccept-invite * Add newline at end of file * Fix alignment * Fix logger name for synapse_auto_accept_invite The name of the logger needs to match the name of the Python module. Ref: https://github.com/matrix-org/synapse-auto-accept-invite/blob/d673c6767862e0340e58f6e9947c7d90ec190201/synapse_auto_accept_invite/__init__.py#L20 * Add missing document start YAML annotation * Remove trailing spaces --------- Co-authored-by: Slavi Pantaleev --- README.md | 1 + ...ing-playbook-synapse-auto-accept-invite.md | 24 +++++++++++++++++++ roles/custom/matrix-synapse/defaults/main.yml | 17 +++++++++++++ .../tasks/ext/setup_install.yml | 10 ++++++++ .../setup_install.yml | 23 ++++++++++++++++++ .../synapse/customizations/Dockerfile.j2 | 4 ++++ 6 files changed, 79 insertions(+) create mode 100644 docs/configuring-playbook-synapse-auto-accept-invite.md create mode 100644 roles/custom/matrix-synapse/tasks/ext/synapse-auto-accept-invite/setup_install.yml diff --git a/README.md b/README.md index 847fe78e8..460399308 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,7 @@ Various services that don't fit any other category. | Name | Default? | Description | Documentation | | ---- | -------- | ----------- | ------------- | | [sliding-sync](https://github.com/matrix-org/sliding-sync)| x | Sliding Sync support for clients which require it (e.g. Element X) | [Link](docs/configuring-playbook-sliding-sync-proxy.md) | +| [synapse_auto_accept_invite](https://github.com/matrix-org/synapse-auto-accept-invite) | x | A Synapse module to automatically accept invites. | [Link](docs/configuring-playbook-synapse-auto-accept-invite.md) | | [synapse_auto_compressor](https://github.com/matrix-org/rust-synapse-compress-state/#automated-tool-synapse_auto_compressor) | x | A cli tool that automatically compresses `state_groups` database table in background. | [Link](docs/configuring-playbook-synapse-auto-compressor.md) | | [synapse-simple-antispam](https://github.com/t2bot/synapse-simple-antispam) (advanced) | x | A spam checker module | [Link](docs/configuring-playbook-synapse-simple-antispam.md) | | [Matrix Corporal](https://github.com/devture/matrix-corporal) (advanced) | x | Reconciliator and gateway for a managed Matrix server | [Link](docs/configuring-playbook-matrix-corporal.md) | diff --git a/docs/configuring-playbook-synapse-auto-accept-invite.md b/docs/configuring-playbook-synapse-auto-accept-invite.md new file mode 100644 index 000000000..ccc4b0c33 --- /dev/null +++ b/docs/configuring-playbook-synapse-auto-accept-invite.md @@ -0,0 +1,24 @@ +# Setting up Synapse Auto Invite Accept (optional) + +The playbook can install and configure [synapse-auto-invite-accept](https://github.com/matrix-org/synapse-auto-accept-invite) for you. + +See that project's [documentation](https://github.com/matrix-org/synapse-auto-accept-invite) to learn what it does and why it might be useful to you. +In short, it automatically accepts room invites. You can specify that only 1:1 room invites are auto-accepted. Defaults to false if not specified. + +If you decide that you'd like to let this playbook install it for you, you need a configuration like this: + +```yaml +matrix_synapse_ext_synapse_auto_accept_invite_enabled: true + +matrix_synapse_ext_synapse_auto_accept_invite_accept_invites_only_direct_messages: true +``` + +## Synapse worker deployments + +In a [workerized Synapse deployment](https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/c9a842147e09647c355799ca024d65a5de66b099/docs/configuring-playbook-synapse.md#load-balancing-with-workers) it is possible to run this module on a worker to reduce the load on the main process (Default is 'null'). For example add this to your configuration: + +```yaml +matrix_synapse_ext_synapse_auto_accept_invite_worker_to_run_on: 'matrix-synapse-worker-generic-0' +``` + +There might be an [issue with federation](https://github.com/matrix-org/synapse-auto-accept-invite/issues/18). \ No newline at end of file diff --git a/roles/custom/matrix-synapse/defaults/main.yml b/roles/custom/matrix-synapse/defaults/main.yml index 56d4162cf..943d04032 100644 --- a/roles/custom/matrix-synapse/defaults/main.yml +++ b/roles/custom/matrix-synapse/defaults/main.yml @@ -40,12 +40,18 @@ matrix_synapse_container_image_customizations_enabled: |- matrix_synapse_container_image_customizations_s3_storage_provider_installation_enabled or matrix_synapse_container_image_customizations_templates_enabled + or + matrix_synapse_container_image_customizations_auto_accept_invite_installation_enabled }} # Controls whether custom build steps will be added to the Dockerfile for installing s3-storage-provider. # The version that will be installed is specified in `matrix_synapse_ext_synapse_s3_storage_provider_version`. matrix_synapse_container_image_customizations_s3_storage_provider_installation_enabled: "{{ matrix_synapse_ext_synapse_s3_storage_provider_enabled }}" +# Controls whether custom build steps will be added to the Dockerfile for installing auto-accept-invite module. +# The version that will be installed is specified in `matrix_synapse_ext_synapse_auto_accept_invite_version`. +matrix_synapse_container_image_customizations_auto_accept_invite_installation_enabled: "{{ matrix_synapse_ext_synapse_auto_accept_invite_enabled }}" + # Controls whether custom build steps will be added to the Dockerfile for customizing the email templates used by Synapse. # # Example usage: @@ -1212,6 +1218,17 @@ matrix_synapse_ext_synapse_s3_storage_provider_update_db_day_count: 0 # This is a systemd timer OnCalendar definition. Learn more here: https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS matrix_synapse_ext_synapse_s3_storage_provider_periodic_migration_schedule: '*-*-* 05:00:00' +# Synapse module to automatically accept room invites. +# See: https://github.com/matrix-org/synapse-auto-accept-invite +# Installing it requires building a customized Docker image for Synapse (see `matrix_synapse_container_image_customizations_enabled`). +# Enabling this will enable customizations and inject the appropriate Dockerfile clauses for installing synapse-auto-accept-invite. +matrix_synapse_ext_synapse_auto_accept_invite_enabled: false +matrix_synapse_ext_synapse_auto_accept_invite_version: 1.1.3 +# Specifies whether only direct messages (1:1 rooms) will be auto accepted. +matrix_synapse_ext_synapse_auto_accept_invite_accept_invites_only_direct_messages: false +# When Synapse workers enabled it is possible (but not required) to assign a worker to run this module on (null = main process). +matrix_synapse_ext_synapse_auto_accept_invite_worker_to_run_on: null + # Specifies whether an external media repository is enabled. # If it is, the Synapse media repo and media-repo workers will be disabled automatically. matrix_synapse_ext_media_repo_enabled: false diff --git a/roles/custom/matrix-synapse/tasks/ext/setup_install.yml b/roles/custom/matrix-synapse/tasks/ext/setup_install.yml index 4adb6566a..f7be477aa 100644 --- a/roles/custom/matrix-synapse/tasks/ext/setup_install.yml +++ b/roles/custom/matrix-synapse/tasks/ext/setup_install.yml @@ -72,3 +72,13 @@ - when: matrix_synapse_ext_synapse_s3_storage_provider_enabled | bool ansible.builtin.include_tasks: "{{ role_path }}/tasks/ext/s3-storage-provider/setup_install.yml" + +# synapse-auto-accept-invite +- tags: + - setup-all + - setup-synapse + - install-all + - install-synapse + block: + - when: matrix_synapse_ext_synapse_auto_accept_invite_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/ext/synapse-auto-accept-invite/setup_install.yml" diff --git a/roles/custom/matrix-synapse/tasks/ext/synapse-auto-accept-invite/setup_install.yml b/roles/custom/matrix-synapse/tasks/ext/synapse-auto-accept-invite/setup_install.yml new file mode 100644 index 000000000..06457e370 --- /dev/null +++ b/roles/custom/matrix-synapse/tasks/ext/synapse-auto-accept-invite/setup_install.yml @@ -0,0 +1,23 @@ +--- + +- ansible.builtin.set_fact: + matrix_synapse_modules: | + {{ + matrix_synapse_modules | default([]) + + + [ + { + "module": "synapse_auto_accept_invite.InviteAutoAccepter", + "config": { + "accept_invites_only_for_direct_messages": matrix_synapse_ext_synapse_auto_accept_invite_accept_invites_only_direct_messages, + "worker_to_run_on": matrix_synapse_ext_synapse_auto_accept_invite_worker_to_run_on, + }, + }] + }} + + matrix_synapse_additional_loggers_auto: > + {{ + matrix_synapse_additional_loggers_auto + + + [{'name': 'synapse_auto_accept_invite', 'level': 'INFO'}] + }} diff --git a/roles/custom/matrix-synapse/templates/synapse/customizations/Dockerfile.j2 b/roles/custom/matrix-synapse/templates/synapse/customizations/Dockerfile.j2 index 6257f1985..39367fe09 100644 --- a/roles/custom/matrix-synapse/templates/synapse/customizations/Dockerfile.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/customizations/Dockerfile.j2 @@ -1,6 +1,10 @@ #jinja2: lstrip_blocks: "True" FROM {{ matrix_synapse_docker_image }} +{% if matrix_synapse_container_image_customizations_auto_accept_invite_installation_enabled %} +RUN pip install synapse-auto-accept-invite=={{ matrix_synapse_ext_synapse_auto_accept_invite_version }} +{% endif %} + {% if matrix_synapse_container_image_customizations_s3_storage_provider_installation_enabled %} RUN pip install synapse-s3-storage-provider=={{ matrix_synapse_ext_synapse_s3_storage_provider_version }} {% endif %}