|
@@ -4,6 +4,9 @@ from django.contrib.messages import constants as message_constants
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
from pathlib import Path
|
|
|
|
|
|
+import ldap
|
|
|
+from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
|
|
|
+
|
|
|
########
|
|
|
#
|
|
|
# Django
|
|
@@ -22,6 +25,9 @@ CSRF_TRUSTED_ORIGINS = sv.CSRF_TRUSTED_ORIGINS
|
|
|
ALLOWED_HOSTS = sv.ALLOWED_HOSTS
|
|
|
INTERNAL_IPS = sv.INTERNAL_IPS
|
|
|
|
|
|
+# https if nginx responce HTTP_X_FORWARDED_PROTO=https
|
|
|
+SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
|
|
+
|
|
|
# Application definition
|
|
|
INSTALLED_APPS = [
|
|
|
'design_template',
|
|
@@ -39,8 +45,8 @@ INSTALLED_APPS = [
|
|
|
'webservice_running.apps.WebserviceRunningConfig',
|
|
|
'django_tables2',
|
|
|
'schema_graph',
|
|
|
- "django.contrib.sites",
|
|
|
- "django.contrib.flatpages",
|
|
|
+ # "django.contrib.sites",
|
|
|
+ # "django.contrib.flatpages",
|
|
|
"django_extensions",
|
|
|
'rest_framework',
|
|
|
"rest_framework_api_key",
|
|
@@ -138,6 +144,16 @@ AUTH_PASSWORD_VALIDATORS = [
|
|
|
},
|
|
|
]
|
|
|
|
|
|
+#Password hashgen
|
|
|
+
|
|
|
+PASSWORD_HASHERS = [
|
|
|
+ 'django.contrib.auth.hashers.Argon2PasswordHasher',
|
|
|
+ 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
|
|
+ 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
|
|
|
+ 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
|
|
|
+ 'django.contrib.auth.hashers.ScryptPasswordHasher',
|
|
|
+]
|
|
|
+
|
|
|
# Internationalization
|
|
|
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
|
|
LANGUAGE_CODE = 'ru'
|
|
@@ -393,9 +409,16 @@ REST_FRAMEWORK = {
|
|
|
}
|
|
|
|
|
|
SPAGHETTI_SAUCE = {
|
|
|
- 'apps': ['auth', 'sharix_admin',
|
|
|
- 'tickets', 'admin',
|
|
|
- 'flatpages', 'sessions', 'sites', 'dbsynce'],
|
|
|
+ 'apps': [
|
|
|
+ 'auth',
|
|
|
+ 'sharix_admin',
|
|
|
+ 'tickets',
|
|
|
+ 'admin',
|
|
|
+ # 'flatpages',
|
|
|
+ 'sessions',
|
|
|
+ # 'sites',
|
|
|
+ 'dbsynce'
|
|
|
+ ],
|
|
|
'show_fields': False,
|
|
|
'show_proxy': True,
|
|
|
}
|
|
@@ -413,3 +436,122 @@ EMAIL_USE_TLS = sv.EMAIL_USE_TLS
|
|
|
EMAIL_HOST_USER = sv.EMAIL_HOST_USER
|
|
|
EMAIL_HOST_PASSWORD = sv.EMAIL_HOST_PASSWORD
|
|
|
DEFAULT_FROM_EMAIL = sv.DEFAULT_FROM_EMAIL
|
|
|
+
|
|
|
+#LDAP
|
|
|
+# Baseline configuration.
|
|
|
+
|
|
|
+AUTH_LDAP_PROTO = "ldap"
|
|
|
+AUTH_LDAP_HOST = "ldap.sharix.ru"
|
|
|
+AUTH_LDAP_PORT = '389' # must be str
|
|
|
+
|
|
|
+#AUTH_LDAP_GID = "502" # group ID to add signed up users
|
|
|
+#AUTH_LDAP_BASE_UID = 1000 # Integer
|
|
|
+
|
|
|
+#AUTH_LDAP_SERVER_URI = LDAP_PROTO+"://"+LDAP_HOST+":"+LDAP_PORT
|
|
|
+AUTH_LDAP_SERVER_URI = AUTH_LDAP_PROTO+"://"+AUTH_LDAP_HOST
|
|
|
+
|
|
|
+#If we want to use there - we should create custom ldap login backend - https://django-auth-ldap.readthedocs.io/en/latest/custombehavior.html
|
|
|
+#LDAP_LOGIN_ATTEMPT_LIMIT = 100
|
|
|
+#LDAP_RESET_TIME = 15 * 60
|
|
|
+
|
|
|
+#AUTH_LDAP_BASE_DN = "dc=ldap,dc=sharix,dc=ru"
|
|
|
+AUTH_LDAP_BASE_DN = "dc=ldap,dc=sharix,dc=ru"
|
|
|
+AUTH_LDAP_BIND_DN = "cn=admin,dc=ldap,dc=sharix,dc=ru"
|
|
|
+AUTH_LDAP_BIND_PASSWORD = "secret"
|
|
|
+AUTH_LDAP_USER_SEARCH = LDAPSearch(
|
|
|
+ "ou=users,dc=ldap,dc=sharix,dc=ru", ldap.SCOPE_SUBTREE, "(telephoneNumber=%(user)s)"
|
|
|
+# "ou=users,dc=ldap,dc=sharix,dc=ru", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"
|
|
|
+)
|
|
|
+# Or:
|
|
|
+# AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=users,dc=example,dc=com'
|
|
|
+
|
|
|
+# Set up the basic group parameters.
|
|
|
+AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
|
|
|
+ "ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+# "ou=apps,dc=ldap,dc=sharix,dc=ru",
|
|
|
+#TODO need to specify only django users
|
|
|
+ ldap.SCOPE_SUBTREE,
|
|
|
+ "(objectClass=groupOfNames)",
|
|
|
+)
|
|
|
+AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr="cn")
|
|
|
+
|
|
|
+# Simple group restrictions
|
|
|
+#AUTH_LDAP_REQUIRE_GROUP = "cn=client,ou=groups,dc=ldap,dc=sharix,dc=ru"
|
|
|
+#AUTH_LDAP_REQUIRE_GROUP = "cn=django,ou=apps,dc=ldap,dc=sharix,dc=ru"
|
|
|
+#AUTH_LDAP_DENY_GROUP = "cn=disabled,ou=django,ou=groups,dc=example,dc=com"
|
|
|
+#AUTH_LDAP_DENY_GROUP = "cn=handlers,ou=apps,dc=ldap,dc=sharix,dc=ru"
|
|
|
+
|
|
|
+# TODO - it duplicates local lib for ldap, decide where it's better to be placed.
|
|
|
+#Most likely left side - Django, right side - LDAP
|
|
|
+# Populate the Django user from the LDAP directory.
|
|
|
+AUTH_LDAP_USER_ATTR_MAP = {
|
|
|
+ "id": "uid",
|
|
|
+ "password": "userPassword",
|
|
|
+ "last_name": "sn",
|
|
|
+ "middle_name": "initials",
|
|
|
+ "first_name": "givenName",
|
|
|
+ "email": "mail",
|
|
|
+ "avatar": "jpegPhoto",
|
|
|
+ "phone": "telephoneNumber",
|
|
|
+ "username": "uid",
|
|
|
+}
|
|
|
+
|
|
|
+AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
|
|
+ "is_active": [
|
|
|
+ "cn=PLATFORM-ADMIN,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ "cn=PLATFORM-SUPERVISOR,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ "cn=PLATFORM-SUPPORT,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ "cn=PLATFORM-TECHSUPPORT,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ "cn=METASERVICE-ADMIN,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ "cn=CLIENT,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ "cn=django_admin,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ ],
|
|
|
+ "is_staff": [
|
|
|
+ "cn=PLATFORM-TECHSUPPORT,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ "cn=django_admin,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+ ],
|
|
|
+ "is_superuser": "cn=django_admin,ou=groups,dc=ldap,dc=sharix,dc=ru",
|
|
|
+}
|
|
|
+
|
|
|
+#AUTH_LDAP_REQUIRE_GROUP = (
|
|
|
+# LDAPGroupQuery("cn=client,ou=groups,dc=ldap,dc=sharix,dc=ru")
|
|
|
+# | LDAPGroupQuery("cn=platform_admin,ou=groups,dc=ldap,dc=sharix,dc=ru")
|
|
|
+#) & ~LDAPGroupQuery("cn=metaservice_admin,ou=groups,dc=ldap,dc=sharix,dc=ru")
|
|
|
+
|
|
|
+# This is the default, but I like to be explicit.
|
|
|
+AUTH_LDAP_ALWAYS_UPDATE_USER = True
|
|
|
+
|
|
|
+# Use LDAP group membership to calculate group permissions.
|
|
|
+AUTH_LDAP_FIND_GROUP_PERMS = True
|
|
|
+
|
|
|
+# Cache distinguished names and group memberships for an hour to minimize
|
|
|
+# LDAP traffic.
|
|
|
+AUTH_LDAP_CACHE_TIMEOUT = 3600
|
|
|
+
|
|
|
+AUTH_LDAP_MIRROR_GROUPS = True
|
|
|
+
|
|
|
+# Keep ModelBackend around for per-user permissions and maybe a local
|
|
|
+# superuser.
|
|
|
+AUTHENTICATION_BACKENDS = (
|
|
|
+ "django_auth_ldap.backend.LDAPBackend",
|
|
|
+# "django.contrib.auth.backends.ModelBackend",
|
|
|
+)
|
|
|
+
|
|
|
+LOGGING = {
|
|
|
+ 'version': 1,
|
|
|
+ 'disable_existing_loggers': False,
|
|
|
+ 'handlers': {
|
|
|
+ 'file': {
|
|
|
+ 'level': 'DEBUG',
|
|
|
+ 'class': 'logging.FileHandler',
|
|
|
+ 'filename': '/var/log/django-ldap.log',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'loggers': {
|
|
|
+ 'django_auth_ldap': {
|
|
|
+ 'handlers': ['file'],
|
|
|
+ 'level': 'DEBUG',
|
|
|
+ 'propagate': True,
|
|
|
+ },
|
|
|
+ },
|
|
|
+}
|