Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Add LDAP authentication #701
Conversation
matrixbot
commented
Apr 6, 2016
|
Can one of the admins verify this patch? |
matrixbot
commented
Apr 6, 2016
|
Can one of the admins verify this patch? |
matrixbot
commented
Apr 6, 2016
|
Can one of the admins verify this patch? |
matrixbot
commented
Apr 6, 2016
|
Can one of the admins verify this patch? |
|
@matrixbot ok to test (Sorry about the matrixbot spam) |
|
Oh, I'll need to add the new dependency manually to get the tests to run. |
|
Although see: http://matrix.org/jenkins/job/SynapseFlake8Packaging/176/violations/file/synapse/handlers/auth.py/ for some code style violations :) |
erikjohnston
and 1 other
commented on an outdated diff
Apr 6, 2016
| @@ -407,11 +423,51 @@ def _find_user_id_and_pwd_hash(self, user_id): | ||
| else: | ||
| defer.returnValue(user_infos.popitem()) | ||
| - def _check_password(self, user_id, password, stored_hash): | ||
| - """Checks that user_id has passed password, raises LoginError if not.""" | ||
| - if not self.validate_hash(password, stored_hash): | ||
| - logger.warn("Failed password login for user %s", user_id) | ||
| - 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)))) |
erikjohnston
Owner
|
erikjohnston
and 1 other
commented on an outdated diff
Apr 6, 2016
| - def _check_password(self, user_id, password, stored_hash): | ||
| - """Checks that user_id has passed password, raises LoginError if not.""" | ||
| - if not self.validate_hash(password, stored_hash): | ||
| - logger.warn("Failed password login for user %s", user_id) | ||
| - 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)))) | ||
| + | ||
| + | ||
| + @defer.inlineCallbacks | ||
| + def _check_local_password(self, user_id, password): | ||
| + try: | ||
| + user_id, password_hash = yield self._find_user_id_and_pwd_hash(user_id) | ||
| + defer.returnValue(not self.validate_hash(password, password_hash)) | ||
| + except: |
erikjohnston
Owner
|
erikjohnston
commented on an outdated diff
Apr 6, 2016
| + | ||
| + local_name = UserID.from_string(user_id).localpart | ||
| + | ||
| + dn = "%s=%s, %s" % (self.ldap_search_property, local_name, self.ldap_search_base) | ||
| + logger.debug("DN for LDAP authentication: %s" % dn) | ||
| + | ||
| + l.simple_bind_s(dn.encode('utf-8'), password.encode('utf-8')) | ||
| + | ||
| + if not (yield self.does_user_exist(user_id)): | ||
| + user_id, access_token = ( | ||
| + yield self.hs.get_handlers().registration_handler.register(localpart=local_name) | ||
| + ) | ||
| + | ||
| + defer.returnValue(True) | ||
| + except ldap.LDAPError, e: | ||
| + logger.info("LDAP error: %s" % e) |
erikjohnston
Owner
|
|
Does |
|
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 |
erikjohnston
self-assigned this
Apr 6, 2016
|
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 |
erikjohnston
commented on the diff
Apr 6, 2016
| @@ -407,11 +425,60 @@ def _find_user_id_and_pwd_hash(self, user_id): | ||
| else: | ||
| defer.returnValue(user_infos.popitem()) | ||
| - def _check_password(self, user_id, password, stored_hash): | ||
| - """Checks that user_id has passed password, raises LoginError if not.""" | ||
| - if not self.validate_hash(password, stored_hash): | ||
| - logger.warn("Failed password login for user %s", user_id) | ||
| - 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)) | ||
| + )) |
erikjohnston
Owner
|
DoubleMalt
added some commits
Apr 5, 2016
|
All checks pass :) |
|
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 Also, feel free to add yourself to the |
|
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
merged commit f942980
into
matrix-org:develop
Apr 7, 2016
DoubleMalt
deleted the
DoubleMalt:ldap-auth
branch
Apr 11, 2016
|
JFTR if you want to avoid the dependency of OpenLDAP installed in the system, a pure-Python option would be the ldap3 package. |
DoubleMalt commentedApr 6, 2016
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: