# HG changeset patch # User Julien Tayon # Date 1582669890 -3600 # Node ID 2ad148f22c2ff2894b55fb9585a7c1f71cfdc384 # Parent 4ebfdf607b49ac831ba171d45fe0064b55826aa6 [ldapfeed] add option to enable starttls on ldap servers Modern ldap servers connection often use, or even require starttls. diff -r 4ebfdf607b49 -r 2ad148f22c2f cubicweb/server/sources/ldapfeed.py --- a/cubicweb/server/sources/ldapfeed.py Tue Feb 25 23:30:32 2020 +0100 +++ b/cubicweb/server/sources/ldapfeed.py Tue Feb 25 23:31:30 2020 +0100 @@ -118,6 +118,13 @@ 'help': 'additional filters to be set in the ldap query to find valid users', 'group': 'ldap-source', 'level': 2, }), + ('start-tls', + {'type': 'choice', + 'choices': ('true', 'false'), + 'default': 'false', + 'help': 'Start tls on connection (before bind)', + 'group': 'ldap-source', 'level': 1, + }), ('user-login-attr', {'type' : 'string', 'default': 'uid', @@ -197,6 +204,7 @@ self._authenticate = getattr(self, '_auth_%s' % self.authmode) self.cnx_dn = typedconfig['data-cnx-dn'] self.cnx_pwd = typedconfig['data-cnx-password'] + self.start_tls = typedconfig['start-tls'] == "true" self.user_base_dn = str(typedconfig['user-base-dn']) self.user_base_scope = LDAP_SCOPES[typedconfig['user-scope']] self.user_login_attr = typedconfig['user-login-attr'] @@ -285,6 +293,8 @@ server, client_strategy=ldap3.RESTARTABLE, auto_referrals=False, raise_exceptions=True, **kwargs) + if self.start_tls: + conn.start_tls() # Now bind with the credentials given. Let exceptions propagate out. if user is None: @@ -326,6 +336,9 @@ if self._conn is None: self._conn = self._connect() ldapcnx = self._conn + if self.start_tls: + ldapcnx.start_tls() + self.info("ldap start_tls started for %s", self.uri) if not ldapcnx.search(base, searchstr, search_scope=scope, attributes=set(attrs) - {'dn'}): return [] result = [] diff -r 4ebfdf607b49 -r 2ad148f22c2f doc/book/admin/ldap.rst --- a/doc/book/admin/ldap.rst Tue Feb 25 23:30:32 2020 +0100 +++ b/doc/book/admin/ldap.rst Tue Feb 25 23:31:30 2020 +0100 @@ -83,6 +83,8 @@ * `data-cnx-password`, password to use to open data connection to the ldap (eg used to respond to rql queries) +* `start-tls`, starting TLS before bind (valid values: "true", "false") + If the LDAP server accepts anonymous binds, then it is possible to leave data-cnx-dn and data-cnx-password empty. This is, however, quite unlikely in practice. Beware that the LDAP server might hide attributes