Repository navigation
feat: manage bot WAF rules in terraform and upsize the prod database - #1601
Merged
Merged
Conversation
Codify the custom WAF rules on the production zone, which were added in the dashboard while a headless-browser crawl overloaded the database, and bring the Cloud SQL tier back to 4 vCPUs. The tier was raised by hand earlier and then reverted by the next terraform apply. The zone's entrypoint ruleset already exists, so it's imported. Import blocks with for_each need Terraform 1.7 or later, so CI moves to 1.9.8.
piscisaureus
had a problem deploying
to
staging
November 28, 2026 05:38 — with
GitHub Actions
Failure
* Import into cloudflare_ruleset.custom_firewall[0]; import targets can't call functions * Set each rule's ref to its current ID so rule IDs stay stable * Guard the ruleset with prevent_destroy * Match Mastodon's older http.rb-first user agent too * Correct the comment on which requests the rules match
piscisaureus
had a problem deploying
to
staging
November 28, 2026 05:45 — with
GitHub Actions
Failure
Contributor
Author
|
Live incident, landing without review |
CaffeeLake
pushed a commit
to CaffeeLake/jsr
that referenced
this pull request
Nov 30, 2026
…o#1597) Most HTML traffic on jsr.io is unverified automation: about 3M requests a day with a bot score under 30, against roughly 0.4M from likely humans. The scrapers spread across thousands of IPs, so the busiest single IP makes about 16 page requests a minute and never trips the per-IP Worker limits. This builds on the challenge rules that are already live (see jsr-io#1601), adds a challenge for scraping networks, and adds log-only rules to measure the rest of the website before anything there is challenged. Module files served from R2, api.jsr.io and npm.jsr.io are never matched. * `terraform/bots.tf`, custom rules, in evaluation order: * Log: Cloudflare's scraping detection IDs on website requests. * Log: website requests without an HTML Accept header that score under 30. The challenge rules only see `text/html` requests, so this covers what `website_requests` adds. * The two existing `managed_challenge` rules, unchanged apart from the e2e exemption below. * Challenge: page requests carrying Bot Management detection 50331656 (networks that scrape many zones), whatever their score. It catches a crawl of doc and diff pages from 1,000+ proxy and VPN IPs, at most about 11 requests each, that scores 30 or more. * `website_requests` mirrors the LB's routing: requests on jsr.io except API, login and sitemap routes, badge endpoints (shields.io fetches them server-side), the OG image route, static resources, and module-file requests the LB would serve from R2. A new test in `lb/main_test.ts` checks that the module path regex matches `isModuleFilePath`, and CI now runs the LB tests. * Rate limiting, log only: more than 20 website 404s a minute per IP and colo. The zone's plan doesn't allow JA4 as a characteristic, throttling (a mitigation timeout of 0), or request headers in rate limiting expressions, so the rule matches by path and leaves out module-file paths for every client. * The post-deploy e2e tests send an `x-jsr-e2e` header carrying the `E2E_BYPASS_TOKEN` secret, which replaces the `Deno/` user agent exemption. `e2e_bypass_token` is sensitive, so the plan shows the custom rules as `(sensitive value)`. * Removes the `@font-face` for the missing `DMMono-Bold.woff2` (about 2.3k 404s an hour) and declares the existing `DMMono-Medium.woff2` at weight 500. The LB's `FRONTEND_RATELIMIT` and `DOCS_RATELIMIT` stay for now; they can go once the WAF rules have run for a while. Bot Management settings aren't managed here: prod already has JavaScript detections and model auto-updates on. The new rules and the `http_ratelimit` entrypoint were created on the prod zone through the API with the same refs, so the first apply updates them in place. The hand-applied rules exempt `Deno/` user agents instead of the e2e header; the apply switches them over. `E2E_BYPASS_TOKEN` was reset to a hex value in both environments so it passes the variable validation. The live ruleset also has two temporary log rules measuring detection 50331656. They aren't in terraform, so applying this removes them. --------- Co-authored-by: Bert Belder <bbelder@cloudflare.com>
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
terraform/bots.tf: manages the production zone's custom WAFruleset (
http_request_firewall_custom). Staging isn't managed.header starts with
text/html: one for bot scores under 10 and forthe Lightpanda headless browser (user agent and JA4), one for
scores 10-29. The LB never serves module files to such requests,
so module downloads, the Deno CLI, and npm clients aren't matched.
The e2e tests (Deno user agent) and fediverse link-preview fetchers
are exempt.
unchanged.
now, so the apply doesn't change behavior or rule IDs.
dashboard), so it's adopted with an
importblock. The ruleset IDis set in
prod.tfvars. The resource hasprevent_destroy, sincereplacing it would delete every custom rule in the zone.
removedblock withdestroy = false. Reverting this PR as is would delete the rules.terraform/db.tf: prod Cloud SQL tierdb-custom-2-6144->db-custom-4-6144. It was raised to 4 vCPUs by hand on Nov 27 andreverted to 2 by the terraform apply on Nov 28 03:54 UTC. Changing the
tier restarts the instance (about 30-60 seconds of database downtime).
importblocks withfor_eachneed 1.7 or later.
Context: on Nov 28 01:45-02:00 UTC a distributed headless-browser crawl
pushed Hyperdrive past its origin connection limit and the site hung.
Since the challenge rules went live, challenge solve rates are
0.08-0.1% and database load is down from 140-260k to 20-50k queries
per 5 minutes.
This overlaps with #1597; that PR will need to build on
cloudflare_ruleset.custom_firewallinstead of creating its own.