Skip to content

Commit 99ed96c

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: update current stable version [skip ci] Updated translations via Crowdin Fix mirror address setting not working (go-gitea#20850) Support Proxy protocol (go-gitea#12527) Fix SQL Query for `SearchTeam` (go-gitea#20844) Double check CloneURL is acceptable (go-gitea#20869) Fix graceful doc (go-gitea#20883) Pad GPG Key ID with preceding zeroes (go-gitea#20878) [skip ci] Updated translations via Crowdin call builtinUnused() if internal SSH is disabled (go-gitea#20877) Don't open new page for ext wiki on same repository (go-gitea#20725) [skip ci] Updated translations via Crowdin Fix the mode of custom dir to 0700 in docker-rootless (go-gitea#20861) Fix UI mis-align for PR commit history (go-gitea#20845)
2 parents 23ecac1 + 7854c44 commit 99ed96c

File tree

43 files changed

+1018
-126
lines changed

Some content is hidden

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

43 files changed

+1018
-126
lines changed

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: 21 additions & 1 deletion
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

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: 8 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.

integrations/api_team_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func TestAPITeamSearch(t *testing.T) {
223223
defer prepareTestEnv(t)()
224224

225225
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
226-
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
226+
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17})
227227

228228
var results TeamSearchResults
229229

integrations/api_user_orgs_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@ func TestUserOrgs(t *testing.T) {
2626
orgs := getUserOrgs(t, adminUsername, normalUsername)
2727

2828
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"})
29+
user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"})
2930

3031
assert.Equal(t, []*api.Organization{
32+
{
33+
ID: 17,
34+
UserName: user17.Name,
35+
FullName: user17.FullName,
36+
AvatarURL: user17.AvatarLink(),
37+
Description: "",
38+
Website: "",
39+
Location: "",
40+
Visibility: "public",
41+
},
3142
{
3243
ID: 3,
3344
UserName: user3.Name,
@@ -82,8 +93,19 @@ func TestMyOrgs(t *testing.T) {
8293
var orgs []*api.Organization
8394
DecodeJSON(t, resp, &orgs)
8495
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"})
96+
user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"})
8597

8698
assert.Equal(t, []*api.Organization{
99+
{
100+
ID: 17,
101+
UserName: user17.Name,
102+
FullName: user17.FullName,
103+
AvatarURL: user17.AvatarLink(),
104+
Description: "",
105+
Website: "",
106+
Location: "",
107+
Visibility: "public",
108+
},
87109
{
88110
ID: 3,
89111
UserName: user3.Name,

integrations/org_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func TestOrgRestrictedUser(t *testing.T) {
197197
func TestTeamSearch(t *testing.T) {
198198
defer prepareTestEnv(t)()
199199

200-
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
201-
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
200+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15})
201+
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17})
202202

203203
var results TeamSearchResults
204204

@@ -209,8 +209,9 @@ func TestTeamSearch(t *testing.T) {
209209
resp := session.MakeRequest(t, req, http.StatusOK)
210210
DecodeJSON(t, resp, &results)
211211
assert.NotEmpty(t, results.Data)
212-
assert.Len(t, results.Data, 1)
213-
assert.Equal(t, "test_team", results.Data[0].Name)
212+
assert.Len(t, results.Data, 2)
213+
assert.Equal(t, "review_team", results.Data[0].Name)
214+
assert.Equal(t, "test_team", results.Data[1].Name)
214215

215216
// no access if not organization member
216217
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})

models/asymkey/gpg_key.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ func (key *GPGKey) AfterLoad(session *xorm.Session) {
6363
}
6464
}
6565

66+
// PaddedKeyID show KeyID padded to 16 characters
67+
func (key *GPGKey) PaddedKeyID() string {
68+
if len(key.KeyID) > 15 {
69+
return key.KeyID
70+
}
71+
zeros := "0000000000000000"
72+
return zeros[0:16-len(key.KeyID)] + key.KeyID
73+
}
74+
6675
// ListGPGKeys returns a list of public keys belongs to given user.
6776
func ListGPGKeys(ctx context.Context, uid int64, listOptions db.ListOptions) ([]*GPGKey, error) {
6877
sess := db.GetEngine(ctx).Table(&GPGKey{}).Where("owner_id=? AND primary_key_id=''", uid)

models/fixtures/org_user.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@
6363
uid: 29
6464
org_id: 17
6565
is_public: true
66+
67+
-
68+
id: 12
69+
uid: 2
70+
org_id: 17
71+
is_public: true

models/fixtures/user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
avatar_email: [email protected]
310310
num_repos: 2
311311
is_active: true
312-
num_members: 3
312+
num_members: 4
313313
num_teams: 3
314314

315315
-

0 commit comments

Comments
 (0)