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

Fixed #9063: Ask LDAP for user DN, don't concatenate username+baseDN. #11544

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sunflowerbofh
Copy link
Contributor

@sunflowerbofh sunflowerbofh commented Jul 21, 2022

Description

Until now in the LDAP authentication the bind dn was concatenated with username and basedn. There might be cases where you want users from different subtrees (can be solved by using a corresponding filter), or maybe stay open if there will be some LDAP group mapping feature added later on.
Therefore when the user enters his/her name in the login form the backend should find out the corresponding dn and use that one for LDAP binding.
If no dn is found the previous mechanism (concatenation username+basedn) will go on.
The statements above are only valid for LDAP (not AD related).

Fixes #9063

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Used the LDAP Synchronisation and Test LDAP Login function and the login page in debugging mode with correct user, correct and wrong password, wrong user.

  • Check with correct username and wrong password and base dn for the whole domain (dc=example,dc=com) -> no login
  • Check with correct username snd correct password -> login
  • Check with wrong username and some password -> no login

Test Configuration:

  • PHP version: php8.1
  • MySQL version: mariadb-server 1:10.6.8-1
  • Webserver version: apache2 2.4.54-2
  • OS version: Debian bullseye

Checklist:

  • I have read the Contributing documentation available here: https://snipe-it.readme.io/docs/contributing-overview
  • I have formatted this PR according to the project guidelines: https://snipe-it.readme.io/docs/contributing-overview#pull-request-guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • [.] New and existing unit tests pass locally with my changes
    (unit tests errors refer to missing database.sqlite and have nothing to do with the change)

@uberbrady
Copy link
Collaborator

This looks pretty close to my own take on this: #11041 - I've been afraid to take that one out of WIP because I haven't had anyone to test it, and I've had a hard time configuring my own slapd server to have a sufficiently complex subtree configuration.

Does that one look pretty close to what you were trying to do?

One thing I like about your approach is that it makes fewer changes. But I'd love to hear what you think about my take, @sunflowerbofh - I figure it's 6 of one, half a dozen of the other, in the end. Either one will work.

@sunflowerbofh
Copy link
Contributor Author

sunflowerbofh commented Aug 2, 2022 via email

Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's probably been a while, but I'd love to take this one - it's just so much cleaner than how I tried to do it. I'll certainly have to do some testing, but I like the way this changes the minimal amount of code necessary to get the job done.

Just had one small ask regarding the number of results returned (and debugging output, regarding that) - if we can get that fixed, then I'll get to testing and we'll see about getting it merged.

Thank you for contributing, and thanks for making a really easy-to-review PR for me!

$userresults = ldap_search($connection, $baseDn, $filterQuery);
$userentries = ldap_get_entries($connection, $userresults);
// Can be empty if user does not exist
if ( $userentries["count"] > 0 ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this actually be == 1 - so if you managed to find two identical-ish looking user, it would refuse to log you in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the condition to ( $userentries["count"] == 1 ) s. also #11715

\Log::debug('User dn is empty.');
}
} else {
\Log::debug('Status of LDAP entries for user ' .$username. ': no result.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do the above-listed change, you'll probably want to output the 'failed' $userentries["count"] here so they can troubleshoot that there were either no results, or more than one result, I figure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although that case should always be 0 in reality I added a further debugging parameter, s. also #11715
You can merge the other MR and close this one, or the other way round, I wouldn't care too much.

BTW: Since the last changes in develop LDAP login does not seem to work any more ("SAML page requested, but SAML does not seem to enabled."). We have no SAML active (maybe this should be opened as separated issue?).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can safely ignore the SAML logging. It's simply because it's in a service provider so it gets loaded on every request. It has nothing at all to do with LDAP syncing or auth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Since the last changes in develop LDAP login does not seem to work any more"
Sorry, was my fault. Since bookworm I have to activate "Allow invalid SSL Certificate" although we have an official letsencrypt certificate with our LDAP servers. Something seems having become stricter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to help you along with your specific issues - come ping us on Discord, maybe we can figure something out. Sometimes it's having a modern CA bundle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has nothing to do with snipe-it, but just FYI: When ldap.so is linked towards libgnutls, LDAP is much stricter than when linked against libssl. On systems where a patched php-ldap is installed, there is no certificate problem.

sunflowerbofh added a commit to sunflowerbofh/snipe-it that referenced this pull request Aug 23, 2022
Signed-off-by: Katharina Drexel <katharina.drexel@bfh.ch>
@sunflowerbofh sunflowerbofh mentioned this pull request Aug 23, 2022
10 tasks
Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the changes you made in the other PR. After I’ve tested it, we’ll take that and it should close both of these out automagically :P

sunflowerbofh added a commit to sunflowerbofh/snipe-it that referenced this pull request Sep 26, 2022
Signed-off-by: Katharina Drexel <katharina.drexel@bfh.ch>
@snipe
Copy link
Owner

snipe commented Dec 22, 2022

@uberbrady did you get a chance to test this? This PR is pretty old now, so we should merge it or close it IMHO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants