Skip to content

Commit 640b554

Browse files
committed
feat(controller): Adding LDAP/AD auth support
1 parent e991073 commit 640b554

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DEBIAN_FRONTEND=noninteractive
1616
# HACK: install git so we can install bacongobbler's fork of django-fsm
1717
# install openssh-client for temporary fleetctl wrapper
1818
apt-get update && \
19-
apt-get install -yq python-dev libffi-dev libpq-dev libyaml-dev git
19+
apt-get install -yq python-dev libffi-dev libpq-dev libyaml-dev git libldap2-dev libsasl2-dev
2020

2121
# install pip
2222
curl -sSL https://raw.githubusercontent.com/pypa/pip/6.0.8/contrib/get-pip.py | python -

deis/settings.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import string
99
import sys
1010
import tempfile
11+
import ldap
12+
13+
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
14+
1115

1216
PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
1317

@@ -138,6 +142,7 @@
138142
'django.contrib.sites',
139143
'django.contrib.staticfiles',
140144
# Third-party apps
145+
'django_auth_ldap',
141146
'guardian',
142147
'json_field',
143148
'gunicorn',
@@ -151,6 +156,7 @@
151156
)
152157

153158
AUTHENTICATION_BACKENDS = (
159+
"django_auth_ldap.backend.LDAPBackend",
154160
"django.contrib.auth.backends.ModelBackend",
155161
"guardian.backends.ObjectPermissionBackend",
156162
)
@@ -324,6 +330,16 @@
324330
# server - Hostname based on CoreOS server hostname
325331
UNIT_HOSTNAME = 'default'
326332

333+
# LDAP DEFAULT SETTINGS (Overrided by confd later)
334+
LDAP_ENDPOINT = ""
335+
BIND_DN = ""
336+
BIND_PASSWORD = ""
337+
USER_BASEDN = ""
338+
USER_FILTER = ""
339+
GROUP_BASEDN = ""
340+
GROUP_FILTER = ""
341+
GROUP_TYPE = ""
342+
327343
# Create a file named "local_settings.py" to contain sensitive settings data
328344
# such as database configuration, admin email, or passwords and keys. It
329345
# should also be used for any settings which differ between development
@@ -334,9 +350,41 @@
334350
except ImportError:
335351
pass
336352

337-
338353
# have confd_settings within container execution override all others
339354
# including local_settings (which may end up in the container)
340355
if os.path.exists('/templates/confd_settings.py'):
341356
sys.path.append('/templates')
342357
from confd_settings import * # noqa
358+
359+
# LDAP Backend Configuration
360+
# Should be always after the confd_settings import.
361+
LDAP_USER_SEARCH = LDAPSearch(
362+
base_dn=USER_BASEDN,
363+
scope=ldap.SCOPE_SUBTREE,
364+
filterstr="(%s=%%(user)s)" % USER_FILTER
365+
)
366+
LDAP_GROUP_SEARCH = LDAPSearch(
367+
base_dn=GROUP_BASEDN,
368+
scope=ldap.SCOPE_SUBTREE,
369+
filterstr="(%s=%s)" % (GROUP_FILTER, GROUP_TYPE)
370+
)
371+
AUTH_LDAP_SERVER_URI = LDAP_ENDPOINT
372+
AUTH_LDAP_BIND_DN = BIND_DN
373+
AUTH_LDAP_BIND_PASSWORD = BIND_PASSWORD
374+
AUTH_LDAP_USER_SEARCH = LDAP_USER_SEARCH
375+
AUTH_LDAP_GROUP_SEARCH = LDAP_GROUP_SEARCH
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": 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

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ django-cors-headers==1.0.0
99
django-fsm==2.2.0
1010
django-guardian==1.2.5
1111
django-json-field==0.5.7
12+
django-auth-ldap==1.2.5
1213
djangorestframework==3.0.5
1314
docker-py==0.7.2
1415
gunicorn==19.3.0
@@ -19,3 +20,4 @@ PyYAML==3.11
1920
setproctitle==1.1.8
2021
static==1.1.1
2122
South==1.0.2
23+
python-ldap==2.4.19

templates/confd_settings.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@
4545
WEB_ENABLED = bool({{ getv "/deis/controller/webEnabled" }})
4646
{{ end }}
4747
UNIT_HOSTNAME = '{{ if exists "/deis/controller/unitHostname" }}{{ getv "/deis/controller/unitHostname" }}{{ else }}default{{ end }}'
48+
49+
# AUTH
50+
# LDAP
51+
{{ if exists "/deis/controller/auth/ldap/endpoint" }}
52+
LDAP_ENDPOINT = '{{ if exists "/deis/controller/auth/ldap/endpoint" }}{{ getv "/deis/controller/auth/ldap/endpoint"}}{{ else }} {{ end }}'
53+
BIND_DN = '{{ if exists "/deis/controller/auth/ldap/bind/dn" }}{{ getv "/deis/controller/auth/ldap/bind/dn"}}{{ else }} {{ end }}'
54+
BIND_PASSWORD = '{{ if exists "/deis/controller/auth/ldap/bind/password" }}{{ getv "/deis/controller/auth/ldap/bind/password"}}{{ else }} {{ end }}'
55+
USER_BASEDN = '{{ if exists "/deis/controller/auth/ldap/user/basedn" }}{{ getv "/deis/controller/auth/ldap/user/basedn"}}{{ else }} {{ end }}'
56+
USER_FILTER = '{{ if exists "/deis/controller/auth/ldap/user/filter" }}{{ getv "/deis/controller/auth/ldap/user/filter"}}{{ else }} {{ end }}'
57+
GROUP_BASEDN = '{{ if exists "/deis/controller/auth/ldap/group/basedn" }}{{ getv "/deis/controller/auth/ldap/group/basedn"}}{{ else }} {{ end }}'
58+
GROUP_FILTER = '{{ if exists "/deis/controller/auth/ldap/group/filter" }}{{ getv "/deis/controller/auth/ldap/group/filter"}}{{ else }} {{ end }}'
59+
GROUP_TYPE = '{{ if exists "/deis/controller/auth/ldap/group/type" }}{{ getv "/deis/controller/auth/ldap/group/type"}}{{ else }} {{ end }}'
60+
{{ end }}

0 commit comments

Comments
 (0)