diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d6763b2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:2.7 + +# Add the python LDAP module +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + python-dev libldap2-dev libsasl2-dev libssl-dev \ + curl + +RUN pip install python-ldap + +# Add the LDAP auth daemon from our fork of https://github.com/nginxinc/nginx-ldap-auth +RUN curl -L https://raw.githubusercontent.com/Mapscape/nginx-ldap-auth/master/nginx-ldap-auth-daemon.py > /usr/local/bin/nginx-ldap-auth-daemon.py \ + && chmod +x /usr/local/bin/nginx-ldap-auth-daemon.py + +EXPOSE 8888 + +# Run the daemon application +CMD ["python", "-u", "/usr/local/bin/nginx-ldap-auth-daemon.py"] + diff --git a/nginx-ldap-auth-daemon.py b/nginx-ldap-auth-daemon.py index be288b3..aafd80c 100755 --- a/nginx-ldap-auth-daemon.py +++ b/nginx-ldap-auth-daemon.py @@ -7,7 +7,10 @@ import sys, os, signal, base64, ldap, Cookie from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler -Listen = ('localhost', 8888) +# Default binding is to '' (all interfaces). To specifically +# bind to an interface (e.g. localhost), set the environment +# variable BIND_ADDRESS. +Listen = (os.getenv('BIND_ADDRESS', ''), 8888) #Listen = "/tmp/auth.sock" # Also uncomment lines in 'Requests are # processed with UNIX sockets' section below @@ -167,6 +170,9 @@ def do_GET(self): self.auth_failed(ctx, 'attempt to use empty password') return + # Switch off SSL certificate verification + ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER) + try: ctx['action'] = 'initializing LDAP connection' ldap_obj = ldap.initialize(ctx['url']); @@ -176,7 +182,10 @@ def do_GET(self): # ldap_obj.set_option(ldap.OPT_REFERRALS, 0) ctx['action'] = 'binding as search user' - ldap_obj.bind_s(ctx['binddn'], ctx['bindpasswd'], ldap.AUTH_SIMPLE) + if ctx['binddn'] == '': + ldap_obj.simple_bind_s() + else: + ldap_obj.bind_s(ctx['binddn'], ctx['bindpasswd'], ldap.AUTH_SIMPLE) ctx['action'] = 'preparing search filter' searchfilter = ctx['template'] % { 'username': ctx['user'] }