I have Drupal 6.12 running with various modules installed and everything working beautifully thus far... I am now trying to implement LDAP authentication and have installed the LDAP integration ver 6.x-1.0-alpha2. This Drupal installation is being used in an educational institution.

Currently, the module seem to be working quite nicely and authentication works 'most' of the time... trying to identify the isse with the 'problem' accounts, I have enabled logging and have tracked it down to this error:

Error: 2 users found with $cn=doejohn under o=myorg.

I have looked over the issue and realised that authentication is failing when I have two (or more) users that have the same username (although in different containers in our eDirectory). Thus, all of the employees have unique usernames regardless of the container they are in... however, students CAN have username that are identical to exsting employees. I can specify various DNs for the search, however, the module 'by design' does subscope searches, and it so happens that employees (teachers, janitors, supply staff, etc) will be 'inside' a location container and students will be within another container inside that location...
thus:
employee: CN=doejohn, ou=theschool,ou=thislocation,o=myorg
student: CN=doejohn, ou=students, ou=theschool, ou=thislocation,o=myorg

How can I configure my module to support this? Currently, I simply have 'o=myorg' as my base DN as I need every employee to be able to login to the site... and in the near future, students will alos need to login... thus, in the short term I would like to filter out accounts with 'ou=students', but ideally, I would need anyone to be able to log in...

Am I overlooking something in my approach, or does the state of this module (alpha2) just not have this kind of functionality yet?

Please help... I am willing to 'attempt' a code patch/fix/kludge, but not even sure where to start or how to approach it.
Any suggestions?

Comments

miglius’s picture

If you can change LDAP structure, I would suggest to add a ou=employees,ou=theschool,ou=thislocation,o=myorg and move all employees over to this branch. Then you will be able to specify different Bind DNs in the LDAP_integration module:
ou=students, ou=theschool, ou=thislocation,o=myorg and ou=employees,ou=theschool,ou=thislocation,o=myorg

mainer’s picture

Appreciate the suggestion, and that would also be my choice... but considering the numbers of schools and offices and the existing eDirectory structure, I have a better chance of winning the lottery than getting any of that changed. :)

Q: I also manage several moodle sites for online learning and stuff, and the moodle ldap feature does not suffer the same failure for users that fail on my Drupal setup. Don't get me wrong, I by far prefer drupal and its nomenclature... but am guessing that the fetch/validation operation is different between both systems. I would have to guess that Moodle fetches and validates one at a time and posts login failure once it is out of usernames/pwds pairs... whereas the Drupal module throws an error if more than one user is found (without any validation being done before this error)?

I would not need to filter or do anything else if the module could simply fetch and validate every user, one at a time, until it is out of users/pwd matches...

I am going to try and look at the code right now... but feel that it is most likely out of my reach to make any useful changes. I will keep you updated.

Appreciate your input! More than happy to entertain any other ideas you may have, or even better, tell me if my resoning (above) is sound/on the right track.

mainer’s picture

Alright... so I looked over some of the code in the ldapauth.module....

A few reasons why there is no 'easy' fix for my situation from what I can make out of the code...

- if you allowed similar CNs in the _ldapauth_user_lookup call, there would be a problem in the Drupal user list - if a user authenticated successfully against LDAP first time, the user is registered in the Drupal system... so being a flat namespace in Drupal, you would have identical user accounts one the second user tries to log in.... correct?

*uggggh, from what I can see, I may have to abandon Drupal because of this... arrrgh. Hmmph.

Q: Based on your suggestion above however, (revamping the LDAP structure), there would still be a common CN for some users... but the OU attribute would differentiate them - making my comment above incorrect? Not a flat namespace if what you suggest works... because although the namelookup would find them in different DNs, would it not still cause conflict in creating the user in Drupal? I am unclear as to why your suggestion would work (because there would still be two users found with multiple DNs listed), and I assume it stops iterating through the DN list once a user is found and authenticated successfully... if it gets that far, because once the user is registered, it would only check for the password in ldap? (which would fail if it were the second user trying to log in)

Q: Before returning the result of the _ldapauth_user_lookup call, could we not eliminate the duplicates by only registering the correct user/pwd lookup?

I am obviously a newb in trying to work through this code (quite impressive btw!) and obviously don't have the full picture of the process yet...

Appreciate yout time/patience and suggestions as I really would prefer to use DRUPAL + LDAP in my organization.

Thanx Miglius, hope to hear from you some more on this...

nb: I can appreciate that our LDAP structure is the issue here... however, surely in large organizations, this still occurs? How would this module accomodate that?

miglius’s picture

> Q: Based on your suggestion above however....

The drupal user name is created based on the string which was entered to login to the site. To cope with the flat drupal users you could configure the module to require to login with the strings like "my name:student" and "my name:employee", then configure the ldap auth module to strip :student and :employee before sending the username to authenticate with ldap. However you still have to move employees to separate branch (which unfortunately is not the case for you).

> Q: Before returning the result of the _ldapauth_user_lookup call, could we not eliminate...

This is a potential security risk I'm not comfortable with. There are a small but still a chance that both users will have the same password, especially suppose their account are created in ldap with the same default password. Then both of those users will end up logging in as the first user.

I'm not familiar how moodle is coping with this particular situation. Maybe it would be worth to look at it's logic?

Anyway, it looks like you're trying to solve the particular bad LDAP design consequence, but not the root problem itself. I think that chances are quite high that you will have name clashes between employees or students as well. That means that you (or all institution) will have to move to unique usernames and identify users by unique IDs, not by the first and last names.

mainer’s picture

Ahh, you bring clarity to the Drupal process for registering users.
I much appreciate the comments and armed a little better to have this discussion with the network admins or our organization.

I will tinker with one of my Moodle setups to see if I can follow the logic in that process. Again, very much appreciate your time. If anything pops up with regards to my particular situation and any other approaches, please don't hesitate to communicate with me here!

Cheers.

miglius’s picture

Issue tags: +ldapauth
mainer’s picture

If I were to list the 'deepest' DNs first, and work my way back up the tree that way, would this make a difference? Your suggestion of having the LDAP structure re-worked to put employees in their own container and avoid nesting of OUs suggests we could still have common CNs (usernames) and authentication woud work? Thus, when a user authenticates and iterates through the listed DNs, does it search one of them and attempt to validate the user if it finds one BEFORE proceeding to the next DN in the list, or does it do a full search of the entire tree (iterating all the DNs I list...) before attempting to validate the user(s) found (and failing immediately if matches$<>1 )?

Beating a dead horse I know... but just a thought that popped up from what you explained earlier....

mainer’s picture

Alright, tinkered some more... answered some of my own Qs in the process.

The users I tested that had same CN usernames were in different branches... so I changed the DN list and put in specific branches... thinking that what you suggested about the LDAP structure change might help...
but alas, no. The process fails as soon as it encounters 'incorrect credentials', however, the matches$ problem does not occur. So your final comments about each user needing to have unique usernames ultimately remains true.

All this being said, I would have to think this ugly issue will raise its ugly head again in larger enterprises as similar CNs will occur (in different branches, there is definitely improper LDAP structures out there)... based on this experimentation here, I can appreciate your concern about auto-generated pwds being a concern, but one, pretty remote chance, and two, can be documented in the release / installation notes...

..iterating through an array of returned users from the lookup call instead of just killing the process at the first found user would seem logical to me... undoubtedly a significant change to the inner workings of the process and dependencies with the other LDAP modules, but surely this will be a limiting factor for many orgs.

Again, thanx for your time and patience as I knit some kind of ugly kludge for my situation... essentially just trying to fully understand the process.

I would appreciate your feedback on these comments once again.

Cheers!

mainer’s picture

Well, I seem to be just bombing this issue eh?

I have found what I think will be a short term solution... authentication wise for now... I changed the CN parameter and specified 'mail'... so that the user accounts created in Drupal will be the employees email address, which are obviously unique in the tree! I tested this with only two accounts at the moment, but it worked... students are not provided an email address, so it takes care of that issue, and if they have access to their own school's moodle, then they don't need to log into the main website (although I would have liked a one stop login 'area')... but I am still working out this idea.

Now, the design of your module was surely not to use the email addies for this purpose (although it is used on all the major sites....). I am hoping I can easily 'mask' or specify which attribute to use (First name or shortened email addy to the username) for posts, comments, etc, as I would not want bots to pick up all these email adresses and increase our spam hundredfold.

Am I missing some very obvious security/management issues in this approach? Again, like all the posts above, your feedback is appreciated and welcomed here once again...

Thanx miglius (and whomever may reply), have a good weekend. :)

miglius’s picture

During the authentication the module loops through all Base DNs configured and searches for the user in all those base DNs. However, it was a design decision that if several users are matched in the searched base DN, the authentication is forbidden. Only if one user is found, the authentication will proceed. We're using LDAP integration in environments with a closed user groups and security in mind and we cannot afford taking any chance that a user can be logged in to different account in case of the duplicate full name and default ldap password. There should be no ambiguity left where security is concerned.

If you put the "deeper" DN first in the Base DN section, the authentication will work for those users in the "deeper" layer as only one match will be resulted in the user search, however when somebody from the upper layer will try to authenticate, a user search will pick that deeper duplicate as well which result in two matches and the authentication will fail.

If you decide to use e-mail address as the username, but don't want it to be displayed on the pages, you can always change the behavior at drupal theming layer by overriding the default function which prints out the username, i.e. http://api.drupal.org/api/function/theme_username/6.

mainer’s picture

U have echoed everything I discovered on the weekend trying to hammer this out. You have worded it far better than I would have, but I did indeed confirm everything you describe here above. I respect the design decision, and knew as embarked on this project that the LDAP structure was going to be an issue.

I am a fan of proper structure and protocol as well, I was just trying to limit the amount of frustration in dealing with this in my setup. I appreciate the time and thought you have given to my questions. You have truly been helpful.

Cheers!

zeezhao’s picture

Hi. Just checking to see if there was any other subsequent solution, apart from using emails as username. Thanks

cgmonroe’s picture

Clearing out old support requests - reopen if problem still exists in newest code (dev)

Have not checked this, but since Drupal REQUIRES unique user names but LDAP can have duplicates. If you are using something that can not be guaranteed to be unique (e.g., there might be two J. Smiths), you probably need to use the "PhP code to alter login names" and force people to add a domain identifier of some sort. E.g. jsmith@faculty or faculty/jsmith... then transform this to a valid ldap filter string.

cgmonroe’s picture

Status: Active » Closed (fixed)