From ad08d3eaea8c513d68404788dcf2113a318de900 Mon Sep 17 00:00:00 2001 From: David Papp Date: Mon, 2 Nov 2026 13:52:20 +0100 Subject: [PATCH 1/3] feat(use-cases): add a certbot example --- .gitignore | 1 + README.md | 3 + use-cases/README.md | 1 + use-cases/certbot/README.md | 159 ++++++++++++++++++++++++++ use-cases/certbot/config.yaml | 25 ++++ use-cases/certbot/demo.sh | 25 ++++ use-cases/certbot/docker-compose.yml | 90 +++++++++++++++ use-cases/certbot/make-certs.sh | 11 ++ use-cases/certbot/nginx.conf | 11 ++ use-cases/certbot/pebble-config.json | 12 ++ use-cases/certbot/security_rules.yaml | 16 +++ use-cases/certbot/upstreams.yaml | 20 ++++ 12 files changed, 374 insertions(+) create mode 100644 use-cases/certbot/README.md create mode 100644 use-cases/certbot/config.yaml create mode 100755 use-cases/certbot/demo.sh create mode 100644 use-cases/certbot/docker-compose.yml create mode 100755 use-cases/certbot/make-certs.sh create mode 100644 use-cases/certbot/nginx.conf create mode 100644 use-cases/certbot/pebble-config.json create mode 100644 use-cases/certbot/security_rules.yaml create mode 100644 use-cases/certbot/upstreams.yaml diff --git a/.gitignore b/.gitignore index 42e6a5f..1c21353 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .venv/ __pycache__/ sticky.key +pebble-tls/ diff --git a/README.md b/README.md index b2a17ed..fc489b3 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,9 @@ is at [docs.gen0sec.com](https://docs.gen0sec.com). - [Load-balancing methods](./use-cases/lb-methods/): one route per `lb.method` (round robin, maglev, ring hash, least request and more) over the same three servers. Needs Synapse 0.8.9 or later. +- [Certificates from certbot](./use-cases/certbot/): serve the certificates certbot + issues and renews, with the webroot challenge routed through Synapse. Needs + Synapse 0.8.9 or later. - [Load balancing on a passthrough host](./use-cases/lb-passthrough/): one passthrough host per `lb.method`, without terminating TLS. Needs Synapse 0.8.9 or later. diff --git a/use-cases/README.md b/use-cases/README.md index 49fce75..a7e7af2 100644 --- a/use-cases/README.md +++ b/use-cases/README.md @@ -17,6 +17,7 @@ closest to what you want and copy it. Every set uses placeholder values | [`capture-ids-ml`](./capture-ids-ml/) | agent | yes | `CAP_NET_RAW`, `CAP_BPF`, `CAP_NET_ADMIN`, and `CAP_SYS_ADMIN` or `CAP_PERFMON` | Detect-only XDP IDS with capture and four ML models that download with the API key; needs the `-ml` package | | [`agent-full-ml`](./agent-full-ml/) | agent | yes | `CAP_NET_RAW`, `CAP_BPF`, `CAP_NET_ADMIN`, and `CAP_SYS_ADMIN` or `CAP_PERFMON` | XDP firewall, smart firewall, blocking IDS with managed rules, capture and four ML models; needs the `-ml` package and an API key | | [`lb-methods`](./lb-methods/) | proxy | no | none: the demo listens on port 8080 | One route per `lb.method` over the same three servers; `maglev`, `ring_hash` and `least_request` need Synapse 0.8.9 or later | +| [`certbot`](./certbot/) | proxy | no | none: the demo listens on ports 8089 and 8443 | Serve and renew certificates that certbot writes, with the webroot challenge routed through Synapse; needs Synapse 0.8.9 or later | | [`lb-passthrough`](./lb-passthrough/) | proxy | no | none: the demo listens on port 8080 | One passthrough host per `lb.method`, without terminating TLS; `maglev` and `ring_hash` on a passthrough host need Synapse 0.8.9 or later | | [`lb-source-ip-persistence`](./lb-source-ip-persistence/) | proxy | no | none: the demo listens on port 8080 | Pin a client address to the server it first got, whatever `lb.method` says; needs Synapse 0.8.9 or later | | [`sticky-sessions`](./sticky-sessions/) | proxy | no | none: the demo listens on port 8088 | Keep a client on the server it first got with a signed cookie, and what happens to a cookie that does not verify; needs Synapse 0.8.9 or later | diff --git a/use-cases/certbot/README.md b/use-cases/certbot/README.md new file mode 100644 index 0000000..97a7fb0 --- /dev/null +++ b/use-cases/certbot/README.md @@ -0,0 +1,159 @@ +# Certificates from certbot + +Let certbot get and renew the certificate, and have Synapse serve it, without +a restart. **Needs Synapse 0.8.9 or later.** Earlier releases read the same +directory, but do not pick up a renewal made by certbot's link swap. + +```yaml +proxy: + listeners: + - { name: http, address: "0.0.0.0:80", mode: http } + - { name: https, address: "0.0.0.0:443", mode: tls } + certificates: "/etc/letsencrypt/live" + acme: + enabled: false +``` + +```yaml +hosts: + app.example.com: + tls: + terminate: + cert: app.example.com + paths: + "/": + upstream: whoami:80 + "/.well-known/acme-challenge": + upstream: webroot:80 +``` + +## Things to know + +- `proxy.certificates` is certbot's `live` directory: one subdirectory per + domain, each with `fullchain.pem` and `privkey.pem`. The subdirectory is named + after the first `-d` name given to certbot. `cert:` on the host names it. +- The directory MUST exist when Synapse starts. It MAY be empty. A missing + directory is a start-up error (from 0.8.8). While it is empty, a TLS + handshake fails with alert 40 and the log says that no certificates were found. +- Synapse watches the directory and reads the certificate at each handshake. A + renewal needs no restart and no `SIGHUP`. +- `proxy.acme.enabled: false` turns the embedded ACME client off. It is + deprecated. +- With it off, Synapse answers nothing on `/.well-known/acme-challenge` by + itself. The request goes to the host's routes, so a second path sends it to + the directory certbot writes the challenge file to (`--webroot`). Write the + path without a trailing slash: with one, the route does not match and the + challenge goes to the `/` upstream. +- Certbot needs the plaintext listener on port 80 to reach the host from the + CA. The challenge cannot be answered on 443. +- `certbot renew` is meant to run from cron or a timer. Run it with + `--no-random-sleep-on-renew` when you test it by hand, or it waits up to + several minutes. + +## Run + +The demo uses [Pebble](https://github.com/letsencrypt/pebble), a test ACME +server, so nothing reaches Let's Encrypt. Docker and Compose are needed. + +```sh +cd use-cases/certbot +./make-certs.sh # a test certificate for Pebble's API +docker compose up -d +docker compose run --rm client # before: no certificate yet +docker compose run --rm certbot # issue +docker compose run --rm client # after: the issued chain +``` + +To renew at once, and see that Synapse keeps running: + +```sh +docker inspect -f '{{.State.StartedAt}}' $(docker compose ps -q synapse) +docker compose run --rm --entrypoint certbot certbot \ + renew --force-renewal --no-random-sleep-on-renew +docker compose run --rm client +docker inspect -f '{{.State.StartedAt}}' $(docker compose ps -q synapse) +docker compose down -v +``` + +The image is the 0.8.9 release image. To use a build of your own, set +`SYNAPSE_IMAGE`. + +### What it prints + +Before issuing, the handshake fails and the challenge path reaches the webroot +(404, no file yet): + +``` +== the certificate on app.example.com:443 +...SSL alert number 40 +== the challenge path on http, with no file behind it + HTTP/1.1 404 Not Found +``` + +Certbot issues through port 80: + +``` +Requesting a certificate for app.example.com +Successfully received certificate. +Certificate is saved at: /etc/letsencrypt/live/app.example.com/fullchain.pem +``` + +Synapse then serves the chain, and it verifies against Pebble's root: + +``` +serial=5CDE5864DFDD051B +issuer=CN=Pebble Intermediate CA 6a73b6 +DNS:app.example.com +Verification: OK +``` + +After the forced renewal the serial has changed and the container's start time +is the same as before (`2026-11-02T12:44:47.182364177Z` in both reads): + +``` +serial=3AA7426B5BC3656B +``` + +The serials, the issuer name and the dates differ on every run. + +### What goes wrong + +Without the challenge path in the routes, the request goes to `/`, and the CA +reads another server's answer: + +``` +Type: unauthorized +Detail: The key authorization file from the server did not match this challenge +"..." != "Hostname: whoami ..." +``` + +Without the `live` directory, Synapse does not start: + +``` +proxy failed to start: listener "https" (0.0.0.0:443, mode=tls): proxy.certificates directory "/etc/letsencrypt/live" does not exist; fix or create it, or remove proxy.certificates +``` + +That is why `docker-compose.yml` creates it first. + +## For production + +- Remove the `pebble`, `client` and `init` services, `REQUESTS_CA_BUNDLE` and + the `--server` flag. Certbot then uses Let's Encrypt. +- Use your own host name for `-d`, for the `hosts:` key and for `cert:`. +- Keep `/etc/letsencrypt` on a volume that Synapse mounts read-only and certbot + mounts read-write, and run `certbot renew` from a timer. +- The host must be reachable on port 80 from the internet. + +## Not checked here + +The set was run against Pebble only. It was not run against Let's Encrypt, and +the published 0.8.9 image was not pulled: the run used a 0.8.9 build of the +binary. + +## Files + +- `config.yaml`, `upstreams.yaml`, `security_rules.yaml`: the Synapse set. +- `docker-compose.yml`: Synapse, a test back-end, the webroot, Pebble, certbot. +- `nginx.conf`: serves the webroot. +- `pebble-config.json`, `make-certs.sh`: the test ACME server. +- `demo.sh`: what the `client` service prints. diff --git a/use-cases/certbot/config.yaml b/use-cases/certbot/config.yaml new file mode 100644 index 0000000..703721b --- /dev/null +++ b/use-cases/certbot/config.yaml @@ -0,0 +1,25 @@ +# Proxy mode, no firewall or capture, so the container needs no privileges. +mode: proxy + +firewall: + mode: none +capture: + enabled: false + +proxy: + listeners: + # The plaintext listener answers the ACME http-01 challenge. Without it + # no certificate can be issued. + - { name: http, address: "0.0.0.0:80", mode: http } + - { name: https, address: "0.0.0.0:443", mode: tls } + upstream: + conf: "/etc/synapse/upstreams.yaml" + # Certbot's directory: one subdirectory per domain, holding fullchain.pem and + # privkey.pem. The directory must exist when Synapse starts; it may be empty. + certificates: "/etc/letsencrypt/live" + # The embedded ACME client is deprecated. Certbot does the issuing. + acme: + enabled: false + +logging: + level: info diff --git a/use-cases/certbot/demo.sh b/use-cases/certbot/demo.sh new file mode 100755 index 0000000..7667180 --- /dev/null +++ b/use-cases/certbot/demo.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Runs in the client container: what Synapse serves for app.example.com now. +# Pebble makes a new root on every start, so fetch the one in use, over its +# own API port, which the test certificate in /pebble-tls secures. +get() { printf 'GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n' "$2" "$1"; } +get pebble /roots/0 | openssl s_client -quiet -CAfile /pebble-tls/cert.pem \ + -connect pebble:15000 2>/dev/null | sed -n '/BEGIN CERT/,/END CERT/p' > /tmp/root.pem + +echo "== the certificate on app.example.com:443" +out=$(openssl s_client -connect app.example.com:443 -servername app.example.com \ + -CAfile /tmp/root.pem &1) +cert=$(echo "$out" | openssl x509 2>/dev/null) +if [ -z "$cert" ]; then + echo "$out" | grep -E 'alert|error' | head -3 +else + echo "$cert" | openssl x509 -noout -serial -issuer -dates -ext subjectAltName + echo "$out" | grep '^Verification' +fi + +echo "== a request on https" +get app.example.com / | openssl s_client -quiet -CAfile /tmp/root.pem \ + -connect app.example.com:443 -servername app.example.com 2>&1 | grep -E '^(Hostname|Host):|error' + +echo "== the challenge path on http, with no file behind it" +wget -S -O /dev/null http://app.example.com/.well-known/acme-challenge/none 2>&1 | grep -E '^ HTTP/' diff --git a/use-cases/certbot/docker-compose.yml b/use-cases/certbot/docker-compose.yml new file mode 100644 index 0000000..f66c7e6 --- /dev/null +++ b/use-cases/certbot/docker-compose.yml @@ -0,0 +1,90 @@ +# Run: ./make-certs.sh && docker compose up -d +# The image is the 0.8.9 release image. To use a build of your own, set +# SYNAPSE_IMAGE (for example SYNAPSE_IMAGE=synapse:local docker compose up -d). +# +# Pebble is a test ACME server. It checks the challenge by connecting to +# app.example.com on port 80; the network alias makes that name reach Synapse. +# For a real server, drop pebble and see the README. +services: + # Certbot's directory must exist when Synapse starts. It is a named volume, so + # this one-shot service makes the empty live directory first. + init: + image: busybox:1.36 + command: ["mkdir", "-p", "/etc/letsencrypt/live"] + volumes: ["letsencrypt:/etc/letsencrypt"] + synapse: + image: ${SYNAPSE_IMAGE:-registry.gen0sec.com/gen0sec/synapse:0.8.9} + command: ["-c", "/etc/synapse/config.yaml"] + ports: ["8089:80", "8443:443"] + volumes: + - ".:/etc/synapse:ro" + - "letsencrypt:/etc/letsencrypt:ro" + networks: + certbot: + ipv4_address: 172.30.8.10 + aliases: [app.example.com] + depends_on: + init: { condition: service_completed_successfully } + whoami: { condition: service_started } + webroot: { condition: service_started } + whoami: + image: traefik/whoami:v1.10.3 + hostname: whoami + networks: [certbot] + webroot: + image: nginx:1.27-alpine + volumes: + - "./nginx.conf:/etc/nginx/conf.d/default.conf:ro" + - "webroot:/usr/share/nginx/html:ro" + networks: [certbot] + pebble: + image: ghcr.io/letsencrypt/pebble:2.9.0 + command: ["-config", "/etc/pebble/pebble-config.json"] + environment: + # Skip the pauses Pebble adds to behave like a busy CA. + PEBBLE_VA_NOSLEEP: "1" + volumes: + - "./pebble-config.json:/etc/pebble/pebble-config.json:ro" + - "./pebble-tls:/pebble-tls:ro" + networks: [certbot] + certbot: + image: certbot/certbot:v2.11.0 + profiles: ["demo"] + environment: + # Trust the test server's certificate. Remove this for a real server. + REQUESTS_CA_BUNDLE: /pebble-tls/cert.pem + command: + - certonly + - --webroot + - -w + - /var/www/html + - -d + - app.example.com + - --server + - https://pebble:14000/dir + - --email + - admin@example.com + - --agree-tos + - --no-eff-email + volumes: + - "letsencrypt:/etc/letsencrypt" + - "webroot:/var/www/html" + - "./pebble-tls:/pebble-tls:ro" + networks: [certbot] + client: + image: alpine/openssl:3.3.2 + profiles: ["demo"] + entrypoint: ["/bin/sh", "/demo/demo.sh"] + volumes: + - "./demo.sh:/demo/demo.sh:ro" + - "./pebble-tls:/pebble-tls:ro" + networks: [certbot] + +volumes: + letsencrypt: + webroot: + +networks: + certbot: + ipam: + config: [{ subnet: 172.30.8.0/24 }] diff --git a/use-cases/certbot/make-certs.sh b/use-cases/certbot/make-certs.sh new file mode 100755 index 0000000..150fa9e --- /dev/null +++ b/use-cases/certbot/make-certs.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# Make the certificate Pebble, the test ACME server, serves on its own API port, +# in ./pebble-tls. Certbot trusts exactly this file. Test material only: with a +# real ACME server there is nothing to make. +set -eu +cd "$(dirname "$0")" +mkdir -p pebble-tls +[ -s pebble-tls/cert.pem ] || openssl req -x509 -newkey rsa:2048 -nodes -days 30 \ + -subj "/CN=pebble" -addext "subjectAltName=DNS:pebble" \ + -keyout pebble-tls/key.pem -out pebble-tls/cert.pem +chmod 644 pebble-tls/key.pem diff --git a/use-cases/certbot/nginx.conf b/use-cases/certbot/nginx.conf new file mode 100644 index 0000000..7803bfc --- /dev/null +++ b/use-cases/certbot/nginx.conf @@ -0,0 +1,11 @@ +# The webroot: serves the files certbot writes for the http-01 challenge. +server { + listen 80; + root /usr/share/nginx/html; + location / { + return 404; + } + location /.well-known/acme-challenge/ { + try_files $uri =404; + } +} diff --git a/use-cases/certbot/pebble-config.json b/use-cases/certbot/pebble-config.json new file mode 100644 index 0000000..c17d088 --- /dev/null +++ b/use-cases/certbot/pebble-config.json @@ -0,0 +1,12 @@ +{ + "pebble": { + "listenAddress": "0.0.0.0:14000", + "managementListenAddress": "0.0.0.0:15000", + "certificate": "/pebble-tls/cert.pem", + "privateKey": "/pebble-tls/key.pem", + "httpPort": 80, + "tlsPort": 443, + "ocspResponderURL": "", + "externalAccountBindingRequired": false + } +} diff --git a/use-cases/certbot/security_rules.yaml b/use-cases/certbot/security_rules.yaml new file mode 100644 index 0000000..baf9794 --- /dev/null +++ b/use-cases/certbot/security_rules.yaml @@ -0,0 +1,16 @@ +# No rules: Synapse looks for this file next to config.yaml and logs a warning +# when it is missing. +access_rules: + id: example-access + name: No access rules + description: Empty on purpose + allow: + ips: [] + country: [] + asn: [] + block: + ips: [] + country: [] + asn: [] +waf_rules: + rules: [] diff --git a/use-cases/certbot/upstreams.yaml b/use-cases/certbot/upstreams.yaml new file mode 100644 index 0000000..22955c6 --- /dev/null +++ b/use-cases/certbot/upstreams.yaml @@ -0,0 +1,20 @@ +# One host. Its certificate comes from certbot; the webroot challenge goes to +# a plain web server that serves the directory certbot writes to. +version: 2 + +hosts: + app.example.com: + tls: + terminate: + # The directory name under proxy.certificates, which is the first -d + # name certbot was given. + cert: app.example.com + paths: + "/": + upstream: whoami:80 + # With proxy.acme.enabled false, Synapse answers nothing here itself: the + # request goes wherever the host's routes send it. Send it to the webroot, + # the directory certbot writes the challenge file to. Write the path + # without a trailing slash: it then covers everything under it. + "/.well-known/acme-challenge": + upstream: webroot:80 From d7e77633c6e27db9f3b27aa2e8eda83a87365153 Mon Sep 17 00:00:00 2001 From: David Papp Date: Mon, 2 Nov 2026 14:12:13 +0100 Subject: [PATCH 2/3] fix(certbot): redirect the app to https, and two README and demo fixes --- use-cases/certbot/README.md | 47 ++++++++++++++++++++++++-------- use-cases/certbot/demo.sh | 3 ++ use-cases/certbot/make-certs.sh | 7 +++-- use-cases/certbot/upstreams.yaml | 2 ++ 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/use-cases/certbot/README.md b/use-cases/certbot/README.md index 97a7fb0..3f39133 100644 --- a/use-cases/certbot/README.md +++ b/use-cases/certbot/README.md @@ -23,6 +23,7 @@ hosts: paths: "/": upstream: whoami:80 + force_https: true "/.well-known/acme-challenge": upstream: webroot:80 ``` @@ -46,6 +47,13 @@ hosts: challenge goes to the `/` upstream. - Certbot needs the plaintext listener on port 80 to reach the host from the CA. The challenge cannot be answered on 443. +- `force_https: true` on `/` redirects every other request on port 80 to HTTPS, + so the app is not served in clear. The challenge route has no `force_https` + and stays plain HTTP. The redirect goes to the first `tls` listener's port + (443); set `proxy.https_redirect_port` if clients reach HTTPS on another + port, as the demo's `8443` mapping does from the host. +- Put the challenge route in before the first issue. Without it the challenge + falls to `/` and is redirected to HTTPS, where there is no certificate yet. - `certbot renew` is meant to run from cron or a timer. Run it with `--no-random-sleep-on-renew` when you test it by hand, or it waits up to several minutes. @@ -80,12 +88,15 @@ The image is the 0.8.9 release image. To use a build of your own, set ### What it prints -Before issuing, the handshake fails and the challenge path reaches the webroot -(404, no file yet): +Before issuing, the handshake fails, plain HTTP on `/` is redirected, and the +challenge path reaches the webroot (404, no file yet): ``` == the certificate on app.example.com:443 ...SSL alert number 40 +== a request on http +HTTP/1.1 301 Moved Permanently +Location: https://app.example.com:443/ == the challenge path on http, with no file behind it HTTP/1.1 404 Not Found ``` @@ -101,30 +112,37 @@ Certificate is saved at: /etc/letsencrypt/live/app.example.com/fullchain.pem Synapse then serves the chain, and it verifies against Pebble's root: ``` -serial=5CDE5864DFDD051B -issuer=CN=Pebble Intermediate CA 6a73b6 +serial=438B3F45B317B805 +issuer=CN=Pebble Intermediate CA 7fb12e DNS:app.example.com Verification: OK ``` After the forced renewal the serial has changed and the container's start time -is the same as before (`2026-11-02T12:44:47.182364177Z` in both reads): +is the same as before (`2026-11-02T12:56:46.334774266Z` in both reads): ``` -serial=3AA7426B5BC3656B +serial=7E3AAB75D18199E5 ``` The serials, the issuer name and the dates differ on every run. +A first certificate was not always served at once. In 3 of 7 runs of this demo +against a 0.8.9 build, Synapse did not load the certificate certbot had just +issued, and kept failing the handshake until the next change in the directory +(the forced renewal loaded it). The other 4 loaded it within seconds. The cause +was not found. If the "after" check still shows alert 40, check the log for +`Certificate changed` before you trust the result. + ### What goes wrong -Without the challenge path in the routes, the request goes to `/`, and the CA -reads another server's answer: +Without the challenge path in the routes, the request goes to `/`, which +redirects it to HTTPS, where there is no certificate yet. The CA reports: ``` -Type: unauthorized -Detail: The key authorization file from the server did not match this challenge -"..." != "Hostname: whoami ..." +Type: connection +Detail: Get "https://app.example.com:443/.well-known/acme-challenge/...": +remote error: tls: handshake failure ``` Without the `live` directory, Synapse does not start: @@ -139,10 +157,15 @@ That is why `docker-compose.yml` creates it first. - Remove the `pebble`, `client` and `init` services, `REQUESTS_CA_BUNDLE` and the `--server` flag. Certbot then uses Let's Encrypt. +- Replace `--email admin@example.com` with your own address, or use + `--register-unsafely-without-email`. Let's Encrypt refuses `example.com` + contacts. This was not tried against Let's Encrypt. - Use your own host name for `-d`, for the `hosts:` key and for `cert:`. - Keep `/etc/letsencrypt` on a volume that Synapse mounts read-only and certbot mounts read-write, and run `certbot renew` from a timer. -- The host must be reachable on port 80 from the internet. +- Port 80 MUST reach Synapse from the internet: the CA fetches the challenge + there. Keep `force_https: true` on `/` and leave it off the challenge route. + That redirects the app to HTTPS and keeps the challenge on plain HTTP. ## Not checked here diff --git a/use-cases/certbot/demo.sh b/use-cases/certbot/demo.sh index 7667180..d02f05c 100755 --- a/use-cases/certbot/demo.sh +++ b/use-cases/certbot/demo.sh @@ -21,5 +21,8 @@ echo "== a request on https" get app.example.com / | openssl s_client -quiet -CAfile /tmp/root.pem \ -connect app.example.com:443 -servername app.example.com 2>&1 | grep -E '^(Hostname|Host):|error' +echo "== a request on http" +get app.example.com / | nc app.example.com 80 | sed -n '1p;2p' | tr -d '\r' + echo "== the challenge path on http, with no file behind it" wget -S -O /dev/null http://app.example.com/.well-known/acme-challenge/none 2>&1 | grep -E '^ HTTP/' diff --git a/use-cases/certbot/make-certs.sh b/use-cases/certbot/make-certs.sh index 150fa9e..8a1c279 100755 --- a/use-cases/certbot/make-certs.sh +++ b/use-cases/certbot/make-certs.sh @@ -1,11 +1,12 @@ #!/bin/sh # Make the certificate Pebble, the test ACME server, serves on its own API port, -# in ./pebble-tls. Certbot trusts exactly this file. Test material only: with a -# real ACME server there is nothing to make. +# in ./pebble-tls, again once it has under a day left. Certbot trusts exactly +# this file. Test material only: with a real ACME server there is nothing to make. set -eu cd "$(dirname "$0")" mkdir -p pebble-tls -[ -s pebble-tls/cert.pem ] || openssl req -x509 -newkey rsa:2048 -nodes -days 30 \ +# Make it again when it is missing or has under a day left. +openssl x509 -checkend 86400 -noout -in pebble-tls/cert.pem >/dev/null 2>&1 || openssl req -x509 -newkey rsa:2048 -nodes -days 30 \ -subj "/CN=pebble" -addext "subjectAltName=DNS:pebble" \ -keyout pebble-tls/key.pem -out pebble-tls/cert.pem chmod 644 pebble-tls/key.pem diff --git a/use-cases/certbot/upstreams.yaml b/use-cases/certbot/upstreams.yaml index 22955c6..1a929f0 100644 --- a/use-cases/certbot/upstreams.yaml +++ b/use-cases/certbot/upstreams.yaml @@ -12,6 +12,8 @@ hosts: paths: "/": upstream: whoami:80 + # Plain HTTP stays open only for the challenge path below. + force_https: true # With proxy.acme.enabled false, Synapse answers nothing here itself: the # request goes wherever the host's routes send it. Send it to the webroot, # the directory certbot writes the challenge file to. Write the path From 539b64c9cf53532643d97391d6ceb6cc26fb05bb Mon Sep 17 00:00:00 2001 From: David Papp Date: Mon, 2 Nov 2026 21:12:07 +0100 Subject: [PATCH 3/3] docs(certbot): the first certificate is served at once with the fixed build --- use-cases/certbot/README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/use-cases/certbot/README.md b/use-cases/certbot/README.md index 3f39133..330e156 100644 --- a/use-cases/certbot/README.md +++ b/use-cases/certbot/README.md @@ -127,12 +127,19 @@ serial=7E3AAB75D18199E5 The serials, the issuer name and the dates differ on every run. -A first certificate was not always served at once. In 3 of 7 runs of this demo -against a 0.8.9 build, Synapse did not load the certificate certbot had just -issued, and kept failing the handshake until the next change in the directory -(the forced renewal loaded it). The other 4 loaded it within seconds. The cause -was not found. If the "after" check still shows alert 40, check the log for -`Certificate changed` before you trust the result. +Synapse loads the first certificate when certbot creates its directory under +`/etc/letsencrypt/live`, so it is served without waiting for a renewal. Builds +before this fix, 0.8.9-rc.2 and earlier, could miss a first certificate: +certbot makes the directory and its links within a fraction of a millisecond, +and under load Synapse sometimes saw only the directory. The handshake then +failed with alert 40 until the next change in the directory (the forced renewal +loaded it). If the "after" check shows alert 40 on such a build, look for +`Certificate changed` in the log and update. + +With the fixed build, the first certificate was served at the first poll in 10 +of 10 runs of this demo, and in 10 of 10 runs with Synapse sharing one CPU with +two busy loops. The same starved runs on a build without the fix served it 1 +time in 10. ### What goes wrong @@ -170,8 +177,8 @@ That is why `docker-compose.yml` creates it first. ## Not checked here The set was run against Pebble only. It was not run against Let's Encrypt, and -the published 0.8.9 image was not pulled: the run used a 0.8.9 build of the -binary. +the published 0.8.9 image was not pulled: the run used a build of the 0.8.9 +branch that includes the first-certificate fix. ## Files