From cf10d7aef8ff9ca0e178e87981d9e4fd3018193c Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 15 Jan 2023 16:32:46 +0100 Subject: [PATCH] services.openssh: support freeform settings (#193757) * services.openssh: support freeform settings Keep "extraConfig" but introduces "settings". Also renames several options (mkRenamedOptionModule [ "services" "openssh" "kbdInteractiveAuthentication" ] [ "services" "openssh" "settings" "KbdInteractiveAuthentication" ]) (mkRenamedOptionModule [ "services" "openssh" "passwordAuthentication" ] [ "services" "openssh" "settings" "PasswordAuthentication" ]) (mkRenamedOptionModule [ "services" "openssh" "useDns" ] [ "services" "openssh" "settings" "UseDns" ]) (mkRenamedOptionModule [ "services" "openssh" "permitRootLogin" ] [ "services" "openssh" "settings" "PermitRootLogin" ]) * updated doc * regen doc --- nixos/doc/manual/configuration/ssh.section.md | 2 +- .../from_md/configuration/ssh.section.xml | 2 +- .../from_md/release-notes/rl-2305.section.xml | 18 +++ .../manual/release-notes/rl-2305.section.md | 2 + .../modules/profiles/installation-device.nix | 2 +- .../modules/services/networking/ssh/sshd.nix | 128 ++++++++++-------- nixos/modules/services/security/fail2ban.nix | 2 +- nixos/modules/virtualisation/amazon-image.nix | 2 +- nixos/modules/virtualisation/azure-common.nix | 6 +- .../virtualisation/brightbox-image.nix | 2 +- .../virtualisation/cloudstack-config.nix | 2 +- .../virtualisation/digital-ocean-config.nix | 2 +- .../virtualisation/google-compute-config.nix | 4 +- .../virtualisation/openstack-config.nix | 4 +- nixos/tests/borgbackup.nix | 6 +- nixos/tests/btrbk.nix | 6 +- nixos/tests/google-oslogin/server.nix | 4 +- nixos/tests/sourcehut.nix | 6 +- nixos/tests/turbovnc-headless-server.nix | 2 +- 19 files changed, 124 insertions(+), 78 deletions(-) diff --git a/nixos/doc/manual/configuration/ssh.section.md b/nixos/doc/manual/configuration/ssh.section.md index cba81eb43f49..9e239a848178 100644 --- a/nixos/doc/manual/configuration/ssh.section.md +++ b/nixos/doc/manual/configuration/ssh.section.md @@ -8,7 +8,7 @@ services.openssh.enable = true; By default, root logins using a password are disallowed. They can be disabled entirely by setting -[](#opt-services.openssh.permitRootLogin) to `"no"`. +[](#opt-services.openssh.settings.PermitRootLogin) to `"no"`. You can declaratively specify authorised RSA/DSA public keys for a user as follows: diff --git a/nixos/doc/manual/from_md/configuration/ssh.section.xml b/nixos/doc/manual/from_md/configuration/ssh.section.xml index a330457f51d6..e0d4031443ef 100644 --- a/nixos/doc/manual/from_md/configuration/ssh.section.xml +++ b/nixos/doc/manual/from_md/configuration/ssh.section.xml @@ -9,7 +9,7 @@ services.openssh.enable = true; By default, root logins using a password are disallowed. They can be disabled entirely by setting - to + to "no". diff --git a/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml index d6dea111b97b..e1317621418d 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml @@ -324,6 +324,24 @@ services.usbmuxd.package + + + A few openssh options have been moved from extraConfig to the + new freeform option settings and renamed as + follow: + services.openssh.kbdInteractiveAuthentication + to + services.openssh.settings.KbdInteractiveAuthentication, + services.openssh.passwordAuthentication to + services.openssh.settings.PasswordAuthentication, + services.openssh.useDns to + services.openssh.settings.UseDns, + services.openssh.permitRootLogin to + services.openssh.settings.PermitRootLogin, + services.openssh.logLevel to + services.openssh.settings.LogLevel. + + services.mastodon gained a tootctl wrapped diff --git a/nixos/doc/manual/release-notes/rl-2305.section.md b/nixos/doc/manual/release-notes/rl-2305.section.md index beffe19c2ea7..1620e98f3aa3 100644 --- a/nixos/doc/manual/release-notes/rl-2305.section.md +++ b/nixos/doc/manual/release-notes/rl-2305.section.md @@ -85,6 +85,8 @@ In addition to numerous new and upgraded packages, this release has the followin - The module `usbmuxd` now has the ability to change the package used by the daemon. In case you're experiencing issues with `usbmuxd` you can try an alternative program like `usbmuxd2`. Available as [services.usbmuxd.package](#opt-services.usbmuxd.package) +- A few openssh options have been moved from extraConfig to the new freeform option `settings` and renamed as follow: `services.openssh.kbdInteractiveAuthentication` to `services.openssh.settings.KbdInteractiveAuthentication`, `services.openssh.passwordAuthentication` to `services.openssh.settings.PasswordAuthentication`, `services.openssh.useDns` to `services.openssh.settings.UseDns`, `services.openssh.permitRootLogin` to `services.openssh.settings.PermitRootLogin`, `services.openssh.logLevel` to `services.openssh.settings.LogLevel`. + - `services.mastodon` gained a tootctl wrapped named `mastodon-tootctl` similar to `nextcloud-occ` which can be executed from any user and switches to the configured mastodon user with sudo and sources the environment variables. - The `dnsmasq` service now takes configuration via the diff --git a/nixos/modules/profiles/installation-device.nix b/nixos/modules/profiles/installation-device.nix index 4d9bd69666c0..980720691a43 100644 --- a/nixos/modules/profiles/installation-device.nix +++ b/nixos/modules/profiles/installation-device.nix @@ -72,7 +72,7 @@ with lib; # mounting the storage in a different system. services.openssh = { enable = true; - permitRootLogin = "yes"; + settings.PermitRootLogin = "yes"; }; # Enable wpa_supplicant, but don't start it by default. diff --git a/nixos/modules/services/networking/ssh/sshd.nix b/nixos/modules/services/networking/ssh/sshd.nix index 37d7518ab3c4..3a8640171b70 100644 --- a/nixos/modules/services/networking/ssh/sshd.nix +++ b/nixos/modules/services/networking/ssh/sshd.nix @@ -12,8 +12,23 @@ let then cfgc.package else pkgs.buildPackages.openssh; + # reports boolean as yes / no + mkValueStringSshd = v: + if isInt v then toString v + else if isString v then v + else if true == v then "yes" + else if false == v then "no" + else throw "unsupported type ${typeOf v}: ${(lib.generators.toPretty {}) v}"; + + # dont use the "=" operator + settingsFormat = (pkgs.formats.keyValue { + mkKeyValue = lib.generators.mkKeyValueDefault { + mkValueString = mkValueStringSshd; + } " ";}); + + configFile = settingsFormat.generate "config" cfg.settings; sshconf = pkgs.runCommand "sshd.conf-validated" { nativeBuildInputs = [ validationPackage ]; } '' - cat >$out <$out <