-
Notifications
You must be signed in to change notification settings - Fork 178
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
Added tls certs and keys settings #87
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import re | ||
|
||
import ssl | ||
from jupyterhub.auth import Authenticator | ||
import ldap3 | ||
from ldap3.utils.conv import escape_filter_chars | ||
|
@@ -41,6 +41,33 @@ def _server_port_default(self): | |
""" | ||
) | ||
|
||
server_ca_file = Unicode( | ||
config=True, | ||
help=""" | ||
Path of the CA certificate file for the *secure* LDAP server | ||
|
||
If you're receiving `CERTIFICATE_VERIFY_FAILED` errors, you have to use this setting. | ||
""" | ||
) | ||
|
||
client_certificate_file = Unicode( | ||
config=True, | ||
help=""" | ||
Path of the certificate file for the LDAP client | ||
|
||
If you're receiving `SSLV3_ALERT_HANDSHAKE_FAILURE` errors, you have to use this setting. | ||
""" | ||
) | ||
|
||
client_key_file = Unicode( | ||
config=True, | ||
help=""" | ||
Path of the key file for the LDAP client | ||
|
||
If you're receiving `SSLV3_ALERT_HANDSHAKE_FAILURE` errors, you have to use this setting. | ||
""" | ||
) | ||
|
||
bind_dn_template = Union( | ||
[List(),Unicode()], | ||
config=True, | ||
|
@@ -268,11 +295,22 @@ def authenticate(self, handler, data): | |
password = data['password'] | ||
# Get LDAP Connection | ||
def getConnection(userdn, username, password): | ||
server = ldap3.Server( | ||
self.server_address, | ||
port=self.server_port, | ||
use_ssl=self.use_ssl | ||
) | ||
if self.use_ssl: | ||
ca_cert = None | ||
client_cert = None | ||
client_key = None | ||
if self.server_ca_file != '': | ||
ca_cert = self.server_ca_file | ||
if self.client_certificate_file != '': | ||
client_cert = self.client_certificate_file | ||
if self.client_key_file != '': | ||
client_key = self.client_key_file | ||
Comment on lines
+298
to
+307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming we go for a merge of this PR, we should also simplify this logic to by letting the new traitlets based config have |
||
tlsSettings = ldap3.Tls(local_private_key_file=client_key, | ||
local_certificate_file=client_cert, | ||
ca_certs_file=ca_cert, validate=ssl.CERT_REQUIRED) | ||
server = ldap3.Server(self.server_address, port=self.server_port, use_ssl=True, tls=tlsSettings) | ||
else: | ||
server = ldap3.Server(self.server_address, port=self.server_port, use_ssl=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the last changes it should be now possible to only supply certain options, before that, it was needed to use all the three new settings to work with tls endpoints. |
||
self.log.debug('Attempting to bind {username} with {userdn}'.format( | ||
username=username, | ||
userdn=userdn | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not satisfied with the documentation that i wrote, but i think this could be left for another moment.