-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
docs: zh-cn translations for fail2ban setup #20588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22db5b0
docs: zh-cn translations for fail2ban setup
e7215e7
Update docs/content/doc/usage/fail2ban-setup.zh-cn.md
wxiaoguang 3cf9239
Update docs/content/doc/usage/fail2ban-setup.zh-cn.md
wxiaoguang 4ffc1af
Update docs/content/doc/usage/fail2ban-setup.zh-cn.md
wxiaoguang 97c7536
Update docs/content/doc/usage/fail2ban-setup.zh-cn.md
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
date: "2022-08-01T00:00:00+00:00" | ||
title: "使用: 设置 Fail2ban" | ||
slug: "fail2ban-setup" | ||
weight: 16 | ||
toc: false | ||
draft: false | ||
menu: | ||
sidebar: | ||
parent: "usage" | ||
name: "设置 Fail2ban" | ||
weight: 16 | ||
identifier: "fail2ban-setup" | ||
--- | ||
|
||
# 使用 Fail2ban 阻止攻击者的暴力登录 | ||
|
||
**Fail2ban 检查客户端登录日志,将多次登录失败的客户端识别为攻击者并在一段时间内阻止其访问服务。如果你的实例是公开的,这一点尤其重要。请管理员仔细设置 fail2ban,错误的配置将导致防火墙阻止你访问自己的服务器。** | ||
|
||
Gitea 会在日志文件 `log/gitea.log` 中记录登录失败的 CLI、SSH 或 HTTP 客户端 IP 地址,而你需要将 Gitea 的日志输出模式从默认的 `console` 更改为 `file`。这表示将日志输出到文件,使得 fail2ban 可以定期扫描日志内容。 | ||
|
||
|
||
当用户的身份验证失败时,日志中会记录此类信息: | ||
|
||
```log | ||
2018/04/26 18:15:54 [I] Failed authentication attempt for user from xxx.xxx.xxx.xxx | ||
``` | ||
|
||
```log | ||
2020/10/15 16:08:44 [E] invalid credentials from xxx.xxx.xxx.xxx | ||
``` | ||
|
||
## 设置 Fail2ban | ||
|
||
添加日志过滤器规则到配置文件 `/etc/fail2ban/filter.d/gitea.conf`: | ||
|
||
```ini | ||
[Definition] | ||
failregex = .*(Failed authentication attempt|invalid credentials|Attempted access of unknown user).* from <HOST> | ||
ignoreregex = | ||
``` | ||
|
||
添加监狱规则到配置文件 `/etc/fail2ban/jail.d/gitea.conf`: | ||
|
||
```ini | ||
[gitea] | ||
enabled = true | ||
filter = gitea | ||
logpath = /var/lib/gitea/log/gitea.log | ||
maxretry = 10 | ||
findtime = 3600 | ||
bantime = 900 | ||
action = iptables-allports | ||
``` | ||
|
||
如果你的 Gitea 实例运行在 Docker 容器中,并且直接将容器端口暴露到外部网络,你还需要添加 `chain="FORWARD"` 到监狱规则配置文件 `/etc/fail2ban/jail.d/gitea-docker.conf` 以适应 Docker 的网络转发规则。但如果你在容器的宿主机上使用 Nginx 反向代理连接到 Gitea 则无需这样配置。 | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```ini | ||
[gitea-docker] | ||
enabled = true | ||
filter = gitea | ||
logpath = /var/lib/gitea/log/gitea.log | ||
maxretry = 10 | ||
findtime = 3600 | ||
bantime = 900 | ||
action = iptables-allports[chain="FORWARD"] | ||
``` | ||
|
||
最后,运行 `systemctl restart fail2ban` 即可应用更改。现在,你可以使用 `systemctl status fail2ban` 检查 fail2ban 运行状态。 | ||
|
||
上述规则规定客户端在 1 小时内,如果登录失败的次数达到 10 次,则通过 iptables 锁定该客户端 IP 地址 15 分钟。 | ||
|
||
## 设置反向代理 | ||
|
||
如果你使用 Nginx 反向代理到 Gitea 实例,你还需要设置 Nginx 的 HTTP 头部值 `X-Real-IP` 将真实的客户端 IP 地址传递给 Gitea。否则 Gitea 程序会将客户端地址错误解析为反向代理服务器的地址,例如回环地址 `127.0.0.1`。 | ||
|
||
``` | ||
proxy_set_header X-Real-IP $remote_addr; | ||
``` | ||
|
||
额外注意,在 Gitea 的配置文件 `app.ini` 中存在下列默认值: | ||
|
||
``` | ||
REVERSE_PROXY_LIMIT = 1 | ||
REVERSE_PROXY_TRUSTED_PROXIES = 127.0.0.0/8,::1/128 | ||
``` | ||
|
||
`REVERSE_PROXY_LIMIT` 限制反向代理服务器的层数,设置为 `0` 表示不使用这些标头。`REVERSE_PROXY_TRUSTED_PROXIES` 表示受信任的反向代理服务器网络地址,经过该网络地址转发来的流量会经过解析 `X-Real-IP` 头部得到真实客户端地址。(参考 [configuration cheat sheet](https://docs.gitea.io/en-us/config-cheat-sheet/#security-security)) | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Uh oh!
There was an error while loading. Please reload this page.