feat(relay): a setup kit for a real machine; the relay's own name answers CAA so its certificate can renew
The apex CAA set allows issuance by DNS-01 only, and the relay publishes challenge records only for apps' names, so no authority could issue or renew the relay's own certificate. The relay now answers CAA at its own host name with the same authorities and no method restriction; every other name still climbs to the apex. deploy/relay holds the service unit, settings and certbot hook, and docs/relay-deploy.md the steps. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
00f8aadc71
commit
975a4d0452
8 files changed
+677
-8
No files matched your search
@@ -0,0 +1,24 @@
|
||||
# The certificate authorities the relay offers to apps, in the order they
|
||||
# are tried, and the source of the zone's CAA record. Installed as
|
||||
# /etc/wanderbooks-relay/authorities.toml. The relay reads it again within
|
||||
# half a minute of a change; a file with a mistake is refused and the old
|
||||
# list stays in force. At most 16 entries.
|
||||
#
|
||||
# An app sends requests only to authorities compiled into it (Let's
|
||||
# Encrypt, Google Trust Services, ZeroSSL, SSL.com), so a different
|
||||
# authority here is only useful if the program already knows it.
|
||||
#
|
||||
# A binding secret (binding_kid, binding_hmac_key) is never put here: the
|
||||
# relay refuses a file that has one. An authority that needs a binding
|
||||
# (needs_binding = true) is offered as not usable, because no per-app
|
||||
# source of bindings is built yet, so only authorities that need none work.
|
||||
|
||||
[[authority]]
|
||||
# A short name for this authority, unique in the file.
|
||||
id = "letsencrypt"
|
||||
# Its ACME directory address (RFC 8555), https, from its own documentation.
|
||||
directory = "https://acme-v02.api.letsencrypt.org/directory"
|
||||
# The name this authority goes by in a CAA record (its "issuer domain
|
||||
# name"). The relay publishes `issue "letsencrypt.org;
|
||||
# validationmethods=dns-01"` at the domain's apex from this.
|
||||
caa_domain = "letsencrypt.org"
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
# certbot runs this each time it gets or renews the relay's certificate
|
||||
# (a "deploy hook"): it copies the new files to where the relay reads them
|
||||
# and restarts the relay, which reads its certificate only when it starts.
|
||||
# Installed as /etc/letsencrypt/renewal-hooks/deploy/wanderbooks-relay.sh,
|
||||
# mode 0755. certbot sets RENEWED_LINEAGE to the certificate's folder.
|
||||
set -eu
|
||||
dest=/etc/wanderbooks-relay
|
||||
install -o root -g wanderbooks-relay -m 0644 "$RENEWED_LINEAGE/fullchain.pem" "$dest/relay-cert.pem"
|
||||
install -o root -g wanderbooks-relay -m 0640 "$RENEWED_LINEAGE/privkey.pem" "$dest/relay-key.pem"
|
||||
systemctl restart wanderbooks-relay
|
||||
@@ -0,0 +1,71 @@
|
||||
# Settings for the relay (docs/relay-deploy.md). Every key here is a real
|
||||
# key of `relay::Config`; a key the relay does not know stops it from
|
||||
# starting, so a typo is caught at once. Installed as
|
||||
# /etc/wanderbooks-relay/relay.toml.
|
||||
#
|
||||
# Replace each <placeholder> before starting. Times, in [limits], are in
|
||||
# milliseconds.
|
||||
|
||||
# The domain the relay serves and is the DNS server of.
|
||||
domain = "wanderbooks.link"
|
||||
|
||||
# The host an app's line dials. The program has this name built in, so
|
||||
# leave it as it is.
|
||||
relay_host = "relay.wanderbooks.link"
|
||||
|
||||
# Where the router listens: TCP 443. "[::]" is every IPv6 and IPv4
|
||||
# address of the machine (Linux answers both on one socket). Use
|
||||
# "0.0.0.0:443" for IPv4 only.
|
||||
router_addr = "[::]:443"
|
||||
|
||||
# Where DNS listens: UDP and TCP, the same number. 53 in production.
|
||||
dns_addr = "[::]:53"
|
||||
|
||||
# The registry: the one durable table, name to the app's public key.
|
||||
# Back it up (docs/relay-deploy.md); losing it lets anyone claim a name
|
||||
# someone else holds. The state folder is made by the service unit.
|
||||
registry_path = "/var/lib/wanderbooks-relay/registry.sqlite3"
|
||||
|
||||
# The relay's own certificate for relay.wanderbooks.link, PEM, the whole
|
||||
# chain, and its private key, PEM. The relay reads them once, when it
|
||||
# starts: a new certificate needs a restart. These are not the apps'
|
||||
# certificates; the relay holds none of those.
|
||||
tls_cert = "/etc/wanderbooks-relay/relay-cert.pem"
|
||||
tls_key = "/etc/wanderbooks-relay/relay-key.pem"
|
||||
|
||||
# The certificate authorities offered to apps, and the zone's CAA record
|
||||
# is made from the same file (see authorities.toml). The file is read
|
||||
# again within half a minute of a change. Keep this on: without a list
|
||||
# the relay publishes no CAA record, and no app can get a certificate.
|
||||
authorities_path = "/etc/wanderbooks-relay/authorities.toml"
|
||||
|
||||
# The addresses every name under the domain points at: this machine's
|
||||
# public addresses. Leave address_v6 empty ([]) if the machine has none.
|
||||
address_v4 = ["<server IPv4>"]
|
||||
address_v6 = ["<server IPv6>"]
|
||||
|
||||
# The domain's name servers, as the DNS answers for them. They must be the
|
||||
# same names, with the same addresses, as the host records and NS records
|
||||
# at the registrar. Two names, because the registry of a domain wants at
|
||||
# least two; both may be this one machine.
|
||||
[[nameservers]]
|
||||
name = "ns1.wanderbooks.link"
|
||||
v4 = ["<server IPv4>"]
|
||||
v6 = ["<server IPv6>"]
|
||||
|
||||
[[nameservers]]
|
||||
name = "ns2.wanderbooks.link"
|
||||
v4 = ["<server IPv4>"]
|
||||
v6 = ["<server IPv6>"]
|
||||
|
||||
# Limits. Every one has a default (crates/relay/src/config.rs) sized for
|
||||
# hundreds of thousands of apps on a large machine. Only the two that
|
||||
# matter for memory are set here, for a 1 GB machine: an idle app costs
|
||||
# about 15.4 KiB (the measurement in crates/relay/tests/memory.rs).
|
||||
[limits]
|
||||
# Apps connected at once. Past this a new app is turned away until one
|
||||
# leaves. 20,000 idle lines is about 310 MiB.
|
||||
max_lines = 20000
|
||||
# Connections of every kind at once: apps' lines, assistants being
|
||||
# spliced through, and connections still saying hello.
|
||||
max_connections = 40000
|
||||
@@ -0,0 +1,70 @@
|
||||
# The relay for wanderbooks.link (plan P15, unit B2; docs/relay-deploy.md).
|
||||
#
|
||||
# One process, one account, two jobs: it routes an assistant's TLS
|
||||
# connection down the line an app holds open (TCP 443), and it is the
|
||||
# domain's DNS server (UDP and TCP 53). It runs as its own account with no
|
||||
# shell, and the only file it writes is its registry, in its state folder.
|
||||
#
|
||||
# Install: the binary is /usr/local/bin/wanderbooks-relay (the `relay`
|
||||
# program from `cargo build --release -p relay`), the settings are
|
||||
# /etc/wanderbooks-relay/relay.toml and the certificate files that file
|
||||
# names sit beside it. See docs/relay-deploy.md for every step.
|
||||
|
||||
[Unit]
|
||||
Description=wanderbooks relay: routes web assistants to apps, and is the DNS of wanderbooks.link
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=wanderbooks-relay
|
||||
Group=wanderbooks-relay
|
||||
DynamicUser=no
|
||||
# Makes /var/lib/wanderbooks-relay, owned by the account, and is the only
|
||||
# writable place (the registry lives there).
|
||||
StateDirectory=wanderbooks-relay
|
||||
StateDirectoryMode=0700
|
||||
WorkingDirectory=/var/lib/wanderbooks-relay
|
||||
ExecStart=/usr/local/bin/wanderbooks-relay /etc/wanderbooks-relay/relay.toml
|
||||
# The relay shuts down cleanly on SIGINT (Ctrl-C) and on nothing else: a
|
||||
# SIGTERM would end it at once. So systemd stops it with SIGINT.
|
||||
KillSignal=SIGINT
|
||||
TimeoutStopSec=30
|
||||
Restart=on-failure
|
||||
RestartSec=2s
|
||||
# The relay writes its log lines to standard error; the journal keeps them.
|
||||
# One line a minute carries the counters (lines, routed, shed, ...).
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
# Ports 53 and 443 are below 1024. This one capability lets the account
|
||||
# bind them and nothing more.
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
|
||||
# Each idle app is one open socket, and each caller in flight is another.
|
||||
# 262144 is far above what a small machine can hold in memory.
|
||||
LimitNOFILE=262144
|
||||
|
||||
# The account and the filesystem.
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
PrivateTmp=yes
|
||||
PrivateDevices=yes
|
||||
ProtectKernelTunables=yes
|
||||
ProtectKernelModules=yes
|
||||
ProtectKernelLogs=yes
|
||||
ProtectControlGroups=yes
|
||||
ProtectClock=yes
|
||||
ProtectHostname=yes
|
||||
LockPersonality=yes
|
||||
RestrictRealtime=yes
|
||||
RestrictSUIDSGID=yes
|
||||
RestrictNamespaces=yes
|
||||
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
|
||||
SystemCallArchitectures=native
|
||||
UMask=0077
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in new issue
Block a user