2018-11-11 12:41:48 +00:00
|
|
|
"""
|
|
|
|
Django settings for passbook project.
|
|
|
|
|
|
|
|
Generated by 'django-admin startproject' using Django 2.1.3.
|
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/2.1/topics/settings/
|
|
|
|
|
|
|
|
For the full list of settings and their values, see
|
|
|
|
https://docs.djangoproject.com/en/2.1/ref/settings/
|
|
|
|
"""
|
|
|
|
|
2018-11-16 08:10:35 +00:00
|
|
|
import importlib
|
2018-11-11 12:41:48 +00:00
|
|
|
import os
|
2019-02-11 16:36:36 +00:00
|
|
|
import sys
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-09-30 17:04:04 +01:00
|
|
|
import structlog
|
2019-04-04 20:48:50 +01:00
|
|
|
from sentry_sdk import init as sentry_init
|
|
|
|
from sentry_sdk.integrations.celery import CeleryIntegration
|
|
|
|
from sentry_sdk.integrations.django import DjangoIntegration
|
2018-11-23 08:44:22 +00:00
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
from passbook import __version__
|
2018-11-16 08:10:35 +00:00
|
|
|
from passbook.lib.config import CONFIG
|
2019-04-29 18:16:49 +01:00
|
|
|
from passbook.lib.sentry import before_send
|
2018-11-16 08:10:35 +00:00
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2018-12-09 21:12:41 +00:00
|
|
|
STATIC_ROOT = BASE_DIR + '/static'
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
|
|
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
|
|
|
|
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
2019-09-30 17:04:04 +01:00
|
|
|
SECRET_KEY = CONFIG.y('secret_key',
|
|
|
|
"9$@r!d^1^jrn#fk#1#@ks#9&i$^s#1)_13%$rwjrhd=e8jfi_s") # noqa Debug
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-09-30 17:04:04 +01:00
|
|
|
DEBUG = CONFIG.y_bool('debug')
|
2018-11-11 12:41:48 +00:00
|
|
|
INTERNAL_IPS = ['127.0.0.1']
|
2019-04-04 20:49:10 +01:00
|
|
|
ALLOWED_HOSTS = ['*']
|
2019-03-14 17:01:41 +00:00
|
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2018-11-16 08:10:35 +00:00
|
|
|
LOGIN_URL = 'passbook_core:auth-login'
|
2018-12-14 08:49:34 +00:00
|
|
|
# CSRF_FAILURE_VIEW = 'passbook.core.views.errors.CSRFErrorView.as_view'
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Custom user model
|
|
|
|
AUTH_USER_MODEL = 'passbook_core.User'
|
|
|
|
|
2018-12-09 20:06:36 +00:00
|
|
|
CSRF_COOKIE_NAME = 'passbook_csrf'
|
|
|
|
SESSION_COOKIE_NAME = 'passbook_session'
|
|
|
|
LANGUAGE_COOKIE_NAME = 'passbook_language'
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
2019-04-10 17:46:33 +01:00
|
|
|
'django.contrib.auth.backends.ModelBackend',
|
2018-11-11 12:41:48 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# Application definition
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2019-03-08 14:49:45 +00:00
|
|
|
'django.contrib.postgres',
|
2019-09-30 17:04:04 +01:00
|
|
|
# 'rest_framework',
|
|
|
|
# 'drf_yasg',
|
2018-12-26 13:32:33 +00:00
|
|
|
'passbook.core.apps.PassbookCoreConfig',
|
|
|
|
'passbook.admin.apps.PassbookAdminConfig',
|
|
|
|
'passbook.api.apps.PassbookAPIConfig',
|
|
|
|
'passbook.audit.apps.PassbookAuditConfig',
|
|
|
|
'passbook.lib.apps.PassbookLibConfig',
|
|
|
|
'passbook.ldap.apps.PassbookLdapConfig',
|
|
|
|
'passbook.oauth_client.apps.PassbookOAuthClientConfig',
|
|
|
|
'passbook.oauth_provider.apps.PassbookOAuthProviderConfig',
|
2019-07-05 14:21:48 +01:00
|
|
|
'passbook.oidc_provider.apps.PassbookOIDCProviderConfig',
|
2018-12-26 13:32:33 +00:00
|
|
|
'passbook.saml_idp.apps.PassbookSAMLIDPConfig',
|
2019-02-25 11:29:40 +00:00
|
|
|
'passbook.otp.apps.PassbookOTPConfig',
|
2018-12-26 13:32:33 +00:00
|
|
|
'passbook.captcha_factor.apps.PassbookCaptchaFactorConfig',
|
2019-02-25 16:21:56 +00:00
|
|
|
'passbook.hibp_policy.apps.PassbookHIBPConfig',
|
2019-02-26 08:10:37 +00:00
|
|
|
'passbook.pretend.apps.PassbookPretendConfig',
|
2019-03-03 16:12:05 +00:00
|
|
|
'passbook.password_expiry_policy.apps.PassbookPasswordExpiryPolicyConfig',
|
2019-03-03 19:26:25 +00:00
|
|
|
'passbook.suspicious_policy.apps.PassbookSuspiciousPolicyConfig',
|
2019-03-20 21:42:47 +00:00
|
|
|
'passbook.app_gw.apps.PassbookApplicationApplicationGatewayConfig',
|
2018-11-11 12:41:48 +00:00
|
|
|
]
|
|
|
|
|
2018-11-16 08:10:35 +00:00
|
|
|
REST_FRAMEWORK = {
|
|
|
|
# Use Django's standard `django.contrib.auth` permissions,
|
|
|
|
# or allow read-only access for unauthenticated users.
|
|
|
|
'DEFAULT_PERMISSION_CLASSES': [
|
|
|
|
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-03-21 10:08:08 +00:00
|
|
|
CACHES = {
|
|
|
|
"default": {
|
|
|
|
"BACKEND": "django_redis.cache.RedisCache",
|
2019-10-01 14:30:35 +01:00
|
|
|
"LOCATION": (f"redis://:{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}:6379"
|
|
|
|
f"/{CONFIG.y('redis.cache_db')}"),
|
2019-03-21 10:08:08 +00:00
|
|
|
"OPTIONS": {
|
|
|
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-30 17:04:04 +01:00
|
|
|
DJANGO_REDIS_IGNORE_EXCEPTIONS = True
|
|
|
|
DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
|
|
|
|
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
|
|
|
SESSION_CACHE_ALIAS = "default"
|
2019-03-21 10:08:08 +00:00
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
MIDDLEWARE = [
|
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
2019-03-20 21:42:47 +00:00
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
2018-11-11 12:41:48 +00:00
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
|
|
]
|
|
|
|
|
2019-06-25 17:11:08 +01:00
|
|
|
ROOT_URLCONF = 'passbook.root.urls'
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': [],
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.debug',
|
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2019-09-30 17:04:04 +01:00
|
|
|
WSGI_APPLICATION = 'passbook.root.wsgi.application'
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Database
|
|
|
|
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
|
|
|
|
|
2019-09-30 17:04:04 +01:00
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.postgresql',
|
|
|
|
'HOST': CONFIG.y('postgresql.host'),
|
|
|
|
'NAME': CONFIG.y('postgresql.name'),
|
|
|
|
'USER': CONFIG.y('postgresql.user'),
|
|
|
|
'PASSWORD': CONFIG.y('postgresql.password'),
|
2018-11-11 12:41:48 +00:00
|
|
|
}
|
2019-09-30 17:04:04 +01:00
|
|
|
}
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
|
|
|
|
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
|
|
|
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
|
|
|
|
TIME_ZONE = 'UTC'
|
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
|
|
|
USE_L10N = True
|
|
|
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
2018-11-27 15:23:29 +00:00
|
|
|
|
|
|
|
# Celery settings
|
|
|
|
# Add a 10 minute timeout to all Celery tasks.
|
|
|
|
CELERY_TASK_SOFT_TIME_LIMIT = 600
|
|
|
|
CELERY_BEAT_SCHEDULE = {}
|
|
|
|
CELERY_CREATE_MISSING_QUEUES = True
|
|
|
|
CELERY_TASK_DEFAULT_QUEUE = 'passbook'
|
2019-09-30 17:04:04 +01:00
|
|
|
CELERY_BROKER_URL = (f"redis://:{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}"
|
|
|
|
f":6379/{CONFIG.y('redis.message_queue_db')}")
|
|
|
|
CELERY_RESULT_BACKEND = (f"redis://:{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}"
|
|
|
|
f":6379/{CONFIG.y('redis.message_queue_db')}")
|
2019-03-03 19:48:31 +00:00
|
|
|
|
2019-04-11 14:30:42 +01:00
|
|
|
|
|
|
|
if not DEBUG:
|
|
|
|
sentry_init(
|
2019-07-03 16:35:54 +01:00
|
|
|
dsn="https://33cdbcb23f8b436dbe0ee06847410b67@sentry.beryju.org/3",
|
2019-04-11 14:30:42 +01:00
|
|
|
integrations=[
|
|
|
|
DjangoIntegration(),
|
2019-09-30 17:04:04 +01:00
|
|
|
CeleryIntegration()
|
2019-04-11 14:30:42 +01:00
|
|
|
],
|
|
|
|
send_default_pii=True,
|
2019-04-29 18:16:49 +01:00
|
|
|
before_send=before_send,
|
2019-07-05 15:00:01 +01:00
|
|
|
release='passbook@%s' % __version__
|
2019-04-11 14:30:42 +01:00
|
|
|
)
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
|
|
|
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
|
2019-09-30 17:04:04 +01:00
|
|
|
|
|
|
|
structlog.configure_once(
|
|
|
|
processors=[
|
|
|
|
structlog.stdlib.add_log_level,
|
|
|
|
structlog.stdlib.PositionalArgumentsFormatter(),
|
|
|
|
structlog.processors.TimeStamper(),
|
|
|
|
structlog.processors.StackInfoRenderer(),
|
|
|
|
# structlog.processors.format_exc_info,
|
|
|
|
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
|
|
|
|
],
|
|
|
|
context_class=structlog.threadlocal.wrap_dict(dict),
|
|
|
|
logger_factory=structlog.stdlib.LoggerFactory(),
|
|
|
|
wrapper_class=structlog.stdlib.BoundLogger,
|
|
|
|
cache_logger_on_first_use=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
LOG_PRE_CHAIN = [
|
|
|
|
# Add the log level and a timestamp to the event_dict if the log entry
|
|
|
|
# is not from structlog.
|
|
|
|
structlog.stdlib.add_log_level,
|
|
|
|
structlog.processors.TimeStamper(),
|
|
|
|
]
|
|
|
|
|
2018-11-11 12:41:48 +00:00
|
|
|
with CONFIG.cd('log'):
|
2019-09-30 17:04:04 +01:00
|
|
|
LOGGING_HANDLER_MAP = {
|
|
|
|
'passbook': 'DEBUG',
|
|
|
|
'django': 'WARNING',
|
|
|
|
'celery': 'WARNING',
|
|
|
|
'grpc': 'DEBUG',
|
|
|
|
'oauthlib': 'DEBUG',
|
|
|
|
'oauth2_provider': 'DEBUG',
|
|
|
|
'daphne': 'INFO',
|
|
|
|
}
|
2018-11-11 12:41:48 +00:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
2019-09-30 17:04:04 +01:00
|
|
|
'disable_existing_loggers': False,
|
2018-11-11 12:41:48 +00:00
|
|
|
'formatters': {
|
2019-09-30 17:04:04 +01:00
|
|
|
"plain": {
|
|
|
|
"()": structlog.stdlib.ProcessorFormatter,
|
|
|
|
"processor": structlog.processors.JSONRenderer(),
|
|
|
|
"foreign_pre_chain": LOG_PRE_CHAIN,
|
|
|
|
},
|
|
|
|
"colored": {
|
|
|
|
"()": structlog.stdlib.ProcessorFormatter,
|
|
|
|
"processor": structlog.dev.ConsoleRenderer(colors=DEBUG),
|
|
|
|
"foreign_pre_chain": LOG_PRE_CHAIN,
|
2018-11-11 12:41:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'console': {
|
2019-09-30 17:04:04 +01:00
|
|
|
'level': DEBUG,
|
2018-11-11 12:41:48 +00:00
|
|
|
'class': 'logging.StreamHandler',
|
2019-09-30 17:04:04 +01:00
|
|
|
'formatter': "colored" if DEBUG else "plain",
|
2018-11-11 12:41:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
}
|
|
|
|
}
|
2019-09-30 17:04:04 +01:00
|
|
|
for handler_name, level in LOGGING_HANDLER_MAP.items():
|
|
|
|
LOGGING['loggers'][handler_name] = {
|
|
|
|
'handlers': ['console'],
|
|
|
|
'level': level,
|
|
|
|
'propagate': True,
|
|
|
|
}
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-02-11 16:36:36 +00:00
|
|
|
TEST = False
|
|
|
|
TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
|
|
|
|
TEST_OUTPUT_VERBOSE = 2
|
|
|
|
|
|
|
|
TEST_OUTPUT_FILE_NAME = 'unittest.xml'
|
|
|
|
|
|
|
|
if any('test' in arg for arg in sys.argv):
|
|
|
|
LOGGING = None
|
|
|
|
TEST = True
|
2019-02-26 13:24:50 +00:00
|
|
|
CELERY_TASK_ALWAYS_EAGER = True
|
2019-02-11 16:36:36 +00:00
|
|
|
|
2019-09-30 17:04:04 +01:00
|
|
|
|
2018-11-24 21:27:02 +00:00
|
|
|
_DISALLOWED_ITEMS = ['INSTALLED_APPS', 'MIDDLEWARE', 'AUTHENTICATION_BACKENDS']
|
2018-11-16 08:10:35 +00:00
|
|
|
# Load subapps's INSTALLED_APPS
|
|
|
|
for _app in INSTALLED_APPS:
|
|
|
|
if _app.startswith('passbook') and \
|
|
|
|
not _app.startswith('passbook.core'):
|
|
|
|
if 'apps' in _app:
|
|
|
|
_app = '.'.join(_app.split('.')[:-2])
|
|
|
|
try:
|
|
|
|
app_settings = importlib.import_module("%s.settings" % _app)
|
|
|
|
INSTALLED_APPS.extend(getattr(app_settings, 'INSTALLED_APPS', []))
|
|
|
|
MIDDLEWARE.extend(getattr(app_settings, 'MIDDLEWARE', []))
|
|
|
|
AUTHENTICATION_BACKENDS.extend(getattr(app_settings, 'AUTHENTICATION_BACKENDS', []))
|
2018-11-24 21:27:02 +00:00
|
|
|
for _attr in dir(app_settings):
|
|
|
|
if not _attr.startswith('__') and _attr not in _DISALLOWED_ITEMS:
|
|
|
|
globals()[_attr] = getattr(app_settings, _attr)
|
2018-11-16 08:10:35 +00:00
|
|
|
except ImportError:
|
|
|
|
pass
|
2018-11-24 21:27:02 +00:00
|
|
|
|
|
|
|
if DEBUG:
|
|
|
|
INSTALLED_APPS.append('debug_toolbar')
|
|
|
|
MIDDLEWARE.append('debug_toolbar.middleware.DebugToolbarMiddleware')
|