I’m exploring a PAM compatibility layer that allows GNOME Keyring to be unlocked after non-password authentication by supplying a replacement PAM_AUTHTOK before pam_gnome_keyring.so runs. Has this approach been tried before, and are there any architectural reasons it wouldn’t be recommended?
By non-password do you mean fingerprint authentication, or smartcard? Cause the fingerprint explicitly does not unlock the keyring cause it’s not secure to do so currently. In the future this might change with the new generation of fingerprint sensors that windows requires, but for the time being most of them are very insecure.
Yeah, I mean smartcards/NFC, not fingerprints. Specifically DESFire AES-128 mutual auth. I’m working on a centralized NFC authentication service with identity resolution through FreeIPA.
The goal is to keep GNOME Keyring functional without workarounds like a blank password.
Yes, it has been done, at least once. I have been running exactly this on my own laptop since August: a small PAM module sitting above pam_gnome_keyring.so that sets PAM_AUTHTOK, after which the existing keyring module does its normal job. Mine pulls the password out of a TPM rather than a smartcard, but the PAM half is the same shape as what you describe, so the traps below should transfer.
On Jordan’s point, I read it as an objection to the authenticator rather than to the mechanism. Whether a fingerprint match is strong enough to stand in for a password is a separate argument from whether handing pam_gnome_keyring.so a token works at all. With DESFire AES-128 mutual auth you are in a much better spot than a fingerprint sensor, so your real question is where the secret lives and who can make it appear.
Four things I would flag, roughly in the order of how much they hurt.
1. Where you insert the module, not just which service you patch. If any module that can authenticate with a password runs below your insertion point, you have just handed it a token nobody typed. On Ubuntu this bites in gdm-password, which can succeed via fingerprint once it is enabled system wide, so patching only the services with “fingerprint” in the name is not enough. My installer refuses to touch a stack of that shape instead of trying to be clever about it.
2. Return PAM_IGNORE in every path. Mine is auth optional and returns PAM_IGNORE whatever happens, its own failures included. Returning PAM_SUCCESS would make it an authentication decision, which is not its job and which it has no information to make.
3. A failed authentication still triggers your unlock. libpam keeps walking the stack after the distro’s required line fails, so the module below it runs anyway. The login does fail and the token is discarded, but the secret has already been fetched by then. In my case that is a TPM unseal on every bad scan. In yours it is whatever the NFC service does on the read path, which matters if you plan any rate limiting or audit trail around it.
4. Do not block the login. Anything that talks to hardware or to a network service can hang, and a hung auth module hangs the greeter. Mine forks a helper and kills it after 25 seconds, then returns PAM_IGNORE. With FreeIPA in the loop that seems even more worth designing for than in my case.
One thing unrelated to PAM that cost me an evening: on distros that pre-start gnome-keyring-daemon through its user units, the daemon is already up before PAM gets to it, so PAM starts a second one and the session keeps talking to the first. You unlock the wrong instance and it looks like nothing happened at all. Masking gnome-keyring-daemon.socket and gnome-keyring-daemon.service sorts it out.
Code if it is useful to read: GitHub - dmitriitimoshenko/tpm-keyring-unlock: TPM-sealed auto-unlock for the GNOME login keyring - works with fingerprint login, without weakening the keyring · GitHub. The module itself is one short C file, the rest is an installer being paranoid about /etc/pam.d. I wrote it, so weigh the framing accordingly.