Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 38275ea

Browse files
author
Kooper
committed
feat(controller): add LDAP authentication
Restore user authentication in LDAP as it was in v1 Basically it is a rollback of 2883c0c on the up2date codebase, with updated versions of involved components.
1 parent f132b25 commit 38275ea

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

rootfs/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ RUN adduser --system \
99

1010
COPY requirements.txt /app/requirements.txt
1111

12-
RUN buildDeps='gcc git libffi-dev libpq-dev python3-dev python3-pip python3-wheel python3-setuptools'; \
12+
RUN buildDeps='gcc git libffi-dev libpq-dev libldap2-dev libsasl2-dev python3-dev python3-pip python3-wheel python3-setuptools'; \
1313
apt-get update && \
1414
apt-get install -y --no-install-recommends \
1515
$buildDeps \
1616
sudo \
1717
libpq5 \
18+
libldap-2.4 \
1819
python3-minimal \
1920
# cryptography package needs pkg_resources
2021
python3-pkg-resources && \

rootfs/api/settings/production.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from distutils.util import strtobool
55
import os.path
66
import tempfile
7+
import ldap
8+
9+
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
710

811
# A boolean that turns on/off debug mode.
912
# https://docs.djangoproject.com/en/1.9/ref/settings/#debug
@@ -106,6 +109,7 @@
106109
)
107110

108111
AUTHENTICATION_BACKENDS = (
112+
"django_auth_ldap.backend.LDAPBackend",
109113
"django.contrib.auth.backends.ModelBackend",
110114
"guardian.backends.ObjectPermissionBackend",
111115
)
@@ -339,3 +343,48 @@
339343
}
340344

341345
APP_URL_REGEX = '[a-z0-9-]+'
346+
347+
# LDAP settings taken from environment variables.
348+
LDAP_ENDPOINT = os.environ.get('LDAP_ENDPOINT', '')
349+
LDAP_BIND_DN = os.environ.get('LDAP_BIND_DN', '')
350+
LDAP_BIND_PASSWORD = os.environ.get('LDAP_BIND_PASSWORD', '')
351+
LDAP_USER_BASEDN = os.environ.get('LDAP_USER_BASEDN', '')
352+
LDAP_USER_FILTER = os.environ.get('LDAP_USER_FILTER', 'username')
353+
LDAP_GROUP_BASEDN = os.environ.get('LDAP_GROUP_BASEDN', '')
354+
LDAP_GROUP_FILTER = os.environ.get('LDAP_GROUP_FILTER', '')
355+
356+
# Django LDAP backend configuration.
357+
# See https://pythonhosted.org/django-auth-ldap/reference.html
358+
# for variables' details.
359+
# In order to debug LDAP configuration it is possible to enable
360+
# verbose logging from auth-ldap plugin:
361+
# https://pythonhosted.org/django-auth-ldap/logging.html
362+
363+
AUTH_LDAP_SERVER_URI = LDAP_ENDPOINT
364+
AUTH_LDAP_BIND_DN = LDAP_BIND_DN
365+
AUTH_LDAP_BIND_PASSWORD = LDAP_BIND_PASSWORD
366+
AUTH_LDAP_USER_SEARCH = LDAPSearch(
367+
base_dn=LDAP_USER_BASEDN,
368+
scope=ldap.SCOPE_SUBTREE,
369+
filterstr="(%s=%%(user)s)" % LDAP_USER_FILTER
370+
)
371+
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
372+
base_dn=LDAP_GROUP_BASEDN,
373+
scope=ldap.SCOPE_SUBTREE,
374+
filterstr="(%s)" % LDAP_GROUP_FILTER
375+
)
376+
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
377+
AUTH_LDAP_USER_ATTR_MAP = {
378+
"first_name": "givenName",
379+
"last_name": "sn",
380+
"email": "mail",
381+
"username": LDAP_USER_FILTER,
382+
}
383+
AUTH_LDAP_GLOBAL_OPTIONS = {
384+
ldap.OPT_X_TLS_REQUIRE_CERT: False,
385+
ldap.OPT_REFERRALS: False
386+
}
387+
AUTH_LDAP_ALWAYS_UPDATE_USER = True
388+
AUTH_LDAP_MIRROR_GROUPS = True
389+
AUTH_LDAP_FIND_GROUP_PERMS = True
390+
AUTH_LDAP_CACHE_GROUPS = False

rootfs/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Deis controller requirements
22
backoff==1.3.2
33
Django==1.10.4
4+
django-auth-ldap==1.2.8
45
django-cors-middleware==1.3.1
56
django-guardian==1.4.6
67
djangorestframework==3.5.3
@@ -12,6 +13,7 @@ morph==0.1.2
1213
ndg-httpsclient==0.4.2
1314
packaging==16.8
1415
psycopg2==2.6.2
16+
pyldap==2.4.25.1
1517
pyOpenSSL==16.2.0
1618
pytz==2016.10
1719
requests==2.12.3

0 commit comments

Comments
 (0)