Skip to content

Commit 2e7895b

Browse files
spantaleevclaude
andcommitted
Rework Continuwuity ReCAPTCHA gating to use a derived internal flag
Move the enablement logic out of `defaults/main.yml` and into a derived `matrix_continuwuity_recaptcha_enabled` flag in `vars/main.yml`, since it is computed (not user-facing) state. Continuwuity has no native enable-captcha toggle, so presence of both keys is what enables the flow. Replace the partial-config validation with a single consistency check that fails only when exactly one of the two keys is set, and keep both keys empty by default so nothing is rendered when ReCAPTCHA is unused. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 154d220 commit 2e7895b

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

roles/custom/matrix-continuwuity/defaults/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ matrix_continuwuity_config_turn_password: ''
191191
# Controls whether the self-check feature should validate SSL certificates.
192192
matrix_continuwuity_self_check_validate_certificates: true
193193

194-
# If set, registration will require Google ReCAPTCHA verification.
195-
matrix_continuwuity_recaptcha_enabled: "{{ matrix_continuwuity_config_recaptcha_site_key != '' and matrix_continuwuity_config_recaptcha_private_site_key != '' }}"
194+
# Configuring both of these settings makes registration require Google ReCAPTCHA verification.
195+
# Both must be set together (or both left empty). Setting only one of them is a configuration error.
196+
# When both are set, ReCAPTCHA gets enabled automatically (see `matrix_continuwuity_recaptcha_enabled` in `vars/main.yml`).
196197
matrix_continuwuity_config_recaptcha_site_key: ''
197198
matrix_continuwuity_config_recaptcha_private_site_key: ''
198199

roles/custom/matrix-continuwuity/tasks/validate_config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
- {'old': 'matrix_continuwuity_docker_image_registry_prefix_upstream_default', 'new': 'matrix_continuwuity_container_image_registry_prefix_upstream_default'}
3939
- {'old': 'matrix_continuwuity_container_image_force_pull', 'new': '<removed> (the new community.docker.docker_image_pull module handles this natively)'}
4040

41-
- name: Fail if required Continuwuity variables are undefined
41+
- name: Fail if Continuwuity ReCAPTCHA is only partially configured
4242
ansible.builtin.fail:
43-
msg: "The `{{ item.name }}` variable must be defined and have a non-null value."
44-
with_items:
45-
- {'name': 'matrix_continuwuity_config_recaptcha_site_key', when: "{{ matrix_continuwuity_config_recaptcha_private_site_key | string | length > 0 }}"}
46-
- {'name': 'matrix_continuwuity_config_recaptcha_private_site_key', when: "{{ matrix_continuwuity_config_recaptcha_site_key | string | length > 0 }}"}
47-
when: "item.when | bool and (lookup('vars', item.name, default='') == '' or lookup('vars', item.name, default='') is none)"
43+
msg: >-
44+
You have configured only one of `matrix_continuwuity_config_recaptcha_site_key` and
45+
`matrix_continuwuity_config_recaptcha_private_site_key`. Configure both to enable ReCAPTCHA
46+
registration, or leave both empty to disable it.
47+
when: "(matrix_continuwuity_config_recaptcha_site_key | string | length > 0) != (matrix_continuwuity_config_recaptcha_private_site_key | string | length > 0)"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# SPDX-FileCopyrightText: 2025 MDAD project contributors
22
# SPDX-FileCopyrightText: 2025 Slavi Pantaleev
3+
# SPDX-FileCopyrightText: 2026 Catalan Lover <catalanlover@protonmail.com>
34
#
45
# SPDX-License-Identifier: AGPL-3.0-or-later
56

67
---
78

9+
# Continuwuity has no dedicated "enable ReCAPTCHA" setting. It enables ReCAPTCHA registration based on the
10+
# presence of a recaptcha private site key, so we only render the keys when both have been configured.
11+
# This avoids rendering empty keys, which would otherwise enable a broken ReCAPTCHA flow.
12+
matrix_continuwuity_recaptcha_enabled: "{{ matrix_continuwuity_config_recaptcha_site_key | string | length > 0 and matrix_continuwuity_config_recaptcha_private_site_key | string | length > 0 }}"
13+
814
matrix_continuwuity_client_api_url_endpoint_public: "{{ 'https' if matrix_playbook_ssl_enabled else 'http' }}://{{ matrix_continuwuity_hostname }}/_matrix/client/versions"
915
matrix_continuwuity_federation_api_url_endpoint_public: "{{ 'https' if matrix_playbook_ssl_enabled else 'http' }}://{{ matrix_continuwuity_hostname }}:{{ matrix_federation_public_port }}/_matrix/federation/v1/version"

0 commit comments

Comments
 (0)