Skip to content

Commit 79902b2

Browse files
committed
Усилен security baseline и вычищены мёртвые настройки
1 parent cb800db commit 79902b2

6 files changed

Lines changed: 20 additions & 115 deletions

File tree

deploy/nginx/host/dev/dev.procollab.ru

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
server {
22
listen 80;
33
server_name dev.procollab.ru;
4+
server_tokens off;
45

56
location ^~ /.well-known/acme-challenge/ {
67
root /var/www/certbot;
@@ -16,6 +17,7 @@ server {
1617
server {
1718
listen 443 ssl;
1819
server_name dev.procollab.ru;
20+
server_tokens off;
1921

2022
ssl_certificate /etc/letsencrypt/live/dev.procollab.ru-0001/fullchain.pem;
2123
ssl_certificate_key /etc/letsencrypt/live/dev.procollab.ru-0001/privkey.pem;

nginx/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ server {
44

55
server_name api.procollab.ru;
66
client_max_body_size 100M;
7+
server_tokens off;
78

89
location / {
910
proxy_pass http://web:8000;

poetry.lock

Lines changed: 1 addition & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

procollab/settings.py

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
from datetime import timedelta
55
from pathlib import Path
66

7-
import sentry_sdk
87
from decouple import config
9-
from sentry_sdk.integrations.django import DjangoIntegration
108

119
mimetypes.add_type("application/javascript", ".js", True)
1210
mimetypes.add_type("text/css", ".css", True)
@@ -18,8 +16,6 @@
1816

1917
DEBUG = config("DEBUG", default=False, cast=bool)
2018

21-
SENTRY_DSN = config("SENTRY_DSN", default="", cast=str)
22-
2319
AUTOPOSTING_ON = config("AUTOPOSTING_ON", default=False, cast=bool)
2420

2521
TELEGRAM_BOT_TOKEN = config("TELEGRAM_BOT_TOKEN", default="", cast=str)
@@ -36,7 +32,6 @@
3632
"https://www.procollab.ru",
3733
"https://app.procollab.ru",
3834
"https://dev.procollab.ru",
39-
"https://www.procollab.ru",
4035
]
4136

4237
ALLOWED_HOSTS = [
@@ -48,7 +43,6 @@
4843
"app.procollab.ru",
4944
"dev.procollab.ru",
5045
"procollab.ru",
51-
"dev.procollab.ru",
5246
"web", # From Docker
5347
]
5448

@@ -61,16 +55,6 @@
6155
"django.contrib.auth.hashers.ScryptPasswordHasher",
6256
]
6357

64-
# Application definition
65-
if SENTRY_DSN:
66-
sentry_sdk.init(
67-
dsn=SENTRY_DSN,
68-
integrations=[DjangoIntegration()],
69-
release="dev" if DEBUG else "prod",
70-
traces_sample_rate=1.0,
71-
send_default_pii=True,
72-
)
73-
7458
INSTALLED_APPS = [
7559
# daphne is required for channels, should be installed before django.contrib.static
7660
"daphne",
@@ -81,7 +65,6 @@
8165
"django.contrib.sessions",
8266
"django.contrib.messages",
8367
"django.contrib.staticfiles",
84-
"debug_toolbar",
8568
# My apps
8669
"core.apps.CoreConfig",
8770
"industries.apps.IndustriesConfig",
@@ -125,7 +108,6 @@
125108
"django.contrib.auth.middleware.AuthenticationMiddleware",
126109
"django.contrib.messages.middleware.MessageMiddleware",
127110
"django.middleware.clickjacking.XFrameOptionsMiddleware",
128-
"debug_toolbar.middleware.DebugToolbarMiddleware",
129111
"core.log.middleware.CustomLoguruMiddleware",
130112
]
131113

@@ -145,6 +127,9 @@
145127

146128
ROOT_URLCONF = "procollab.urls"
147129

130+
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
131+
SECURE_SSL_REDIRECT = not DEBUG
132+
148133
TEMPLATES = [
149134
{
150135
"BACKEND": "django.template.backends.django.DjangoTemplates",
@@ -184,24 +169,15 @@
184169
RUNNING_TESTS = "test" in sys.argv
185170

186171
if DEBUG:
172+
INSTALLED_APPS.append("debug_toolbar")
173+
MIDDLEWARE.insert(-1, "debug_toolbar.middleware.DebugToolbarMiddleware")
187174
DATABASES = {
188175
"default": {
189176
"ENGINE": "django.db.backends.sqlite3",
190177
"NAME": "db.sqlite3",
191178
}
192179
}
193180

194-
# DATABASES = {
195-
# "default": {
196-
# "ENGINE": "django.db.backends.postgresql",
197-
# "NAME": config("DATABASE_NAME", default="postgres", cast=str),
198-
# "USER": config("DATABASE_USER", default="postgres", cast=str),
199-
# "PASSWORD": config("DATABASE_PASSWORD", default="postgres", cast=str),
200-
# "HOST": config("DATABASE_HOST", default="db", cast=str),
201-
# "PORT": config("DATABASE_PORT", default="5432", cast=str),
202-
# }
203-
# }
204-
205181
if RUNNING_TESTS:
206182
CACHES = {
207183
"default": {
@@ -244,8 +220,6 @@
244220
"rest_framework.renderers.JSONRenderer",
245221
]
246222

247-
DB_SERVICE = config("DB_SERVICE", default="postgres", cast=str)
248-
249223
DATABASES = {
250224
"default": {
251225
"ENGINE": "django.db.backends.postgresql",
@@ -333,7 +307,8 @@
333307
if DEBUG:
334308
SIMPLE_JWT["ACCESS_TOKEN_LIFETIME"] = timedelta(weeks=2)
335309

336-
SESSION_COOKIE_SECURE = False
310+
SESSION_COOKIE_SECURE = not DEBUG
311+
CSRF_COOKIE_SECURE = not DEBUG
337312

338313
EMAIL_BACKEND = "anymail.backends.unisender_go.EmailBackend"
339314

@@ -348,19 +323,8 @@
348323
},
349324
}
350325

351-
EMAIL_USE_TLS = True
352-
353-
EMAIL_PORT = config("EMAIL_PORT", default=587, cast=int)
354326
EMAIL_USER = config("EMAIL_USER", cast=str, default="example@mail.ru")
355327

356-
# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
357-
# EMAIL_USE_TLS = True
358-
# EMAIL_HOST = config("EMAIL_HOST", default="smtp.gmail.com", cast=str)
359-
# EMAIL_PORT = config("EMAIL_PORT", default=587, cast=int)
360-
# EMAIL_HOST_USER = config("EMAIL_USER", cast=str, default="example@mail.ru")
361-
# EMAIL_USER = EMAIL_HOST_USER
362-
# EMAIL_HOST_PASSWORD = config("EMAIL_PASSWORD", cast=str, default="password")
363-
364328
SELECTEL_ACCOUNT_ID = config("SELECTEL_ACCOUNT_ID", cast=str, default="123456")
365329
SELECTEL_CONTAINER_NAME = config(
366330
"SELECTEL_CONTAINER_NAME", cast=str, default="procollab_media"
@@ -387,26 +351,6 @@
387351
if DEBUG:
388352
SELECTEL_SWIFT_URL += "debug/"
389353

390-
PROMETHEUS_LATENCY_BUCKETS = (
391-
0.01,
392-
0.025,
393-
0.05,
394-
0.075,
395-
0.1,
396-
0.25,
397-
0.5,
398-
0.75,
399-
1.0,
400-
2.5,
401-
5.0,
402-
7.5,
403-
10.0,
404-
25.0,
405-
50.0,
406-
75.0,
407-
float("inf"),
408-
)
409-
410354
DATA_UPLOAD_MAX_NUMBER_FIELDS = None # for mailing
411355

412356

procollab/urls.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44
from django.urls import include, path, re_path
55
from drf_yasg import openapi
66
from drf_yasg.views import get_schema_view
7+
from rest_framework import authentication, permissions
78
from rest_framework_simplejwt.views import (
89
TokenObtainPairView,
910
TokenRefreshView,
1011
TokenVerifyView,
1112
)
12-
from core.permissions import IsStaffOrReadOnly
13+
from users.authentication import ActivityTrackingJWTAuthentication
1314

1415
schema_view = get_schema_view(
1516
openapi.Info(
1617
title="ProCollab API",
1718
default_version="v1",
1819
description="API for ProCollab",
1920
),
20-
public=True,
21-
permission_classes=[IsStaffOrReadOnly],
21+
public=False,
22+
authentication_classes=[
23+
authentication.SessionAuthentication,
24+
authentication.BasicAuthentication,
25+
ActivityTrackingJWTAuthentication,
26+
],
27+
permission_classes=[permissions.IsAdminUser],
2228
)
2329

2430
urlpatterns = [

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ django-rest-passwordreset = "^1.3.0"
4646
django-filter = "^22.1"
4747
setuptools = "^65.5.0"
4848
drf-yasg = "^1.21.4"
49-
sentry-sdk = "^1.10.1"
5049
whitenoise = "^6.2.0"
5150
six = "^1.16.0"
5251
aiohttp = "^3.8.3"

0 commit comments

Comments
 (0)