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

pam.d authentication fails #15702

Closed
2 of 6 tasks
yahess opened this issue May 2, 2021 · 6 comments · Fixed by #15825
Closed
2 of 6 tasks

pam.d authentication fails #15702

yahess opened this issue May 2, 2021 · 6 comments · Fixed by #15825

Comments

@yahess
Copy link

yahess commented May 2, 2021

  • Gitea version (or commit ref): 1.15.0+dev-206-gae6d7860b
  • Git version: 2.25.1
  • Operating system: Ubuntu 20.04
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:

Description

Authentication via pam.d krb5 module fails with error

...dels/login_source.go:831:UserSignIn() [W] Failed to login 'USERID' via 'systemusers': e-mail invalid [email: USERID]

@yahess yahess changed the title pam.d authetication fails pam.d authentication fails May 2, 2021
@lunny
Copy link
Member

lunny commented May 7, 2021

I think maybe we can enable pam tags for docker build since it's Linux.

@zeripath
Copy link
Contributor

zeripath commented May 9, 2021

@yahess are you sure that pam is compiled into your version of Gitea? as @lunny says pam isn't included in the docker builds or builds by default.

@yahess
Copy link
Author

yahess commented May 10, 2021

Hi,

I have the following version. I build it using the install from source guide.

root@gitea:~/gitea# ./gitea --version
Gitea version 1.15.0+dev-206-gae6d7860b built with GNU Make 4.2.1, go1.16.3 : bindata, pam

@zeripath
Copy link
Contributor

What were your TAGS for the build?

@yahess
Copy link
Author

yahess commented May 10, 2021

TAGS="bindata pam" make build

@zeripath
Copy link
Contributor

OK, so let's jump back a bit. This error report is coming from:

log.Warn("Failed to login '%s' via '%s': %v", username, source.Name, err)

Which implies that the user in question is not in the db at present. (see L777 of that function)

The error (a models.ErrEmailInvalid) with the string content e-mail invalid [email: USERID] can only be returned by:

// ValidateEmail check if email is a allowed address
func ValidateEmail(email string) error {
if len(email) == 0 {
return nil
}
if _, err := mail.ParseAddress(email); err != nil {
return ErrEmailInvalid{email}
}
// TODO: add an email allow/block list
return nil
}

and so will be coming from L888 within:

gitea/models/user.go

Lines 854 to 855 in 1e6fa57

// CreateUser creates record of a new user.
func CreateUser(u *User) (err error) {

(This was added by #13475 and amended slightly by #13627)

The problem is that neither of these PRs considered what happens with PAM:

// LoginViaPAM queries if login/password is valid against the PAM,
// and create a local user if success when enabled.
func LoginViaPAM(user *User, login, password string, sourceID int64, cfg *PAMConfig) (*User, error) {
pamLogin, err := pam.Auth(cfg.ServiceName, login, password)
if err != nil {
if strings.Contains(err.Error(), "Authentication failure") {
return nil, ErrUserNotExist{0, login, 0}
}
return nil, err
}
if user != nil {
return user, nil
}
// Allow PAM sources with `@` in their name, like from Active Directory
username := pamLogin
idx := strings.Index(pamLogin, "@")
if idx > -1 {
username = pamLogin[:idx]
}
user = &User{
LowerName: strings.ToLower(username),
Name: username,
Email: pamLogin,
Passwd: password,
LoginType: LoginPAM,
LoginSource: sourceID,
LoginName: login, // This is what the user typed in
IsActive: true,
}
return user, CreateUser(user)
}

in particular:

Email: pamLogin,

This makes no attempt to check that the pamLogin would be a valid email under those constraints.


So... The question is what to do?

I think we can leave the email blank or we could try adding the noreply suffix. An alternative is to change the pam module you're linking in to return the email address instead of the username.

zeripath added a commit to zeripath/gitea that referenced this issue May 10, 2021
PAM autoregistration of users currently fails due to email invalidity.
This PR adds a new setting to PAM to allow an email domain to be set
or just sets the email to the noreply address and if that fails falls
back to uuid@localhost

Fix go-gitea#15702

Signed-off-by: Andrew Thornton <[email protected]>
zeripath added a commit that referenced this issue May 13, 2021
* Restore PAM user autocreation functionality

PAM autoregistration of users currently fails due to email invalidity.
This PR adds a new setting to PAM to allow an email domain to be set
or just sets the email to the noreply address and if that fails falls
back to uuid@localhost

Fix #15702

Signed-off-by: Andrew Thornton <[email protected]>

* As per KN4CKER

Signed-off-by: Andrew Thornton <[email protected]>
zeripath added a commit to zeripath/gitea that referenced this issue May 14, 2021
Backport go-gitea#15825

* Restore PAM user autocreation functionality

PAM autoregistration of users currently fails due to email invalidity.
This PR adds a new setting to PAM to allow an email domain to be set
or just sets the email to the noreply address and if that fails falls
back to uuid@localhost

Fix go-gitea#15702

Signed-off-by: Andrew Thornton <[email protected]>

* As per KN4CKER

Signed-off-by: Andrew Thornton <[email protected]>
techknowlogick pushed a commit that referenced this issue May 19, 2021
Backport #15825

* Restore PAM user autocreation functionality

PAM autoregistration of users currently fails due to email invalidity.
This PR adds a new setting to PAM to allow an email domain to be set
or just sets the email to the noreply address and if that fails falls
back to uuid@localhost

Fix #15702

Signed-off-by: Andrew Thornton <[email protected]>

* As per KN4CKER

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: 6543 <[email protected]>
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this issue Aug 10, 2021
* Restore PAM user autocreation functionality

PAM autoregistration of users currently fails due to email invalidity.
This PR adds a new setting to PAM to allow an email domain to be set
or just sets the email to the noreply address and if that fails falls
back to uuid@localhost

Fix go-gitea#15702

Signed-off-by: Andrew Thornton <[email protected]>

* As per KN4CKER

Signed-off-by: Andrew Thornton <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
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