Skip to content

Commit 82f89ff

Browse files
willnorrislunny
andauthored
auth/reverseproxy: Add support for full name (go-gitea#20776)
This adds support for getting the user's full name from the reverse proxy in addition to username and email. Tested locally with caddy serving as reverse proxy with Tailscale authentication. Signed-off-by: Will Norris <[email protected]> Signed-off-by: Will Norris <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 1f14609 commit 82f89ff

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

custom/conf/app.example.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,10 @@ INTERNAL_TOKEN=
377377
;; Name of cookie used to store authentication information.
378378
;COOKIE_REMEMBER_NAME = gitea_incredible
379379
;;
380-
;; Reverse proxy authentication header name of user name and email
380+
;; Reverse proxy authentication header name of user name, email, and full name
381381
;REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
382382
;REVERSE_PROXY_AUTHENTICATION_EMAIL = X-WEBAUTH-EMAIL
383+
;REVERSE_PROXY_AUTHENTICATION_FULL_NAME = X-WEBAUTH-FULLNAME
383384
;;
384385
;; Interpret X-Forwarded-For header or the X-Real-IP header and set this as the remote IP for the request
385386
;REVERSE_PROXY_LIMIT = 1
@@ -694,6 +695,7 @@ ROUTER = console
694695
;ENABLE_REVERSE_PROXY_AUTHENTICATION = false
695696
;ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
696697
;ENABLE_REVERSE_PROXY_EMAIL = false
698+
;ENABLE_REVERSE_PROXY_FULL_NAME = false
697699
;;
698700
;; Enable captcha validation for registration
699701
;ENABLE_CAPTCHA = false

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

+4
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
492492
authentication.
493493
- `REVERSE_PROXY_AUTHENTICATION_EMAIL`: **X-WEBAUTH-EMAIL**: Header name for reverse proxy
494494
authentication provided email.
495+
- `REVERSE_PROXY_AUTHENTICATION_FULL_NAME`: **X-WEBAUTH-FULLNAME**: Header name for reverse proxy
496+
authentication provided full name.
495497
- `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.
496498
Number of trusted proxy count. Set to zero to not use these headers.
497499
- `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 +579,8 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
577579
for reverse authentication.
578580
- `ENABLE_REVERSE_PROXY_EMAIL`: **false**: Enable this to allow to auto-registration with a
579581
provided email rather than a generated email.
582+
- `ENABLE_REVERSE_PROXY_FULL_NAME`: **false**: Enable this to allow to auto-registration with a
583+
provided full name for the user.
580584
- `ENABLE_CAPTCHA`: **false**: Enable this to use captcha validation for registration.
581585
- `REQUIRE_EXTERNAL_REGISTRATION_CAPTCHA`: **false**: Enable this to force captcha validation
582586
even for External Accounts (i.e. GitHub, OpenID Connect, etc). You also must enable `ENABLE_CAPTCHA`.

modules/setting/service.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var Service = struct {
3838
EnableReverseProxyAuth bool
3939
EnableReverseProxyAutoRegister bool
4040
EnableReverseProxyEmail bool
41+
EnableReverseProxyFullName bool
4142
EnableCaptcha bool
4243
RequireExternalRegistrationCaptcha bool
4344
RequireExternalRegistrationPassword bool
@@ -127,6 +128,7 @@ func newService() {
127128
Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
128129
Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
129130
Service.EnableReverseProxyEmail = sec.Key("ENABLE_REVERSE_PROXY_EMAIL").MustBool()
131+
Service.EnableReverseProxyFullName = sec.Key("ENABLE_REVERSE_PROXY_FULL_NAME").MustBool()
130132
Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool(false)
131133
Service.RequireExternalRegistrationCaptcha = sec.Key("REQUIRE_EXTERNAL_REGISTRATION_CAPTCHA").MustBool(Service.EnableCaptcha)
132134
Service.RequireExternalRegistrationPassword = sec.Key("REQUIRE_EXTERNAL_REGISTRATION_PASSWORD").MustBool()

modules/setting/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ var (
186186
CookieRememberName string
187187
ReverseProxyAuthUser string
188188
ReverseProxyAuthEmail string
189+
ReverseProxyAuthFullName string
189190
ReverseProxyLimit int
190191
ReverseProxyTrustedProxies []string
191192
MinPasswordLength int
@@ -909,6 +910,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
909910

910911
ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
911912
ReverseProxyAuthEmail = sec.Key("REVERSE_PROXY_AUTHENTICATION_EMAIL").MustString("X-WEBAUTH-EMAIL")
913+
ReverseProxyAuthFullName = sec.Key("REVERSE_PROXY_AUTHENTICATION_FULL_NAME").MustString("X-WEBAUTH-FULLNAME")
912914

913915
ReverseProxyLimit = sec.Key("REVERSE_PROXY_LIMIT").MustInt(1)
914916
ReverseProxyTrustedProxies = sec.Key("REVERSE_PROXY_TRUSTED_PROXIES").Strings(",")

routers/web/admin/admin.go

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func Config(ctx *context.Context) {
257257
ctx.Data["ScriptType"] = setting.ScriptType
258258
ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser
259259
ctx.Data["ReverseProxyAuthEmail"] = setting.ReverseProxyAuthEmail
260+
ctx.Data["ReverseProxyAuthFullName"] = setting.ReverseProxyAuthFullName
260261

261262
ctx.Data["SSH"] = setting.SSH
262263
ctx.Data["LFS"] = setting.LFS

services/auth/reverseproxy.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,15 @@ func (r *ReverseProxy) newUser(req *http.Request) *user_model.User {
105105
}
106106
}
107107

108+
var fullname string
109+
if setting.Service.EnableReverseProxyFullName {
110+
fullname = req.Header.Get(setting.ReverseProxyAuthFullName)
111+
}
112+
108113
user := &user_model.User{
109-
Name: username,
110-
Email: email,
114+
Name: username,
115+
Email: email,
116+
FullName: fullname,
111117
}
112118

113119
overwriteDefault := user_model.CreateUserOverwriteOptions{

0 commit comments

Comments
 (0)