-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: NotAShelf <[email protected]>
- Loading branch information
1 parent
2048601
commit e93ed3a
Showing
8 changed files
with
157 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
pkgs, | ||
lib, | ||
config, | ||
... | ||
}: let | ||
inherit (lib) mkDefault mkForce mkIf; | ||
inherit (config.modules) device; | ||
in { | ||
imports = [ | ||
./fail2ban.nix | ||
./nftables.nix | ||
]; | ||
|
||
config = { | ||
services = { | ||
# enable opensnitch firewall | ||
# inactive until opensnitch UI is opened | ||
opensnitch.enable = true; | ||
}; | ||
|
||
networking = { | ||
firewall = { | ||
enable = mkDefault true; | ||
package = mkDefault pkgs.iptables-nftables-compat; | ||
allowedTCPPorts = [ | ||
443 | ||
8080 | ||
]; | ||
allowedUDPPorts = []; | ||
allowedTCPPortRanges = mkIf (device.type != "server") [ | ||
{ | ||
#KDEconnect | ||
from = 1714; | ||
to = 1764; | ||
} | ||
]; | ||
allowedUDPPortRanges = mkIf (device.type != "server") [ | ||
{ | ||
#KDEconnect | ||
from = 1714; | ||
to = 1764; | ||
} | ||
]; | ||
allowPing = device.type == "server"; | ||
logReversePathDrops = true; | ||
logRefusedConnections = false; | ||
checkReversePath = mkForce false; # Don't filter DHCP packets, according to nixops-libvirtd | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: let | ||
inherit (lib) mkIf mkMerge concatStringsSep mkForce; | ||
|
||
cfg = config.modules.services; | ||
in { | ||
# fail2ban firewall jail | ||
services.fail2ban = { | ||
enable = true; | ||
banaction = "iptables-multiport[blocktype=DROP]"; | ||
maxretry = 7; | ||
ignoreIP = [ | ||
"127.0.0.0/8" | ||
"10.0.0.0/8" | ||
"192.168.0.0/16" | ||
]; | ||
|
||
jails = mkMerge [ | ||
{ | ||
# sshd jail | ||
sshd = mkForce '' | ||
enabled = true | ||
port = ${concatStringsSep "," (map toString config.services.openssh.ports)} | ||
mode = aggressive | ||
''; | ||
} | ||
(mkIf cfg.vaultwarden.enable { | ||
# vaultwarden and vaultwarden admin interface jails | ||
vaultwarden = '' | ||
enabled = true | ||
port = 80,443,8822 | ||
filter = vaultwarden | ||
banaction = %(banaction_allports)s | ||
logpath = /var/log/vaultwarden.log | ||
maxretry = 3 | ||
bantime = 14400 | ||
findtime = 14400 | ||
''; | ||
|
||
vaultwarden-admin = '' | ||
enabled = true | ||
port = 80,443 | ||
filter = vaultwarden-admin | ||
banaction = %(banaction_allports)s | ||
logpath = /var/log/vaultwarden.log | ||
maxretry = 3 | ||
bantime = 14400 | ||
findtime = 14400 | ||
''; | ||
}) | ||
]; | ||
|
||
bantime-increment = { | ||
enable = true; | ||
rndtime = "12m"; | ||
overalljails = true; | ||
multipliers = "4 8 16 32 64 128 256 512 1024 2048"; | ||
maxtime = "192h"; # get banned for 192 hours idiot | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
_: { | ||
networking.nftables = { | ||
enable = false; | ||
tables = { | ||
# TODO: write a proper filter table | ||
# accept: ssh, http, https and in the future, DNS | ||
# block: everything else | ||
default-filter = { | ||
content = ""; | ||
family = "inet"; | ||
}; | ||
}; | ||
}; | ||
} |