From 30bc0a46b449e4126e57e0baa3bdf57b2cb3621e Mon Sep 17 00:00:00 2001 From: Phil Date: Fri, 27 Nov 2026 11:52:22 -0700 Subject: [PATCH] caddy: access logs, security headers; dns: CAA records - (logging) snippet: JSON access log at /data/logs/access.log, rotated, tokens/OIDC codes and API key headers masked - (security_headers)/(no_framing): nosniff, Referrer-Policy and X-Frame-Options only where the app sets none; drop Server/X-Powered-By - (static_site): adds a CSP (base-uri, object-src, frame-ancestors, form-action) and Permissions-Policy to the four static sites - CAA records: Let's Encrypt + ZeroSSL on both domains, Amazon on thesatelliteoflove.com for links. (CloudFront/ACM), no wildcards Co-Authored-By: Claude Opus 5.5 --- dns.yml | 31 +++++++ roles/docker/templates/Caddyfile.j2 | 125 +++++++++++++++++++++++----- 2 files changed, 133 insertions(+), 23 deletions(-) diff --git a/dns.yml b/dns.yml index ddc2d70..eb87c05 100644 --- a/dns.yml +++ b/dns.yml @@ -62,6 +62,26 @@ - name: "repair" ip: "{{ network.netcup_ip }}" + # CAA: only these CAs may issue certificates for each domain (and its + # subdomains). Let's Encrypt is what Caddy uses; sectigo.com is ZeroSSL, + # Caddy's automatic fallback CA. Amazon covers links.thesatelliteoflove.com + # (CloudFront with an ACM certificate). No CA may issue wildcards. + caa_records: + - zone: thesatelliteoflove.com + records: + - '0 issue "letsencrypt.org"' + - '0 issue "sectigo.com"' + - '0 issue "amazon.com"' + - '0 issue "amazontrust.com"' + - '0 issue "awstrust.com"' + - '0 issue "amazonaws.com"' + - '0 issuewild ";"' + - zone: nerder.land + records: + - '0 issue "letsencrypt.org"' + - '0 issue "sectigo.com"' + - '0 issuewild ";"' + # DNS records to remove for decommissioned services removed_records: - name: thesatelliteoflove.com @@ -117,3 +137,14 @@ loop: "{{ query('subelements', domains, 'dns_records') }}" loop_control: loop_var: item + + - name: Set CAA records restricting which CAs may issue certificates + amazon.aws.route53: + state: present + zone: "{{ item.zone }}" + record: "{{ item.zone }}" + type: CAA + ttl: 3600 + value: "{{ item.records }}" + overwrite: true + loop: "{{ caa_records }}" diff --git a/roles/docker/templates/Caddyfile.j2 b/roles/docker/templates/Caddyfile.j2 index 4b59701..d7683c5 100644 --- a/roles/docker/templates/Caddyfile.j2 +++ b/roles/docker/templates/Caddyfile.j2 @@ -8,55 +8,126 @@ } } -{{ subdomains.pocketid }} { +# JSON access log shared by every site, in the caddy_data volume +# (/data/logs). Read by humans and, later, CrowdSec. Caddy already redacts +# Cookie/Authorization headers; the filter also masks ?token= (Gotify clients +# put their app token in the query string). +(logging) { + log { + output file /data/logs/access.log { + roll_size 50MiB + roll_keep 10 + roll_keep_for 720h + } + format filter { + request>uri query { + replace token REDACTED + replace access_token REDACTED + replace code REDACTED + } + request>headers>X-Gotify-Key replace REDACTED + request>headers>X-Api-Key replace REDACTED + } + } +} + +# Headers for proxied apps. "?" only sets a header the app didn't send, so +# apps with their own (stricter) values keep them. Server/X-Powered-By are +# dropped so responses don't advertise software versions. +(security_headers) { + header { + ?X-Content-Type-Options nosniff + ?Referrer-Policy strict-origin-when-cross-origin + -Server + -X-Powered-By + } +} + +# Refuse to be framed by other sites (clickjacking). Not for apps that are +# meant to be embedded elsewhere (HeyForm forms). +(no_framing) { + header ?X-Frame-Options SAMEORIGIN +} + +# Static sites: everything above plus a CSP. No default-src so existing +# scripts, styles and images keep working; it blocks plugins, +# hijacking, framing and forms posting off-site. +(static_site) { + import logging import hsts + import security_headers + header { + Content-Security-Policy "base-uri 'self'; object-src 'none'; frame-ancestors 'self'; form-action 'self'" + X-Frame-Options SAMEORIGIN + Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" + } +} + +# Every proxied site: log, HSTS and the shared headers. +(site) { + import logging + import hsts + import security_headers +} + +{{ subdomains.pocketid }} { + import site + import no_framing reverse_proxy pocket-id:1411 } paper.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy paperlessngx-webserver-1:8000 } cal.thesatelliteoflove.com { - import hsts + import site + import no_framing redir /.well-known/caldav /dav.php 302 redir /.well-known/carddav /dav.php 302 reverse_proxy baikal-baikal-1:80 } {{ subdomains.books }} { - import hsts + import site + import no_framing reverse_proxy kavita:5000 } audio.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy audiobookshelf-audiobookshelf-1:80 } loclog.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy dawarich_app:3000 } watcher.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy changedetection:5000 } snippets.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy bytestash:5000 } git.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy gitea:3000 } thesatelliteoflove.com { - import hsts + import static_site # WebFinger for phil@ serves two readers: the fediverse (GoToSocial's account # domain is this apex) and Tailscale, which finds the tailnet's login # provider through the OpenID issuer link. @@ -76,33 +147,38 @@ thesatelliteoflove.com { } bookmarks.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy hoarder-web-1:3000 } social.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy gotosocial:8080 } models.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy manyfold-app-1:3214 } gotify.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy gotify:80 } gotify-assistant.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy igotify-assistant:8080 } pdg.thesatelliteoflove.com { - import hsts + import static_site root * /srv/pdg # "{path}/" keeps the /dir -> /dir/ redirect; "{path}/index.html" is # needed for "/" itself, which "{path}/" never matches in Caddy 2.11. @@ -117,7 +193,8 @@ pdg.thesatelliteoflove.com { } starpunk.thesatelliteoflove.com { - import hsts + import site + import no_framing # MCP endpoint and its OAuth protected resource metadata (StarPunk v2.15.0) @mcp path /mcp /mcp/* /.well-known/oauth-protected-resource /.well-known/oauth-protected-resource/* handle @mcp { @@ -129,34 +206,36 @@ starpunk.thesatelliteoflove.com { } repair.nerder.land { - import hsts + import static_site root * /srv/repair file_server } nerder.land { - import hsts + import static_site root * /srv/nerderland file_server } forms.nerder.land { - import hsts + import site reverse_proxy heyform-heyform-1:9157 } listmonk.nerder.land { - import hsts + import site + import no_framing reverse_proxy listmonk:9000 } repaircafe.nerder.land { - import hsts + import site redir /volunteer-signup https://listmonk.nerder.land/subscription/form 301 } gokapi.thesatelliteoflove.com { - import hsts + import site + import no_framing reverse_proxy gokapi:53842 }