Mitigate distributed Gitea filter-permutation crawl #720
No files matched your search
@@ -1,66 +1,66 @@
|
||||
{
|
||||
"id": "gitea",
|
||||
"jwt_secret": {
|
||||
"encrypted_data": "fZnJWLiiqzUpFtNirS33sclrlHmXPzKyMiIujp1hmwqWw6b3/ySeam4R/9F0\nqLr1jnW+fDmYmdUW6wPoFGk=\n",
|
||||
"iv": "Wx88w/nBFI50Ej0b\n",
|
||||
"auth_tag": "5JjuZuwouAvoMDk2LgAoLQ==\n",
|
||||
"encrypted_data": "+ng9wqOn2puvEn1fDNfQ2GO4H6eA0v/3CDPzTFEiGAitl4keUK2Nw8t251qt\nNmIzEJ6/nU8vsgs/PdedYgU=\n",
|
||||
"iv": "AurYsSRNI20Vh1ci\n",
|
||||
"auth_tag": "M5YXwpFaegEPRxADy0oWRg==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"internal_token": {
|
||||
"encrypted_data": "ASlbrrBLfMpuAHma3ApAs7I9Lm0xuUvLBz1IfNuaarjliQczOehbmZsqS883\nqCRV/rGwE8BO33VBTqmB49KUyee7B+KFbzyTVkXjrpHRofY4LOcYW7/OfMJP\n+hfAnWAlZeQud3Z8IfusXGDVHQ3U5ebFTwSaAMuMj4fPzg==\n",
|
||||
"iv": "UHIYNKU0OUNjY3sN\n",
|
||||
"auth_tag": "3laBspfgWoYdZqBD5pHVAA==\n",
|
||||
"encrypted_data": "PyeoWmN+zOLvJjV/MOHH7REXqTqDhZ2IJuXVL9bnVLQ6nqk9ot4nMaB4C0pN\nuVMAIoTUcnifbFna4mBHAyhM1b5FJ2pI5205QUQqEidiOGRtlbZYJLYB6pop\nONZdGUgBOThiJBJpQ27oqaPCCCIxBaySURP8CK98voTMFQ==\n",
|
||||
"iv": "BG7jQgkKqbV3vjQY\n",
|
||||
"auth_tag": "//Eb7FO9JOXhfd32p/BOvA==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"secret_key": {
|
||||
"encrypted_data": "4BVf7PGXARAaZbX7226LCF5xEpPhexxcLLfvGodGNuBjSOEliTXsQiHdFTIj\ng5nJzXx4D4sjhvY4FgcNEhVUreBWYke8dn0L3uz5xiogFSLtHlU=\n",
|
||||
"iv": "JCJJRAS2iDRIo9U2\n",
|
||||
"auth_tag": "i2mcB9IQWlXlavZ2zycoBw==\n",
|
||||
"encrypted_data": "IxsGNtcqD6eQawpCUZGGnzddO0UMzX1IHFegf4uEXsgM0u1Ifg6PV0owtoqe\nxBn4oi6VdeBGoe9zKmLJJy9BWBfykWNJV7Udl7/ghcOraXbb7EM=\n",
|
||||
"iv": "YLsBmy+2JmbSNVx4\n",
|
||||
"auth_tag": "R8PDJHOP3FHIEua8nSsb7g==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"postgresql_password": {
|
||||
"encrypted_data": "5855l2MyYjqg/kUPyGPFcoqbObJZh/v79wFBAaBy0Vhe9VAo/G/1tqvvgA==\n",
|
||||
"iv": "xwK5hEkkROs16hma\n",
|
||||
"auth_tag": "sAPM/xsMMmoK71pj+5DqEQ==\n",
|
||||
"encrypted_data": "kIuy9AkEDMPTGJrlv5qTvp2UjhkzNCh66UA76vz8D0D+7KGNTNEcY/qlqg==\n",
|
||||
"iv": "kUVlpG7ePP4Ilhy0\n",
|
||||
"auth_tag": "WAqWxHb5uWgXC+R5MADHeA==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"s3_key_id": {
|
||||
"encrypted_data": "K5fgxcHgxGcgDro96mgIowHJD6FFdea/+DtNyT8YMZ9OnrwBPWQTTtJqMpol\n",
|
||||
"iv": "EZmdjcXjGUFKi5xP\n",
|
||||
"auth_tag": "mRdO3XjYr2z+EZeEiorh/A==\n",
|
||||
"encrypted_data": "Kv+I61WTeilBydTC4q/fRbBLhpd0zemqCtn16xL7H5y01+YcYKUv0NB3o5Gy\n",
|
||||
"iv": "+eDTHhTV6M6Chzer\n",
|
||||
"auth_tag": "fXJy0c+tWikfWJKtLPocAA==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"s3_secret_key": {
|
||||
"encrypted_data": "S7xrrCDLuhOpprDNFTM/8ME2vDK3U2bhCKQalsFrxbsv1+ogHllF/G5zrL1p\n5H0pMkeDDvgN3oNNr2UbmYJJnmyyZyWDy5m1Dv9BiIv20RY1ucc=\n",
|
||||
"iv": "nANI8bJR5UOd0YCP\n",
|
||||
"auth_tag": "Wlkr2dEYJ2ytMO28VL8aKw==\n",
|
||||
"encrypted_data": "mKl8BtP7/jzCE2jPRlIH5prsY5pxNfnpLnD/gcSuUQiEmBsUopTxm8tZ9l8R\nwVi2f5b+WShAcE5GhdWwhsmGA+pDRDUfGPpAqYyvN8pCiJ8zVuU=\n",
|
||||
"iv": "A6TNSdC/TNWtVOGo\n",
|
||||
"auth_tag": "gqaiLmvXKZCvlPriP23uaw==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"s3_bucket": {
|
||||
"encrypted_data": "l9icd2M+a+P1japoRLGEYOXtkuMLnuotsE4nWyXER+i+XZE=\n",
|
||||
"iv": "922rYakCutpFO5aP\n",
|
||||
"auth_tag": "zDanzudY8PBBZBRGHvU6Hg==\n",
|
||||
"encrypted_data": "vviGK8AAsvahCpbWFW7HF6rCOnlkkrxgV5AacPPFq93bUvU=\n",
|
||||
"iv": "Syqh6hjoP+x1HJQb\n",
|
||||
"auth_tag": "/UlNOVhGcA+hKYRzk1PshQ==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"runners": {
|
||||
"encrypted_data": "KR6YIzLKjcERHjwda5GHVN77qX6CDC/ihIRy8hZxoiRb+o+i3lJW3cX0EiM2\n36iK1apHRXZWCz7eM1SPRVU9AH/S4yaUBi/dhIvqta011KI2I8bgtkKvU9Af\nvemkIFfyDiq+fFU3irNoiK5tzUuU9FlwdCdohkZMINorcJq87cIvvzF5pDVv\niMLFqbRr7i4tUO9KYUGG6rnndz7crw/gjm6da64N9qSUKfxaaejjzT/ouruo\nxn8mJmHEfPyUf0A8mn/0p6VEnP/5AX5+YPRrOvuv2LxskpKp0hsIe7hU\n",
|
||||
"iv": "eJVs/QvBuWfQO3k1\n",
|
||||
"auth_tag": "crTUFAioi9e8k5I9TcTl3g==\n",
|
||||
"encrypted_data": "BtRK25fHnJwAl22Z1o8GplMYGwi5G4VCLPeEArFqMNlZtlPjqiJkYHjFNexR\n1NqOxJjVeueU/aYO61uDanhCi1xNHdPvwVSr6WOuLBGURWEqtKEoS387kwaJ\nRdnQVWlW6egy3gFKfguroabqaptGSp9GmS4Kf431J1bVTAgkft4HOSF+chQz\nUErGIHMBzagWw+yvQZQWN3jeVuJfhUUj+4mZx80j48yZ6C/PBNyKNlgKgflr\nJjMwQQxMXHVx5Dz607jQaNzj0wQT5GYfN2Srnis/2RumvIsbIseTpqNL\n",
|
||||
"iv": "DcYf02SDZwc47JPS\n",
|
||||
"auth_tag": "Yn2MOb2QYSf5TU1azpcw2w==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
},
|
||||
"bot_filter": {
|
||||
"encrypted_data": "lo3Nr87mIoMbjpQ2/Txc5MdWM3OPVEwZKCe2Uz+vkjjW4tVe7SzcJgQABR28\ng8nZfHRHPtwi5FJbEvOXDMAnQGduVoI/GMF+Be1OiS7efqZQ2qI4psGTrotc\nQmCbYr6XOXKz7v06y0i9pWZxBnZMr8j95ts5J5XWX9lc5pVY8q0ujm7j9Yb4\ntSUByBUCGJYkCg8uMqNMFEickBKsQodMlT/2VyYG/gFwEjUsB9f0COpTL1zN\n1hdWUtzk0eXVxmB50USYYrPQzgQrAQ0XwEkEq8mLeb7cAhGskQn7DNU+cZOZ\nCvtv2GzbSCIOAMgV5S4W23yZQUiaiB/B4t8jBrzoa4af91xJ228OUNGlCEUm\ncQB9f/0Zf9fRelOd/hpXqOakP4CfIV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Vs/NaTeieM=\n",
|
||||
"iv": "F7ETWs45VmzIMXHG\n",
|
||||
"auth_tag": "8gILpr45x4lQ17cRqLOKEQ==\n",
|
||||
"version": 3,
|
||||
"cipher": "aes-256-gcm"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,28 @@
|
||||
|
||||
This file is used to list changes made in each version of the kosmos_gitea cookbook.
|
||||
|
||||
# 0.3.11
|
||||
|
||||
- Mitigate a distributed anonymous crawl of combinatorial issue/pull filter
|
||||
URLs (e.g. `/kosmos/chef/issues?assignee=..&labels=..&milestone=..`). The
|
||||
crawler spreads ~1 request across tens of thousands of client IPs with
|
||||
spoofed browser User-Agents and no referer, so the existing per-IP zones
|
||||
(`bots`, `expensive`) never engage.
|
||||
- Detect the filter-permutation list pages (`$filter_perm`) and cap the
|
||||
anonymous ones with a single non-IP `filters` bucket (1r/s, burst 5).
|
||||
- Exempt authenticated sessions: `rewrite_by_lua_block` validates the
|
||||
`i_like_gitea` cookie once against a signed-in-only route
|
||||
(`/_gitea_signed_in` -> `/user/settings`, 200 when signed in, 303 for
|
||||
anonymous) and caches the result per session. Cookie presence alone is not
|
||||
enough, because Gitea issues it to anonymous visitors too. Probe failures
|
||||
fail open so a flaky Gitea cannot throttle a signed-in user.
|
||||
- The internal probe runs its own empty-key `limit_req` zone so it cannot
|
||||
poison `r->main->limit_req_set` and disable the main request's limits.
|
||||
- Disallow the combinatorial tree-browse routes (`/*/src/branch/`,
|
||||
`/*/commits/branch/`, and the `tag` variants) in `robots.txt`; these were not
|
||||
covered before and are what the current AI crawlers walk.
|
||||
- Bump cookbook to 0.3.11.
|
||||
|
||||
# 0.3.10
|
||||
|
||||
- Upgrade Gitea from 28.3.0 to 28.4.0 (maintenance/security release, no `app.ini`
|
||||
|
||||
@@ -4,7 +4,7 @@ maintainer_email 'ops@kosmos.org'
|
||||
license 'MIT'
|
||||
description 'Installs/configures Gitea'
|
||||
long_description 'Installs/configures Gitea'
|
||||
version '0.3.10'
|
||||
version '0.3.11'
|
||||
chef_version '>= 14.0'
|
||||
|
||||
depends "firewall"
|
||||
|
||||
@@ -34,6 +34,38 @@ server {
|
||||
# Only non-empty keys are counted, so normal requests are unaffected.
|
||||
limit_req zone=expensive burst=5 nodelay;
|
||||
|
||||
# --- Anonymous filter-permutation flood ------------------------------------
|
||||
# Count only anonymous issue/pull *filter* requests against a single global
|
||||
# bucket. Authenticated sessions are validated once (cached) and always
|
||||
# exempt; everything else stays unlimited. $filter_perm and the zones are
|
||||
# defined in /etc/openresty/conf.d/rate_limits.conf.
|
||||
#
|
||||
# The gate itself lives in "location /" below, NOT here: a server-level
|
||||
# rewrite_by_lua would be inherited by the internal probe location, and its
|
||||
# subrequest would then re-enter the gate and try to capture itself.
|
||||
set $filter_key "";
|
||||
set $probe_noop "";
|
||||
|
||||
limit_req zone=filters burst=5 nodelay;
|
||||
|
||||
# Internal: real-login probe. Gitea answers 200 when the session is signed in
|
||||
# and 303 -> /user/login otherwise. The subrequest inherits the client's
|
||||
# Cookie header. Its own empty-key limit_req replaces the inherited zones so
|
||||
# it cannot set the main request's limit_req flag.
|
||||
location = /_gitea_signed_in {
|
||||
internal;
|
||||
limit_req zone=probe_noop burst=1 nodelay;
|
||||
proxy_pass http://_gitea_web/user/settings;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_connect_timeout 1s;
|
||||
proxy_read_timeout 2s;
|
||||
}
|
||||
|
||||
location ~ ^/(avatars|repo-avatars)/.*$ {
|
||||
proxy_buffers 1024 8k;
|
||||
proxy_pass http://_gitea_web;
|
||||
@@ -62,6 +94,51 @@ server {
|
||||
}
|
||||
|
||||
location / {
|
||||
# Anonymous filter-permutation gate: sets $filter_key so the server-level
|
||||
# "limit_req zone=filters" counts only anonymous filter requests. Scoped to
|
||||
# this location so the internal probe location below does not inherit it.
|
||||
rewrite_by_lua_block {
|
||||
if ngx.var.filter_perm ~= "1" then
|
||||
return
|
||||
end
|
||||
|
||||
-- Rate-limited bot UAs are never probed (this keeps them in the per-IP
|
||||
-- bots zone and avoids limit_req_set poisoning of the main request);
|
||||
-- treat them as anonymous.
|
||||
if (ngx.var.bot_name or "") ~= "" then
|
||||
ngx.var.filter_key = "filters"
|
||||
return
|
||||
end
|
||||
|
||||
local cookie = ngx.var.http_cookie
|
||||
local session = cookie and cookie:match("i_like_gitea=([^;]+)")
|
||||
if not session then
|
||||
ngx.var.filter_key = "filters"
|
||||
return
|
||||
end
|
||||
|
||||
local cache = ngx.shared.gitea_auth
|
||||
local key = ngx.md5(session)
|
||||
local signed_in = cache:get(key)
|
||||
if signed_in == nil then
|
||||
local status = ngx.location.capture("/_gitea_signed_in").status
|
||||
if status == 200 then
|
||||
signed_in = true
|
||||
cache:set(key, signed_in, 300) -- real login, cache 5 min
|
||||
elseif status >= 300 and status < 400 then
|
||||
signed_in = false
|
||||
cache:set(key, signed_in, 30) -- anonymous, cache 30 s
|
||||
else
|
||||
signed_in = true -- probe failed: fail open for auth users
|
||||
cache:set(key, signed_in, 10)
|
||||
end
|
||||
end
|
||||
|
||||
if not signed_in then
|
||||
ngx.var.filter_key = "filters"
|
||||
end
|
||||
}
|
||||
|
||||
proxy_buffers 1024 8k;
|
||||
proxy_pass http://_gitea_web;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
@@ -62,3 +62,30 @@ map $expensive_request $expensive_key {
|
||||
}
|
||||
|
||||
limit_req_zone $expensive_key zone=expensive:20m rate=10r/m; # ~1 per 6s per IP
|
||||
|
||||
# Anonymous combinatorial filter-permutation flood.
|
||||
#
|
||||
# A distributed crawler spreads ~1 request across tens of thousands of client
|
||||
# IPs, so the per-IP zones above never fill. These list pages are filter
|
||||
# permutations of issue/pull lists and are CPU/DB heavy to render.
|
||||
#
|
||||
# $filter_perm is 1 only for /<owner>/<repo>/(issues|pulls) with filter query
|
||||
# params. Anchored so API paths (/api/v1/...) and other pages never match.
|
||||
map $request_uri $filter_perm {
|
||||
default 0;
|
||||
~*^/[^/]+/[^/]+/(issues|pulls)\?.*(assignee|labels|milestone|poster|project)= 1;
|
||||
}
|
||||
|
||||
# Per-session cache of "is this i_like_gitea cookie a real login?" answers.
|
||||
# Filled by rewrite_by_lua_block in the Gitea vhost.
|
||||
lua_shared_dict gitea_auth 10m;
|
||||
|
||||
# Only anonymous filter permutations reach this key; authenticated sessions and
|
||||
# everything else leave it empty, and empty keys are not counted.
|
||||
limit_req_zone $filter_key zone=filters:5m rate=1r/s;
|
||||
|
||||
# Dummy zone with an always-empty key. Referenced only by the internal
|
||||
# /_gitea_signed_in probe location so that its location-level limit_req
|
||||
# replaces the inherited server-level zones. This prevents the subrequest from
|
||||
# setting r->main->limit_req_set and disabling the main request's limits.
|
||||
limit_req_zone $probe_noop zone=probe_noop:1m rate=1000r/s;
|
||||
@@ -15,6 +15,10 @@ Disallow: /*/raw/
|
||||
Disallow: /*/archive/
|
||||
Disallow: /*/src/commit/
|
||||
Disallow: /*/commits/commit/
|
||||
Disallow: /*/src/branch/
|
||||
Disallow: /*/commits/branch/
|
||||
Disallow: /*/src/tag/
|
||||
Disallow: /*/commits/tag/
|
||||
Disallow: /*.patch$
|
||||
Disallow: /*.diff$
|
||||
Allow: /
|
||||
Reference in new issue
Block a user