From f92f3b5996b306d63b44ea7fc72593480f3c77cf Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 18:42:24 -0700 Subject: [PATCH 1/6] Defeat the Edge Cache in the Media Check and Name the Zone Settings The live check asks for each media file with a per-run query, on the first request and on the legacy hop, so an edge copy cannot answer for a file a release lost. Page classes gain no-transform, which opts the bundle out of Cloudflare's content rewrites whatever the zone enables. deploy/README.md names the Browser Cache TTL and Caching Level the lifetimes depend on, and OPERATIONS.md corrects the robots.txt default and says client_ip is client-chosen behind Cloudflare. Co-Authored-By: Claude Opus 5.5 --- OPERATIONS.md | 4 ++-- checks/check-live-urls.sh | 13 +++++++++++-- checks/tests/test_check_live_urls_sample.py | 19 ++++++++++++++++++- deploy/Caddyfile | 9 +++++---- deploy/README.md | 18 +++++++++++++++++- 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index 28b8b9a..dbe888f 100644 --- a/OPERATIONS.md +++ b/OPERATIONS.md @@ -290,9 +290,9 @@ 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. +**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 caches no HTML or JSON by default, and XML and text are not among its cached extensions. Every real-content `404` therefore still reaches Traefik. `robots.txt` is the one exception Cloudflare caches by default, and its `no-cache` answer keeps it from being stored. 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. +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. The line is not 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. The inward pass then cannot distinguish a reader from a health check. That holds only where Cloudflare does not proxy the hostname. Behind Cloudflare the forwarded chain can start with an address the client wrote. Caddy reads the chain from the left, so `client_ip` is then whatever the client chose. Nothing in the Caddyfile matches on it, so nothing is exposed. On a proxied hostname, read the reader from the last element of `ClientHost` in the edge log instead. ### Reading a 404 list without being fooled by it diff --git a/checks/check-live-urls.sh b/checks/check-live-urls.sh index 5dce9bb..463ebdc 100755 --- a/checks/check-live-urls.sh +++ b/checks/check-live-urls.sh @@ -405,6 +405,10 @@ check_render() { [ "$code" = "200" ] || echo "render $url expected 200, got $code" >>"$FAILED" } +# A caching proxy may answer a media URL from its copy for the file's lifetime, so a file a release lost would still pass. +# The edge's cache key includes the query string and the file server ignores it, so a query no earlier run sent reaches the origin. +CACHE_BUST="live-check=$(date +%s)-$$" + # Invoked indirectly, the same way as check_render above. # shellcheck disable=SC2329 # The build gate proves the media SET against files on disk. @@ -419,7 +423,7 @@ check_media() { # The redirect URL gets a line of its own, because an empty one would let read shift the type into its place. local format='%{http_code} %{size_download}\n%{redirect_url}\n%{content_type}\n' # Command substitution rather than `read < <(...)`, because process substitution discards curl's exit status. - out=$(curl_retry -q -s -o /dev/null -w "$format" --max-time 30 "${auth[@]}" "$BASE$url") || rc=$? + out=$(curl_retry -q -s -o /dev/null -w "$format" --max-time 30 "${auth[@]}" "$BASE$url?$CACHE_BUST") || rc=$? { read -r code len read -r target @@ -446,6 +450,11 @@ check_media() { esac fi what="media $url -> $target" + # The rule drops the query, so the hop needs its own. + case "$target" in + *\?*) target="$target&$CACHE_BUST" ;; + *) target="$target?$CACHE_BUST" ;; + esac rc=0 out=$(curl_retry -q -s -o /dev/null -w "$format" --max-time 30 "${target_auth[@]}" "$target") || rc=$? { @@ -524,7 +533,7 @@ check_redirect() { } export -f curl_retry transfer_failure check_render check_redirect check_media -export BASE FAILED CURLRC CHECKRC SAMPLE +export BASE FAILED CURLRC CHECKRC SAMPLE CACHE_BUST echo "==> $BASE" diff --git a/checks/tests/test_check_live_urls_sample.py b/checks/tests/test_check_live_urls_sample.py index 1cc459d..87bbd1e 100644 --- a/checks/tests/test_check_live_urls_sample.py +++ b/checks/tests/test_check_live_urls_sample.py @@ -189,7 +189,9 @@ class Handler(http.server.BaseHTTPRequestHandler): def do_GET(self) -> None: self.requested.append(self.path) if self.path.startswith("/wp-content/uploads/"): - self.answer(301, location="/media/" + self.path.split("/uploads/", 1)[1]) + # Caddy's rule drops the query, as here. + path = self.path.split("?", 1)[0] + self.answer(301, location="/media/" + path.split("/uploads/", 1)[1]) elif self.path.startswith(("/media/", "/external/")): self.answer(200, body=b"\x89PNG", content_type="image/png") elif self.path in self.redirects: @@ -297,6 +299,21 @@ def test_full_run_is_the_default_and_follows_every_redirect(self) -> None: self.assertIn(DESTINATION, requested) self.assertEqual(non_static(requested), listed | {"/", DESTINATION}) + def test_media_requests_carry_a_query_no_earlier_run_sent(self) -> None: + tokens = [] + for _ in range(2): + with MockSite() as site: + result = run(SCRIPT, site.base) + requested = list(site.requested) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + media = [p for p in requested if p not in non_static(requested)] + hops = [p for p in media if p.startswith("/media/")] + self.assertTrue(hops) + found = {re.findall(r"live-check=([^&]+)", p)[-1] for p in media} + self.assertEqual(len(found), 1, media) + tokens.append(found.pop()) + self.assertNotEqual(tokens[0], tokens[1]) + if __name__ == "__main__": unittest.main() diff --git a/deploy/Caddyfile b/deploy/Caddyfile index c02835b..d5736bb 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -75,7 +75,8 @@ 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" + # The no-transform directive opts every page out of an edge's content rewrites, whatever the zone enables. + header Cache-Control "no-cache, no-transform" redir @post_id {by_id} 301 @@ -149,7 +150,7 @@ handle_errors { # A missing file in a cached class would otherwise keep that class's lifetime. - header Cache-Control "no-cache" + header Cache-Control "no-cache, no-transform" rewrite * /404.html file_server } @@ -181,7 +182,7 @@ http://viljoen.family:8080, http://viljoen.vps.insanegenius.net:8080 {$FAMILY_SI @code path *.css *.js header @code Cache-Control "no-cache" @page not path *.svg *.css *.js - header @page Cache-Control "no-cache" + header @page Cache-Control "no-cache, no-transform" # The root follows the browser's first language, and /en/ and /af/ never redirect, so the language switch always holds. @af_first { @@ -200,7 +201,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" + header Cache-Control "no-cache, no-transform" @af_page path /af/* handle @af_page { rewrite * /af/index.html diff --git a/deploy/README.md b/deploy/README.md index e32d719..b547c48 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -280,7 +280,7 @@ 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 | +| Pages, feeds, the sitemap, `index.json`, `robots.txt`, and every other path | `no-cache, no-transform` | 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 | @@ -291,6 +291,22 @@ request. The family site keeps its own, shorter list in its block, and its error `no-cache` the same way. Its language redirects answer `no-cache` as well, because the `@page` matcher reaches them. +`no-transform` keeps an edge from rewriting a page. Cloudflare's Email Address Obfuscation is on +by default on a new zone, and it skips a response carrying the directive. The bundle therefore +opts out whatever the zone sets. It also stops Cloudflare changing a response's compression, which costs nothing here, +since Caddy already serves the precompressed siblings. + +**Two zone settings decide whether these lifetimes hold behind Cloudflare.** Both are the host +side's to set. + +- **Browser Cache TTL must be "Respect Existing Headers".** A new zone's default is 4 hours. + Cloudflare replaces an origin lifetime shorter than that setting with the setting. A browser + would then keep a replaced image for 4 hours rather than one. +- **Caching Level must not be "Ignore Query String".** `check-live-urls.sh` asks for each media + file with a query no earlier run sent, so the edge's copy cannot answer for a file a release + lost. The default level, Standard, keys the cache on the query string. Ignore Query String + would answer from the copy again. + ## Trusting the proxy A proxy fronts Caddy in every environment, so the peer address is always the proxy and the real From a3789c5f73f2c5e206bca7a21fbed4e06ab59434 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 18:45:05 -0700 Subject: [PATCH 2/6] Write the Cache Lifetimes Section One Paragraph per Line Co-Authored-By: Claude Opus 5.5 --- deploy/README.md | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/deploy/README.md b/deploy/README.md index b547c48..4caf253 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -273,10 +273,7 @@ No check reads `X-Robots-Tag`, so a missing value shows only in the served heade ## 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. +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 | | --- | --- | --- | @@ -284,28 +281,14 @@ bounded by anything this repository controls. | `/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. - -`no-transform` keeps an edge from rewriting a page. Cloudflare's Email Address Obfuscation is on -by default on a new zone, and it skips a response carrying the directive. The bundle therefore -opts out whatever the zone sets. It also stops Cloudflare changing a response's compression, which costs nothing here, -since Caddy already serves the precompressed siblings. - -**Two zone settings decide whether these lifetimes hold behind Cloudflare.** Both are the host -side's to set. - -- **Browser Cache TTL must be "Respect Existing Headers".** A new zone's default is 4 hours. - Cloudflare replaces an origin lifetime shorter than that setting with the setting. A browser - would then keep a replaced image for 4 hours rather than one. -- **Caching Level must not be "Ignore Query String".** `check-live-urls.sh` asks for each media - file with a query no earlier run sent, so the edge's copy cannot answer for a file a release - lost. The default level, Standard, keys the cache on the query string. Ignore Query String - would answer from the copy again. +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. + +`no-transform` keeps an edge from rewriting a page. Cloudflare's Email Address Obfuscation is on by default on a new zone, and it skips a response carrying the directive. The bundle therefore opts out whatever the zone sets. It also stops Cloudflare changing a response's compression, which costs nothing here, since Caddy already serves the precompressed siblings. + +**Two zone settings decide whether these lifetimes hold behind Cloudflare.** Both are the host side's to set. + +- **Browser Cache TTL must be "Respect Existing Headers".** A new zone's default is 4 hours. Cloudflare replaces an origin lifetime shorter than that setting with the setting. A browser would then keep a replaced image for 4 hours rather than one. +- **Caching Level must not be "Ignore Query String".** `check-live-urls.sh` asks for each media file with a query no earlier run sent, so the edge's copy cannot answer for a file a release lost. The default level, Standard, keys the cache on the query string. Ignore Query String would answer from the copy again. ## Trusting the proxy From f99a790c44ea86b8a6d27ac804c31aff05d28df7 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 18:50:56 -0700 Subject: [PATCH 3/6] Serve the Blog's Error Page Precompressed and Name the Page Value Co-Authored-By: Claude Opus 5.5 --- checks/tests/test_check_live_urls_sample.py | 5 +++-- deploy/Caddyfile | 4 +++- deploy/README.md | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/checks/tests/test_check_live_urls_sample.py b/checks/tests/test_check_live_urls_sample.py index 87bbd1e..6adfb07 100644 --- a/checks/tests/test_check_live_urls_sample.py +++ b/checks/tests/test_check_live_urls_sample.py @@ -307,8 +307,9 @@ def test_media_requests_carry_a_query_no_earlier_run_sent(self) -> None: requested = list(site.requested) self.assertEqual(result.returncode, 0, result.stdout + result.stderr) media = [p for p in requested if p not in non_static(requested)] - hops = [p for p in media if p.startswith("/media/")] - self.assertTrue(hops) + self.assertTrue(any(p.startswith("/wp-content/") for p in media)) + for p in media: + self.assertRegex(p, r"live-check=", p) found = {re.findall(r"live-check=([^&]+)", p)[-1] for p in media} self.assertEqual(len(found), 1, media) tokens.append(found.pop()) diff --git a/deploy/Caddyfile b/deploy/Caddyfile index d5736bb..e5386fa 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -152,7 +152,9 @@ # A missing file in a cached class would otherwise keep that class's lifetime. header Cache-Control "no-cache, no-transform" rewrite * /404.html - file_server + file_server { + precompressed br gzip + } } log { diff --git a/deploy/README.md b/deploy/README.md index 4caf253..8bd23c9 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -281,9 +281,9 @@ Every file the blog serves, and its error page, names its own lifetime. A browse | `/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. +A `404` answers with the page value, `no-cache, no-transform`, whatever its path, since a missing file in a cached class would otherwise keep that class's lifetime. The blog's redirects answer with it 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 the same way. Its language redirects carry it as well, because the `@page` matcher reaches them. -`no-transform` keeps an edge from rewriting a page. Cloudflare's Email Address Obfuscation is on by default on a new zone, and it skips a response carrying the directive. The bundle therefore opts out whatever the zone sets. It also stops Cloudflare changing a response's compression, which costs nothing here, since Caddy already serves the precompressed siblings. +`no-transform` keeps an edge from rewriting a page. Cloudflare's Email Address Obfuscation is on by default on a new zone, and it skips a response carrying the directive. The bundle therefore opts out whatever the zone sets. It also stops Cloudflare changing a response's compression, which costs nothing here, since Caddy serves the precompressed siblings of every page, the error page included. **Two zone settings decide whether these lifetimes hold behind Cloudflare.** Both are the host side's to set. From c479d24e73a7efa5d14910b9b633540121a6e880 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 18:58:03 -0700 Subject: [PATCH 4/6] Bust the Media Cache One Way and Qualify client_ip in the README Co-Authored-By: Claude Opus 5.5 --- checks/check-live-urls.sh | 5 +---- deploy/README.md | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/checks/check-live-urls.sh b/checks/check-live-urls.sh index 463ebdc..a3e77dc 100755 --- a/checks/check-live-urls.sh +++ b/checks/check-live-urls.sh @@ -451,10 +451,7 @@ check_media() { fi what="media $url -> $target" # The rule drops the query, so the hop needs its own. - case "$target" in - *\?*) target="$target&$CACHE_BUST" ;; - *) target="$target?$CACHE_BUST" ;; - esac + target="$target?$CACHE_BUST" rc=0 out=$(curl_retry -q -s -o /dev/null -w "$format" --max-time 30 "${target_auth[@]}" "$target") || rc=$? { diff --git a/deploy/README.md b/deploy/README.md index 8bd23c9..413e28d 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -296,6 +296,8 @@ A proxy fronts Caddy in every environment, so the peer address is always the pro client arrives in `X-Forwarded-For`. `trusted_proxies` is what makes Caddy believe it. Without it, `client_ip` and `remote_ip` are both the proxy and the forwarded header has no effect at all. +Behind Cloudflare the forwarded chain can start with an address the client wrote. Caddy reads the chain from the left, so `client_ip` is then whatever the client chose. Nothing in the Caddyfile matches on it, and [`OPERATIONS.md`](../OPERATIONS.md#the-log-is-three-tiers-and-each-is-blind-to-something) names the field to read instead. + **The CIDRs come from the container, not the bundle.** The same artifact runs on hosts whose docker subnets differ, so any literal in the bundle is wrong on one of them. From f31c0c5f4150dddc1bb250fd8854fcbe34100688 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 19:36:46 -0700 Subject: [PATCH 5/6] Drop no-transform Until Its Effect on Compression Is Measured Co-Authored-By: Claude Opus 5.5 --- deploy/Caddyfile | 9 ++++----- deploy/README.md | 6 ++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/deploy/Caddyfile b/deploy/Caddyfile index e5386fa..88cf259 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -75,8 +75,7 @@ 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. - # The no-transform directive opts every page out of an edge's content rewrites, whatever the zone enables. - header Cache-Control "no-cache, no-transform" + header Cache-Control "no-cache" redir @post_id {by_id} 301 @@ -150,7 +149,7 @@ handle_errors { # A missing file in a cached class would otherwise keep that class's lifetime. - header Cache-Control "no-cache, no-transform" + header Cache-Control "no-cache" rewrite * /404.html file_server { precompressed br gzip @@ -184,7 +183,7 @@ http://viljoen.family:8080, http://viljoen.vps.insanegenius.net:8080 {$FAMILY_SI @code path *.css *.js header @code Cache-Control "no-cache" @page not path *.svg *.css *.js - header @page Cache-Control "no-cache, no-transform" + 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 { @@ -203,7 +202,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, no-transform" + header Cache-Control "no-cache" @af_page path /af/* handle @af_page { rewrite * /af/index.html diff --git a/deploy/README.md b/deploy/README.md index 413e28d..e7d2fb5 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -277,13 +277,11 @@ Every file the blog serves, and its error page, names its own lifetime. A browse | Class | `Cache-Control` | Why | | --- | --- | --- | -| Pages, feeds, the sitemap, `index.json`, `robots.txt`, and every other path | `no-cache, no-transform` | A copy may be kept but is revalidated on every use, so a deploy shows at once | +| 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 the page value, `no-cache, no-transform`, whatever its path, since a missing file in a cached class would otherwise keep that class's lifetime. The blog's redirects answer with it 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 the same way. Its language redirects carry it as well, because the `@page` matcher reaches them. - -`no-transform` keeps an edge from rewriting a page. Cloudflare's Email Address Obfuscation is on by default on a new zone, and it skips a response carrying the directive. The bundle therefore opts out whatever the zone sets. It also stops Cloudflare changing a response's compression, which costs nothing here, since Caddy serves the precompressed siblings of every page, the error page included. +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. **Two zone settings decide whether these lifetimes hold behind Cloudflare.** Both are the host side's to set. From 61ded162576600c6f5d0ce5c0a1617ca3f6acdea Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 19:50:40 -0700 Subject: [PATCH 6/6] Use Reference Links in the Deploy README and Say no-cache Revalidates Co-Authored-By: Claude Opus 5.5 --- OPERATIONS.md | 2 +- deploy/README.md | 36 +++++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index dbe888f..938eb05 100644 --- a/OPERATIONS.md +++ b/OPERATIONS.md @@ -290,7 +290,7 @@ 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 caches no HTML or JSON by default, and XML and text are not among its cached extensions. Every real-content `404` therefore still reaches Traefik. `robots.txt` is the one exception Cloudflare caches by default, and its `no-cache` answer keeps it from being stored. 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. +**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 caches no HTML or JSON by default, and XML and text are not among its cached extensions. Every real-content `404` therefore still reaches Traefik. `robots.txt` is the one exception Cloudflare caches by default, and its `no-cache` answer has any copy revalidated before use. 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. The line is not 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. The inward pass then cannot distinguish a reader from a health check. That holds only where Cloudflare does not proxy the hostname. Behind Cloudflare the forwarded chain can start with an address the client wrote. Caddy reads the chain from the left, so `client_ip` is then whatever the client chose. Nothing in the Caddyfile matches on it, so nothing is exposed. On a proxied hostname, read the reader from the last element of `ClientHost` in the edge log instead. diff --git a/deploy/README.md b/deploy/README.md index e7d2fb5..d2305ea 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -26,7 +26,7 @@ macOS or Windows contributor runs them through a container or a remote Linux hos **`brotli` is easy to miss and degrades silently.** The Caddyfile serves `precompressed br gzip`, so without the binary every text response falls back to gzip while the site keeps working and nothing errors. `make-release.sh` warns loudly when it is absent, and `REQUIRE_BROTLI=1` turns that into a hard failure. **CI must set it.** Measured on the home page: 18,845 bytes raw, 6,395 gzip, 5,105 brotli. -[`capture/build-redirects.py`](../capture/build-redirects.py) additionally needs the capture directory holding the source export, which is not in this repo. It runs by hand rather than in CI, and its outputs under `deploy/maps/` are committed. +[`capture/build-redirects.py`][capture-build-redirects] additionally needs the capture directory holding the source export, which is not in this repo. It runs by hand rather than in CI, and its outputs under `deploy/maps/` are committed. ## Container contract @@ -43,14 +43,14 @@ neither. Seven facts are the whole contract: 4. Caddy binds `:8080`, plain HTTP, with `admin off` and `auto_https off`. TLS and the public listener belong to the fronting proxy. 5. Caddy runs with **`--watch`**. This is not optional. See - [Reloading without a restart](#reloading-without-a-restart). + [Reloading without a restart][reloading-without-a-restart]. 6. The release tree is world-readable and world-traversable, so any uid can serve it. 7. The container sets `SITE_ENV`, which the bundle stamps on every response as `X-Blog-Env`. It sets `SITE_ROBOTS`, stamped as `X-Robots-Tag` on the blog, and `FAMILY_SITE_ROBOTS`, stamped as `X-Robots-Tag` on the family site. It sets `TRUSTED_PROXIES`, and a local mirror also sets - `FAMILY_SITE_ADDRESS`. See [Identifying the environment](#identifying-the-environment), - [Trusting the proxy](#trusting-the-proxy), and - [Serving the family site on a local name](#serving-the-family-site-on-a-local-name). + `FAMILY_SITE_ADDRESS`. See [Identifying the environment][identifying-the-environment], + [Trusting the proxy][trusting-the-proxy], and + [Serving the family site on a local name][serving-the-family-site-on-a-local-name]. ## Building a release @@ -63,7 +63,7 @@ EXPECT_RELEASE="$RELEASE" checks/check-live-urls.sh "$SITE_BASE_URL" ``` The deploy root and the base URL are the only host-specific values, and they pair per -environment. Copy [`example.env`](../.secrets/example.env) to `~/.secrets/blog.local.production.env`, which is the +environment. Copy [`example.env`][example-env] to `~/.secrets/blog.local.production.env`, which is the file read when `ENV_FILE` is unset, and add `~/.secrets/blog...env` for each further environment. A single environment therefore needs `~/.secrets/blog.local.production.env` and nothing else, since a differently named file is read only when `ENV_FILE` names it. The real files @@ -168,7 +168,7 @@ Production's deploy sets it, and so does a hand run against the VPS production s more than 40 distinct pages in a burst. It also bans one when more than 10 distinct pages answer `404`, `403` or `400` in a short window. Images, CSS and JS count toward neither. The whole contract is over 1,200 URLs. The sample takes one URL from each redirect class in -[How the redirects are expressed](#how-the-redirects-are-expressed). It adds one from each shape +[How the redirects are expressed][how-the-redirects-are-expressed]. It adds one from each shape of page that must render, one from each media tree, and the three family pages. It also adds `/all/`, `/feed.xml`, and `/sitemap.xml`, the fixed redirect destinations no list names. Before its first request, the script asserts that this stays within 30 distinct pages across both hosts. An @@ -294,7 +294,7 @@ A proxy fronts Caddy in every environment, so the peer address is always the pro client arrives in `X-Forwarded-For`. `trusted_proxies` is what makes Caddy believe it. Without it, `client_ip` and `remote_ip` are both the proxy and the forwarded header has no effect at all. -Behind Cloudflare the forwarded chain can start with an address the client wrote. Caddy reads the chain from the left, so `client_ip` is then whatever the client chose. Nothing in the Caddyfile matches on it, and [`OPERATIONS.md`](../OPERATIONS.md#the-log-is-three-tiers-and-each-is-blind-to-something) names the field to read instead. +Behind Cloudflare the forwarded chain can start with an address the client wrote. Caddy reads the chain from the left, so `client_ip` is then whatever the client chose. Nothing in the Caddyfile matches on it, and [`OPERATIONS.md`][operations-log-tiers] names the field to read instead. **The CIDRs come from the container, not the bundle.** The same artifact runs on hosts whose docker subnets differ, so any literal in the bundle is wrong on one of them. @@ -370,7 +370,7 @@ The Caddyfile carries **16 `redir` directives**, reading **5 map files** through Directives and URL classes are not one to one, in both directions. `@mapped` is a single directive serving four classes, because their key spaces are disjoint and merging them keeps those four classes to one lookup. `@uploads` is one directive covering a URL set that is gated separately. -Each row below is a **URL class**, named by the matcher that serves it, so the table can be checked against [`Caddyfile`](./Caddyfile) by grep rather than by trust. +Each row below is a **URL class**, named by the matcher that serves it. The table can then be checked against [`Caddyfile`][caddyfile] by grep rather than by trust. Every class below is a legacy shape, closed by the migration, so no count here moves when content is added. New content is served by the render half of the contract, never by these. @@ -394,7 +394,7 @@ Every class below is a legacy shape, closed by the migration, so no count here m | `@blogger_page` | 2 | `/p/.html` -> `//`, Blogger's static-page shape | | `@feed_type` | 2 | a WordPress post, attachment, term, author, site, comments, or about feed at `/feed/atom/`, `/feed/rss/`, `/feed/rss2/` or `/feed/rdf/` -> the same feed at `/feed/`, which another row resolves | -**Those seventeen classes account for every line in [`checks/redirect-urls.txt`](../checks/redirect-urls.txt), with nothing in the contract outside the table.** Completeness is the property worth holding, and the list's line count is how to check it. `check-live-urls.sh` classifies the list by the same rows to sample production. A unit test holds each class's count to the size column above, so a new row needs a new class there. +**Those seventeen classes account for every line in [`checks/redirect-urls.txt`][checks-redirect-urls], with nothing in the contract outside the table.** Completeness is the property worth holding, and the list's line count is how to check it. `check-live-urls.sh` classifies the list by the same rows to sample production. A unit test holds each class's count to the size column above, so a new row needs a new class there. `@uploads` is deliberately absent from that table and from the redirect contract. It rewrites `/wp-content/uploads/(.*)` to `/media/$1`, preserving all 778 legacy image URLs, which are gated by `golden-media-legacy.txt` on their own. Counting them here would double-count a set that has its own list. @@ -402,7 +402,7 @@ Every class below is a legacy shape, closed by the migration, so no count here m Two orderings are load-bearing. `@post_child_feed` precedes `@post_child` because both match the same shape and the broader one would claim both. No golden URL is five segments under a date, so `@post_child` cannot swallow a page that must render, and `@uploads` rewrites under a prefix no rendered page occupies. -`blogger.map` carries more entries than there are Blogger-era posts, because that platform served a long title at a truncated address and both forms answer. A few addresses Blogger served, or the contract lists, match neither form. The mechanism is in [`capture/README.md`](../capture/README.md), beside the generator that implements it. `slugs.map` is generated by [`capture/build-redirects.py`](../capture/build-redirects.py), which recovers each attachment's parent from the media inventory, since each has `post_parent = 0` in the export. 85 entries resolve to a real post, and 21 go to `/` because nothing on the site claims them. The generator gives the rest a fixed destination. +`blogger.map` carries more entries than there are Blogger-era posts, because that platform served a long title at a truncated address and both forms answer. A few addresses Blogger served, or the contract lists, match neither form. The mechanism is in [`capture/README.md`][capture-readme], beside the generator that implements it. `slugs.map` is generated by [`capture/build-redirects.py`][capture-build-redirects], which recovers each attachment's parent from the media inventory, since each has `post_parent = 0` in the export. 85 entries resolve to a real post, and 21 go to `/` because nothing on the site claims them. The generator gives the rest a fixed destination. **Two shapes in the Caddyfile look wrong and are correct.** The `map` on `{re.label.1}` sits outside `route`, before the matcher that sets that placeholder runs. A map resolves lazily, when a directive reads its output, so it sees the matched request. And `handle_errors` rewrites to `/404.html` and serves it with `file_server`, which keeps the error's `404` status rather than answering `200`. @@ -421,3 +421,17 @@ Each of these fails silently when it fails, which is why it is checked rather th disk-full outage later. `umask 022` is pinned because the release and staging directories come from `mkdir` rather than rsync and would otherwise inherit the caller's umask. Under `umask 077` they land 700, and Caddy cannot then traverse into the release at all. + + + +[caddyfile]: ./Caddyfile +[capture-build-redirects]: ../capture/build-redirects.py +[capture-readme]: ../capture/README.md +[checks-redirect-urls]: ../checks/redirect-urls.txt +[example-env]: ../.secrets/example.env +[how-the-redirects-are-expressed]: #how-the-redirects-are-expressed +[identifying-the-environment]: #identifying-the-environment +[operations-log-tiers]: ../OPERATIONS.md#the-log-is-three-tiers-and-each-is-blind-to-something +[reloading-without-a-restart]: #reloading-without-a-restart +[serving-the-family-site-on-a-local-name]: #serving-the-family-site-on-a-local-name +[trusting-the-proxy]: #trusting-the-proxy