I'm using Keycloak (version 26.1.0) as my identity provider for web applications and want to extend this to authenticate users logging into Ubuntu 24.04 workstations. I've successfully configured zhaow-de/pam-keycloak-oidc and datajoint-company/pam-oauth2 to connect to my Keycloak server.
However, I've hit a roadblock. Keycloak authentication only succeeds if a local user account with the same username already exists on the Ubuntu system. If the local account doesn't exist, the login fails, even though Keycloak itself authenticates the user. This is true for both pam-keycloak-oidc and pam-oauth2.
I've discovered that creating a local user (with any password) before attempting the Keycloak login resolves the issue. This suggests the PAM modules are checking for a local user before even attempting to establish a session.
My goal is to have home directories and user accounts dynamically created for Keycloak-authenticated users on their first login. I've attempted to use pam_mkhomedir.so in /etc/pam.d/common-auth to achieve this, but my analysis indicates that authentication fails before the session initialization stage where pam_mkhomedir.so would be invoked.
I'm dubtful about modifying PAM config in the file /etc/pam.d/common-auth? Is that the correct file, or should I instead be configuring PAM in /etc/pam.d/sshd (or another file)? Any guidance on the correct PAM configuration to allow dynamic user creation for Keycloak-authenticated users would be greatly appreciated. I'm particularly interested in the proper order of PAM modules and how to ensure 1st user logins from IdP and automatic creation of their home directories.
EDIT
Adding relevant lines of nsswitch.conf:
passwd: files systemd sss
group: files systemd sss
shadow: files systemd sss
gshadow: files systemd
pam_mkhomedir.soconfiguration?session required pam_mkhomedir.so skel=/etc/skel umask=0022in the last line of/etc/pam.d/common-sessionpasswd:,group:shadow:andgshadow:lines in/etc/nsswitch.conflike? Those lines dictate how users and groups are resolved... and if the Keycloak user and group names cannot be resolved into UIDs/GIDs, then as far as the lower levels of the system are concerned, those users won't really exist./etc/nsswitch.conf.