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

Commit

Permalink
Merge branch 'develop' into rei/complement_workers_in_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed May 24, 2022
2 parents 5eec113 + f5b1c09 commit 9888b74
Show file tree
Hide file tree
Showing 52 changed files with 463 additions and 183 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ aff1eb7c671b0a3813407321d2702ec46c71fa56

# Update black to 20.8b1 (#9381).
0a00b7ff14890987f09112a2ae696c61001e6cf1

# Convert tests/rest/admin/test_room.py to unix file endings (#7953).
c4268e3da64f1abb5b31deaeb5769adb6510c0a7
1 change: 1 addition & 0 deletions changelog.d/12611.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +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.
1 change: 1 addition & 0 deletions changelog.d/12672.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.
1 change: 0 additions & 1 deletion changelog.d/12672.misc

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/12703.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert namespace class `Codes` into a string enum.
1 change: 1 addition & 0 deletions changelog.d/12718.feature
Original file line number Diff line number Diff line change
@@ -0,0 +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.
1 change: 1 addition & 0 deletions changelog.d/12744.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a `drop_federated_event` callback to `SpamChecker` to disregard inbound federated events before they take up much processing power, in an emergency.
1 change: 1 addition & 0 deletions changelog.d/12808.feature
Original file line number Diff line number Diff line change
@@ -0,0 +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).
1 change: 1 addition & 0 deletions changelog.d/12809.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Send `USER_IP` commands on a different Redis channel, in order to reduce traffic to workers that do not process these commands.
1 change: 1 addition & 0 deletions changelog.d/12818.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove Caddy from the Synapse workers image used in Complement.
1 change: 1 addition & 0 deletions changelog.d/12819.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Complement's shared registration secret to the Complement worker image. This fixes tests that depend on it.
1 change: 1 addition & 0 deletions changelog.d/12823.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +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.
1 change: 1 addition & 0 deletions changelog.d/12826.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support registering Application Services when running with workers under Complement.
1 change: 1 addition & 0 deletions changelog.d/12833.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add some type hints to test files.
1 change: 1 addition & 0 deletions changelog.d/12842.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable 'faster room join' Complement tests when testing against Synapse with workers.
1 change: 1 addition & 0 deletions changelog.d/12853.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the docker file after a dependency update.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RUN \
# NB: In poetry 1.2 `poetry export` will be moved into a plugin; we'll need to also
# pip install poetry-plugin-export (https://github.com/python-poetry/poetry-plugin-export).
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --user git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5
pip install --user "poetry-core==1.1.0a7" "git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5"

WORKDIR /synapse

Expand Down
12 changes: 1 addition & 11 deletions docker/complement/SynapseWorkers.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
# https://github.com/matrix-org/synapse/blob/develop/docker/README-testing.md#testing-with-postgresql-and-single-or-multi-process-synapse
FROM matrixdotorg/synapse-workers

# Download a caddy server to stand in front of nginx and terminate TLS using Complement's
# custom CA.
# We include this near the top of the file in order to cache the result.
RUN curl -OL "https://github.com/caddyserver/caddy/releases/download/v2.3.0/caddy_2.3.0_linux_amd64.tar.gz" && \
tar xzf caddy_2.3.0_linux_amd64.tar.gz && rm caddy_2.3.0_linux_amd64.tar.gz && mv caddy /root

# Install postgresql
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y postgresql-13
Expand All @@ -31,16 +25,12 @@ COPY conf-workers/workers-shared.yaml /conf/workers/shared.yaml

WORKDIR /data

# Copy the caddy config
COPY conf-workers/caddy.complement.json /root/caddy.json

COPY conf-workers/postgres.supervisord.conf /etc/supervisor/conf.d/postgres.conf
COPY conf-workers/caddy.supervisord.conf /etc/supervisor/conf.d/caddy.conf

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

# Expose caddy's listener ports
# Expose nginx's listener ports
EXPOSE 8008 8448

ENTRYPOINT ["/start-complement-synapse-workers.sh"]
Expand Down
72 changes: 0 additions & 72 deletions docker/complement/conf-workers/caddy.complement.json

This file was deleted.

7 changes: 0 additions & 7 deletions docker/complement/conf-workers/caddy.supervisord.conf

This file was deleted.

23 changes: 20 additions & 3 deletions docker/complement/conf-workers/start-complement-synapse-workers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ function log {
echo "$d $@"
}

# Replace the server name in the caddy config
sed -i "s/{{ server_name }}/${SERVER_NAME}/g" /root/caddy.json

# Set the server name of the homeserver
export SYNAPSE_SERVER_NAME=${SERVER_NAME}

Expand Down Expand Up @@ -39,6 +36,26 @@ export SYNAPSE_WORKER_TYPES="\
appservice, \
pusher"

# Add Complement's appservice registration directory, if there is one
# (It can be absent when there are no application services in this test!)
if [ -d /complement/appservice ]; then
export SYNAPSE_AS_REGISTRATION_DIR=/complement/appservice
fi

# Generate a TLS key, then generate a certificate by having Complement's CA sign it
# Note that both the key and certificate are in PEM format (not DER).
openssl genrsa -out /conf/server.tls.key 2048

openssl req -new -key /conf/server.tls.key -out /conf/server.tls.csr \
-subj "/CN=${SERVER_NAME}"

openssl x509 -req -in /conf/server.tls.csr \
-CA /complement/ca/ca.crt -CAkey /complement/ca/ca.key -set_serial 1 \
-out /conf/server.tls.crt

export SYNAPSE_TLS_CERT=/conf/server.tls.crt
export SYNAPSE_TLS_KEY=/conf/server.tls.key

export PYTHONDONTWRITEBYTECODE=1
export PYTHONPROFILEIMPORTTIME=1

Expand Down
6 changes: 6 additions & 0 deletions docker/complement/conf-workers/workers-shared.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ enable_registration: true
enable_registration_without_verification: true
bcrypt_rounds: 4

## Registration ##

# Needed by Complement to register admin users
# DO NOT USE in a production configuration! This should be a random secret.
registration_shared_secret: complement

## Federation ##

# trust certs signed by Complement's CA
Expand Down
16 changes: 16 additions & 0 deletions docker/conf-workers/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ server {
listen 8008;
listen [::]:8008;

{% if tls_cert_path is not none and tls_key_path is not none %}
listen 8448 ssl;
listen [::]:8448 ssl;

ssl_certificate {{ tls_cert_path }};
ssl_certificate_key {{ tls_key_path }};

# Some directives from cipherlist.eu (fka cipherli.st):
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Requires nginx >= 1.5.9
{% endif %}

server_name localhost;

# Nginx by default only allows file uploads up to 1M in size
Expand Down
11 changes: 10 additions & 1 deletion docker/conf-workers/shared.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
redis:
enabled: true

{{ shared_worker_config }}
{% if appservice_registrations is not none %}
## Application Services ##
# A list of application service config files to use.
app_service_config_files:
{%- for path in appservice_registrations %}
- "{{ path }}"
{%- endfor %}
{%- endif %}

{{ shared_worker_config }}
20 changes: 20 additions & 0 deletions docker/configure_workers_and_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
# * SYNAPSE_REPORT_STATS: Whether to report stats.
# * SYNAPSE_WORKER_TYPES: A comma separated list of worker names as specified in WORKER_CONFIG
# below. Leave empty for no workers, or set to '*' for all possible workers.
# * SYNAPSE_AS_REGISTRATION_DIR: If specified, a directory in which .yaml and .yml files
# will be treated as Application Service registration files.
# * SYNAPSE_TLS_CERT: Path to a TLS certificate in PEM format.
# * SYNAPSE_TLS_KEY: Path to a TLS key. If this and SYNAPSE_TLS_CERT are specified,
# Nginx will be configured to serve TLS on port 8448.
#
# NOTE: According to Complement's ENTRYPOINT expectations for a homeserver image (as defined
# in the project's README), this script may be run multiple times, and functionality should
Expand All @@ -29,6 +34,7 @@
import os
import subprocess
import sys
from pathlib import Path
from typing import Any, Dict, List, Mapping, MutableMapping, NoReturn, Set

import jinja2
Expand Down Expand Up @@ -488,11 +494,23 @@ def generate_worker_files(
master_log_config = generate_worker_log_config(environ, "master", data_dir)
shared_config["log_config"] = master_log_config

# Find application service registrations
appservice_registrations = None
appservice_registration_dir = os.environ.get("SYNAPSE_AS_REGISTRATION_DIR")
if appservice_registration_dir:
# Scan for all YAML files that should be application service registrations.
appservice_registrations = [
str(reg_path.resolve())
for reg_path in Path(appservice_registration_dir).iterdir()
if reg_path.suffix.lower() in (".yaml", ".yml")
]

# Shared homeserver config
convert(
"/conf/shared.yaml.j2",
"/conf/workers/shared.yaml",
shared_worker_config=yaml.dump(shared_config),
appservice_registrations=appservice_registrations,
)

# Nginx config
Expand All @@ -501,6 +519,8 @@ def generate_worker_files(
"/etc/nginx/conf.d/matrix-synapse.conf",
worker_locations=nginx_location_config,
upstream_directives=nginx_upstream_config,
tls_cert_path=os.environ.get("SYNAPSE_TLS_CERT"),
tls_key_path=os.environ.get("SYNAPSE_TLS_KEY"),
)

# Supervisord config
Expand Down
45 changes: 35 additions & 10 deletions docs/modules/spam_checker_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,29 @@ The available spam checker callbacks are:
### `check_event_for_spam`

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

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

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

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

### `user_may_join_room`

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

### `should_drop_federated_event`

_First introduced in Synapse v1.60.0_

```python
async def should_drop_federated_event(event: "synapse.events.EventBase") -> bool
```

Called when checking whether a remote server can federate an event with us. **Returning
`True` from this function will silently drop a federated event and split-brain our view
of a room's DAG, and thus you shouldn't use this callback unless you know what you are
doing.**

If multiple modules implement this callback, they will be considered in order. If a
callback returns `False`, Synapse falls through to the next one. The value of the first
callback that does not return `False` will be used. If this happens, Synapse will not call
any of the subsequent implementations of this callback.

## Example

The example below is a module that implements the spam checker callback
Expand Down
Loading

0 comments on commit 9888b74

Please sign in to comment.