Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add LDAP authentication #701

Merged
merged 14 commits into from
Apr 7, 2016
Merged

Conversation

DoubleMalt
Copy link
Contributor

This pul request enables LDAP authentication. If a users authenticate successfully via the configured LDAP server and are not yet in the local database, they are created.

Missing parts:

  • get email from LDAP server
  • get full name from LDAP server

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

3 similar comments
@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@erikjohnston
Copy link
Member

@matrixbot ok to test

(Sorry about the matrixbot spam)

@erikjohnston
Copy link
Member

Oh, I'll need to add the new dependency manually to get the tests to run.

@erikjohnston
Copy link
Member

raise LoginError(403, "", errcode=Codes.FORBIDDEN)
@defer.inlineCallbacks
def _check_password(self, user_id, password):
defer.returnValue(not ((yield self._check_ldap_password(user_id, password)) or (yield self._check_local_password(user_id, password))))
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit hard to follow. Maybe something like the following is clearer?

if self.ldap_enabled:
    valid_ldap = yield self._check_ldap_password(user_id, password))
    if valid_ldap:
       defer.returnValue(True)

valid_password = yield self._check_local_password(user_id, password)
defer.returnValue(valid_password)

This way we don't attempt (and log) if we've tried to do LDAP each time someone logs in to a HS with LDAP disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the first line of _check_ldap_password bails immediately if ldap_enabled is false. I can put the log level for the message on debug.

I honestly have a harder time parsing your code to see that it returns true if any of the two methods return true, but that's probably just my personal preference. I don't have a problem to change the code to you suggestion if you feel strongly about it :)

@erikjohnston
Copy link
Member

Does python-ldap have a system dependency? If it does then I'd probably want to make the python-ldap dependency optional somehow, otherwise its going to break everyone's synapse on upgrade.

@DoubleMalt
Copy link
Contributor Author

Unfortunately it depends on openldap-dev. How could I make it optional in the python-dependencies file?

@erikjohnston
Copy link
Member

Unfortunately it depends on openldap-dev. How could I make it optional in the python-dependencies file?

I think the easiest is just to omit it from the dependency list entirely, and only try and import it if ldap is enabled. Since importing is cheap after its done initially, I'd probably import it in __init__ (to catch early if ldap is enabled, but they didn't add the dependency) and then just reimport it in _check_ldap_password

@erikjohnston erikjohnston self-assigned this Apr 6, 2016
@erikjohnston
Copy link
Member

The unit tests are failing due to the fact that Mocks evaluate to True. I propose being slightly evil and changing the ldap enabled tests to if self.ldap_enabled is True and if self.ldap_enabled is not True

(yield self._check_ldap_password(user_id, password))
or
(yield self._check_local_password(user_id, password))
))
Copy link
Member

Choose a reason for hiding this comment

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

Line 234 needs to be updated now that this no longer raises but instead returns a boolean.

@DoubleMalt
Copy link
Contributor Author

All checks pass :)

@erikjohnston
Copy link
Member

Excellent! If you could just sign off on this contribution we can land it: https://github.com/matrix-org/synapse/blob/master/CONTRIBUTING.rst#sign-off

Simply replying here with Signed-off-by: Your Name <[email protected]>, is sufficient.

Also, feel free to add yourself to the AUTHORS.rst!

Signed-off-by: Christoph Witzany <[email protected]>
@erikjohnston
Copy link
Member

Woo! Thanks :)

(The failure seems to be due to jenkins failing to set the commit status on github, intriguingly. All the tests pass though)

@erikjohnston erikjohnston merged commit f942980 into matrix-org:develop Apr 7, 2016
@DoubleMalt DoubleMalt deleted the ldap-auth branch April 11, 2016 09:35
@simsasaile simsasaile mentioned this pull request Apr 18, 2016
@aperezdc
Copy link
Contributor

aperezdc commented May 2, 2016

JFTR if you want to avoid the dependency of OpenLDAP installed in the system, a pure-Python option would be the ldap3 package.

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 this pull request may close these issues.

4 participants