build(etc): 完善 Fail2ban 防爆破配置

- 将 SSH 封禁改为端口无关的 allports 策略
- 新增 Gitea SSH 双链防护和失败日志过滤器
- 补充公共策略、再犯封禁及部署验证文档
This commit is contained in:
cnphpbb
2026-11-08 23:37:44 +08:00
parent db3749375c
commit a13785c6e2
9 changed files with 246 additions and 14 deletions
+23
View File
@@ -0,0 +1,23 @@
# fail2ban filter: Gitea 内置 SSH 服务
#
# 只匹配 Gitea >= 1.15 的确定性失败信号 sshConnectionFailed()。
# 旧版 publicKeyHandler() 打的 "Failed authentication attempt" 是「单次公钥尝试失败」,
# 用户随后仍可能登录成功,属于误报,必须排除(官方文档也标了 DEPRECATED)。
#
# 已用 fail2ban-regex 1.1.0 实测(见 docs/fail2ban-verify.md):
# 命中:sshConnectionFailed() 的 IPv4 / 带端口 / 无端口 / IPv6[方括号] / docker json 整行
# 排除:publicKeyHandler() 误报行、web 的 "invalid credentials" 行
[Definition]
# 不锚定行首行尾:容器 json-file 一行是 {"log":"...\n","stream":...} 包着的,
# 用 ^.*? / .*$ 同时兼容「纯文件行」和「docker json 整行」。
# 端口可选:Gitea 用 Go 的 RemoteAddr(),IPv4 是 1.2.3.4:5678,IPv6 是 [::1]:5678。
failregex = ^.*?sshConnectionFailed\(\) \[W\] Failed authentication attempt from <HOST>(?::\d+)?.*$
ignoreregex =
[Init]
# Gitea 默认 FLAGS=stdflags 含 date,Go 的 date 格式是 2009/01/23(斜杠)。
# 同时接受 [-] 兼容改过格式的部署。%% 是 configparser 转义,等价于 %Y/%m/%d %H:%M:%S。
datepattern = %%Y[-/]%%m[-/]%%d %%H:%%M:%%S