Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ A request crosses the proxy before it reaches the site, so no single log answers

**The one routerless https `404` that is not a routing fault is the edge restarting.** It arrives on a hostname the proxy does serve, in a minute that also carries `502`s. The host side restarts the edge nightly and when it pushes a change during the day, and its documentation holds that schedule. The routes return within a minute. Such a window is an intentional update blip, so leave it alone. Investigate only a window that does not look like one, such as one that outlasts a restart or recurs with no `502` beside it.

**A hostname Cloudflare proxies adds a tier above Traefik, and that tier keeps no record you can read.** The free plan shows aggregates and a sample, never a line per request. A request its rules block or its cache answers therefore reaches no tier below. Cloudflare never caches HTML, XML, JSON, or text by default, so every real-content `404` still reaches Traefik. A file type it does cache is answered from Cloudflare for as long as the bundle's `Cache-Control` allows, which [`deploy/README.md`](./deploy/README.md#cache-lifetimes) sets. A count for `/media/` is then a floor, and a first sighting is still logged, which is all the inward pass needs. `ClientHost` on a proxied request is the forwarded chain rather than one address, where Traefik trusts Cloudflare's ranges. Without that trust Traefik strips the header, and the field is Cloudflare's own address, which a pass would read as a reader. That trust is the host side's setting. A client may send a chain of its own, and Cloudflare appends the address it saw. [`checks/log-review.jq`](./checks/log-review.jq) keeps the last element for that reason, and the `403` cross-check below does the same.

Two properties of the Caddy side are worth knowing before parsing it. Its access log is `format console`, so each line is a timestamp, a level, and a logger name followed by a JSON object rather than being JSON itself, and a parser that assumes one object per line reads nothing. And `trusted_proxies` is what makes `client_ip` the reader rather than the proxy, which is the same setting "Serving" describes as a security boundary. Without it every request in the log appears to come from one internal address, and the inward pass cannot distinguish a reader from a health check.

### Reading a 404 list without being fooled by it
Expand Down Expand Up @@ -362,7 +364,7 @@ set -euo pipefail
since="$(( ($(date -u +%s) - $(date -u -d "$start" +%s)) / 3600 + 1 ))h"
jq -r 'select(.DownstreamStatus == 403)
| select(.RequestHost == "blog.insanegenius.com" or .RequestHost == "viljoen.family")
| .ClientHost' window.jsonl | sort -u > blocked.txt
| .ClientHost | split(",") | last | ltrimstr(" ")' window.jsonl | sort -u > blocked.txt
ssh "$VPS_SSH_HOST" "docker exec crowdsec cscli alerts list --since $since -l 0 -o raw" |
cut -d, -f3 | sort -u > alerted.txt
ssh "$VPS_SSH_HOST" 'docker exec crowdsec cscli decisions list -a -l 0 -o raw' |
Expand Down
2 changes: 2 additions & 0 deletions checks/log-review.jq
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ select(.["request_X-Blog-Check"] == null)
| select(.RequestHost == $blog or .RequestHost == $family)
| select(.DownstreamStatus == 404)
| select(scanner | not)
# Behind a proxy ClientHost is the forwarded chain, and its last element is the address Cloudflare saw.
| .ClientHost |= (split(",") | last | ltrimstr(" "))
15 changes: 15 additions & 0 deletions deploy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
}

route {
# Explicit lifetimes replace whatever heuristic a browser or an edge cache would apply, so a deploy shows at once.
# The baseline runs first so a redirect carries it too, and the file classes below override it.
header Cache-Control "no-cache"

redir @post_id {by_id} 301

# WordPress served every feed under a type suffix too, so dropping it hands the address to the bare feed's rule.
Expand Down Expand Up @@ -130,6 +134,12 @@
redir @mapped {mapped} 301
redir @mapped_slash {mapped_slash} 301

@fingerprinted path /assets/*
header @fingerprinted Cache-Control "public, max-age=31536000, immutable"
# An hour bounds how long a replaced image is still served from any copy.
@media path /media/* /*.png /*.ico
header @media Cache-Control "public, max-age=3600"

# The proxy forwards Accept-Encoding unchanged and adds no compression of its own.
# Serving the precompressed siblings here is what reaches the client.
file_server {
Expand All @@ -138,6 +148,8 @@
}

handle_errors {
# A missing file in a cached class would otherwise keep that class's lifetime.
header Cache-Control "no-cache"
rewrite * /404.html
file_server
}
Expand Down Expand Up @@ -168,6 +180,8 @@ http://viljoen.family:8080, http://viljoen.vps.insanegenius.net:8080 {$FAMILY_SI
header @svg Cache-Control "public, max-age=604800"
@code path *.css *.js
header @code Cache-Control "no-cache"
@page not path *.svg *.css *.js
header @page Cache-Control "no-cache"

# The root follows the browser's first language, and /en/ and /af/ never redirect, so the language switch always holds.
@af_first {
Expand All @@ -186,6 +200,7 @@ http://viljoen.family:8080, http://viljoen.vps.insanegenius.net:8080 {$FAMILY_SI

# A single-page site has nowhere better to send a stray path than the page itself.
handle_errors {
header Cache-Control "no-cache"
@af_page path /af/*
handle @af_page {
rewrite * /af/index.html
Expand Down
20 changes: 20 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,26 @@ variable would hold both at the stricter value. Set both to `noindex, nofollow`
container, since neither falls back to the other.
No check reads `X-Robots-Tag`, so a missing value shows only in the served header.

## Cache lifetimes

Every file the blog serves, and its error page, names its own lifetime. A browser and an edge cache
then behave the same with or without a caching proxy in front. Without a lifetime a browser guesses
from `Last-Modified`, and an edge cache applies a default by file extension. Neither guess is
bounded by anything this repository controls.

| Class | `Cache-Control` | Why |
| --- | --- | --- |
| Pages, feeds, the sitemap, `index.json`, `robots.txt`, and every other path | `no-cache` | A copy may be kept but is revalidated on every use, so a deploy shows at once |
| `/assets/`, the fingerprinted stylesheet and script | `public, max-age=31536000, immutable` | The name changes with the content, so a copy is never stale |
| `/media/` and the root icons | `public, max-age=3600` | An image rarely changes, and an hour bounds how long a replaced one is still served from any copy |

A `404` answers with `no-cache` whatever its path, since a missing file in a cached class would
otherwise keep that class's lifetime. The blog's redirects answer `no-cache` too, since the
baseline header runs before them. A map entry a release changes is then followed at the next
request. The family site keeps its own, shorter list in its block, and its error page answers
`no-cache` the same way. Its language redirects answer `no-cache` as well, because the `@page`
matcher reaches them.

## Trusting the proxy

A proxy fronts Caddy in every environment, so the peer address is always the proxy and the real
Expand Down
Loading