Merge "[DMAAP] DMaaP ServiceMesh compatibility"
[oom.git] / kubernetes / contrib / components / netbox / components / netbox-app / resources / config / configuration / ldap_config.py
1 import ldap
2 import os
3
4 from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
5
6 # Server URI
7 AUTH_LDAP_SERVER_URI = os.environ.get('AUTH_LDAP_SERVER_URI', '')
8
9 # The following may be needed if you are binding to Active Directory.
10 AUTH_LDAP_CONNECTION_OPTIONS = {
11     ldap.OPT_REFERRALS: 0
12 }
13
14 # Set the DN and password for the NetBox service account.
15 AUTH_LDAP_BIND_DN = os.environ.get('AUTH_LDAP_BIND_DN', '')
16 AUTH_LDAP_BIND_PASSWORD = os.environ.get('AUTH_LDAP_BIND_PASSWORD', '')
17
18 # Include this setting if you want to ignore certificate errors. This might be needed to accept a self-signed cert.
19 # Note that this is a NetBox-specific setting which sets:
20 #     ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
21 LDAP_IGNORE_CERT_ERRORS = os.environ.get('LDAP_IGNORE_CERT_ERRORS', 'False').lower() == 'true'
22
23 AUTH_LDAP_USER_SEARCH = LDAPSearch(os.environ.get('AUTH_LDAP_USER_SEARCH_BASEDN', ''),
24                                     ldap.SCOPE_SUBTREE,
25                                     "(sAMAccountName=%(user)s)")
26
27 # This search ought to return all groups to which the user belongs. django_auth_ldap uses this to determine group
28 # heirarchy.
29 AUTH_LDAP_GROUP_SEARCH = LDAPSearch(os.environ.get('AUTH_LDAP_GROUP_SEARCH_BASEDN', ''), ldap.SCOPE_SUBTREE,
30                                     "(objectClass=group)")
31 AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
32
33 # Define a group required to login.
34 AUTH_LDAP_REQUIRE_GROUP = os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', '')
35
36 # Define special user types using groups. Exercise great caution when assigning superuser status.
37 AUTH_LDAP_USER_FLAGS_BY_GROUP = {
38     "is_active": os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', ''),
39     "is_staff": os.environ.get('AUTH_LDAP_IS_ADMIN_DN', ''),
40     "is_superuser": os.environ.get('AUTH_LDAP_IS_SUPERUSER_DN', '')
41 }
42
43 # For more granular permissions, we can map LDAP groups to Django groups.
44 AUTH_LDAP_FIND_GROUP_PERMS = os.environ.get('AUTH_LDAP_FIND_GROUP_PERMS', 'True').lower() == 'true'
45
46 # Cache groups for one hour to reduce LDAP traffic
47 AUTH_LDAP_CACHE_GROUPS = os.environ.get('AUTH_LDAP_CACHE_GROUPS', 'True').lower() == 'true'
48 AUTH_LDAP_GROUP_CACHE_TIMEOUT = int(os.environ.get('AUTH_LDAP_CACHE_GROUPS', 3600))
49
50 # Populate the Django user from the LDAP directory.
51 AUTH_LDAP_USER_ATTR_MAP = {
52     "first_name": os.environ.get('AUTH_LDAP_ATTR_FIRSTNAME', 'givenName'),
53     "last_name": os.environ.get('AUTH_LDAP_ATTR_LASTNAME', 'sn'),
54     "email": os.environ.get('AUTH_LDAP_ATTR_MAIL', 'mail')
55 }