From 0d7cd666520621ebb3f2fb0e590064e8621e249e Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sat, 11 Mar 2023 22:29:16 +0100 Subject: [PATCH] nixos/users-groups: Update password scheme validation Updates the warnings message for statefully set up passwords, now that weak algorithms have been removed from our libxcrypt package. Additionall we now add proper validation for hashing schemes used in `hashedPassword`. Neither will prevent a rebuiild, but instead issue a warning, that this requires immediate remediation, or else users will be unable to login. Reuses the crypt scheme ids as provided by the libxcrypt package. --- nixos/modules/config/users-groups.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index ee4692fc6a6a..5fb38a4e2ff8 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -539,7 +539,9 @@ in { ###### implementation - config = { + config = let + cryptSchemeIdPatternGroup = "(${lib.concatStringsSep "|" pkgs.libxcrypt.enabledCryptSchemeIds})"; + in { users.users = { root = { @@ -601,15 +603,16 @@ in { text = '' users=() while IFS=: read -r user hash tail; do - if [[ "$hash" = "$"* && ! "$hash" =~ ^\$(y|gy|7|2b|2y|2a|6)\$ ]]; then + if [[ "$hash" = "$"* && ! "$hash" =~ ^\''$${cryptSchemeIdPatternGroup}\$ ]]; then users+=("$user") fi done