molinaj31

ldap-config

Feb 27th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. import ldap
  2.  
  3. # Server URI
  4. AUTH_LDAP_SERVER_URI = "ldaps://dc.domain.com:"
  5.  
  6. # The following may be needed if you are binding to Active Directory.
  7. AUTH_LDAP_CONNECTION_OPTIONS = {
  8.     ldap.OPT_REFERRALS: 0
  9. }
  10.  
  11. # Set the DN and password for the NetBox service account.
  12. AUTH_LDAP_BIND_DN = "CN=netboxsvc,OU=Service Accounts,OU=users,DC=domain,DC=com"
  13. AUTH_LDAP_BIND_PASSWORD = "plaintextpass"
  14.  
  15. # Include this setting if you want to ignore certificate errors. This might be needed to accept a self-signed cert.
  16. # Note that this is a NetBox-specific setting which sets:
  17. #     ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
  18. LDAP_IGNORE_CERT_ERRORS = True
  19.  
  20. from django_auth_ldap.config import LDAPSearch
  21.  
  22. # This search matches users with the sAMAccountName equal to the provided username. This is required if the user's
  23. # username is not in their DN (Active Directory).
  24. AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=domain,dc=com",
  25.                                     ldap.SCOPE_SUBTREE,
  26.                                     "(sAMAccountName=%(user)s)")
  27.  
  28. # If a user's DN is producible from their username, we don't need to search.
  29. AUTH_LDAP_USER_DN_TEMPLATE = None
  30.  
  31. # You can map user attributes to Django attributes as so.
  32. AUTH_LDAP_USER_ATTR_MAP = {
  33.     "first_name": "givenName",
  34.     "last_name": "sn"
  35. }
  36.  
  37. from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
  38.  
  39. # This search ought to return all groups to which the user belongs. django_auth_ldap uses this to determine group
  40. # heirarchy.
  41. AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=users,dc=domain,dc=com", ldap.SCOPE_SUBTREE,
  42.                                     "(objectClass=group)")
  43. AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
  44.  
  45. # Define a group required to login.
  46. AUTH_LDAP_REQUIRE_GROUP = "CN=netbox-user,OU=Security Groups,OU=users,DC=domain,DC=com"
  47.  
  48. # Define special user types using groups. Exercise great caution when assigning superuser status.
  49. AUTH_LDAP_USER_FLAGS_BY_GROUP = {
  50.     "is_active": "cn=netbox-user,ou=security groups,ou=users,dc=domain,dc=com",
  51.     "is_staff": "cn=netbox-user,ou=security groups,ou=users,dc=domain,dc=com"",
  52.    "is_superuser": "cn=netbox-admin,ou=security groups,ou=users,dc=domain,dc=com""
  53. }
  54. # For more granular permissions, we can map LDAP groups to Django groups.
  55. AUTH_LDAP_FIND_GROUP_PERMS = True
  56.  
  57. # Cache groups for one hour to reduce LDAP traffic
  58. AUTH_LDAP_CACHE_GROUPS = True
  59. AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
Advertisement
Add Comment
Please, Sign In to add comment