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

Commit 4fef76c

Browse files
authored
Remove Caddy from the Synapse workers image used in Complement. (#12818)
1 parent fbf904b commit 4fef76c

File tree

7 files changed

+38
-93
lines changed

7 files changed

+38
-93
lines changed

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.

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: 15 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,21 @@ export SYNAPSE_WORKER_TYPES="\
3936
appservice, \
4037
pusher"
4138

39+
40+
# Generate a TLS key, then generate a certificate by having Complement's CA sign it
41+
# Note that both the key and certificate are in PEM format (not DER).
42+
openssl genrsa -out /conf/server.tls.key 2048
43+
44+
openssl req -new -key /conf/server.tls.key -out /conf/server.tls.csr \
45+
-subj "/CN=${SERVER_NAME}"
46+
47+
openssl x509 -req -in /conf/server.tls.csr \
48+
-CA /complement/ca/ca.crt -CAkey /complement/ca/ca.key -set_serial 1 \
49+
-out /conf/server.tls.crt
50+
51+
export SYNAPSE_TLS_CERT=/conf/server.tls.crt
52+
export SYNAPSE_TLS_KEY=/conf/server.tls.key
53+
4254
# Run the script that writes the necessary config files and starts supervisord, which in turn
4355
# starts everything else
4456
exec /configure_workers_and_start.py

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/configure_workers_and_start.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
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_TLS_CERT: Path to a TLS certificate in PEM format.
25+
# * SYNAPSE_TLS_KEY: Path to a TLS key. If this and SYNAPSE_TLS_CERT are specified,
26+
# Nginx will be configured to serve TLS on port 8448.
2427
#
2528
# NOTE: According to Complement's ENTRYPOINT expectations for a homeserver image (as defined
2629
# in the project's README), this script may be run multiple times, and functionality should
@@ -501,6 +504,8 @@ def generate_worker_files(
501504
"/etc/nginx/conf.d/matrix-synapse.conf",
502505
worker_locations=nginx_location_config,
503506
upstream_directives=nginx_upstream_config,
507+
tls_cert_path=os.environ.get("SYNAPSE_TLS_CERT"),
508+
tls_key_path=os.environ.get("SYNAPSE_TLS_KEY"),
504509
)
505510

506511
# Supervisord config

0 commit comments

Comments
 (0)