Skip to content

Commit 22731a2

Browse files
committed
Merge main branch
2 parents 40011bb + aedfc92 commit 22731a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1344
-389
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,7 @@ issues:
171171
- path: models/user/openid.go
172172
linters:
173173
- golint
174+
- path: models/user/badge.go
175+
linters:
176+
- revive
177+
text: "exported: type name will be used as user.UserBadge by other packages, and that stutters; consider calling this Badge"

build/generate-licenses.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func main() {
3939

4040
defer util.Remove(file.Name())
4141

42+
if err := os.RemoveAll(destination); err != nil {
43+
log.Fatalf("Cannot clean destination folder: %v", err)
44+
}
45+
46+
if err := os.MkdirAll(destination, 0o755); err != nil {
47+
log.Fatalf("Cannot create destination: %v", err)
48+
}
49+
4250
req, err := http.NewRequest("GET", url, nil)
4351
if err != nil {
4452
log.Fatalf("Failed to download archive. %s", err)

cmd/doctor.go

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package cmd
66

77
import (
8+
"errors"
89
"fmt"
910
golog "log"
1011
"os"
@@ -123,32 +124,62 @@ func runRecreateTable(ctx *cli.Context) error {
123124
})
124125
}
125126

126-
func runDoctor(ctx *cli.Context) error {
127-
stdCtx, cancel := installSignals()
128-
defer cancel()
129-
130-
// Silence the default loggers
131-
log.DelNamedLogger("console")
132-
log.DelNamedLogger(log.DEFAULT)
133-
134-
// Now setup our own
127+
func setDoctorLogger(ctx *cli.Context) {
135128
logFile := ctx.String("log-file")
136129
if !ctx.IsSet("log-file") {
137130
logFile = "doctor.log"
138131
}
139-
140132
colorize := log.CanColorStdout
141133
if ctx.IsSet("color") {
142134
colorize = ctx.Bool("color")
143135
}
144136

145137
if len(logFile) == 0 {
146138
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"NONE","stacktracelevel":"NONE","colorize":%t}`, colorize))
147-
} else if logFile == "-" {
139+
return
140+
}
141+
142+
defer func() {
143+
recovered := recover()
144+
if recovered == nil {
145+
return
146+
}
147+
148+
err, ok := recovered.(error)
149+
if !ok {
150+
panic(recovered)
151+
}
152+
if errors.Is(err, os.ErrPermission) {
153+
fmt.Fprintf(os.Stderr, "ERROR: Unable to write logs to provided file due to permissions error: %s\n %v\n", logFile, err)
154+
} else {
155+
fmt.Fprintf(os.Stderr, "ERROR: Unable to write logs to provided file: %s\n %v\n", logFile, err)
156+
}
157+
fmt.Fprintf(os.Stderr, "WARN: Logging will be disabled\n Use `--log-file` to configure log file location\n")
158+
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"NONE","stacktracelevel":"NONE","colorize":%t}`, colorize))
159+
}()
160+
161+
if logFile == "-" {
148162
log.NewLogger(1000, "doctor", "console", fmt.Sprintf(`{"level":"trace","stacktracelevel":"NONE","colorize":%t}`, colorize))
149163
} else {
150164
log.NewLogger(1000, "doctor", "file", fmt.Sprintf(`{"filename":%q,"level":"trace","stacktracelevel":"NONE"}`, logFile))
151165
}
166+
}
167+
168+
func runDoctor(ctx *cli.Context) error {
169+
stdCtx, cancel := installSignals()
170+
defer cancel()
171+
172+
// Silence the default loggers
173+
log.DelNamedLogger("console")
174+
log.DelNamedLogger(log.DEFAULT)
175+
176+
// Now setup our own
177+
setDoctorLogger(ctx)
178+
179+
colorize := log.CanColorStdout
180+
if ctx.IsSet("color") {
181+
colorize = ctx.Bool("color")
182+
}
152183

153184
// Finally redirect the default golog to here
154185
golog.SetFlags(0)

cmd/web.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func runHTTPRedirector() {
7676
http.Redirect(w, r, target, http.StatusTemporaryRedirect)
7777
})
7878

79-
err := runHTTP("tcp", source, "HTTP Redirector", handler)
79+
err := runHTTP("tcp", source, "HTTP Redirector", handler, setting.RedirectorUseProxyProtocol)
8080
if err != nil {
8181
log.Fatal("Failed to start port redirection: %v", err)
8282
}
@@ -231,40 +231,38 @@ func listen(m http.Handler, handleRedirector bool) error {
231231
if handleRedirector {
232232
NoHTTPRedirector()
233233
}
234-
err = runHTTP("tcp", listenAddr, "Web", m)
234+
err = runHTTP("tcp", listenAddr, "Web", m, setting.UseProxyProtocol)
235235
case setting.HTTPS:
236236
if setting.EnableAcme {
237237
err = runACME(listenAddr, m)
238238
break
239-
} else {
240-
if handleRedirector {
241-
if setting.RedirectOtherPort {
242-
go runHTTPRedirector()
243-
} else {
244-
NoHTTPRedirector()
245-
}
239+
}
240+
if handleRedirector {
241+
if setting.RedirectOtherPort {
242+
go runHTTPRedirector()
243+
} else {
244+
NoHTTPRedirector()
246245
}
247-
err = runHTTPS("tcp", listenAddr, "Web", setting.CertFile, setting.KeyFile, m)
248246
}
247+
err = runHTTPS("tcp", listenAddr, "Web", setting.CertFile, setting.KeyFile, m, setting.UseProxyProtocol, setting.ProxyProtocolTLSBridging)
249248
case setting.FCGI:
250249
if handleRedirector {
251250
NoHTTPRedirector()
252251
}
253-
err = runFCGI("tcp", listenAddr, "FCGI Web", m)
252+
err = runFCGI("tcp", listenAddr, "FCGI Web", m, setting.UseProxyProtocol)
254253
case setting.HTTPUnix:
255254
if handleRedirector {
256255
NoHTTPRedirector()
257256
}
258-
err = runHTTP("unix", listenAddr, "Web", m)
257+
err = runHTTP("unix", listenAddr, "Web", m, setting.UseProxyProtocol)
259258
case setting.FCGIUnix:
260259
if handleRedirector {
261260
NoHTTPRedirector()
262261
}
263-
err = runFCGI("unix", listenAddr, "Web", m)
262+
err = runFCGI("unix", listenAddr, "Web", m, setting.UseProxyProtocol)
264263
default:
265264
log.Fatal("Invalid protocol: %s", setting.Protocol)
266265
}
267-
268266
if err != nil {
269267
log.Critical("Failed to start server: %v", err)
270268
}

cmd/web_acme.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ func runACME(listenAddr string, m http.Handler) error {
113113

114114
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
115115
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
116-
err := runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
116+
err := runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, "Let's Encrypt HTTP Challenge", myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)), setting.RedirectorUseProxyProtocol)
117117
if err != nil {
118118
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
119119
}
120120
}()
121121
}
122122

123-
return runHTTPSWithTLSConfig("tcp", listenAddr, "Web", tlsConfig, m)
123+
return runHTTPSWithTLSConfig("tcp", listenAddr, "Web", tlsConfig, m, setting.UseProxyProtocol, setting.ProxyProtocolTLSBridging)
124124
}
125125

126126
func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {

cmd/web_graceful.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"code.gitea.io/gitea/modules/setting"
1616
)
1717

18-
func runHTTP(network, listenAddr, name string, m http.Handler) error {
19-
return graceful.HTTPListenAndServe(network, listenAddr, name, m)
18+
func runHTTP(network, listenAddr, name string, m http.Handler, useProxyProtocol bool) error {
19+
return graceful.HTTPListenAndServe(network, listenAddr, name, m, useProxyProtocol)
2020
}
2121

2222
// NoHTTPRedirector tells our cleanup routine that we will not be using a fallback http redirector
@@ -36,7 +36,7 @@ func NoInstallListener() {
3636
graceful.GetManager().InformCleanup()
3737
}
3838

39-
func runFCGI(network, listenAddr, name string, m http.Handler) error {
39+
func runFCGI(network, listenAddr, name string, m http.Handler, useProxyProtocol bool) error {
4040
// This needs to handle stdin as fcgi point
4141
fcgiServer := graceful.NewServer(network, listenAddr, name)
4242

@@ -47,7 +47,7 @@ func runFCGI(network, listenAddr, name string, m http.Handler) error {
4747
}
4848
m.ServeHTTP(resp, req)
4949
}))
50-
})
50+
}, useProxyProtocol)
5151
if err != nil {
5252
log.Fatal("Failed to start FCGI main server: %v", err)
5353
}

cmd/web_https.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ var (
129129
defaultCiphersChaChaFirst = append(defaultCiphersChaCha, defaultCiphersAES...)
130130
)
131131

132-
// runHTTPs listens on the provided network address and then calls
132+
// runHTTPS listens on the provided network address and then calls
133133
// Serve to handle requests on incoming TLS connections.
134134
//
135135
// Filenames containing a certificate and matching private key for the server must
136136
// be provided. If the certificate is signed by a certificate authority, the
137137
// certFile should be the concatenation of the server's certificate followed by the
138138
// CA's certificate.
139-
func runHTTPS(network, listenAddr, name, certFile, keyFile string, m http.Handler) error {
139+
func runHTTPS(network, listenAddr, name, certFile, keyFile string, m http.Handler, useProxyProtocol, proxyProtocolTLSBridging bool) error {
140140
tlsConfig := &tls.Config{}
141141
if tlsConfig.NextProtos == nil {
142142
tlsConfig.NextProtos = []string{"h2", "http/1.1"}
@@ -184,9 +184,9 @@ func runHTTPS(network, listenAddr, name, certFile, keyFile string, m http.Handle
184184
return err
185185
}
186186

187-
return graceful.HTTPListenAndServeTLSConfig(network, listenAddr, name, tlsConfig, m)
187+
return graceful.HTTPListenAndServeTLSConfig(network, listenAddr, name, tlsConfig, m, useProxyProtocol, proxyProtocolTLSBridging)
188188
}
189189

190-
func runHTTPSWithTLSConfig(network, listenAddr, name string, tlsConfig *tls.Config, m http.Handler) error {
191-
return graceful.HTTPListenAndServeTLSConfig(network, listenAddr, name, tlsConfig, m)
190+
func runHTTPSWithTLSConfig(network, listenAddr, name string, tlsConfig *tls.Config, m http.Handler, useProxyProtocol, proxyProtocolTLSBridging bool) error {
191+
return graceful.HTTPListenAndServeTLSConfig(network, listenAddr, name, tlsConfig, m, useProxyProtocol, proxyProtocolTLSBridging)
192192
}

custom/conf/app.example.ini

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ RUN_MODE = ; prod
2929
;; The protocol the server listens on. One of 'http', 'https', 'unix' or 'fcgi'. Defaults to 'http'
3030
;PROTOCOL = http
3131
;;
32+
;; Expect PROXY protocol headers on connections
33+
;USE_PROXY_PROTOCOL = false
34+
;;
35+
;; Use PROXY protocol in TLS Bridging mode
36+
;PROXY_PROTOCOL_TLS_BRIDGING = false
37+
;;
38+
; Timeout to wait for PROXY protocol header (set to 0 to have no timeout)
39+
;PROXY_PROTOCOL_HEADER_TIMEOUT=5s
40+
;;
41+
; Accept PROXY protocol headers with UNKNOWN type
42+
;PROXY_PROTOCOL_ACCEPT_UNKNOWN=false
43+
;;
3244
;; Set the domain for the server
3345
;DOMAIN = localhost
3446
;;
@@ -51,6 +63,8 @@ RUN_MODE = ; prod
5163
;REDIRECT_OTHER_PORT = false
5264
;PORT_TO_REDIRECT = 80
5365
;;
66+
;; expect PROXY protocol header on connections to https redirector.
67+
;REDIRECTOR_USE_PROXY_PROTOCOL = %(USE_PROXY_PROTOCOL)
5468
;; Minimum and maximum supported TLS versions
5569
;SSL_MIN_VERSION=TLSv1.2
5670
;SSL_MAX_VERSION=
@@ -76,13 +90,19 @@ RUN_MODE = ; prod
7690
;; Do not set this variable if PROTOCOL is set to 'unix'.
7791
;LOCAL_ROOT_URL = %(PROTOCOL)s://%(HTTP_ADDR)s:%(HTTP_PORT)s/
7892
;;
93+
;; When making local connections pass the PROXY protocol header.
94+
;LOCAL_USE_PROXY_PROTOCOL = %(USE_PROXY_PROTOCOL)
95+
;;
7996
;; Disable SSH feature when not available
8097
;DISABLE_SSH = false
8198
;;
8299
;; Whether to use the builtin SSH server or not.
83100
;START_SSH_SERVER = false
84101
;;
85-
;; Username to use for the builtin SSH server.
102+
;; Expect PROXY protocol header on connections to the built-in SSH server
103+
;SSH_SERVER_USE_PROXY_PROTOCOL = false
104+
;;
105+
;; Username to use for the builtin SSH server. If blank, then it is the value of RUN_USER.
86106
;BUILTIN_SSH_SERVER_USER = %(RUN_USER)s
87107
;;
88108
;; Domain name to be exposed in clone URL
@@ -377,9 +397,10 @@ INTERNAL_TOKEN=
377397
;; Name of cookie used to store authentication information.
378398
;COOKIE_REMEMBER_NAME = gitea_incredible
379399
;;
380-
;; Reverse proxy authentication header name of user name and email
400+
;; Reverse proxy authentication header name of user name, email, and full name
381401
;REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
382402
;REVERSE_PROXY_AUTHENTICATION_EMAIL = X-WEBAUTH-EMAIL
403+
;REVERSE_PROXY_AUTHENTICATION_FULL_NAME = X-WEBAUTH-FULLNAME
383404
;;
384405
;; Interpret X-Forwarded-For header or the X-Real-IP header and set this as the remote IP for the request
385406
;REVERSE_PROXY_LIMIT = 1
@@ -694,6 +715,7 @@ ROUTER = console
694715
;ENABLE_REVERSE_PROXY_AUTHENTICATION = false
695716
;ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
696717
;ENABLE_REVERSE_PROXY_EMAIL = false
718+
;ENABLE_REVERSE_PROXY_FULL_NAME = false
697719
;;
698720
;; Enable captcha validation for registration
699721
;ENABLE_CAPTCHA = false

docker/rootless/usr/local/bin/docker-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mkdir -p ${HOME} && chmod 0700 ${HOME}
55
if [ ! -w ${HOME} ]; then echo "${HOME} is not writable"; exit 1; fi
66

77
# Prepare custom folder
8-
mkdir -p ${GITEA_CUSTOM} && chmod 0500 ${GITEA_CUSTOM}
8+
mkdir -p ${GITEA_CUSTOM} && chmod 0700 ${GITEA_CUSTOM}
99

1010
# Prepare temp folder
1111
mkdir -p ${GITEA_TEMP} && chmod 0700 ${GITEA_TEMP}

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ params:
1818
description: Git with a cup of tea
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
21-
version: 1.16.9
21+
version: 1.17.1
2222
minGoVersion: 1.18
2323
goVersion: 1.19
2424
minNodeVersion: 14

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ The following configuration set `Content-Type: application/vnd.android.package-a
238238
## Server (`server`)
239239

240240
- `PROTOCOL`: **http**: \[http, https, fcgi, http+unix, fcgi+unix\]
241+
- `USE_PROXY_PROTOCOL`: **false**: Expect PROXY protocol headers on connections
242+
- `PROXY_PROTOCOL_TLS_BRIDGING`: **false**: When protocol is https, expect PROXY protocol headers after TLS negotiation.
243+
- `PROXY_PROTOCOL_HEADER_TIMEOUT`: **5s**: Timeout to wait for PROXY protocol header (set to 0 to have no timeout)
244+
- `PROXY_PROTOCOL_ACCEPT_UNKNOWN`: **false**: Accept PROXY protocol headers with Unknown type.
241245
- `DOMAIN`: **localhost**: Domain name of this server.
242246
- `ROOT_URL`: **%(PROTOCOL)s://%(DOMAIN)s:%(HTTP\_PORT)s/**:
243247
Overwrite the automatically generated public URL.
@@ -262,12 +266,15 @@ The following configuration set `Content-Type: application/vnd.android.package-a
262266
most cases you do not need to change the default value. Alter it only if
263267
your SSH server node is not the same as HTTP node. Do not set this variable
264268
if `PROTOCOL` is set to `http+unix`.
269+
- `LOCAL_USE_PROXY_PROTOCOL`: **%(USE_PROXY_PROTOCOL)**: When making local connections pass the PROXY protocol header.
270+
This should be set to false if the local connection will go through the proxy.
265271
- `PER_WRITE_TIMEOUT`: **30s**: Timeout for any write to the connection. (Set to -1 to
266272
disable all timeouts.)
267273
- `PER_WRITE_PER_KB_TIMEOUT`: **10s**: Timeout per Kb written to connections.
268274

269275
- `DISABLE_SSH`: **false**: Disable SSH feature when it's not available.
270276
- `START_SSH_SERVER`: **false**: When enabled, use the built-in SSH server.
277+
- `SSH_SERVER_USE_PROXY_PROTOCOL`: **false**: Expect PROXY protocol header on connections to the built-in SSH Server.
271278
- `BUILTIN_SSH_SERVER_USER`: **%(RUN_USER)s**: Username to use for the built-in SSH Server.
272279
- `SSH_USER`: **%(BUILTIN_SSH_SERVER_USER)**: SSH username displayed in clone URLs. This is only for people who configure the SSH server themselves; in most cases, you want to leave this blank and modify the `BUILTIN_SSH_SERVER_USER`.
273280
- `SSH_DOMAIN`: **%(DOMAIN)s**: Domain name of this server, used for displayed clone URL.
@@ -313,6 +320,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
313320
- `LFS_LOCKS_PAGING_NUM`: **50**: Maximum number of LFS Locks returned per page.
314321

315322
- `REDIRECT_OTHER_PORT`: **false**: If true and `PROTOCOL` is https, allows redirecting http requests on `PORT_TO_REDIRECT` to the https port Gitea listens on.
323+
- `REDIRECTOR_USE_PROXY_PROTOCOL`: **%(USE_PROXY_PROTOCOL)**: expect PROXY protocol header on connections to https redirector.
316324
- `PORT_TO_REDIRECT`: **80**: Port for the http redirection service to listen on. Used when `REDIRECT_OTHER_PORT` is true.
317325
- `SSL_MIN_VERSION`: **TLSv1.2**: Set the minimum version of ssl support.
318326
- `SSL_MAX_VERSION`: **\<empty\>**: Set the maximum version of ssl support.
@@ -492,6 +500,8 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
492500
authentication.
493501
- `REVERSE_PROXY_AUTHENTICATION_EMAIL`: **X-WEBAUTH-EMAIL**: Header name for reverse proxy
494502
authentication provided email.
503+
- `REVERSE_PROXY_AUTHENTICATION_FULL_NAME`: **X-WEBAUTH-FULLNAME**: Header name for reverse proxy
504+
authentication provided full name.
495505
- `REVERSE_PROXY_LIMIT`: **1**: Interpret X-Forwarded-For header or the X-Real-IP header and set this as the remote IP for the request.
496506
Number of trusted proxy count. Set to zero to not use these headers.
497507
- `REVERSE_PROXY_TRUSTED_PROXIES`: **127.0.0.0/8,::1/128**: List of IP addresses and networks separated by comma of trusted proxy servers. Use `*` to trust all.
@@ -577,6 +587,8 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
577587
for reverse authentication.
578588
- `ENABLE_REVERSE_PROXY_EMAIL`: **false**: Enable this to allow to auto-registration with a
579589
provided email rather than a generated email.
590+
- `ENABLE_REVERSE_PROXY_FULL_NAME`: **false**: Enable this to allow to auto-registration with a
591+
provided full name for the user.
580592
- `ENABLE_CAPTCHA`: **false**: Enable this to use captcha validation for registration.
581593
- `REQUIRE_EXTERNAL_REGISTRATION_CAPTCHA`: **false**: Enable this to force captcha validation
582594
even for External Accounts (i.e. GitHub, OpenID Connect, etc). You also must enable `ENABLE_CAPTCHA`.

0 commit comments

Comments
 (0)