nixos/pam: Warn on insecure `sshAgentAuth` configurations

nicoo 9ed1423d 822c0a86

Changed files
+15 -1
nixos
modules
security
tests
+10
nixos/modules/security/pam.nix
···
];
+
warnings = optional
+
(with lib; with config.security.pam.sshAgentAuth;
+
enable && any (s: hasPrefix "%h" s || hasPrefix "~" s) authorizedKeysFiles)
+
''config.security.pam.sshAgentAuth.authorizedKeysFiles contains files in the user's home directory.
+
+
Specifying user-writeable files there result in an insecure configuration:
+
a malicious process can then edit such an authorized_keys file and bypass the ssh-agent-based authentication.
+
See https://github.com/NixOS/nixpkgs/issues/31611
+
'';
+
environment.systemPackages =
# Include the PAM modules in the system path mostly for the manpages.
[ pkgs.pam ]
+5 -1
nixos/tests/ssh-agent-auth.nix
···
foo.isNormalUser = true;
};
-
security.pam.sshAgentAuth.enable = true;
+
security.pam.sshAgentAuth = {
+
# Must be specified, as nixpkgs CI expects everything to eval without warning
+
authorizedKeysFiles = [ "/etc/ssh/authorized_keys.d/%u" ];
+
enable = true;
+
};
security.${lib.replaceStrings [ "_" ] [ "-" ] n} = {
enable = true;
wheelNeedsPassword = true; # We are checking `pam_ssh_agent_auth(8)` works for a sudoer