From 070b7ab88368bfea9683ace92238bb73eb4206f2 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 11:35:39 -0700 Subject: [PATCH 1/2] Name a Cache Lifetime on Every Response Ahead of an Edge Proxy (#492) * Name a Cache Lifetime on Every Response Ahead of an Edge Proxy A proxy that caches by file extension sits in front of neither site today, and nothing in the bundle says how long a copy may live, so a browser guesses from Last-Modified and an edge would apply its own defaults. Every blog response now carries a Cache-Control: pages and feeds revalidate on every use, the fingerprinted assets are immutable, and media is bounded to an hour so a replaced image propagates without a purge. Both error pages answer no-cache whatever path they stand in for, and the family pages state the same. The log review keeps the last element of ClientHost, since a proxied request carries the forwarded chain there and a client may prepend any value. The operations doc names the edge as a tier above Traefik and what it hides. Verified on the local staging mirror: the live check passes, and each class serves the header the deploy README's table states. * Scope the Lifetime Claims and Name Cloudflare Where the Edge Is Meant The first strict review pass found the deploy README claiming a lifetime on every blog response while the redirects carry none, the operations doc and the jq comment using the edge for Cloudflare where that section means Traefik, the forwarded-chain claim missing the trust condition it depends on, and null guards on a field Traefik always writes. * Shorten Two Cache Lifetime Sentences and Name the Family Matcher The second strict review pass found two sentences over the length rule and a claim that the family block has a default header where the catch-all matcher is what reaches its redirects. * Run the Baseline Cache Header Ahead of the Redirects Copilot found that the redirect handlers end the route before the baseline no-cache header ran, so a 301 carried no lifetime and a changed map target could outlive a deploy in a cache. The baseline now runs first and the file classes override it. Verified on the local staging mirror: the live check passes, a legacy media redirect and a feed redirect answer no-cache, and the media and error classes keep their headers. * Place the Media Lifetime Comment Above the Rule It Explains --- OPERATIONS.md | 4 +++- checks/log-review.jq | 2 ++ deploy/Caddyfile | 15 +++++++++++++++ deploy/README.md | 20 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index d911a640..28b8b9a1 100644 --- a/OPERATIONS.md +++ b/OPERATIONS.md @@ -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 @@ -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' | diff --git a/checks/log-review.jq b/checks/log-review.jq index e64ce8f1..68e1afdc 100644 --- a/checks/log-review.jq +++ b/checks/log-review.jq @@ -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(" ")) diff --git a/deploy/Caddyfile b/deploy/Caddyfile index 3734410c..c02835b8 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -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. @@ -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 { @@ -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 } @@ -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 { @@ -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 diff --git a/deploy/README.md b/deploy/README.md index d0c2e354..e32d719b 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -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 From f35ec0809f470036a6855cde047d989df710ed9e Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Fri, 23 Oct 2026 20:01:42 -0700 Subject: [PATCH 2/2] Defeat the Edge Cache in the Media Check and Name the Zone Settings (#496) * 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 * Write the Cache Lifetimes Section One Paragraph per Line Co-Authored-By: Claude Opus 5.5 * Serve the Blog's Error Page Precompressed and Name the Page Value Co-Authored-By: Claude Opus 5.5 * Bust the Media Cache One Way and Qualify client_ip in the README Co-Authored-By: Claude Opus 5.5 * Drop no-transform Until Its Effect on Compression Is Measured Co-Authored-By: Claude Opus 5.5 * Use Reference Links in the Deploy README and Say no-cache Revalidates Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- OPERATIONS.md | 4 +- checks/check-live-urls.sh | 10 +++- checks/tests/test_check_live_urls_sample.py | 20 +++++++- deploy/Caddyfile | 4 +- deploy/README.md | 53 +++++++++++++-------- 5 files changed, 65 insertions(+), 26 deletions(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index 28b8b9a1..938eb05d 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 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 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 5dce9bb9..a3e77dcf 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,8 @@ check_media() { esac fi what="media $url -> $target" + # The rule drops the query, so the hop needs its own. + target="$target?$CACHE_BUST" rc=0 out=$(curl_retry -q -s -o /dev/null -w "$format" --max-time 30 "${target_auth[@]}" "$target") || rc=$? { @@ -524,7 +530,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 1cc459d8..6adfb07b 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,22 @@ 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)] + 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()) + self.assertNotEqual(tokens[0], tokens[1]) + if __name__ == "__main__": unittest.main() diff --git a/deploy/Caddyfile b/deploy/Caddyfile index c02835b8..88cf2592 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -151,7 +151,9 @@ # A missing file in a cached class would otherwise keep that class's lifetime. header Cache-Control "no-cache" rewrite * /404.html - file_server + file_server { + precompressed br gzip + } } log { diff --git a/deploy/README.md b/deploy/README.md index e32d719b..d2305ea8 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 @@ -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,12 +281,12 @@ 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. +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. + +- **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 @@ -297,6 +294,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-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. @@ -371,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. @@ -395,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. @@ -403,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`. @@ -422,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