-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
182 lines (155 loc) · 5.38 KB
/
config.py
File metadata and controls
182 lines (155 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import typing
from decimal import Decimal
from typing import Literal
from pydantic_settings import BaseSettings
__author__ = "Tempesta Technologies, Inc."
__copyright__ = "Copyright (C) 2023-2025 Tempesta Technologies, Inc."
__license__ = "GPL2"
class AppConfig(BaseSettings):
path_to_tft_config: str = "/etc/tempesta/fw/tft/blocked.conf"
path_to_tfh_config: str = "/etc/tempesta/fw/tfh/blocked.conf"
clickhouse_host: str = "127.0.0.1"
clickhouse_port: int = 8123
clickhouse_user: str = "default"
clickhouse_password: str = ""
clickhouse_table_name: str = "access_log"
clickhouse_database: str = "default"
persistent_users_allow: bool = True
persistent_users_window_offset_min: int = 60
persistent_users_window_duration_min: int = 60
detectors: set[
Literal[
"ip_rps",
"ip_time",
"ip_errors",
"tft_rps",
"tft_time",
"tft_errors",
"tfh_rps",
"tfh_time",
"tfh_errors",
"geoip",
]
] = {"tft_rps", "tft_time", "tft_errors"}
blocking_types: set[Literal["tft", "tfh", "ipset", "nftables"]] = {"tft"}
blocking_window_duration_sec: int = 10
blocking_ipset_name: str = "tempesta_blocked_ips"
blocking_time_min: int = 60
blocking_release_time_min: int = 1
training_mode: Literal["off", "historical", "real"] = "off"
training_mode_duration_min: int = 10
detector_ip_rps_default_threshold: Decimal = Decimal(10)
detector_ip_rps_intersection_percent: Decimal = Decimal(10)
detector_ip_rps_block_users_per_iteration: Decimal = Decimal(10)
detector_ip_time_default_threshold: Decimal = Decimal(10)
detector_ip_time_intersection_percent: Decimal = Decimal(10)
detector_ip_time_block_users_per_iteration: Decimal = Decimal(10)
detector_ip_errors_default_threshold: Decimal = Decimal(10)
detector_ip_errors_intersection_percent: Decimal = Decimal(10)
detector_ip_errors_block_users_per_iteration: Decimal = Decimal(10)
detector_ip_errors_allowed_statuses: list[int] = [
100,
101,
200,
201,
204,
300,
301,
302,
303,
304,
305,
307,
308,
400,
401,
403,
]
detector_tft_rps_default_threshold: Decimal = Decimal(10)
detector_tft_rps_intersection_percent: Decimal = Decimal(10)
detector_tft_rps_block_users_per_iteration: Decimal = Decimal(10)
detector_tft_time_default_threshold: Decimal = Decimal(10)
detector_tft_time_intersection_percent: Decimal = Decimal(10)
detector_tft_time_block_users_per_iteration: Decimal = Decimal(10)
detector_tft_errors_default_threshold: Decimal = Decimal(10)
detector_tft_errors_intersection_percent: Decimal = Decimal(10)
detector_tft_errors_block_users_per_iteration: Decimal = Decimal(10)
detector_tft_errors_allowed_statuses: list[int] = [
100,
101,
200,
201,
204,
300,
301,
302,
303,
304,
305,
307,
308,
400,
401,
403,
]
detector_tfh_rps_default_threshold: Decimal = Decimal(10)
detector_tfh_rps_intersection_percent: Decimal = Decimal(10)
detector_tfh_rps_block_users_per_iteration: Decimal = Decimal(10)
detector_tfh_time_default_threshold: Decimal = Decimal(10)
detector_tfh_time_intersection_percent: Decimal = Decimal(10)
detector_tfh_time_block_users_per_iteration: Decimal = Decimal(10)
detector_tfh_errors_default_threshold: Decimal = Decimal(10)
detector_tfh_errors_intersection_percent: Decimal = Decimal(10)
detector_tfh_errors_block_users_per_iteration: Decimal = Decimal(10)
detector_tfh_errors_allowed_statuses: list[int] = [
100,
101,
200,
201,
204,
300,
301,
302,
303,
304,
305,
307,
308,
400,
401,
403,
]
detector_geoip_rps_default_threshold: Decimal = Decimal(10)
detector_geoip_intersection_percent: Decimal = Decimal(10)
detector_geoip_block_users_per_iteration: Decimal = Decimal(10)
detector_geoip_path_allowed_cities_list: str = (
"/etc/tempesta/webshield/allowed_cities.txt"
)
detector_geoip_path_to_db: str = "/etc/tempesta/webshield/city.db"
tempesta_executable_path: str = ""
tempesta_config_path: str = ""
allowed_user_agents_file_path: str = (
"/etc/tempesta/webshield/allow_user_agents.txt"
)
bots_white_list_allowed: set[typing.Literal['google']] = ('google', )
bots_white_list_external_sources: set[str] = ()
log_level: str = "INFO"
@classmethod
def read(cls, path: str) -> str:
with open(path, "r") as f:
return f.read()
@property
def training_mode_duration_sec(self) -> int:
return self.training_mode_duration_min * 60
@property
def persistent_users_window_offset_sec(self) -> int:
return self.persistent_users_window_offset_min * 60
@property
def persistent_users_window_duration_sec(self) -> int:
return self.persistent_users_window_duration_min * 60
@property
def blocking_release_time_sec(self) -> int:
return self.blocking_release_time_min * 60
@property
def blocking_time_sec(self) -> int:
return self.blocking_time_min * 60