From f04d593f53f34320118f9be131fc895a25a18313 Mon Sep 17 00:00:00 2001 From: erjemin Date: Sun, 18 May 2025 14:50:21 +0300 Subject: [PATCH] =?UTF-8?q?add:=20=D0=97=D0=B0=D1=89=D0=B8=D1=82=D0=B0=20?= =?UTF-8?q?=D1=85=D0=BE=D1=81=D1=82=D0=B0=20=D1=81=20=D0=BF=D0=BE=D0=BC?= =?UTF-8?q?=D0=BE=D1=89=D1=8C=D1=8E=20CrowdSec=20.......?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kubernetes/k3s-protection-with-crowdsec.md | 53 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/kubernetes/k3s-protection-with-crowdsec.md b/kubernetes/k3s-protection-with-crowdsec.md index 8d4927f..ef40a31 100644 --- a/kubernetes/k3s-protection-with-crowdsec.md +++ b/kubernetes/k3s-protection-with-crowdsec.md @@ -262,13 +262,35 @@ IP-адреса по iptables (или nftables) и сделать CrowdSec зл ```shell sudo apt-get install crowdsec-firewall-bouncer-iptables ``` +Проверим, что "вышибала" запустилась: +```shell +sudo systemctl status crowdsec-firewall-bouncer +``` -А затем подключить его в CrowdSec: +Увидим что-то вроде: +```text +● crowdsec-firewall-bouncer.service - The firewall bouncer for CrowdSec + Loaded: loaded (/etc/systemd/system/crowdsec-firewall-bouncer.service; enabled; vendor preset: enabled) + Active: active (running) since Sun 2025-05-18 14:47:10 MSK; 723ms ago + Process: 621537 ExecStartPre=/usr/bin/crowdsec-firewall-bouncer -c /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml -t (code=exited, status=0/SUCCESS) + Process: 621674 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS) + Main PID: 621622 (crowdsec-firewa) + Tasks: 10 (limit: 18978) + Memory: 7.4M + CPU: 401ms + CGroup: /system.slice/crowdsec-firewall-bouncer.service + └─621622 /usr/bin/crowdsec-firewall-bouncer -c /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml + +May 18 14:47:04 opi5 systemd[1]: Starting The firewall bouncer for CrowdSec... +May 18 14:47:10 opi5 systemd[1]: Started The firewall bouncer for CrowdSec. +``` + +Подключить его в CrowdSec: ```shell sudo cscli bouncers add firewall-bounce ``` -Проверим, что "вышибала" установлен: +Проверим, что "вышибала" добавлен: ```shell sudo cscli bouncers list ``` @@ -502,6 +524,7 @@ labels: После редактирования файла, нужно перезапустить CrowdSec, чтоб он применил изменения: ```shell sudo systemctl restart crowdsec +sudo systemctl restart crowdsec-firewall-bouncer ``` Другие сценарии можно настроить по аналогии. "Злость" управляется параметрами `leakspeed`, `capacity` и `blackhole`. @@ -529,9 +552,31 @@ sudo cscli decisions list Время блокировок (`expiration`) могут оказаться даже сильнее чем наши настройки. Это из-за того, что "зловред" может попасть под несколько блокировок одновременно или успеть сделать несколько атак (_а если честно, я сам не -понимаю, как это работает, даже настройки блокировки на 12 часов будут отображаться как 4-часовые_). +понимаю, как это работает... 40часовые блокировки по-умолчанию, но даже настройки блокировки на 12 часов будут +отображаться как 4-часовые_). Плюсом является то, что бгадоря обмену информацией о блокировках, а личного кабинета на сайте CrowdSec можно посмотреть ваши локальные блокировки в веб-интерфейсе: -![crowdsec--security-panel.png](../images/crowdsec--security-panel.png) \ No newline at end of file +![crowdsec--security-panel.png](../images/crowdsec--security-panel.png) + +---- +##### Управление блокировками + +Можно добавить бан вручную (по умолчанию: `duration:4h` и `type:ban`): +```shell +sudo cscli decisions add -i xxx.xxx.xxx.xxx +sudo cscli decisions add --ip xxx.xxx.xxx.xxx --duration 24h --reason "любопытный безопасник" +sudo cscli decisions add --ip xxx.xxx.xxx.xxx --reason "web bruteforce" --type captcha +``` + +Снять блокировку отдельного IP, подсети (диапазона) или вообще все: +```shell +sudo cscli decisions delete --ip xxx.xxx.xxx.xxx +sudo cscli decisions delete --range yyy.yyy.yyyy.yyy/24 +sudo cscli decisions delete --all +``` + + + +