I bumped into NixOS peculiarity, due to which, I can’t fully control firewall on my machine. For example, if I enable OpenSSH service, it automatically allows connection to 22nd port in firewall policies. And even if I remove 22nd port from allowedTCPPorts and allowedUDPPorts, this won’t make any sense, because OpenSSH service in NixOS is programmed to open ssh port when this service is being enabled.
What I want is to force overwrite firewall settings in NixOS. I want ssh port to remain filtered, even if OpenSSH service is enabled. Is there any way to do so?
openFirewall = mkOption {
type = types.bool;
default = true;
description = ''
Whether to automatically open the specified ports in the firewall.
'';
};
this seems to effect.
networking.firewall.allowedTCPPorts = if cfg.openFirewall then cfg.ports else [];
I see, i presume the reasoning is , that if your installing these services, you probably want other machines to connect to it, else you won’t be receiving much mail from users outside of that system.
as what the default behaviour should be , it’s tricky… because it’s easy to forget to open up your firewall, leading to a bit of confusion.
Maybe it should be a standard, but if i know nixpkgs, it’s really ‘do what you want, how you want’ and commit.
The question is should all services should be allowed to do this and made a ‘standard’ in nixpkgs?
Something like networking.firewall.allowedTCPPorts = lib.mkForce [ ]; should prevent NixOS modules (but also your own modules/options!) from adding ports (by not merging them into the list). But in this case services.openssh.openFirewall = false; is usually better as the SSH module is supposed to be the only module that opens ports (an exception was made as SSH access is very important).
Yes. IIRC there was a “rule” that no other modules should modify firewall settings as that is up to the administrator and should be a conscious choice.
Then I guess we’ve either dropped the rule (not sure how well documented this was) or this was missed during the review (which would be unfortunate…). Personally I don’t think any module/service should open any ports, especially not by default (except SSH of course).
Ensure that the module respect other modules functionality.
For example, enabling a module should not open firewall ports by default.
So I’d consider that a (security) bug of the Dovecot and Postfix modules and think that this should then at least be clearly mentioned in the documentation of their enable options.
That is something else, entirely, because the simple-nixos-mailserver is not part of nixpkgs. It opens these ports by default because if your mailserver can’t communicate it is completely useless and the overwhelming majority of users will want a useful mailserver.
Opening ports directly to the web - isn’t the only way to make it usable. In my case, I want to hide all my services(except SMTP Server) behind VPN, and be able to access them only while being connected to VPN. So the only two ports, I need to be opened to the world - is VPN port and SMTP port
I’m not arguing with the default standarts. I just wanted to know, if there’s a way to overwrite them, to match my particular case. But, if there’s no way to do so, I’ll be looking for some sort of software solution of this problem(like using ufw instead of default iptables)