|
8 | 8 | import string |
9 | 9 | import sys |
10 | 10 | import tempfile |
| 11 | +import ldap |
| 12 | + |
| 13 | +from django_auth_ldap.config import LDAPSearch, GroupOfNamesType |
| 14 | + |
11 | 15 |
|
12 | 16 | PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) |
13 | 17 |
|
|
138 | 142 | 'django.contrib.sites', |
139 | 143 | 'django.contrib.staticfiles', |
140 | 144 | # Third-party apps |
| 145 | + 'django_auth_ldap', |
141 | 146 | 'guardian', |
142 | 147 | 'json_field', |
143 | 148 | 'gunicorn', |
|
151 | 156 | ) |
152 | 157 |
|
153 | 158 | AUTHENTICATION_BACKENDS = ( |
| 159 | + "django_auth_ldap.backend.LDAPBackend", |
154 | 160 | "django.contrib.auth.backends.ModelBackend", |
155 | 161 | "guardian.backends.ObjectPermissionBackend", |
156 | 162 | ) |
|
324 | 330 | # server - Hostname based on CoreOS server hostname |
325 | 331 | UNIT_HOSTNAME = 'default' |
326 | 332 |
|
| 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 | + |
327 | 343 | # Create a file named "local_settings.py" to contain sensitive settings data |
328 | 344 | # such as database configuration, admin email, or passwords and keys. It |
329 | 345 | # should also be used for any settings which differ between development |
|
334 | 350 | except ImportError: |
335 | 351 | pass |
336 | 352 |
|
337 | | - |
338 | 353 | # have confd_settings within container execution override all others |
339 | 354 | # including local_settings (which may end up in the container) |
340 | 355 | if os.path.exists('/templates/confd_settings.py'): |
341 | 356 | sys.path.append('/templates') |
342 | 357 | 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 |
0 commit comments