Skip to content

Commit e000cbf

Browse files
committed
Auto-configure synapse-admin to be restricted to a single homeserver (the one managed by the playbook)
1 parent 296199f commit e000cbf

File tree

6 files changed

+77
-10
lines changed

6 files changed

+77
-10
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# 2024-07-01
2+
3+
## synapse-admin is now restricted to your homeserver's URL by default
4+
5+
A new feature introduced in synapse-admin [v0.10.0](https://github.com/Awesome-Technologies/synapse-admin/releases/tag/0.10.0) (released and supported by the playbook since a a few months ago) provides the ability to [restrict its usage to a specific homeserver](https://github.com/Awesome-Technologies/synapse-admin/blob/e21e44362c879ac41f47c580b04210842b6ff3d7/README.md#restricting-available-homeserver) (or multiple homeservers).
6+
7+
The playbook has just started making use of this feature. **From now on, your synapse-admin instance will be restricted to the homeserver you're managing via the playbook**. When configured like this, the *Homeserver URL* field in synapse-admin's web UI changes from a text field to a dropdown having a single value (the URL of your homeserver). This makes usage simpler for most people, as they won't need to manually enter a *Homeserver URL* anymore.
8+
9+
If you'd like **to go back to the old unrestricted behavior**, use the following configuration:
10+
11+
```yml
12+
# Use this configuration to allow synapse-admin to manage any homeserver instance.
13+
matrix_synapse_admin_config_restrictBaseUrl: []
14+
```
15+
16+
117
# 2024-06-25
218
319
## The URL-prefix for Hookshot generic webhooks has changed

docs/configuring-playbook-synapse-admin.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ matrix_synapse_admin_enabled: true
2020
- for [Synapse](./configuring-playbook-synapse.md) (our default homeserver implementation): `matrix_synapse_container_labels_public_client_synapse_admin_api_enabled: true`
2121
- for [Dendrite](./configuring-playbook-dendrite.md): `matrix_dendrite_container_labels_public_client_synapse_admin_api_enabled: true`
2222

23+
By default, synapse-admin installation will be [restricted to only work with one homeserver](https://github.com/Awesome-Technologies/synapse-admin/blob/e21e44362c879ac41f47c580b04210842b6ff3d7/README.md#restricting-available-homeserver) - the one managed by the playbook. To adjust these restrictions, tweak the `matrix_synapse_admin_config_restrictBaseUrl` variable.
24+
2325

2426
## Installing
2527

26-
After configuring the playbook, run the [installation](installing.md) command again:
27-
28-
```
29-
ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start
30-
```
28+
After configuring the playbook, run the [installation](installing.md) command again (`just install-all`).
3129

3230

3331
## Usage
3432

3533
After installation, Synapse Admin will be accessible at: `https://matrix.DOMAIN/synapse-admin/`
3634

3735
To use Synapse Admin, you need to have [registered at least one administrator account](registering-users.md) on your server.
38-
39-
The Homeserver URL to use on Synapse Admin's login page is: `https://matrix.DOMAIN`

roles/custom/matrix-synapse-admin/defaults/main.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ matrix_synapse_admin_enabled: true
66

77
# A path on host where all related files will be saved
88
matrix_synapse_admin_base_path: "{{ matrix_base_data_path }}/synapse-admin"
9+
matrix_synapse_admin_config_path: "{{ matrix_synapse_admin_base_path }}/config"
910
matrix_synapse_admin_docker_src_files_path: "{{ matrix_synapse_admin_base_path }}/docker-src"
1011

1112
matrix_synapse_admin_container_image_self_build: false
@@ -135,3 +136,40 @@ matrix_synapse_admin_hostname: "{{ matrix_server_fqn_matrix }}"
135136
# The path at which Synapse Admin is exposed.
136137
# This value must either be `/` or not end with a slash (e.g. `/synapse-admin`).
137138
matrix_synapse_admin_path_prefix: /synapse-admin
139+
140+
# Default synapse-admin configuration template which covers the generic use case.
141+
# You can customize it by controlling the various variables inside it.
142+
#
143+
# For a more advanced customization, you can extend the default (see `matrix_synapse_admin_configuration_extension_json`)
144+
# or completely replace this variable with your own template.
145+
#
146+
# The side-effect of this lookup is that Ansible would even parse the JSON for us, returning a dict.
147+
# This is unlike what it does when looking up YAML template files (no automatic parsing there).
148+
matrix_synapse_admin_configuration_default: "{{ lookup('template', 'templates/config.json.j2') }}"
149+
150+
# Your custom JSON configuration for synapse-admin should go to `matrix_synapse_admin_configuration_extension_json`.
151+
# This configuration extends the default starting configuration (`matrix_synapse_admin_configuration_default`).
152+
#
153+
# You can override individual variables from the default configuration, or introduce new ones.
154+
#
155+
# If you need something more special, you can take full control by
156+
# completely redefining `matrix_synapse_admin_configuration_default`.
157+
#
158+
# Example configuration extension follows:
159+
#
160+
# matrix_synapse_admin_configuration_extension_json: |
161+
# {
162+
# "some_setting": true,
163+
# "another_setting": false
164+
# }
165+
matrix_synapse_admin_configuration_extension_json: '{}'
166+
167+
matrix_synapse_admin_configuration_extension: "{{ matrix_synapse_admin_configuration_extension_json | from_json if matrix_synapse_admin_configuration_extension_json | from_json is mapping else {} }}"
168+
169+
# Holds the final synapse-admin configuration (a combination of the default and its extension).
170+
# You most likely don't need to touch this variable. Instead, see `matrix_synapse_admin_configuration_default`.
171+
matrix_synapse_admin_configuration: "{{ matrix_synapse_admin_configuration_default | combine(matrix_synapse_admin_configuration_extension, recursive=True) }}"
172+
173+
# Controls the restrictBaseUrl configuration setting, which, if defined,
174+
# restricts the homeserver(s), so that the user can no longer define a homeserver manually during login.
175+
matrix_synapse_admin_config_restrictBaseUrl: "{{ [matrix_homeserver_url] }}" # noqa var-naming

roles/custom/matrix-synapse-admin/tasks/setup_install.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
---
22

3-
- name: Ensure matrix-synapse-admin path exist
3+
- name: Ensure matrix-synapse-admin paths exists
44
ansible.builtin.file:
5-
path: "{{ matrix_synapse_admin_base_path }}"
5+
path: "{{ item.path }}"
66
state: directory
7-
mode: 0700
7+
mode: 0750
88
owner: "{{ matrix_user_username }}"
99
group: "{{ matrix_user_groupname }}"
10+
with_items:
11+
- {path: "{{ matrix_synapse_admin_base_path }}", when: true}
12+
- {path: "{{ matrix_synapse_admin_config_path }}", when: true}
13+
- {path: "{{ matrix_synapse_admin_docker_src_files_path }}", when: "{{ matrix_synapse_admin_container_image_self_build }}"}
14+
when: "item.when | bool"
1015

1116
- name: Ensure matrix-synapse-admin labels file is created
1217
ansible.builtin.template:
@@ -16,6 +21,14 @@
1621
group: "{{ matrix_user_groupname }}"
1722
mode: 0640
1823

24+
- name: Ensure matrix-synapse-admin configuration installed
25+
ansible.builtin.copy:
26+
content: "{{ matrix_synapse_admin_configuration | to_nice_json }}"
27+
dest: "{{ matrix_synapse_admin_config_path }}/config.json"
28+
mode: 0644
29+
owner: "{{ matrix_user_username }}"
30+
group: "{{ matrix_user_groupname }}"
31+
1932
- name: Ensure matrix-synapse-admin image is pulled
2033
community.docker.docker_image:
2134
name: "{{ matrix_synapse_admin_docker_image }}"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"restrictBaseUrl": {{ matrix_synapse_admin_config_restrictBaseUrl | to_json }}
3+
}

roles/custom/matrix-synapse-admin/templates/systemd/matrix-synapse-admin.service.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
3030
-p {{ matrix_synapse_admin_container_http_host_bind_port }}:80 \
3131
{% endif %}
3232
--label-file={{ matrix_synapse_admin_base_path }}/labels \
33+
--mount type=bind,src={{ matrix_synapse_admin_config_path }}/config.json,dst=/app/config.json,ro \
3334
{% for arg in matrix_synapse_admin_container_extra_arguments %}
3435
{{ arg }} \
3536
{% endfor %}

0 commit comments

Comments
 (0)