Mitigate distributed Gitea filter-permutation crawl #720
Labels
Clear labels
monitoring
bug
design
dev environment
docs
duplicate
enhancement
feature
good first issue
idea
invalid
kredits-1
kredits-2
kredits-3
on hold
ops
question
security
ui/ux
wontfix
Infrastructure metrics, alerts, notifications, etc.
service
discourse
Kosmos Community Forums
service
accounts
Kosmos Accounts
service
drone-ci
Kosmos Drone CI
service
email
mail.kosmos.org
service
garage
S3-compatible object storage
service
gitea
Kosmos Gitea
service
ipfs
Kosmos IPFS
service
lightning
Lightning address, lndhub, etc.
service
mastodon
kosmos.social
service
nostr
Relays, Blossom server, etc.
service
postgres
Database cluster
service
remotestorage
Portable data storage for the Web
service
wiki
Kosmos Wiki
service
xmpp
Kosmos Chat
Something is not working
Graphic/visual design
Config, builds, CI, deployment, etc.
Documentation
This issue or pull request already exists
Improving existing functionality
New functionality
Dive in, and start contributing
Something to consider
Not a bug
Small contribution
Medium contribution
Large contribution
Currently not actionable
Manual IT ops activities
Looking for an answer
All your base are belong to us
User interface, process design, etc.
This won't be fixed
release
major
release
minor
release
patch
Milestone
No items
No Milestone
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: kosmos/chef#720
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Gitea was again CPU-saturated by crawler traffic. The dominant source was a distributed crawl of combinatorial issue/pull filter URLs (for example
/kosmos/chef/issues?assignee=0&labels=253,259&milestone=0&poster=0&project=0&state=all&type=all): roughly one request per IP across tens of thousands of IPs, with spoofed browser User-Agents and no referer, so the existing per-IPbotsandexpensivezones never filled. In the hour before the change there were about 45k permutation requests from about 43k distinct IPs; the resulting render and DB load showed up as499s and slow page loads.This adds an aggregate, non-IP bucket for the filter-permutation list pages and exempts authenticated sessions:
rate_limits.conf.erb: a$filter_permmap anchored to/<owner>/<repo>/(issues|pulls)?with filter params (so API paths such as/api/v1/...never match), alua_shared_dictfor the session cache, and a globalfilterszone at 1r/s with burst 5.nginx_conf_web.erb: arewrite_by_lua_blockinsidelocation /that marks only anonymous filter requests with thefilterskey. Authenticated sessions are validated once against a signed-in-only route (/_gitea_signed_inproxying/user/settings, which answers 200 when signed in and 303 otherwise) and cached per session; the probe fails open so a flaky Gitea cannot throttle a signed-in user. The gate is scoped tolocation /so theinternalprobe location does not inherit it and re-enter the gate (a server-level handler caused a subrequest cycle).robots.txt.erb: disallow the combinatorial tree-browse routes (/*/src/branch/,/*/commits/branch/, and thetagvariants), which the current AI crawlers walk.credentials/giteadata bag: add CogBot todeny_user_agents(re-encrypted with the shared secret).Verified on draco and fornax:
nginx -tok and zero lua/subrequest errors after the fix, anonymous filter requests return429once the burst is exhausted, plain pages and assets return200, and CogBot and PerplexityBot return403. Anonymous filter traffic is being shed (thousands of429s per minute) and thegitea-2load average dropped from roughly 4.4 to 2.8.Bumps the cookbook to 0.3.11.
1f67eefbactoac639dcbe9👍