Files
deploy.stack/etc/fail2ban/jail.d/gitea-ssh.local
T
cnphpbb a7395afd4f fix(etc): 修复 Fail2ban 双链配置冲突
- 为 Gitea SSH 的 input 和 forward action 设置独立名称
- 固定 sshd 过滤器的 publickey=invalid 语义
- 补充 jail 数量检查、action 重名检测和实测说明
2026-11-09 00:04:54 +08:00

29 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Gitea 内置 SSH 服务(容器内监听 2222,宿主发布端口不固定)
#
# 日志路径必须稳定:默认的 docker json-file 路径内嵌容器 ID,
# 容器一重建就静默失效(fail2ban 不报错,只是再也不封)。
# 因此要求 Gitea 用 file 模式写到挂载卷,app.ini 配置见 README.md 的「Gitea 侧要求(app.ini)」。
[gitea-ssh]
enabled = true
filter = gitea-ssh
logpath = /var/lib/gitea/log/gitea.log
maxretry = 5
findtime = 10m
bantime = 1d
# 双 action:默认 nftables chain 只 hook input,而 Docker 对发布端口做 DNAT 后
# 走 forward 链,容器流量根本不经过 input。只挂 input 会出现「封禁列表里有 IP、
# 但攻击者照样能连容器端口」。
# 第二条把同一条黑名单再挂到 forward,priority -10 早于 Docker 的
# table ip filter FORWARD(priority 0),确保先于 docker 规则丢弃。
#
# ⚠ 两个 action 必须写不同的 name=:
# ActionReader 里 name 不指定时默认取 jail 名(都是 gitea-ssh),而 actname 只在
# name != jailName 时才加后缀去重 —— 两者同名会撞成同一个 actname "nftables",
# Actions.add() 直接抛 ValueError('Action nftables already exists'),
# 整个 server-stream 中断(实测 fail2ban 1.1.0),forward 链根本不会建出来。
# name 同时决定 nft set 名(addr-set-<name>),不同 name 才能落在不同 set。
action = nftables[type=allports, name=gitea-ssh-in]
nftables[type=allports, name=gitea-ssh-fwd, table=f2b-fwd, chain=f2b-fwd-chain, chain_hook=forward, chain_priority=-10]