Skip to content
Snippets Groups Projects
Verified Commit 5e2ff023 authored by Julian's avatar Julian
Browse files

ldap-sync: Added support for unencrypted LDAP

parent 90b48e26
Branches
No related tags found
No related merge requests found
...@@ -42,9 +42,14 @@ import ldap3 ...@@ -42,9 +42,14 @@ import ldap3
import gitlab import gitlab
from systemd.journal import JournalHandler from systemd.journal import JournalHandler
def connect_ldap(host, port, ca_file, bind_dn, bind_passwd): def connect_ldap(host, port, encryption, ca_file, bind_dn, bind_passwd):
if encryption == 'simple_tls':
tls = ldap3.Tls(validate=ssl.CERT_REQUIRED, ca_certs_file=ca_file) tls = ldap3.Tls(validate=ssl.CERT_REQUIRED, ca_certs_file=ca_file)
server = ldap3.Server(host, port=port, use_ssl=True, get_info=ldap3.ALL, tls=tls) server = ldap3.Server(host, port=port, use_ssl=True, get_info=ldap3.ALL, tls=tls)
elif encryption == 'plain':
server = ldap3.Server(host, port=port, get_info=ldap3.ALL)
else:
raise Exception('Invalid encryption parameter "{}"'.format(encryption))
conn = ldap3.Connection(server, bind_dn, bind_passwd, auto_bind=True) conn = ldap3.Connection(server, bind_dn, bind_passwd, auto_bind=True)
old_search = conn.search old_search = conn.search
def search(*args, **kwargs): def search(*args, **kwargs):
...@@ -166,7 +171,8 @@ def main(config_path, dry_run=True): ...@@ -166,7 +171,8 @@ def main(config_path, dry_run=True):
config = load_config(config_path) config = load_config(config_path)
gl = gitlab.Gitlab(config['ldap_sync']['api_url'], config['ldap_sync']['api_token'], ssl_verify=True) gl = gitlab.Gitlab(config['ldap_sync']['api_url'], config['ldap_sync']['api_token'], ssl_verify=True)
conn = connect_ldap(host=config['ldap']['main']['host'], port=config['ldap']['main']['port'], conn = connect_ldap(host=config['ldap']['main']['host'], port=config['ldap']['main']['port'],
ca_file=config['ldap']['main']['ca_file'], encryption=config['ldap']['main']['encryption'],
ca_file=config['ldap']['main'].get('ca_file'),
bind_dn=config['ldap']['main']['bind_dn'], bind_dn=config['ldap']['main']['bind_dn'],
bind_passwd=config['ldap']['main']['password']) bind_passwd=config['ldap']['main']['password'])
logging.info('Starting user synchronization') logging.info('Starting user synchronization')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment