SV-268158r1131121_rule
V-268158
SRG-OS-000420-GPOS-00186
ANIX-00-001610
CAT II
10
Configure the NixOS firewall to enforce rate limits using the hashlimit module.
For example, to limit SSH to 1 MB/s and to limit HTTP to 1000 connections / minute per IP, add the following Nix code to the NixOS Configuration, usually located in /etc/nixos/configuration.nix or /etc/nixos/flake.nix:
networking.firewall.enable = true;
networking.firewall.extraCommands = ''
ip46tables --append INPUT --protocol tcp --dport 22 --match hashlimit --hashlimit-name stig_byte_limit --hashlimit-mode srcip --hashlimit-above 1000000b/second --jump nixos-fw-refuse
ip46tables --append INPUT --protocol tcp --dport 80 --match hashlimit --hashlimit-name stig_conn_limit --hashlimit-mode srcip --hashlimit-above 1000/minute --jump nixos-fw-refuse
ip46tables --append INPUT --protocol tcp --dport 443 --match hashlimit --hashlimit-name stig_conn_limit --hashlimit-mode srcip --hashlimit-above 1000/minute --jump nixos-fw-refuse
'';
Note: NixOS provides the helper script "ip46tables" to add rules using both "iptables" and "ip6tables".
Rebuild and switch to the new NixOS configuration:
$ sudo nixos-rebuild switch
Verify NixOS firewall enforces rate limits using the hashlimit module.
$ sudo iptables -L | grep limit
nixos-fw-refuse tcp -- anywhere anywhere tcp dpt:ssh limit: above 1000000b/s mode srcip
nixos-fw-refuse tcp -- anywhere anywhere tcp dpt:http limit: above 1000/min burst 5 mode srcip
nixos-fw-refuse tcp -- anywhere anywhere tcp dpt:https limit: above 1000/min burst 5 mode srcip
If the command does not produce any rate limiting rules, this is a finding.
V-268158
False
ANIX-00-001610
Verify NixOS firewall enforces rate limits using the hashlimit module.
$ sudo iptables -L | grep limit
nixos-fw-refuse tcp -- anywhere anywhere tcp dpt:ssh limit: above 1000000b/s mode srcip
nixos-fw-refuse tcp -- anywhere anywhere tcp dpt:http limit: above 1000/min burst 5 mode srcip
nixos-fw-refuse tcp -- anywhere anywhere tcp dpt:https limit: above 1000/min burst 5 mode srcip
If the command does not produce any rate limiting rules, this is a finding.
M
5658