Repository navigation
Description
Describe the bug
I get random failures when trying to log in or use sudo: sudo: PAM authentication error: Error in service module. It seems to happen most often on first login or first sudo use. Usually after 2-3 tries it succeeds. Sometimes during login it works first try.
To Reproduce
- Configure NFS mount with Kerberos
- Try to log in or sudo, sometimes after maybe 10s it fails with
sudo: PAM authentication error: Error in service module
Expected behavior
Login and sudo always work when you provide the correct password.
Additional context
In the journal I see this:
Aug 09 11:16:56 austin-laptop sudo[6409]: pam_unix(sudo:auth): authentication failure; logname= uid=1000 euid=0 tty=/dev/pts/0 ruser=austin rhost= user=austin
Aug 09 11:17:14 austin-laptop sudo[6409]: pam_krb5(sudo:auth): authentication failure; logname=austin uid=1000 euid=0 tty=/dev/pts/0 ruser=austin rhost=
Aug 09 11:17:14 austin-laptop sudo[6409]: pam_ccreds: failed to open cached credentials "/var/cache/.security.db": No such file or directory
Aug 09 11:17:16 austin-laptop sudo[6409]: austin : PAM authentication error: Error in service module ; TTY=pts/0 ; PWD=/home/austin ; USER=root ; COMMAND=/run/current-system/sw/bin/journalctl
Aug 09 11:17:22 austin-laptop sudo[6417]: austin : TTY=pts/0 ; PWD=/home/austin ; USER=root ; COMMAND=/run/current-system/sw/bin/journalctl
Aug 09 11:17:22 austin-laptop sudo[6417]: pam_unix(sudo:session): session opened for user root by (uid=0)
I do have an NFS mount that uses krb5 for authentication, and I've added "Enterprise Login (Kerberos)" in Gnome Online Accounts. The NFS mount is set to only mount on access (x-systemd.automount) because the computer that is the kdc is not always online. To be clear, I log in to the system with a normal local account, Kerberos is just for the NFS mount.
My NFS mount from configuration.nix:
fileSystems."/mnt/nas" = {
device = "server:/mnt/data";
fsType = "nfs";
options = [
"soft"
"noauto"
"noatime"
"nodiratime"
"x-systemd.automount"
"x-systemd.mount-timeout=10"
"timeo=14"
"users"
];
};
This is my Kerberos config from configuration.nix:
krb5.enable = true;
krb5.domain_realm = {
".mydomain" = "MY_REALM";
"mydomain" = "MY_REALM";
};
krb5.realms = {
"MY_REALM" = {
admin_server = "admin_server";
kdc = "admin_server";
master_kdc = "admin_server";
};
};
krb5.libdefaults = {
default_realm = "MY_REALM";
dns_lookup_kdc = false;
dns_lookup_realm = false;
};
krb5.extraConfig = ''
[logging]
kdc = SYSLOG:NOTICE
admin_server = SYSLOG:NOTICE
default = SYSLOG:NOTICE
'';
What stands out to me from the log is pam_ccreds: failed to open cached credentials "/var/cache/.security.db": No such file or directory. pam_ccreds is installed, but that file does not exist.
Notify maintainers
The pam module doesn't seem to have a maintainers list, so based on commit history pinging @Mic92 @infinisil @flokli.
Metadata
❯ nix-shell -p nix-info --run "nix-info -m"
these paths will be fetched (0.05 MiB download, 0.28 MiB unpacked):
/nix/store/gq21dvkri5h3bkg2ly4787kjx8az1s8w-bash-interactive-4.4-p23-dev
copying path '/nix/store/gq21dvkri5h3bkg2ly4787kjx8az1s8w-bash-interactive-4.4-p23-dev' from 'https://cache.nixos.org'...
- system: `"x86_64-linux"`
- host os: `Linux 5.7.12, NixOS, 20.09pre237606.b50ef9afa11 (Nightingale)`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.3.7`
- channels(root): `"nixos-20.09pre237606.b50ef9afa11, home-manager"`
- channels(austin): `"home-manager"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
Maintainer information:
# a list of nixpkgs attributes affected by the problem
attribute:
- pam_ccreds
# a list of nixos modules affected by the problem
module:
- pam
Activity
Mic92 commentedon Aug 11, 2020
I never used
pam_ccredsbut it wants/var/cache/.security.dbto be created, whatever this file do:volhovm commentedon Oct 3, 2020
I have the same problem: although my
sudoworks correctly when I enter the valid password, if I make a mistake it outputssudo: PAM authentication error: Error in service moduleand exits, instead of the usualSorry, try again.and asking me the password again twice. This issue only exist if I turn on Kerberos, that is just commenting out the following solves the issue:What I see in the logs is this:
I do not remember whether this has been an issue since I started to use Kerberos (almost a year ago), or later after some nixos update. I suppose it could be the latter.
austinbutler commentedon Nov 22, 2020
Some further observations. I disabled the built-in
pam.nixmodule and imported a modifiedpam.nixfrom local nixpkgs. The local one has the twopam_cccredslines commented out, removing it from the equation. With this setup there's still a lengthy delay on incorrect password (~15s?).With
pam_krb5out of the way entirely the incorrect password delay is the normal ~2s.austinbutler commentedon Nov 23, 2020
For now I'm settling with just removing all
krb5mentions frompam.nixentirely. My sole use case for Kerberos is NFS encryption, logging in to the system should not consult Kerberos. I think NixOS assumes if you enable anything with Kerberos you want to use it for login as well. Whether that's the correct assumption, I don't know, I'm certainly not a Kerberos or PAM expert (not even close), and maybe my setup is pretty unique.Given that, in my nixpkgs fork I've added a
pamIntegrationoption to krb5, and this seems to work. Not sure whether this would warrant a PR or not...With
krb5.enable = trueandkrb5.pamIntegration = true(or just omittingkrb5.pamIntegration):With
krb5.enable = trueandkrb5.pamIntegration = false:This doesn't address the apparent
pam_ccredsissue, though. @volhovm guessing for youkrb5is actually used for login/sudo, not just NFS?austinbutler commentedon Nov 23, 2020
Interestingly during my experimenting today it apparently did create
/var/cache/.security.db, so I wonder if it's some sort of ordering issue.stale commentedon Jun 4, 2021
I marked this as stale due to inactivity. → More info
austinbutler commentedon Jan 29, 2022
Still an issue for me today.
austinbutler commentedon Jan 16, 2024
This seems to be resolved by #184553 (set
security.pam.krb5.enabled = false;).