Commit graph

191 commits

Author SHA1 Message Date
Philip Taron 01898764b6
treewide: replace "yes" else "no" usages to lib.boolToYesNo (#442387) 2025-10-28 16:25:46 +00:00
Aliaksandr 80f12557f5
treewide: replace "yes" else "no" usages to lib.boolToYesNo 2025-10-21 16:04:34 +03:00
Aliaksandr f28be96fda
treewide: mkAliasOptionModuleMD -> mkAliasOptionModule 2025-10-21 15:42:47 +03:00
Matthieu C. 7ebfdde615
nixos/ssh: fewer empty lines in generated ssh and sshd config files
Co-authored-by: r-vdp <ramses@well-founded.dev>
Co-authored-by:  Marie <tabmeier12@gmail.com>
2025-09-22 01:03:25 +02:00
Haylin Moore cf540f8c98 treewide/nixos: move number typed port options to types.port 2025-09-08 15:27:19 +02:00
Philip Taron d392f98f00
services.openssh: use notify-reload for sshd (#427620) 2025-07-25 16:02:49 -07:00
Wolfgang Walther 5a0711127c
treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
ssoss edadf6cc0f services.openssh: use notify-reload for sshd 2025-07-23 01:24:58 +00:00
Yarny0 6acf53f654 nixos/sshd: don't use -a (KDF rounds) on host keys
The nixos `sshd.nix` module contains a
mechanism to generate ssh host keys prior to
starting sshd if those host keys are missing.
The option `services.openssh.hostKeys` is used to
configure which host keys should exist or be created.
It also declares the key type and other key-related options.

One of those options is `rounds`.
That one is then forwarded to the
`ssh-keygen` program with the `-a` option.
It defines how many rounds of a key derivation function
are to be used on the key's passphrase before the result
is used to en-/decrypt the private key; cf. ssh-keygen(1).

ssh host keys are passwordless;
they are solely protected by filesystem access modes.
Hence, the `-a` option is irrelevant
and silently ignored by `ssh-keygen`.

The commit at hand therefore removes this option from
the host key generation script and the option examples.
2025-06-09 21:06:20 +02:00
Peder Bergebakken Sundt c77ac9dfc3 treewide: fix typos 2025-06-02 16:07:07 +02:00
Silvan Mosberger e52d633a63 Merge remote-tracking branch 'upstream/staging-next' into staging 2025-04-02 18:30:54 +02:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Will Fancher bbf66d50a2
Fix systemd-ssh changes (#390565) 2025-03-17 05:21:36 -04:00
Will Fancher 4dcde98327 nixos/sshd: Fix socket activated SSH connections entering failed state.
In afeb76d628, sshd.service and
sshd@.service were switched to Type=notify. This apparently works for
sshd.service, but not for sshd@.service. Given that the reason for
this working with sshd.service isn't exactly clear, let's revert it
for both of them for now, and revisit Type=notify later.
2025-03-16 23:02:22 -04:00
Philip Taron f4dd3ba6e0
systemd: make systemd-ssh-generator work (#372979) 2025-03-15 21:59:59 -07:00
Marie Ramlow 0ea1aedc4d nixos/sshd: enable root ssh authorized_keys provisioning
This enables provisioning of root ssh keys with systemd credentials
(e.g. passed in via smbios strings or kernel params)
2025-03-15 20:15:44 +01:00
Marie Ramlow afeb76d628 nixos/sshd: always ship a sshd@.service unit for systemd-ssh-generator(1) 2025-03-14 18:34:50 +01:00
Marie Ramlow 63842ed333 nixos/sshd: move key generation into its own systemd unit 2025-03-14 18:34:50 +01:00
Solomon 6cd88104d7
nixos/openssh: allow post-quantum KexAlgorithms introduced in v9.9 (#378875)
`mlkem768x25519-sha256` and the vendor-neutral `sntrup761x25519-sha512`
name are new in OpenSSH 9.9 <https://www.openssh.com/txt/release-9.9>

Co-authored-by: Mynacol <Mynacol@users.noreply.github.com>
2025-02-19 22:04:03 +01:00
Peder Bergebakken Sundt 953f72e76e nixos/*: tag manpage references 2025-01-27 02:47:01 +01:00
K900 099cde3a92
Revert "nixos/ssh: disable authorizedKeysInHomedir by default" 2024-10-20 21:32:29 +03:00
nicoo 6c62fbf539 nixos/sshd: warn if no authorized keys, and no authentication method other than pubkeys, were configured 2024-10-18 20:23:02 +00:00
nicoo 1f08575e3a nixos/sshd: Disable authorizedKeysInHomedir if stateVersion >= 24.11
Co-authored-by: Valentin Gagarin <valentin@gagarin.work>
2024-10-18 20:21:12 +00:00
r-vdp 342b5a8b85
sshd: fix shellcheck warnings in prestart script 2024-09-08 12:24:00 +02:00
Felix Buehler 5f8696e39c nixos/services.openssh: remove with lib; 2024-09-02 22:31:36 +02:00
Sigmanificient e959525e15 lsh: drop 2024-08-20 12:02:12 +02:00
Thomas Gerbet ef6fea2d86 openssh: move Kerberos support into a dedicated package
The `openssh` and `openssh_hpn` packages are now built without
the Kerberos support by default in an effort to reduce the attack surface.

The Kerberos support is likely used only by a fraction of the total users
(I'm guessing mainly users integrating SSH in an Active Directory env) so
dropping it should not impact too many users. It should also be noted that
the Kerberos/GSSAPI auth is disabled by default in the configuration.
`opensshWithKerberos` and `openssh_hpnWithKerberos` are added in order
to provide an easy migration path for users needing this support.

The `openssh_gssapi` package is kept untouched.
2024-06-05 19:45:31 +10:00
lassulus d6f07be682
Merge pull request #314889 from DavHau/pr_sshd
nixos/openssh: allow removing settings
2024-05-30 01:01:07 +02:00
Thomas Gerbet 00015f3ef9
Merge pull request #309036 from tomfitzhenry/sshd-package
nixos/ssh: add services.openssh.package
2024-05-27 09:40:31 +02:00
DavHau 3fe773a174 nixos/openssh: allow removing settings
# Motivation
So far it was not possible to configure sshd to allow password authentication only for a specific user. This is because in the generated config a `Match User xxx` section would be required before the global `PasswordAuthentication` is defined, as otherwise the global option always takes precedence.
The same problem occurs with multiple other options under `settings`.

# Done
This PR fixes that issue for all settings by simply allowing them to be overridden with `null`, which leads to a removal of that setting from the config.
The user can then correctly configure user specific settings using extraConfig, like this:
```
    Match User user1
    PasswordAuthentication yes
    Match all
    PasswordAuthentication no
```
2024-05-26 18:46:27 +02:00
nicoo db5f88c41a
nixos/ssh: Make ~/.ssh/authorized_keys optional in AuthorizedKeysFiles (#279894) 2024-05-06 01:11:03 +00:00
Tom Fitzhenry ff1c82ee07 nixos/ssh: add services.openssh.package
Motivation: Allow the sshd package to be built differently to the ssh
package (programs.ssh.package). For example, build sshd(1) without
openssl, but built ssh(1) with OpenSSL support.

Set the default to be programs.ssh.package, to preserve compatibility.
2024-05-04 23:14:47 +10:00
Tom Fitzhenry 3fd9ef4b40 nixos/ssh: allow PrintMotd to be enabled 2024-04-23 22:53:09 +10:00
Tom Fitzhenry 2e51a2fd03 nixos/ssh: allow UsePAM to be disabled 2024-04-23 22:40:58 +10:00
stuebinm 6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00
Maximilian Bosch 7e45990c06
nixos/sshd: fix socket activated ports when using ListenAddress
Noticed that issue while reviewing #275633: when declaring
`ListenAddress host` without a port, all ports declared by
`Port`/`cfg.ports` will be used with `host` according to
`sshd_config(5)`.

However, if this is done and socket activation is used, only a socket
for port 22 is created instead of a sockets for each port from
`Port`/`cfg.ports`. This patch corrects that behavior.

Also added a regression test for this case.
2024-01-03 19:42:45 +01:00
Bryan Richter e797aaea0b
sshd: Use top-level ports in config check when needed
Previously, if a listenAddress was specified without a `port`, the check
would fail.
2024-01-02 12:51:39 +02:00
Christoph Heiss cc8ba21629
nixos/sshd: add comment explaining different list option types
Signed-off-by: Christoph Heiss <christoph@c8h4.io>
2023-10-28 20:13:26 +02:00
Christoph Heiss a077b7fadb
openssh: add {Allow,Deny}{Users,Groups} settings
`settingsFormat` unfortunaly needed a bit of a rework, see also
discussion in #227442.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
2023-10-19 18:30:51 +02:00
Aaron Andersen 76fb9da41f nixos/openssh: add support for authorized principals 2023-10-06 13:57:19 -04:00
Maximilian Bosch e515dce892 nixos/sshd: fix sshd.conf validity check
When using e.g. `{ addr = "[::]"; port = 22; }` at `listenAddresses`,
the check fails because of an escaping issue[1] with

    last 1 log lines:
    > Invalid test mode specification -f
    For full logs, run 'nix log /nix/store/c6pbpw5hjkjgipmarwyic9zyqr1xaix5-check-sshd-config.drv'

Using `lib.escapeShellArg` appears to solve the problem.

[1] https://github.com/NixOS/nixpkgs/pull/256090#issuecomment-1738063528
2023-09-28 00:11:31 +00:00
Carl Richard Theodor Schneider 716bde190c nixos/sshd: specify lport,laddr for config validation 2023-09-19 18:13:44 +02:00
Yarny0 bbefd70784 nixos/sshd: avoid mock host key, permit RequiredRSASize
With this commit, the validation of `sshd_config`
is performed with `sshd -G` instead of `sshd -t`.
The former does not require a valid host key.
Checking the host key was never useful for us:
We just generated a dummy host key to
make the validation mechanism happy.
With this change the dummy key is no longer needed.

This change not only saves some CPU cycles
(avoid the generation of an RSA key),
but it also permits to set `RequiredRSASize` to a value
larger than the current rsa key default size (3072).
2023-09-05 11:34:09 +02:00
Felix Bühler 0a2745684e
Merge pull request #239624 from Stunkymonkey/use-optionalString-then
treewide: use optionalString instead of 'then ""'
2023-07-22 13:02:47 +02:00
Sandro Jäckel 9999996fd6
nixos/sshd: fix example rendering 2023-06-30 18:14:16 +02:00
Felix Buehler 933a41a73f treewide: use optional instead of 'then []' 2023-06-25 09:11:40 -03:00
Felix Buehler f3719756b5 treewide: use optionalString instead of 'then ""' 2023-06-24 20:19:19 +02:00
Alyssa Ross eeabae56e7
nixos/sshd: add StrictModes option 2023-06-06 16:06:09 +00:00
r-vdp 2b63df0a03 modules/sshd: print the offending keys when we detect duplicate sshd keys. 2023-05-31 12:07:06 +02:00
nyanotech 3aad03a464 nixos/sshd: detect duplicate config keys 2023-05-25 00:01:03 +02:00