caddy: reload instead of restart, validate before deploy, HTTP catch-all, header timeout, body limits; dns: drop stale records
- Caddyfile moves to config/ (directory mount) so 'caddy reload' sees the new file; the handler reloads gracefully instead of restarting - template validate: runs 'caddy validate' with the image Caddy uses - http:// catch-all aborts plain-HTTP requests for unknown hosts / bare IP; known hosts keep the automatic HTTPS redirect (tested) - read_header timeout 10s (default 1 min) - body_limit snippet: 1MB static sites, tinyauth, repaircafe; 10MB Pocket ID, Changedetection, ByteStash, Gotify, iGotify; 20MB Baikal - dns: remove grist, habits, office, podcasts, pdftools (nothing serves them) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1d21bd53cc
commit
9696c0e441
6 files changed
+69
-12
No files matched your search
@@ -92,6 +92,16 @@
|
|||||||
ip: "{{ network.netcup_ip }}"
|
ip: "{{ network.netcup_ip }}"
|
||||||
- name: "kutt" # old AWS IP, no longer ours (takeover risk)
|
- name: "kutt" # old AWS IP, no longer ours (takeover risk)
|
||||||
ip: "44.202.81.119"
|
ip: "44.202.81.119"
|
||||||
|
- name: "grist" # not served (cleanup 2026-11-27)
|
||||||
|
ip: "{{ network.netcup_ip }}"
|
||||||
|
- name: "habits"
|
||||||
|
ip: "{{ network.netcup_ip }}"
|
||||||
|
- name: "office"
|
||||||
|
ip: "{{ network.netcup_ip }}"
|
||||||
|
- name: "podcasts"
|
||||||
|
ip: "{{ network.netcup_ip }}"
|
||||||
|
- name: "pdftools" # pointed at the Tailscale IP; nothing listens for it
|
||||||
|
ip: "{{ network.docker_host_ip }}"
|
||||||
- name: "home"
|
- name: "home"
|
||||||
ip: "{{ network.netcup_ip }}"
|
ip: "{{ network.netcup_ip }}"
|
||||||
- name: "pin"
|
- name: "pin"
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ roles/docker/
|
|||||||
│ └── monitoring/ # changedetection, appriseapi, gotify, cronmaster
|
│ └── monitoring/ # changedetection, appriseapi, gotify, cronmaster
|
||||||
├── templates/ # <service>-compose.yml.j2, env and config templates, Caddyfile.j2
|
├── templates/ # <service>-compose.yml.j2, env and config templates, Caddyfile.j2
|
||||||
├── files/ufw-docker.sh # UFW integration for Docker
|
├── files/ufw-docker.sh # UFW integration for Docker
|
||||||
└── handlers/main.yml # restart caddy, restart obsidian-livesync
|
└── handlers/main.yml # reload caddy, restart crowdsec, restart obsidian-livesync
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
# roles/docker/handlers/main.yml
|
# roles/docker/handlers/main.yml
|
||||||
- name: restart caddy
|
# Graceful: new config without dropping connections. If the new config
|
||||||
community.docker.docker_compose_v2:
|
# fails to load, Caddy keeps running the old one and the deploy fails.
|
||||||
project_src: /opt/stacks/caddy
|
- name: reload caddy
|
||||||
files:
|
ansible.builtin.command: docker exec caddy-caddy-1 caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile
|
||||||
- compose.yml
|
|
||||||
state: restarted
|
|
||||||
|
|
||||||
- name: restart crowdsec
|
- name: restart crowdsec
|
||||||
community.docker.docker_compose_v2:
|
community.docker.docker_compose_v2:
|
||||||
|
|||||||
@@ -4,15 +4,30 @@
|
|||||||
state: directory
|
state: directory
|
||||||
loop:
|
loop:
|
||||||
- /opt/stacks/caddy
|
- /opt/stacks/caddy
|
||||||
|
- /opt/stacks/caddy/config
|
||||||
|
|
||||||
|
# The Caddyfile lives in config/, which is mounted as a directory: a
|
||||||
|
# single-file bind mount would keep showing Caddy the old file after
|
||||||
|
# ansible replaces it, and "caddy reload" would reload stale config.
|
||||||
|
# validate: the new file must pass "caddy validate" with the image Caddy
|
||||||
|
# runs before it replaces the live one, so a broken Caddyfile never lands.
|
||||||
- name: template Caddyfile
|
- name: template Caddyfile
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: Caddyfile.j2
|
src: Caddyfile.j2
|
||||||
dest: /opt/stacks/caddy/Caddyfile
|
dest: /opt/stacks/caddy/config/Caddyfile
|
||||||
owner: root
|
owner: root
|
||||||
mode: '0640'
|
mode: '0640'
|
||||||
group: docker
|
group: docker
|
||||||
notify: restart caddy
|
validate: >-
|
||||||
|
docker run --rm --network none -e CROWDSEC_API_KEY=validate
|
||||||
|
-v %s:/etc/caddy/Caddyfile:ro {{ caddy_image }}
|
||||||
|
caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
|
||||||
|
notify: reload caddy
|
||||||
|
|
||||||
|
- name: remove the old Caddyfile location
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /opt/stacks/caddy/Caddyfile
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: template caddy .env (CrowdSec bouncer key)
|
- name: template caddy .env (CrowdSec bouncer key)
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
|
{
|
||||||
|
servers {
|
||||||
|
timeouts {
|
||||||
|
# Clients get 10 s to send request headers (default 1 min), so
|
||||||
|
# slow-header connections can't pile up. Bodies (uploads) and
|
||||||
|
# responses are not limited.
|
||||||
|
read_header 10s
|
||||||
|
}
|
||||||
|
}
|
||||||
{% if caddy_custom %}
|
{% if caddy_custom %}
|
||||||
# Plugins come from the custom image (repo phil/caddy-custom).
|
# Plugins come from the custom image (repo phil/caddy-custom).
|
||||||
{
|
|
||||||
order crowdsec first
|
order crowdsec first
|
||||||
order appsec after crowdsec
|
order appsec after crowdsec
|
||||||
crowdsec {
|
crowdsec {
|
||||||
@@ -13,9 +21,18 @@
|
|||||||
# CrowdSec being down must not take every site down.
|
# CrowdSec being down must not take every site down.
|
||||||
appsec_fail_open
|
appsec_fail_open
|
||||||
}
|
}
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Plain-HTTP requests for hostnames we don't serve, or for the bare IP:
|
||||||
|
# close the connection instead of redirecting. Known hosts still get
|
||||||
|
# Caddy's automatic HTTPS redirect (inserted before this catch-all), and
|
||||||
|
# ACME HTTP challenges are answered before routing. Unknown names over
|
||||||
|
# HTTPS already fail the TLS handshake (no certificate).
|
||||||
|
http:// {
|
||||||
|
abort
|
||||||
}
|
}
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
# Tell browsers to always use HTTPS for each site for a year. No
|
# Tell browsers to always use HTTPS for each site for a year. No
|
||||||
# includeSubDomains, so hosts not served here are unaffected.
|
# includeSubDomains, so hosts not served here are unaffected.
|
||||||
# defer: replace any HSTS header an app sends itself, so there's only one.
|
# defer: replace any HSTS header an app sends itself, so there's only one.
|
||||||
@@ -75,6 +92,7 @@
|
|||||||
import hsts
|
import hsts
|
||||||
import security_headers
|
import security_headers
|
||||||
import protect
|
import protect
|
||||||
|
import body_limit 1MB
|
||||||
header {
|
header {
|
||||||
Content-Security-Policy "base-uri 'self'; object-src 'none'; frame-ancestors 'self'; form-action 'self'"
|
Content-Security-Policy "base-uri 'self'; object-src 'none'; frame-ancestors 'self'; form-action 'self'"
|
||||||
X-Frame-Options SAMEORIGIN
|
X-Frame-Options SAMEORIGIN
|
||||||
@@ -125,6 +143,14 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Largest request body a site accepts: import body_limit <size>. Only for
|
||||||
|
# sites that never take big uploads; larger requests get 413.
|
||||||
|
(body_limit) {
|
||||||
|
request_body {
|
||||||
|
max_size {args[0]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Every proxied site: log, HSTS and the shared headers.
|
# Every proxied site: log, HSTS and the shared headers.
|
||||||
(site) {
|
(site) {
|
||||||
import logging
|
import logging
|
||||||
@@ -136,6 +162,7 @@
|
|||||||
{{ subdomains.pocketid }} {
|
{{ subdomains.pocketid }} {
|
||||||
import site
|
import site
|
||||||
import no_framing
|
import no_framing
|
||||||
|
import body_limit 10MB
|
||||||
import ratelimit_login pocketid_login /api/webauthn/login/* /api/one-time-access-token* /api/one-time-access-email*
|
import ratelimit_login pocketid_login /api/webauthn/login/* /api/one-time-access-token* /api/one-time-access-email*
|
||||||
reverse_proxy pocket-id:1411
|
reverse_proxy pocket-id:1411
|
||||||
}
|
}
|
||||||
@@ -143,6 +170,7 @@
|
|||||||
{{ subdomains.tinyauth }} {
|
{{ subdomains.tinyauth }} {
|
||||||
import site
|
import site
|
||||||
import no_framing
|
import no_framing
|
||||||
|
import body_limit 1MB
|
||||||
import ratelimit_login tinyauth_login /api/oauth/*
|
import ratelimit_login tinyauth_login /api/oauth/*
|
||||||
reverse_proxy tinyauth:3000
|
reverse_proxy tinyauth:3000
|
||||||
}
|
}
|
||||||
@@ -157,6 +185,7 @@ paper.thesatelliteoflove.com {
|
|||||||
cal.thesatelliteoflove.com {
|
cal.thesatelliteoflove.com {
|
||||||
import site
|
import site
|
||||||
import no_framing
|
import no_framing
|
||||||
|
import body_limit 20MB
|
||||||
redir /.well-known/caldav /dav.php 302
|
redir /.well-known/caldav /dav.php 302
|
||||||
redir /.well-known/carddav /dav.php 302
|
redir /.well-known/carddav /dav.php 302
|
||||||
# Web admin needs Pocket ID; CalDAV/CardDAV (/dav.php) stays as is.
|
# Web admin needs Pocket ID; CalDAV/CardDAV (/dav.php) stays as is.
|
||||||
@@ -189,6 +218,7 @@ loclog.thesatelliteoflove.com {
|
|||||||
watcher.thesatelliteoflove.com {
|
watcher.thesatelliteoflove.com {
|
||||||
import site
|
import site
|
||||||
import no_framing
|
import no_framing
|
||||||
|
import body_limit 10MB
|
||||||
import ratelimit_login cd_login /login
|
import ratelimit_login cd_login /login
|
||||||
# UI needs Pocket ID; the API (own key) stays reachable for scripts.
|
# UI needs Pocket ID; the API (own key) stays reachable for scripts.
|
||||||
@ui not path /api/*
|
@ui not path /api/*
|
||||||
@@ -199,6 +229,7 @@ watcher.thesatelliteoflove.com {
|
|||||||
snippets.thesatelliteoflove.com {
|
snippets.thesatelliteoflove.com {
|
||||||
import site
|
import site
|
||||||
import no_framing
|
import no_framing
|
||||||
|
import body_limit 10MB
|
||||||
import ratelimit_login bytestash_login /api/auth/login /api/auth/register
|
import ratelimit_login bytestash_login /api/auth/login /api/auth/register
|
||||||
reverse_proxy bytestash:5000
|
reverse_proxy bytestash:5000
|
||||||
}
|
}
|
||||||
@@ -255,6 +286,7 @@ models.thesatelliteoflove.com {
|
|||||||
gotify.thesatelliteoflove.com {
|
gotify.thesatelliteoflove.com {
|
||||||
import site
|
import site
|
||||||
import no_framing
|
import no_framing
|
||||||
|
import body_limit 10MB
|
||||||
import ratelimit_login gotify_login /client /user
|
import ratelimit_login gotify_login /client /user
|
||||||
reverse_proxy gotify:80
|
reverse_proxy gotify:80
|
||||||
}
|
}
|
||||||
@@ -262,6 +294,7 @@ gotify.thesatelliteoflove.com {
|
|||||||
gotify-assistant.thesatelliteoflove.com {
|
gotify-assistant.thesatelliteoflove.com {
|
||||||
import site
|
import site
|
||||||
import no_framing
|
import no_framing
|
||||||
|
import body_limit 10MB
|
||||||
reverse_proxy igotify-assistant:8080
|
reverse_proxy igotify-assistant:8080
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,6 +353,7 @@ listmonk.nerder.land {
|
|||||||
|
|
||||||
repaircafe.nerder.land {
|
repaircafe.nerder.land {
|
||||||
import site
|
import site
|
||||||
|
import body_limit 1MB
|
||||||
redir /volunteer-signup https://listmonk.nerder.land/subscription/form 301
|
redir /volunteer-signup https://listmonk.nerder.land/subscription/form 301
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ services:
|
|||||||
env_file: .env # CROWDSEC_API_KEY
|
env_file: .env # CROWDSEC_API_KEY
|
||||||
{% endif %}
|
{% endif %}
|
||||||
volumes:
|
volumes:
|
||||||
- ./Caddyfile:/etc/caddy/Caddyfile
|
- ./config:/etc/caddy:ro
|
||||||
- ./site:/srv
|
- ./site:/srv
|
||||||
- caddy_data:/data
|
- caddy_data:/data
|
||||||
- caddy_config:/config
|
- caddy_config:/config
|
||||||
|
|||||||
Reference in new issue
Block a user