Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate fail2ban sshd ddos jail for non production machines #1143

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions changelog.d/20241031_142143_PL-132477-dheat-ssh_scriv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--

A new changelog entry.

Delete placeholder items that do not apply. Empty sections will be removed
automatically during release.

Leave the XX.XX as is: this is a placeholder and will be automatically filled
correctly during the release and helps when backporting over multiple platform
branches.

-->

### Impact

- Activate DDoS SSH rules in fail2ban for non-production machines

### NixOS XX.XX platform

- Activate DDoS SSH rules in fail2ban for non-production machines. (PL-132477)
This may have impact if you have multiple unauthenticated SSH connections in a short time.
We will roll out this change to production VMs too if no problems occur.
7 changes: 7 additions & 0 deletions doc/src/firewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,10 @@ ip6tables -L -nv # show IPv6 firewall rules w/o DNS resolution

If the intended rules do not show up, check the system journal for possible
syntax errors in {file}`/etc/local/firewall` and re-run {command}`fc-manage -b`.

## Fail2ban

We use fail2ban to protect against brute-force attacks and DoS vectors via unauthenticated connections.

Currently we only have the SSH jail enabled in the `ddos` mode. If you have 5 authentication failures
or trigger the DDoS rules within 10 minutes, your IP will be blocked for 10 minutes.
38 changes: 22 additions & 16 deletions nixos/platform/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -377,22 +377,28 @@ in {
# overrides it
cron.enable = fclib.mkPlatform true;

fail2ban.enable = fclib.mkPlatform true;
fail2ban.ignoreIP =
[
# loopback
"127.0.0.1/8"
"::1"

# rfc1918 addresses
"10.0.0.0/8"
"172.16.0.0/12"
"192.168.0.0/16"
] ++
cfg.static.firewall.trusted ++
(flatten
(builtins.map (v: builtins.attrNames v.networks)
(builtins.attrValues (attrByPath [ "parameters" "interfaces" ] {} cfg.enc))));
fail2ban = let
production = lib.attrByPath [ "parameters" "production" ] false config.flyingcircus.enc;
in {
enable = fclib.mkPlatform true;
maxretry = fclib.mkPlatform 5;
jails.sshd.settings.mode = lib.mkIf production (fclib.mkPlatform "ddos");
ignoreIP =
[
# loopback
"127.0.0.1/8"
"::1"

# rfc1918 addresses
"10.0.0.0/8"
"172.16.0.0/12"
"192.168.0.0/16"
] ++
cfg.static.firewall.trusted ++
(flatten
(builtins.map (v: builtins.attrNames v.networks)
(builtins.attrValues (attrByPath [ "parameters" "interfaces" ] {} cfg.enc))));
};

nscd.enable = true;
openssh.enable = fclib.mkPlatform true;
Expand Down
Loading