Skip to content
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

Gitea Authentication no longer working with NGINX Proxies #8561

Closed
2 of 7 tasks
a20eac1d opened this issue Oct 17, 2019 · 7 comments · Fixed by #8586
Closed
2 of 7 tasks

Gitea Authentication no longer working with NGINX Proxies #8561

a20eac1d opened this issue Oct 17, 2019 · 7 comments · Fixed by #8586

Comments

@a20eac1d
Copy link

Description

I recently updated my Gitea Docker container to the latest version and it seems like one of the last Gitea updates broke compatibility with NGINX web proxies.

After setting up the Gitea instance and creating an account I will be immediately logged in without entering any credentials. When switching devices or computers, I still dont have to login with my password. My account is automatically logged in WORLDWIDE on EVERY device.

The "Logout" button does nothing and simply redirects me to my dashboard.

@zeripath
Copy link
Contributor

zeripath commented Oct 17, 2019

Edit: I've got the wrong end of the stick here.

This is totally the wrong interpretation of the problem.


Hi! It's difficult to know what the causative change is as this is highly configuration dependent on your proxy and I'm not sure how to go about setting up a test environment for this - any test harness would be highly complex.

Could you tell us what the last known working version was?

Are you able to do a git bisect from a known working version and the latest?

The code that handles this is as follows and the majority of it is 3 years old with 10 months being the youngest:

gitea/modules/auth/auth.go

Lines 134 to 169 in 6ddd3b0

if setting.Service.EnableReverseProxyAuth {
webAuthUser := ctx.Req.Header.Get(setting.ReverseProxyAuthUser)
if len(webAuthUser) > 0 {
u, err := models.GetUserByName(webAuthUser)
if err != nil {
if !models.IsErrUserNotExist(err) {
log.Error("GetUserByName: %v", err)
return nil, false
}
// Check if enabled auto-registration.
if setting.Service.EnableReverseProxyAutoRegister {
email := gouuid.NewV4().String() + "@localhost"
if setting.Service.EnableReverseProxyEmail {
webAuthEmail := ctx.Req.Header.Get(setting.ReverseProxyAuthEmail)
if len(webAuthEmail) > 0 {
email = webAuthEmail
}
}
u := &models.User{
Name: webAuthUser,
Email: email,
Passwd: webAuthUser,
IsActive: true,
}
if err = models.CreateUser(u); err != nil {
// FIXME: should I create a system notice?
log.Error("CreateUser: %v", err)
return nil, false
}
return u, false
}
}
return u, false
}
}

As you can see if the X-WEBAUTH-USER header is set then the user will be logged in automatically as the appropriate user.

To log out from this you would need to log out from both Gitea - removing the session from gitea and log out from the WEBAUTH host - meaning that it no longer sends the X-WEBAUTH-USER.

Hmm... we did change some more upstream auth bits but I'm not sure that these would account for this.

@a20eac1d
Copy link
Author

Oh wow, it is the auto-login caused by logging in to HTTP Basic-Auth.

When the login details for both HTTP Basic-Auth and Gitea are the same, it will login automatically.

What a strange feature.
Is there any chance that you could disable it by default? Those two login systems should definitely be seperate. It makes no sense to have it turned on automatically and I'm sure it will cause confusion in the future.

@a20eac1d
Copy link
Author

a20eac1d commented Oct 17, 2019

I tried to disable the feature using: https://docs.gitea.io/en-us/config-cheat-sheet/

ENABLE_REVERSE_PROXY_AUTHENTICATION

Setting it to false does not seem to have any impact on the issue. Am I using it wrong?

[service]
DISABLE_REGISTRATION = true
REQUIRE_SIGNIN_VIEW = true
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = false
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
ENABLE_CAPTCHA = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_ENABLE_TIMETRACKING = true
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_REVERSE_PROXY_AUTHENTICATION = false
ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
ENABLE_REVERSE_PROXY_EMAIL = false

@lunny
Copy link
Member

lunny commented Oct 18, 2019

Those default values are already false.

@zeripath
Copy link
Contributor

He's looking for a way to disable basic authentication in Gitea - I don't think we have that.

@a20eac1d
Copy link
Author

Those default values are already false.

Those default values weren't in the "app.ini" created by Gitea, I had to add them.

But even now, they don't do anything. Setting them to true/false does nothing.

@zeripath
Copy link
Contributor

@a20eac1d those settings are for a different type of login - in that case the proxy server is setting a X-WEBAUTH-USER header. Basic authentication is set using the AUTHORIZATION header with type basic.

We have no setting to turn that mode of authentication off at present - it's used in the API, predominantly for controlling tokens. I think it would be possible to add a simple config switch to disallow this method of authentication though.

zeripath added a commit to zeripath/gitea that referenced this issue Oct 19, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants