fix(caddy): raise the memory cap and challenge cookieless crawlers #870

Sammanfogat
supernaut sammanfogade 2 incheckningar från fix/caddy-memory-and-crawler-edge in i main 2026-11-08 12:14:07 +00:00
Ägare

Problem

On 2026-11-08 every vhost (www, git, id) hung at the TLS handshake. A crawler hit git.bitborg.se
from more than 500 IPs with no cookies, mostly label-filtered issue and PR lists, blame and commit
diffs. No per-IP rate limit tripped.

Caddy grew to about 940 MiB. At MemoryHigh=192M the kernel throttled it 42 011 times and swapped
753 MiB to /swapfile. Caddy fronts every vhost, so all of them stalled. Forgejo, Keycloak and
Postgres stayed healthy.

Change

  • Memory: Caddy gets MemoryHigh=1G, MemoryMax=1536M and MemorySwapMax=0. An overrun now
    restarts Caddy instead of thrashing it.
  • Crawler cookie challenge on git.bitborg.se: a cookieless GET/HEAD to an expensive HTML
    page gets Set-Cookie: bitborg_human=1 and a 302 back to the same URL. Browsers pass unnoticed.
    • Challenged: src/commit/, commit/, commits/, blame/, compare/, pulls/<n>/files,
      pulls/<n>/commits, and issues/pulls lists with labels=.
    • Not challenged: raw files, archives, .diff/.patch, branch and tag views, the API, git, LFS,
      the registry, any POST.
    • Off switch: caddy_crawler_challenge_enabled: false.
  • New CI test test_crawler_challenge.sh runs the real Caddyfile block in the pinned Caddy image.
  • Runbook: memory caps table and an Edge rate limiting subsection.

Trade-offs

  • Link previews and search engines get no commit or blame pages.
  • A browser with all cookies blocked loops on those pages.

Apply

./scripts/apply-reconcile.sh -- --limit bitborg-prod --tags caddy
curl -sI https://git.bitborg.se/bitborg/bitborg-infra/blame/branch/main/README.md

Expect 302 with set-cookie: bitborg_human=1. The live runtime override on prod becomes redundant.

## Problem On 2026-11-08 every vhost (www, git, id) hung at the TLS handshake. A crawler hit `git.bitborg.se` from more than 500 IPs with no cookies, mostly label-filtered issue and PR lists, blame and commit diffs. No per-IP rate limit tripped. Caddy grew to about 940 MiB. At `MemoryHigh=192M` the kernel throttled it 42 011 times and swapped 753 MiB to `/swapfile`. Caddy fronts every vhost, so all of them stalled. Forgejo, Keycloak and Postgres stayed healthy. ## Change - **Memory:** Caddy gets `MemoryHigh=1G`, `MemoryMax=1536M` and `MemorySwapMax=0`. An overrun now restarts Caddy instead of thrashing it. - **Crawler cookie challenge** on `git.bitborg.se`: a cookieless `GET`/`HEAD` to an expensive HTML page gets `Set-Cookie: bitborg_human=1` and a 302 back to the same URL. Browsers pass unnoticed. - Challenged: `src/commit/`, `commit/`, `commits/`, `blame/`, `compare/`, `pulls/<n>/files`, `pulls/<n>/commits`, and `issues`/`pulls` lists with `labels=`. - Not challenged: raw files, archives, `.diff`/`.patch`, branch and tag views, the API, git, LFS, the registry, any `POST`. - Off switch: `caddy_crawler_challenge_enabled: false`. - New CI test `test_crawler_challenge.sh` runs the real Caddyfile block in the pinned Caddy image. - Runbook: memory caps table and an Edge rate limiting subsection. ## Trade-offs - Link previews and search engines get no commit or blame pages. - A browser with all cookies blocked loops on those pages. ## Apply ```sh ./scripts/apply-reconcile.sh -- --limit bitborg-prod --tags caddy curl -sI https://git.bitborg.se/bitborg/bitborg-infra/blame/branch/main/README.md ``` Expect `302` with `set-cookie: bitborg_human=1`. The live runtime override on prod becomes redundant.
supernaut lade till 2 incheckningar 2026-11-08 10:31:36 +00:00
A crawl from more than 500 IPs grew Caddy past MemoryHigh=192M. The kernel throttled and swapped
it, and every vhost stalled at the TLS handshake. Caddy now gets 1G / 1536M with no swap, so an
overrun restarts it instead of thrashing.

Cookieless GETs to expensive Forgejo HTML pages (commit diffs, blame, sha-pinned trees, compare,
PR files, label-filtered lists) now get a cookie and a 302 back to the same URL. Browsers pass
unnoticed. Raw files, archives, the API, git, LFS and the registry are untouched. The new test
runs the real Caddyfile block in CI.
fix(caddy): never challenge diff and patch downloads
Alla kontroller lyckades
ci / ci (pull_request) Successful in 14m26s
2cdfdfad22
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-11-08 10:33:31 +00:00
supernaut sammanfogade incheckning 1bfaa36d17 till main 2026-11-08 12:14:07 +00:00
supernaut tog bort grenen fix/caddy-memory-and-crawler-edge 2026-11-08 12:14:08 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-infra!870
Ingen beskrivning angiven.