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

nixos/sshd: disable openFirewall by default #81490

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bb2020
Copy link
Member

@bb2020 bb2020 commented Mar 2, 2020

Opening SSH port on firewall is a security risk and it should be blocked by default.

I thought this was an urgent issue so I didn't use proper branching and had to create a new PR.
Sorry for the duplicate.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By forcing the user to choose a value this satisfies the argument against unknowingly locking people out of their systems, as well as the argument for a more secure default 👍

If there were to be any change to this PR I might suggest that since this will impact a large number of users we might add an assertion which explains the situation nicer than the existing openFirewall referenced but not declared error, which isn't overly nice or clear.

@aanderse
Copy link
Member

aanderse commented Mar 2, 2020

We should see if @edolstra finds this to be an acceptable compromise. This satisfies issues he has raised in the past, so I think there is a chance he would be accepting of this.

@aanderse aanderse requested a review from edolstra March 2, 2020 11:31
@bb2020 bb2020 force-pushed the ssh-fw branch 2 times, most recently from d3bb37d to 95d0e82 Compare March 2, 2020 11:55
@edolstra
Copy link
Member

edolstra commented Mar 2, 2020

This would be okay, though I still think that the case where you want sshd enabled but you don't want it exposed in the firewall is a pretty rare one. So the current situation has my preference.

@bb2020
Copy link
Member Author

bb2020 commented Mar 2, 2020

One possible scenario would be having two interfaces and assigning one of them as trusted interface with networking.firewall.trustedInterfaces. As you can access to trusted interface freely, one may think that the other interface is safe while it is not.

@aanderse
Copy link
Member

aanderse commented Mar 2, 2020

One possible scenario would be having two interfaces

This is my scenario. I set openFirewall to false and then explicitly open port 22 for a given interface. Though as mentioned maybe more of a rare scenario 😄

@bb2020
Copy link
Member Author

bb2020 commented Mar 2, 2020

Of course you are right. This is a rare situation. However SSH is a dangerous thing when it is unchecked by firewall. I think we should maximize security whenever possible.

@Frostman
Copy link
Member

Frostman commented Mar 2, 2020

if I'm not mistaken, it'll add an extra not that obvious step to the installation process - not only enable sshd but open port for it.

@aanderse
Copy link
Member

aanderse commented Mar 2, 2020

@Frostman posting a clear message to the screen in an assertion if the user hasn't explicitly opened the firewall will clarify any confusion. All services except openssh require the user to explicitly open a port in the firewall.

Personally I'm somewhat indifferent to this PR, but the change has been requested a number of times and it seems like a reasonable solution to me. Since @edolstra seems to find this solution acceptable enough maybe we just wait and see more opinions 🤷‍♂️

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/ssh-openfirewall-exception/12066/1

@Ma27
Copy link
Member

Ma27 commented Mar 22, 2021

AFAIU you won't if you didn't set sshd.openFirewall. If it's null, an eval error will be thrown and thus no bogus config will be deployed.

@aanderse
Copy link
Member

You are correct @Ma27 - this PR forces the user to explicitly set a value... so no risk of breakage.

@MatthewCroughan
Copy link
Contributor

MatthewCroughan commented Mar 22, 2021

AFAIU you won't if you didn't set sshd.openFirewall. If it's null, an eval error will be thrown and thus no bogus config will be deployed.

So does this mean that the default configuration as it is today, made by nixos-generate-config will fail to rebuild?

Edit: Ah, I misremembered. You have to manually enable SSH anyway, so this just makes it a required option. I see.

@MatthewCroughan
Copy link
Contributor

However, what about the installer image? SSH is enabled on that out-of-the-box. This is nice behavior in my view, because it allows easy provisioning, so even if this is merged, openFirewall should still be set to true on the installer image.

@bb2020
Copy link
Member Author

bb2020 commented Mar 22, 2021

However, what about the installer image? SSH is enabled on that out-of-the-box. This is nice behavior in my view, because it allows easy provisioning, so even if this is merged, openFirewall should still be set to true on the installer image.

I tried to achieve that here. I am not sure if it is enough.

@stale
Copy link

stale bot commented Sep 19, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 19, 2021
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 13, 2022
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 8, 2023
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 9, 2023
@infinisil infinisil added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Apr 19, 2023
@wegank wegank added 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 2.status: merge conflict labels Mar 19, 2024
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank marked this pull request as draft March 25, 2024 16:11
@bb2020 bb2020 marked this pull request as ready for review April 3, 2024 15:37
@bb2020 bb2020 force-pushed the ssh-fw branch 3 times, most recently from 69b3d09 to a895f9c Compare April 12, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos 8.has: clean-up 8.has: module (update) 10.rebuild-darwin: 0 10.rebuild-linux: 1-10 significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet