Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 9888b74

Browse files
committed
Merge branch 'develop' into rei/complement_workers_in_ci
2 parents 5eec113 + f5b1c09 commit 9888b74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+463
-183
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ aff1eb7c671b0a3813407321d2702ec46c71fa56
66

77
# Update black to 20.8b1 (#9381).
88
0a00b7ff14890987f09112a2ae696c61001e6cf1
9+
10+
# Convert tests/rest/admin/test_room.py to unix file endings (#7953).
11+
c4268e3da64f1abb5b31deaeb5769adb6510c0a7

changelog.d/12611.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.7.0 that would prevent events from being sent to clients if there's a retention policy in the room when the support for retention policies is disabled.

changelog.d/12672.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.

changelog.d/12672.misc

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog.d/12703.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert namespace class `Codes` into a string enum.

changelog.d/12718.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update [MSC2716](https://github.com/matrix-org/matrix-spec-proposals/pull/2716) implementation to process marker events from the current state to avoid markers being lost in timeline gaps for federated servers which would cause the imported history to be undiscovered.

changelog.d/12744.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a `drop_federated_event` callback to `SpamChecker` to disregard inbound federated events before they take up much processing power, in an emergency.

changelog.d/12808.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update to `check_event_for_spam`. Deprecate the current callback signature, replace it with a new signature that is both less ambiguous (replacing booleans with explicit allow/block) and more powerful (ability to return explicit error codes).

changelog.d/12809.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.

changelog.d/12818.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove Caddy from the Synapse workers image used in Complement.

changelog.d/12819.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add Complement's shared registration secret to the Complement worker image. This fixes tests that depend on it.

changelog.d/12823.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug, introduced in Synapse 1.21.0, that led to media thumbnails being unusable before the index has been added in the background.

changelog.d/12826.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support registering Application Services when running with workers under Complement.

changelog.d/12833.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add some type hints to test files.

changelog.d/12842.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable 'faster room join' Complement tests when testing against Synapse with workers.

changelog.d/12853.docker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the docker file after a dependency update.

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ RUN \
5555
# NB: In poetry 1.2 `poetry export` will be moved into a plugin; we'll need to also
5656
# pip install poetry-plugin-export (https://github.com/python-poetry/poetry-plugin-export).
5757
RUN --mount=type=cache,target=/root/.cache/pip \
58-
pip install --user git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5
58+
pip install --user "poetry-core==1.1.0a7" "git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5"
5959

6060
WORKDIR /synapse
6161

docker/complement/SynapseWorkers.Dockerfile

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
# https://github.com/matrix-org/synapse/blob/develop/docker/README-testing.md#testing-with-postgresql-and-single-or-multi-process-synapse
77
FROM matrixdotorg/synapse-workers
88

9-
# Download a caddy server to stand in front of nginx and terminate TLS using Complement's
10-
# custom CA.
11-
# We include this near the top of the file in order to cache the result.
12-
RUN curl -OL "https://github.com/caddyserver/caddy/releases/download/v2.3.0/caddy_2.3.0_linux_amd64.tar.gz" && \
13-
tar xzf caddy_2.3.0_linux_amd64.tar.gz && rm caddy_2.3.0_linux_amd64.tar.gz && mv caddy /root
14-
159
# Install postgresql
1610
RUN apt-get update && \
1711
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y postgresql-13
@@ -31,16 +25,12 @@ COPY conf-workers/workers-shared.yaml /conf/workers/shared.yaml
3125

3226
WORKDIR /data
3327

34-
# Copy the caddy config
35-
COPY conf-workers/caddy.complement.json /root/caddy.json
36-
3728
COPY conf-workers/postgres.supervisord.conf /etc/supervisor/conf.d/postgres.conf
38-
COPY conf-workers/caddy.supervisord.conf /etc/supervisor/conf.d/caddy.conf
3929

4030
# Copy the entrypoint
4131
COPY conf-workers/start-complement-synapse-workers.sh /
4232

43-
# Expose caddy's listener ports
33+
# Expose nginx's listener ports
4434
EXPOSE 8008 8448
4535

4636
ENTRYPOINT ["/start-complement-synapse-workers.sh"]

docker/complement/conf-workers/caddy.complement.json

Lines changed: 0 additions & 72 deletions
This file was deleted.

docker/complement/conf-workers/caddy.supervisord.conf

Lines changed: 0 additions & 7 deletions
This file was deleted.

docker/complement/conf-workers/start-complement-synapse-workers.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ function log {
99
echo "$d $@"
1010
}
1111

12-
# Replace the server name in the caddy config
13-
sed -i "s/{{ server_name }}/${SERVER_NAME}/g" /root/caddy.json
14-
1512
# Set the server name of the homeserver
1613
export SYNAPSE_SERVER_NAME=${SERVER_NAME}
1714

@@ -39,6 +36,26 @@ export SYNAPSE_WORKER_TYPES="\
3936
appservice, \
4037
pusher"
4138

39+
# Add Complement's appservice registration directory, if there is one
40+
# (It can be absent when there are no application services in this test!)
41+
if [ -d /complement/appservice ]; then
42+
export SYNAPSE_AS_REGISTRATION_DIR=/complement/appservice
43+
fi
44+
45+
# Generate a TLS key, then generate a certificate by having Complement's CA sign it
46+
# Note that both the key and certificate are in PEM format (not DER).
47+
openssl genrsa -out /conf/server.tls.key 2048
48+
49+
openssl req -new -key /conf/server.tls.key -out /conf/server.tls.csr \
50+
-subj "/CN=${SERVER_NAME}"
51+
52+
openssl x509 -req -in /conf/server.tls.csr \
53+
-CA /complement/ca/ca.crt -CAkey /complement/ca/ca.key -set_serial 1 \
54+
-out /conf/server.tls.crt
55+
56+
export SYNAPSE_TLS_CERT=/conf/server.tls.crt
57+
export SYNAPSE_TLS_KEY=/conf/server.tls.key
58+
4259
export PYTHONDONTWRITEBYTECODE=1
4360
export PYTHONPROFILEIMPORTTIME=1
4461

docker/complement/conf-workers/workers-shared.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ enable_registration: true
55
enable_registration_without_verification: true
66
bcrypt_rounds: 4
77

8+
## Registration ##
9+
10+
# Needed by Complement to register admin users
11+
# DO NOT USE in a production configuration! This should be a random secret.
12+
registration_shared_secret: complement
13+
814
## Federation ##
915

1016
# trust certs signed by Complement's CA

docker/conf-workers/nginx.conf.j2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ server {
99
listen 8008;
1010
listen [::]:8008;
1111

12+
{% if tls_cert_path is not none and tls_key_path is not none %}
13+
listen 8448 ssl;
14+
listen [::]:8448 ssl;
15+
16+
ssl_certificate {{ tls_cert_path }};
17+
ssl_certificate_key {{ tls_key_path }};
18+
19+
# Some directives from cipherlist.eu (fka cipherli.st):
20+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
21+
ssl_prefer_server_ciphers on;
22+
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
23+
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
24+
ssl_session_cache shared:SSL:10m;
25+
ssl_session_tickets off; # Requires nginx >= 1.5.9
26+
{% endif %}
27+
1228
server_name localhost;
1329

1430
# Nginx by default only allows file uploads up to 1M in size

docker/conf-workers/shared.yaml.j2

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@
66
redis:
77
enabled: true
88

9-
{{ shared_worker_config }}
9+
{% if appservice_registrations is not none %}
10+
## Application Services ##
11+
# A list of application service config files to use.
12+
app_service_config_files:
13+
{%- for path in appservice_registrations %}
14+
- "{{ path }}"
15+
{%- endfor %}
16+
{%- endif %}
17+
18+
{{ shared_worker_config }}

docker/configure_workers_and_start.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
# * SYNAPSE_REPORT_STATS: Whether to report stats.
2222
# * SYNAPSE_WORKER_TYPES: A comma separated list of worker names as specified in WORKER_CONFIG
2323
# below. Leave empty for no workers, or set to '*' for all possible workers.
24+
# * SYNAPSE_AS_REGISTRATION_DIR: If specified, a directory in which .yaml and .yml files
25+
# will be treated as Application Service registration files.
26+
# * SYNAPSE_TLS_CERT: Path to a TLS certificate in PEM format.
27+
# * SYNAPSE_TLS_KEY: Path to a TLS key. If this and SYNAPSE_TLS_CERT are specified,
28+
# Nginx will be configured to serve TLS on port 8448.
2429
#
2530
# NOTE: According to Complement's ENTRYPOINT expectations for a homeserver image (as defined
2631
# in the project's README), this script may be run multiple times, and functionality should
@@ -29,6 +34,7 @@
2934
import os
3035
import subprocess
3136
import sys
37+
from pathlib import Path
3238
from typing import Any, Dict, List, Mapping, MutableMapping, NoReturn, Set
3339

3440
import jinja2
@@ -488,11 +494,23 @@ def generate_worker_files(
488494
master_log_config = generate_worker_log_config(environ, "master", data_dir)
489495
shared_config["log_config"] = master_log_config
490496

497+
# Find application service registrations
498+
appservice_registrations = None
499+
appservice_registration_dir = os.environ.get("SYNAPSE_AS_REGISTRATION_DIR")
500+
if appservice_registration_dir:
501+
# Scan for all YAML files that should be application service registrations.
502+
appservice_registrations = [
503+
str(reg_path.resolve())
504+
for reg_path in Path(appservice_registration_dir).iterdir()
505+
if reg_path.suffix.lower() in (".yaml", ".yml")
506+
]
507+
491508
# Shared homeserver config
492509
convert(
493510
"/conf/shared.yaml.j2",
494511
"/conf/workers/shared.yaml",
495512
shared_worker_config=yaml.dump(shared_config),
513+
appservice_registrations=appservice_registrations,
496514
)
497515

498516
# Nginx config
@@ -501,6 +519,8 @@ def generate_worker_files(
501519
"/etc/nginx/conf.d/matrix-synapse.conf",
502520
worker_locations=nginx_location_config,
503521
upstream_directives=nginx_upstream_config,
522+
tls_cert_path=os.environ.get("SYNAPSE_TLS_CERT"),
523+
tls_key_path=os.environ.get("SYNAPSE_TLS_KEY"),
504524
)
505525

506526
# Supervisord config

docs/modules/spam_checker_callbacks.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,29 @@ The available spam checker callbacks are:
1111
### `check_event_for_spam`
1212

1313
_First introduced in Synapse v1.37.0_
14+
_Signature extended to support Allow and Code in Synapse v1.60.0_
15+
_Boolean and string return value types deprecated in Synapse v1.60.0_
1416

1517
```python
16-
async def check_event_for_spam(event: "synapse.events.EventBase") -> Union[bool, str]
18+
async def check_event_for_spam(event: "synapse.module_api.EventBase") -> Union["synapse.module_api.ALLOW", "synapse.module_api.error.Codes", str, bool]
1719
```
1820

19-
Called when receiving an event from a client or via federation. The callback must return
20-
either:
21-
- an error message string, to indicate the event must be rejected because of spam and
22-
give a rejection reason to forward to clients;
23-
- the boolean `True`, to indicate that the event is spammy, but not provide further details; or
24-
- the booelan `False`, to indicate that the event is not considered spammy.
21+
Called when receiving an event from a client or via federation. The callback must return either:
22+
- `synapse.module_api.ALLOW`, to allow the operation. Other callbacks
23+
may still decide to reject it.
24+
- `synapse.api.Codes` to reject the operation with an error code. In case
25+
of doubt, `synapse.api.error.Codes.FORBIDDEN` is a good error code.
26+
- (deprecated) a `str` to reject the operation and specify an error message. Note that clients
27+
typically will not localize the error message to the user's preferred locale.
28+
- (deprecated) on `False`, behave as `ALLOW`. Deprecated as confusing, as some
29+
callbacks in expect `True` to allow and others `True` to reject.
30+
- (deprecated) on `True`, behave as `synapse.api.error.Codes.FORBIDDEN`. Deprecated as confusing, as
31+
some callbacks in expect `True` to allow and others `True` to reject.
2532

2633
If multiple modules implement this callback, they will be considered in order. If a
27-
callback returns `False`, Synapse falls through to the next one. The value of the first
28-
callback that does not return `False` will be used. If this happens, Synapse will not call
29-
any of the subsequent implementations of this callback.
34+
callback returns `synapse.module_api.ALLOW`, Synapse falls through to the next one. The value of the
35+
first callback that does not return `synapse.module_api.ALLOW` will be used. If this happens, Synapse
36+
will not call any of the subsequent implementations of this callback.
3037

3138
### `user_may_join_room`
3239

@@ -249,6 +256,24 @@ callback returns `False`, Synapse falls through to the next one. The value of th
249256
callback that does not return `False` will be used. If this happens, Synapse will not call
250257
any of the subsequent implementations of this callback.
251258

259+
### `should_drop_federated_event`
260+
261+
_First introduced in Synapse v1.60.0_
262+
263+
```python
264+
async def should_drop_federated_event(event: "synapse.events.EventBase") -> bool
265+
```
266+
267+
Called when checking whether a remote server can federate an event with us. **Returning
268+
`True` from this function will silently drop a federated event and split-brain our view
269+
of a room's DAG, and thus you shouldn't use this callback unless you know what you are
270+
doing.**
271+
272+
If multiple modules implement this callback, they will be considered in order. If a
273+
callback returns `False`, Synapse falls through to the next one. The value of the first
274+
callback that does not return `False` will be used. If this happens, Synapse will not call
275+
any of the subsequent implementations of this callback.
276+
252277
## Example
253278

254279
The example below is a module that implements the spam checker callback

0 commit comments

Comments
 (0)