-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
nixos-firewall-tool: add nftables support #324615
Conversation
I wonder if the nixos-firewall-tool should just be a single script that handles both iptables and nftables. I was thinking of checking What do you think? @clerie |
Hi @nbdd0121, thank you for the effort putting some work into this. Without looking at the details (as in doing a full review), I think that is something we should merge to get some traction into this topic. Because nobody found a robust solution for deciding between nf- and iptables in the mean time, I think yielding two different packages based on system config is acceptable for now. If someone finds a proper solution we can still change that later. |
0212c16
to
07e2ab5
Compare
echo "nixos-firewall-tool" | ||
echo "" | ||
echo "Can temporarily manipulate the NixOS firewall" | ||
echo "" | ||
echo "Open TCP port:" | ||
echo " nixos-firewall-tool open tcp 8888" | ||
echo "" | ||
echo "Show all firewall rules:" | ||
echo " nixos-firewall-tool show" | ||
echo "" | ||
echo "Open UDP port:" | ||
echo " nixos-firewall-tool open udp 51820" | ||
echo "" | ||
echo "Reset firewall configuration to system settings:" | ||
echo " nixos-firewall-tool reset" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be combined into one echo with mutliline strings. Also echo already prints an empty line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied verbatim from pkgs/by-name/ni/nixos-firewall-tool/nixos-firewall-tool.sh, and I've changed approach to detect for iptables/nftables support instead of having two separate files.
ee9d14d
to
900f9f6
Compare
runtimeInputs = [ | ||
iptables | ||
]; | ||
runtimeInputs = [ ({ inherit iptables nftables; }.${backend}) ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the firewall module have cfg.package
added to the environment package. Maybe the runtimeInputs
can be removed completely and rely on iptables/nft
being in PATH?
900f9f6
to
edb2f9a
Compare
edb2f9a
to
c8b6d9a
Compare
systemctl restart firewall.service | ||
;; | ||
nftables) | ||
nft flush set inet nixos-fw "temp-ports" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This implementation differs from the one with iptables. With iptables, all rules are being reset to the definitions done with nix. With nftables only temporarily opened ports are flushed.
I appreciate the nftables implementation more, as it respects dynamic rules done by other tools like Docker, but maybe this should be highlighted, or the subcommands for nftables should be renamed, and a notice added that reset only works with iptables and for nftables the unit should be restarted manually.
Alternatively, reset could be implemented for nftables with the same functionality, and the current implementation gets moved into another separate subcommand.
Although I am also fine with the implementation as it is right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intentional, since otherwise it's very disruptive. It's especially so when you uses nft sets, everything added there will also be lost.
Arguably the same should be done for iptables by setting up a separate chain, but I don't have bandwidth for it now, I just want to get nftables functionality to work on par with iptables so more people can switch over.
Co-authored-by: Rvfg <[email protected]>
Co-authored-by: Rvfg <[email protected]>
Co-authored-by: Rvfg <[email protected]>
c8b6d9a
to
9d662d9
Compare
Description of changes
Add nftables support in
nixos-firewall-tool
and install it by default when NixOS firewall is enabled.Also add some tests for
nixos-firewall-tool
innixosTests.firewall
.This is the continuation of work of #275126 by @duament. I removed the dependency on #275371 (although I think it's still a good refactor to have, but it doesn't have to block this PR).
All the temporary port openings are added to the temp-ports nft set, so that resetting to default would only require flushing this set. This avoids disrupting tables and sets that are maintained by other services.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.