Skip to content

Commit 93acb7e

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Rework mailer settings (go-gitea#18982) Add default value for clone URLs (go-gitea#20600) [skip ci] Updated translations via Crowdin docs: zh-cn translations for fail2ban setup (go-gitea#20588) Should also support upper-case README files (go-gitea#20581) Fix typos in backup documentation (go-gitea#20567)
2 parents 8f9b8c2 + 036dd8a commit 93acb7e

File tree

22 files changed

+480
-163
lines changed

22 files changed

+480
-163
lines changed

cmd/admin.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ var (
414414
Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN",
415415
},
416416
cli.StringFlag{
417-
Name: "host",
417+
Name: "addr",
418418
Value: "",
419-
Usage: "SMTP Host",
419+
Usage: "SMTP Addr",
420420
},
421421
cli.IntFlag{
422422
Name: "port",
@@ -956,8 +956,8 @@ func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
956956
}
957957
conf.Auth = c.String("auth-type")
958958
}
959-
if c.IsSet("host") {
960-
conf.Host = c.String("host")
959+
if c.IsSet("addr") {
960+
conf.Addr = c.String("addr")
961961
}
962962
if c.IsSet("port") {
963963
conf.Port = c.Int("port")

custom/conf/app.example.ini

+35-27
Original file line numberDiff line numberDiff line change
@@ -1503,50 +1503,58 @@ ROUTER = console
15031503
;; Prefix displayed before subject in mail
15041504
;SUBJECT_PREFIX =
15051505
;;
1506-
;; Mail server
1507-
;; Gmail: smtp.gmail.com:587
1508-
;; QQ: smtp.qq.com:465
1509-
;; As per RFC 8314 using Implicit TLS/SMTPS on port 465 (if supported) is recommended,
1510-
;; otherwise STARTTLS on port 587 should be used.
1511-
;HOST =
1512-
;;
1513-
;; Disable HELO operation when hostnames are different.
1514-
;DISABLE_HELO =
1515-
;;
1516-
;; Custom hostname for HELO operation, if no value is provided, one is retrieved from system.
1506+
;; Mail server protocol. One of "smtp", "smtps", "smtp+startls", "smtp+unix", "sendmail", "dummy".
1507+
;; - sendmail: use the operating system's `sendmail` command instead of SMTP. This is common on Linux systems.
1508+
;; - dummy: send email messages to the log as a testing phase.
1509+
;; If your provider does not explicitly say which protocol it uses but does provide a port,
1510+
;; you can set SMTP_PORT instead and this will be inferred.
1511+
;; (Before 1.18, this was controlled via MAILER_TYPE and IS_TLS_ENABLED.)
1512+
;PROTOCOL =
1513+
;;
1514+
;; Mail server address, e.g. smtp.gmail.com.
1515+
;; For smtp+unix, this should be a path to a unix socket instead.
1516+
;; (Before 1.18, this was combined with SMTP_PORT as HOST.)
1517+
;SMTP_ADDR =
1518+
;;
1519+
;; Mail server port. Common ports are:
1520+
;; 25: insecure SMTP
1521+
;; 465: SMTP Secure
1522+
;; 587: StartTLS
1523+
;; If no protocol is specified, it will be inferred by this setting.
1524+
;; (Before 1.18, this was combined with SMTP_ADDR as HOST.)
1525+
;SMTP_PORT =
1526+
;;
1527+
;; Enable HELO operation. Defaults to true.
1528+
;ENABLE_HELO = true
1529+
;;
1530+
;; Custom hostname for HELO operation.
1531+
;; If no value is provided, one is retrieved from system.
15171532
;HELO_HOSTNAME =
15181533
;;
1519-
;; Whether or not to skip verification of certificates; `true` to disable verification. This option is unsafe. Consider adding the certificate to the system trust store instead.
1520-
;SKIP_VERIFY = false
1534+
;; If set to `true`, completely ignores server certificate validation errors.
1535+
;; This option is unsafe. Consider adding the certificate to the system trust store instead.
1536+
;FORCE_TRUST_SERVER_CERT = false
15211537
;;
1522-
;; Use client certificate
1523-
;USE_CERTIFICATE = false
1524-
;CERT_FILE = custom/mailer/cert.pem
1525-
;KEY_FILE = custom/mailer/key.pem
1526-
;;
1527-
;; Should SMTP connect with TLS, (if port ends with 465 TLS will always be used.)
1528-
;; If this is false but STARTTLS is supported the connection will be upgraded to TLS opportunistically.
1529-
;IS_TLS_ENABLED = false
1538+
;; Use client certificate in connection.
1539+
;USE_CLIENT_CERT = false
1540+
;CLIENT_CERT_FILE = custom/mailer/cert.pem
1541+
;CLIENT_KEY_FILE = custom/mailer/key.pem
15301542
;;
15311543
;; Mail from address, RFC 5322. This can be just an email address, or the `"Name" <[email protected]>` format
15321544
;FROM =
15331545
;;
15341546
;; Sometimes it is helpful to use a different address on the envelope. Set this to use ENVELOPE_FROM as the from on the envelope. Set to `<>` to send an empty address.
15351547
;ENVELOPE_FROM =
15361548
;;
1537-
;; Mailer user name and password
1538-
;; Please Note: Authentication is only supported when the SMTP server communication is encrypted with TLS (this can be via STARTTLS) or `HOST=localhost`.
1549+
;; Mailer user name and password, if required by provider.
15391550
;USER =
15401551
;;
15411552
;; Use PASSWD = `your password` for quoting if you use special characters in the password.
15421553
;PASSWD =
15431554
;;
1544-
;; Send mails as plain text
1555+
;; Send mails only in plain text, without HTML alternative
15451556
;SEND_AS_PLAIN_TEXT = false
15461557
;;
1547-
;; Set Mailer Type (either SMTP, sendmail or dummy to just send to the log)
1548-
;MAILER_TYPE = smtp
1549-
;;
15501558
;; Specify an alternative sendmail binary
15511559
;SENDMAIL_PATH = sendmail
15521560
;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+23-29
Original file line numberDiff line numberDiff line change
@@ -647,41 +647,35 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
647647
## Mailer (`mailer`)
648648

649649
- `ENABLED`: **false**: Enable to use a mail service.
650-
- `DISABLE_HELO`: **\<empty\>**: Disable HELO operation.
651-
- `HELO_HOSTNAME`: **\<empty\>**: Custom hostname for HELO operation.
652-
- `HOST`: **\<empty\>**: SMTP mail host address and port (example: smtp.gitea.io:587).
653-
- As per RFC 8314, if supported, Implicit TLS/SMTPS on port 465 is recommended, otherwise opportunistic TLS via STARTTLS on port 587 should be used.
654-
- `IS_TLS_ENABLED` : **false** : Forcibly use TLS to connect even if not on a default SMTPS port.
655-
- Note, if the port ends with `465` Implicit TLS/SMTPS/SMTP over TLS will be used despite this setting.
656-
- Otherwise if `IS_TLS_ENABLED=false` and the server supports `STARTTLS` this will be used. Thus if `STARTTLS` is preferred you should set `IS_TLS_ENABLED=false`.
657-
- `FROM`: **\<empty\>**: Mail from address, RFC 5322. This can be just an email address, or
658-
the "Name" \<[email protected]\> format.
659-
- `ENVELOPE_FROM`: **\<empty\>**: Address set as the From address on the SMTP mail envelope. Set to `<>` to send an empty address.
650+
- `PROTOCOL`: **\<empty\>**: Mail server protocol. One of "smtp", "smtps", "smtp+startls", "smtp+unix", "sendmail", "dummy". _Before 1.18, this was inferred from a combination of `MAILER_TYPE` and `IS_TLS_ENABLED`._
651+
- SMTP family, if your provider does not explicitly say which protocol it uses but does provide a port, you can set SMTP_PORT instead and this will be inferred.
652+
- **sendmail** Use the operating system's `sendmail` command instead of SMTP. This is common on Linux systems.
653+
- **dummy** Send email messages to the log as a testing phase.
654+
- Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`, `FROM`, `SUBJECT_PREFIX` and `SENDMAIL_PATH`.
655+
- Enabling dummy will ignore all settings except `ENABLED`, `SUBJECT_PREFIX` and `FROM`.
656+
- `SMTP_ADDR`: **\<empty\>**: Mail server address. e.g. smtp.gmail.com. For smtp+unix, this should be a path to a unix socket instead. _Before 1.18, this was combined with `SMTP_PORT` under the name `HOST`._
657+
- `SMTP_PORT`: **\<empty\>**: Mail server port. If no protocol is specified, it will be inferred by this setting. Common ports are listed below. _Before 1.18, this was combined with `SMTP_ADDR` under the name `HOST`._
658+
- 25: insecure SMTP
659+
- 465: SMTP Secure
660+
- 587: StartTLS
661+
- `USE_CLIENT_CERT`: **false**: Use client certificate for TLS/SSL.
662+
- `CLIENT_CERT_FILE`: **custom/mailer/cert.pem**: Client certificate file.
663+
- `CLIENT_KEY_FILE`: **custom/mailer/key.pem**: Client key file.
664+
- `FORCE_TRUST_SERVER_CERT`: **false**: If set to `true`, completely ignores server certificate validation errors. This option is unsafe. Consider adding the certificate to the system trust store instead.
660665
- `USER`: **\<empty\>**: Username of mailing user (usually the sender's e-mail address).
661666
- `PASSWD`: **\<empty\>**: Password of mailing user. Use \`your password\` for quoting if you use special characters in the password.
662-
- Please note: authentication is only supported when the SMTP server communication is encrypted with TLS (this can be via `STARTTLS`) or `HOST=localhost`. See [Email Setup]({{< relref "doc/usage/email-setup.en-us.md" >}}) for more information.
663-
- `SEND_AS_PLAIN_TEXT`: **false**: Send mails as plain text.
664-
- `SKIP_VERIFY`: **false**: Whether or not to skip verification of certificates; `true` to disable verification.
665-
- **Warning:** This option is unsafe. Consider adding the certificate to the system trust store instead.
666-
- **Note:** Gitea only supports SMTP with STARTTLS.
667-
- `USE_CERTIFICATE`: **false**: Use client certificate.
668-
- `CERT_FILE`: **custom/mailer/cert.pem**
669-
- `KEY_FILE`: **custom/mailer/key.pem**
667+
- Please note: authentication is only supported when the SMTP server communication is encrypted with TLS (this can be via `STARTTLS`) or SMTP host is localhost. See [Email Setup]({{< relref "doc/usage/email-setup.en-us.md" >}}) for more information.
668+
- `ENABLE_HELO`: **true**: Enable HELO operation.
669+
- `HELO_HOSTNAME`: **(retrieved from system)**: HELO hostname.
670+
- `FROM`: **\<empty\>**: Mail from address, RFC 5322. This can be just an email address, or the "Name" \<[email protected]\> format.
671+
- `ENVELOPE_FROM`: **\<empty\>**: Address set as the From address on the SMTP mail envelope. Set to `<>` to send an empty address.
670672
- `SUBJECT_PREFIX`: **\<empty\>**: Prefix to be placed before e-mail subject lines.
671-
- `MAILER_TYPE`: **smtp**: \[smtp, sendmail, dummy\]
672-
- **smtp** Use SMTP to send mail
673-
- **sendmail** Use the operating system's `sendmail` command instead of SMTP.
674-
This is common on Linux systems.
675-
- **dummy** Send email messages to the log as a testing phase.
676-
- Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`,
677-
`FROM`, `SUBJECT_PREFIX` and `SENDMAIL_PATH`.
678-
- Enabling dummy will ignore all settings except `ENABLED`, `SUBJECT_PREFIX` and `FROM`.
679-
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be
680-
command or full path).
681-
- `SENDMAIL_ARGS`: **_empty_**: Specify any extra sendmail arguments. (NOTE: you should be aware that email addresses can look like options - if your `sendmail` command takes options you must set the option terminator `--`)
673+
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be command or full path).
674+
- `SENDMAIL_ARGS`: **\<empty\>**: Specify any extra sendmail arguments. (NOTE: you should be aware that email addresses can look like options - if your `sendmail` command takes options you must set the option terminator `--`)
682675
- `SENDMAIL_TIMEOUT`: **5m**: default timeout for sending email through sendmail
683676
- `SENDMAIL_CONVERT_CRLF`: **true**: Most versions of sendmail prefer LF line endings rather than CRLF line endings. Set this to false if your version of sendmail requires CRLF line endings.
684677
- `SEND_BUFFER_LEN`: **100**: Buffer length of mailing queue. **DEPRECATED** use `LENGTH` in `[queue.mailer]`
678+
- `SEND_AS_PLAIN_TEXT`: **false**: Send mails only in plain text, without HTML alternative.
685679

686680
## Cache (`cache`)
687681

docs/content/doc/installation/with-docker.zh-cn.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ volumes:
301301
sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"
302302
```
303303

304-
在下一步中,需要在主机上创建一个名为 `/user/local/bin/gitea` 的文件(具有可执行权限)。该文件将发出从主机到容器的 SSH 转发。将以下内容添加到 `/user/local/bin/gitea`
304+
在下一步中,需要在主机上创建一个名为 `/usr/local/bin/gitea` 的文件(具有可执行权限)。该文件将发出从主机到容器的 SSH 转发。将以下内容添加到 `/usr/local/bin/gitea`
305305

306306
```bash
307307
ssh -p 2222 -o StrictHostKeyChecking=no [email protected] "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
@@ -324,14 +324,14 @@ ports:
324324
ssh-rsa <Gitea Host Key>
325325

326326
# other keys from users
327-
command="/user/local/bin/gitea --config=/data/gitea/conf/app.ini serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty <user pubkey>
327+
command="/usr/local/bin/gitea --config=/data/gitea/conf/app.ini serv key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty <user pubkey>
328328
```
329329

330330
这是详细的说明,当发出 SSH 请求时会发生什么:
331331

332332
1. 使用 `git` 用户向主机发出 SSH 请求,例如 `git clone git@domain:user/repo.git`
333-
2.`/home/git/.ssh/authorized_keys` 中,该命令执行 `/user/local/bin/gitea` 脚本。
334-
3. `/user/local/bin/gitea` 将 SSH 请求转发到端口 2222,该端口已映射到容器的 SSH 端口(22)。
333+
2.`/home/git/.ssh/authorized_keys` 中,该命令执行 `/usr/local/bin/gitea` 脚本。
334+
3. `/usr/local/bin/gitea` 将 SSH 请求转发到端口 2222,该端口已映射到容器的 SSH 端口(22)。
335335
4. 由于 `/home/git/.ssh/authorized_keys` 中存在 `git` 用户的公钥,因此身份验证主机 → 容器成功,并且 SSH 请求转发到在 docker 容器中运行的 Gitea。
336336

337337
如果在 Gitea Web 界面中添加了新的 SSH 密钥,它将以与现有密钥相同的方式附加到 `.ssh/authorized_keys` 中。

docs/content/doc/usage/backup-and-restore.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The command has to be executed with the `RUN_USER = <OS_USERNAME>` specified in
7474
Example:
7575

7676
```none
77-
docker exec -u <OS_USERNAME> -it -w <--tempdir> $(docker ps -qf 'name=^<NAME_OF_DOCKER_CONTAINER>$') bash -c '/user/local/bin/gitea dump -c </path/to/app.ini>'
77+
docker exec -u <OS_USERNAME> -it -w <--tempdir> $(docker ps -qf 'name=^<NAME_OF_DOCKER_CONTAINER>$') bash -c '/usr/local/bin/gitea dump -c </path/to/app.ini>'
7878
```
7979

8080
\*Note: `--tempdir` refers to the temporary directory of the docker environment used by Gitea; if you have not specified a custom `--tempdir`, then Gitea uses `/tmp` or the `TMPDIR` environment variable of the docker container. For `--tempdir` adjust your `docker exec` command options accordingly.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
date: "2022-08-01T00:00:00+00:00"
3+
title: "使用: 设置 Fail2ban"
4+
slug: "fail2ban-setup"
5+
weight: 16
6+
toc: false
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "usage"
11+
name: "设置 Fail2ban"
12+
weight: 16
13+
identifier: "fail2ban-setup"
14+
---
15+
16+
# 使用 Fail2ban 阻止攻击者的暴力登录
17+
18+
**Fail2ban 检查客户端登录日志,将多次登录失败的客户端识别为攻击者并在一段时间内阻止其访问服务。如果你的实例是公开的,这一点尤其重要。请管理员仔细设置 fail2ban,错误的配置将导致防火墙阻止你访问自己的服务器。**
19+
20+
Gitea 会在日志文件 `log/gitea.log` 中记录登录失败的 CLI、SSH 或 HTTP 客户端 IP 地址,而你需要将 Gitea 的日志输出模式从默认的 `console` 更改为 `file`。这表示将日志输出到文件,使得 fail2ban 可以定期扫描日志内容。
21+
22+
当用户的身份验证失败时,日志中会记录此类信息:
23+
24+
```log
25+
2018/04/26 18:15:54 [I] Failed authentication attempt for user from xxx.xxx.xxx.xxx
26+
```
27+
28+
```log
29+
2020/10/15 16:08:44 [E] invalid credentials from xxx.xxx.xxx.xxx
30+
```
31+
32+
## 设置 Fail2ban
33+
34+
添加日志过滤器规则到配置文件 `/etc/fail2ban/filter.d/gitea.conf`:
35+
36+
```ini
37+
[Definition]
38+
failregex = .*(Failed authentication attempt|invalid credentials|Attempted access of unknown user).* from <HOST>
39+
ignoreregex =
40+
```
41+
42+
添加监狱规则到配置文件 `/etc/fail2ban/jail.d/gitea.conf`:
43+
44+
```ini
45+
[gitea]
46+
enabled = true
47+
filter = gitea
48+
logpath = /var/lib/gitea/log/gitea.log
49+
maxretry = 10
50+
findtime = 3600
51+
bantime = 900
52+
action = iptables-allports
53+
```
54+
55+
如果你的 Gitea 实例运行在 Docker 容器中,并且直接将容器端口暴露到外部网络,
56+
你还需要添加 `chain="FORWARD"` 到监狱规则配置文件 `/etc/fail2ban/jail.d/gitea-docker.conf`
57+
以适应 Docker 的网络转发规则。但如果你在容器的宿主机上使用 Nginx 反向代理连接到 Gitea 则无需这样配置。
58+
59+
```ini
60+
[gitea-docker]
61+
enabled = true
62+
filter = gitea
63+
logpath = /var/lib/gitea/log/gitea.log
64+
maxretry = 10
65+
findtime = 3600
66+
bantime = 900
67+
action = iptables-allports[chain="FORWARD"]
68+
```
69+
70+
最后,运行 `systemctl restart fail2ban` 即可应用更改。现在,你可以使用 `systemctl status fail2ban` 检查 fail2ban 运行状态。
71+
72+
上述规则规定客户端在 1 小时内,如果登录失败的次数达到 10 次,则通过 iptables 锁定该客户端 IP 地址 15 分钟。
73+
74+
## 设置反向代理
75+
76+
如果你使用 Nginx 反向代理到 Gitea 实例,你还需要设置 Nginx 的 HTTP 头部值 `X-Real-IP` 将真实的客户端 IP 地址传递给 Gitea。否则 Gitea 程序会将客户端地址错误解析为反向代理服务器的地址,例如回环地址 `127.0.0.1`
77+
78+
```
79+
proxy_set_header X-Real-IP $remote_addr;
80+
```
81+
82+
额外注意,在 Gitea 的配置文件 `app.ini` 中存在下列默认值:
83+
84+
```
85+
REVERSE_PROXY_LIMIT = 1
86+
REVERSE_PROXY_TRUSTED_PROXIES = 127.0.0.0/8,::1/128
87+
```
88+
89+
`REVERSE_PROXY_LIMIT` 限制反向代理服务器的层数,设置为 `0` 表示不使用这些标头。
90+
`REVERSE_PROXY_TRUSTED_PROXIES` 表示受信任的反向代理服务器网络地址,
91+
经过该网络地址转发来的流量会经过解析 `X-Real-IP` 头部得到真实客户端地址。
92+
(参考 [configuration cheat sheet](https://docs.gitea.io/en-us/config-cheat-sheet/#security-security)

modules/markup/renderer.go

+2
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,13 @@ func IsReadmeFile(name string) bool {
328328
// the length of the provided extension list.
329329
// Note that the '.' should be provided in ext, e.g ".md"
330330
func IsReadmeFileExtension(name string, ext ...string) (int, bool) {
331+
name = strings.ToLower(name)
331332
if len(name) < 6 || name[:6] != "readme" {
332333
return 0, false
333334
}
334335

335336
for i, extension := range ext {
337+
extension = strings.ToLower(extension)
336338
if name[6:] == extension {
337339
return i, true
338340
}

modules/markup/renderer_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ func TestMisc_IsReadmeFile(t *testing.T) {
5858
expected: true,
5959
idx: 0,
6060
},
61+
{
62+
name: "README.md",
63+
expected: true,
64+
idx: 0,
65+
},
66+
{
67+
name: "ReAdMe.Md",
68+
expected: true,
69+
idx: 0,
70+
},
6171
{
6272
name: "readme.txt",
6373
expected: true,

0 commit comments

Comments
 (0)