infrastructure/modules/nixos/dgn-firewall/streams.nix
Tom Hubrecht b263c1fc84
All checks were successful
Check meta / check_dns (pull_request) Successful in 15s
Check meta / check_meta (pull_request) Successful in 15s
Build all the nodes / netcore02 (pull_request) Successful in 21s
Check workflows / check_workflows (pull_request) Successful in 22s
Build all the nodes / ap01 (pull_request) Successful in 1m13s
Build all the nodes / geo02 (pull_request) Successful in 1m57s
Build all the nodes / bridge01 (pull_request) Successful in 1m59s
Build all the nodes / storage01 (pull_request) Successful in 2m11s
Build the shell / build-shell (pull_request) Successful in 35s
Run pre-commit on all files / pre-commit (pull_request) Successful in 38s
Build all the nodes / web03 (pull_request) Successful in 1m44s
Build all the nodes / hypervisor03 (pull_request) Successful in 2m59s
Build all the nodes / web02 (pull_request) Successful in 3m4s
Build all the nodes / hypervisor02 (pull_request) Successful in 3m26s
Build all the nodes / rescue01 (pull_request) Successful in 3m40s
Build all the nodes / hypervisor01 (pull_request) Successful in 3m43s
Build all the nodes / tower01 (pull_request) Successful in 3m32s
Build all the nodes / geo01 (pull_request) Successful in 3m48s
Build all the nodes / vault01 (pull_request) Successful in 3m38s
Build all the nodes / build01 (pull_request) Successful in 3m57s
Build all the nodes / web01 (pull_request) Successful in 4m4s
Build all the nodes / compute01 (pull_request) Successful in 4m25s
Build all the nodes / netcore02 (push) Successful in 22s
Build all the nodes / ap01 (push) Successful in 34s
Build all the nodes / bridge01 (push) Successful in 1m53s
Build all the nodes / hypervisor02 (push) Successful in 2m9s
Build all the nodes / build01 (push) Successful in 2m13s
Build all the nodes / hypervisor01 (push) Successful in 2m14s
Build all the nodes / geo01 (push) Successful in 2m17s
Build the shell / build-shell (push) Successful in 33s
Build all the nodes / geo02 (push) Successful in 2m36s
Build all the nodes / tower01 (push) Successful in 2m37s
Build all the nodes / web03 (push) Successful in 2m4s
Build all the nodes / storage01 (push) Successful in 2m38s
Run pre-commit on all files / pre-commit (push) Successful in 30s
Build all the nodes / hypervisor03 (push) Successful in 2m44s
Build all the nodes / web02 (push) Successful in 2m23s
Build all the nodes / compute01 (push) Successful in 2m47s
Build all the nodes / rescue01 (push) Successful in 2m53s
Build all the nodes / web01 (push) Successful in 2m55s
Build all the nodes / vault01 (push) Successful in 2m57s
feat(dgn-firewall): Ban f*cking AI crawlers again
2025-01-16 15:27:41 +01:00

95 lines
1.8 KiB
Nix

# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
let
act = a: [
"nft46"
"${a} element inet reaction ipvXbans { <ip> }"
];
journalctl = u: [
"journalctl"
"-fn0"
"-u"
"${u}.service"
];
ban = after: {
ban.cmd = act "add";
unban = {
inherit after;
cmd = act "delete";
};
};
in
{
ai-crawlers = {
cmd = [
"tail"
"-n0"
"-f"
"/var/log/nginx/access.log"
];
filters.bots = {
regex = builtins.map (name: ''^<ip>.*"[^"]*${name}[^"]*"$'') [
"AI2Bot"
"Amazonbot"
"Applebot"
"Applebot-Extended"
"Bytespider"
"CCBot"
"ChatGPT-User"
"ClaudeBot"
"Diffbot"
"DuckAssistBot"
"FacebookBot"
"GPTBot"
"Google-Extended"
"Kangaroo Bot"
"Meta-ExternalAgent"
"Meta-ExternalFetcher"
"OAI-SearchBot"
"PerplexityBot"
"Timpibot"
"Webzio-Extended"
"YouBot"
"omgili"
];
actions = ban "720h";
};
};
forgejo-slow-crawlers = {
cmd = journalctl "forgejo";
filters.slowness = {
regex = [
"router: slow .* GET /.* for <ip>:0, elapsed .*"
];
actions = ban "72h";
retry = 15;
retryPeriod = "2h";
};
};
ssh = {
cmd = journalctl "sshd";
filters = {
failedlogin = {
regex = [
"authentication failure;.*rhost=<ip>"
"Connection reset by authenticating user .* <ip>"
"Connection closed by invalid user .* <ip> port .*"
"Failed password for .* from <ip>"
"Invalid user .* from <ip> port .*"
"Unable to negotiate with <ip> port .*"
];
actions = ban "48h";
};
};
};
}