Cloudflare edge: zone settings, rate limit and headers
Edge configuration that Cloudflare holds for a zone lives in this repo, in
cloudflare/zones/<zone>.json, and goes live with cloudflare/apply.py.
Argo CD does not apply it: you run the script by hand after the PR is merged.
Tunnel ingress (hostname → service) is not in this file. It stays remotely
managed per tunnel, see cluster-config/infra/*/tunnel.yaml.
What is in a zone file
| Key | What apply.py does |
|---|---|
settings | PATCH /zones/<id>/settings/<id> when the live value differs |
rulesets | per phase, the zone entrypoint holds exactly the rules in the file (PUT replaces it). A rule added in the dashboard in one of these phases disappears on the next --apply, so add it to the file instead |
dns | creates a missing record (same type, name and content), fixes proxied/ttl/priority. A changed content patches the live record instead of adding a second one: always for CNAME and SPF/DMARC/DKIM TXT, for A/AAAA only with --replace (without it the script refuses, so traffic is never split over two origins). It lists records that are in the zone but not in the file and never deletes them |
Run it
set -a; . ~/.config/cloudflare/worldofnines.env; set +a # see "Token" below
cd ~/homelab
python3 cloudflare/apply.py cloudflare/zones/westerweel.work.json # plan only
python3 cloudflare/apply.py cloudflare/zones/westerweel.work.json --apply # then the plan must say 0 changes
The script never prints the token.
Token. It needs, on the zones it manages: Zone Settings Edit, Zone WAF Edit
(rate limiting), Transform Rules Edit, Cache Rules Edit (http_request_cache_settings),
DNS Edit and Zone Read; for --create-zone also Zone Edit on the account plus
CLOUDFLARE_ACCOUNT_ID. On 2026-11-30 the only such token is the one in
~/.config/cloudflare/worldofnines.env (0600, not in git), valid until
2026-12-05. A lasting token with these permissions has to come from Mark. Keep
it in that file or next to it, and in OpenBao under kv/westerweel/ like the
other keys (key-backups). The read-only token in read.env
can see the rules but cannot change them.
westerweel.work: what is set and why
Rate limit on the OIDC token endpoint (phase http_ratelimit, the one
rule the Free plan allows): paths containing /protocol/openid-connect/token,
at most 4 requests per 10 seconds per client IP and Cloudflare colo. The 5th
gets a 429 for 10 seconds. Keycloak's own brute-force detection only locks a
user. This rule slows a password spray across many usernames from one
address. The security report's check kc-edge-rate-limit sends 5 wrong
grants at one per second and expects a 429.
Free-plan limits: the period and the block time are fixed at 10 s, and the
counter is per IP and colo. contains on the path is accepted. Note that the
cluster's own token calls also come from the home IP: oauth2-proxy (Wordsworth)
and Wanderer redeem codes at iam.westerweel.work. With a handful of users that
stays far under 4 per 10 s. If logins start failing with 429 at busy moments,
raise requests_per_period first.
Response headers (phase http_response_headers_transform):
iam,wordsworth,wanderer,api:Permissions-Policyonly. The apps already send CSP,X-Content-Type-Options,Referrer-Policyand framing headers themselves. The policy turns off camera, microphone, geolocation, motion sensors, payment and USB. It leavespublickey-credentials-*alone so WebAuthn keeps working in Keycloak. The rule sets the header, so aPermissions-Policyan app adds later is overwritten here. Change it here.convergence, the static site (everything except/play-rpg*and/parties/): the full set with a same-origin-only CSP. The site loadsstyles.css,config.jsandmain.jsand nothing else.convergenceRPG demo (/play-rpg*,/parties/): it loads Google Fonts, has an inline<style>and talks to a devnet wallet, so its CSP only covers framing, plugins and<base>(frame-ancestors 'self'; object-src 'none'; base-uri 'self'), plus the other headers. A stricter CSP belongs in the convergence repo'sdeploy/nginx.conf, together with the game's code.
Checked after applying on 2026-11-30: the header check of the security report finds nothing missing on these five hosts, and both convergence pages load in headless Chromium without CSP violations.
Not possible on Free: the TLS 1.2 cipher list. The ciphers setting
needs Advanced Certificate Manager (code 1023). The decision is homelab#106.
Until then the gap is accepted in the security report.