OpenLDAP on AlmaLinux series, part 5. Previous: part 4, replication with syncrepl. Earlier parts: part 1 installed slapd with cn=config, part 2 added users, groups and the read-only sssd-bind account, and part 3 enabled StartTLS with a private CA. This part turns client1 into an LDAP client with SSSD. Part 6 covers ACLs, password policy and backups.
A directory is only useful when machines use it. On a modern Red Hat style system the component that does this is SSSD (System Security Services Daemon). It sits between the operating system and LDAP: programs ask the C library for a user (getpwnam, id, ls -l, sshd), the library asks SSSD through the sss NSS module, SSSD queries LDAP, and it keeps a local cache so the answer is still there when the network or the directory is not. This post configures that on client1 against the two OpenLDAP servers from part 4, with encryption required, failover between the servers, offline logins, automatic home directories and a simple access rule.
It applies to AlmaLinux, RHEL, Rocky Linux, Oracle Linux and CentOS Stream 9 and 10. The configuration file is the same on all of them. The tests below ran against SSSD 2.13.1 from the AlmaLinux 10 repository; EL9 ships an older SSSD 2.9 branch, so where a default matters the post says to set the option explicitly rather than rely on it.
What you will build
| Item | Value |
|---|---|
| Client | client1, AlmaLinux 10, root or sudo access |
| LDAP servers | ldap1.example.lan (primary) and ldap2.example.lan (replica), both from parts 1 to 4 |
| Base DN / search bases | dc=example,dc=lan; users in ou=People, groups in ou=Groups |
| Bind account | cn=sssd-bind,ou=Services,dc=example,dc=lan (read-only, part 2) |
| Schema | posixAccount users and posixGroup groups with memberUid, so SSSD’s ldap_schema = rfc2307 |
| Transport | StartTLS on port 389, server certificate checked against the part 3 CA |
| UID range | LDAP users 10000 to 14999, shared groups 15000 to 19999 (part 2), so min_id = 10000 |
| Test users | jdoe (10001) and asmith (10002) in sysadmins and developers; bjones (10003) only in developers |
How SSSD fits together
- sssd is the monitor. It reads
/etc/sssd/sssd.confand starts the other processes. - Data provider (backend) for each domain. Here
sssd_betalks LDAP, keeps the connection, does the failover between servers and knows whether the domain is online or offline. - Responders:
sssd_nssanswers thesssNSS module (getent,id) andsssd_pamanswerspam_sss.so(login, ssh, sudo). They read the cache first and ask the backend only when an entry is missing or expired. - Cache in
/var/lib/sss/db. User and group entries stay valid forentry_cache_timeoutseconds (default 5400, so 90 minutes). Cached password hashes exist only ifcache_credentials = true. - Logs in
/var/log/sssd/:sssd.logfor the monitor,sssd_nss.log,sssd_pam.logand onesssd_<domain>.logper domain (heresssd_LDAP.log).
Prerequisites
- Parts 1 to 4 done: two working slapd servers with the same data, StartTLS working, and the
sssd-bindaccount with its password. client1resolvesldap1.example.lanandldap2.example.lan(DNS or/etc/hosts). The name inldap_urimust be a name in the server certificate’s subject alternative names, because SSSD verifies it (part 3).- The CA certificate on
client1. Part 3 gave two options; this post uses the file from option A,/etc/openldap/certs/ca.crt. If you chose option B (the CA in the system trust store), you can leaveldap_tls_cacertout, but setting it explicitly makes failures easier to read. - Port 389/tcp reachable from
client1to both servers (see the firewalld rules in part 3 and part 4, or the firewalld cheat sheet). - Users with
uidNumber,gidNumber,homeDirectoryand preferablyloginShell. SSSD silently ignores LDAP user entries that lack the object classposixAccountor a UID.
Step 1: Install the packages
dnf install -y sssd sssd-ldap sssd-tools oddjob-mkhomedir authselect
sssd-ldapis the LDAP provider,sssd-common(pulled in) contains the daemons andsss_cache, andsssd-toolscontainssssctl.oddjob-mkhomedircreates a home directory at first login. Its PAM module hands the work to theoddjobddaemon, so the daemon has to run (step 5).authselectis normally installed already; it edits/etc/nsswitch.confand the PAM files for you.
The package names are the same on Oracle Linux, Rocky and RHEL (the AppStream repository). oddjob-mkhomedir comes from AppStream, so it must be enabled.
Step 2: Check the connection with the bind account first
Most SSSD problems are really LDAP problems. Before writing any SSSD configuration, prove from client1 that the bind account can read a user over StartTLS on both servers. Put the CA in place if you have not yet:
install -D -m 0644 /tmp/ca.crt /etc/openldap/certs/ca.crt
restorecon -v /etc/openldap/certs/ca.crt
export LDAPTLS_CACERT=/etc/openldap/certs/ca.crt
ldapsearch -x -ZZ -LLL -H ldap://ldap1.example.lan \
-D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
-b ou=People,dc=example,dc=lan '(uid=jdoe)' uid uidNumber gidNumber homeDirectory loginShell gecos
Expected output (this is the output from the lab):
dn: uid=jdoe,ou=People,dc=example,dc=lan
uid: jdoe
uidNumber: 10001
gidNumber: 10001
homeDirectory: /home/jdoe
gecos: John Doe
loginShell: /bin/bash
Repeat with -H ldap://ldap2.example.lan and check a group, because group membership is what SSSD reads for id:
ldapsearch -x -ZZ -LLL -H ldap://ldap2.example.lan \
-D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
-b ou=Groups,dc=example,dc=lan '(cn=developers)'
dn: cn=developers,ou=Groups,dc=example,dc=lan
objectClass: posixGroup
cn: developers
gidNumber: 15002
description: Application developers
memberUid: asmith
memberUid: jdoe
The group has memberUid values (user names), not member DNs. That is the RFC 2307 style, and it decides the ldap_schema setting below. If either command fails, fix that first with the troubleshooting tables in parts 3 and 4; SSSD cannot do better than ldapsearch.
Step 3: Write /etc/sssd/sssd.conf
[sssd]
services = nss, pam
domains = LDAP
[domain/LDAP]
id_provider = ldap
auth_provider = ldap
chpass_provider = ldap
ldap_uri = ldap://ldap1.example.lan, ldap://ldap2.example.lan
ldap_search_base = dc=example,dc=lan
ldap_user_search_base = ou=People,dc=example,dc=lan
ldap_group_search_base = ou=Groups,dc=example,dc=lan
ldap_schema = rfc2307
ldap_default_bind_dn = cn=sssd-bind,ou=Services,dc=example,dc=lan
ldap_default_authtok_type = password
ldap_default_authtok = CHANGE-ME-sssd-bind-password
ldap_id_use_start_tls = true
ldap_tls_cacert = /etc/openldap/certs/ca.crt
ldap_tls_reqcert = demand
min_id = 10000
cache_credentials = true
enumerate = false
SSSD refuses to start unless the file is owned by root and not readable by others, because it contains the bind password:
chown root:root /etc/sssd/sssd.conf
chmod 0600 /etc/sssd/sssd.conf
sssctl config-check
sssctl config-check validates the file against SSSD’s own schema and catches misspelled option names. A clean file prints:
Issues identified by validators: 0
Messages generated during configuration merging: 0
Used configuration snippet files: 0
What each setting does
| Setting | Meaning and why this value |
|---|---|
services = nss, pam | Responders to start with SSSD. On systemd platforms this line is optional because the responders are socket-activated (sssd.conf(5)), but it is harmless and makes the file explicit. |
domains = LDAP | Which [domain/...] sections are active. The name is only a label; it appears in log file names (sssd_LDAP.log). |
id_provider, auth_provider, chpass_provider | ldap for all three: identity lookups, password checks (SSSD does an LDAP bind as the user) and password changes. |
ldap_uri | A comma separated list in order of preference. The first server is used until it fails, then SSSD moves to the next. This is the failover. |
ldap_search_base, ldap_user_search_base, ldap_group_search_base | Where to search. Narrow bases are faster and keep service entries such as ou=Services out of the lookups. |
ldap_schema = rfc2307 | Group members are listed by name in memberUid. This is the default, but write it down. rfc2307bis would be wrong here, because it expects member DNs. |
ldap_default_bind_dn and ldap_default_authtok | The account SSSD uses to read the directory. Use the read-only account from part 2, never the cn=admin rootDN. The password is stored in clear text in this file (hence mode 0600). ldap_default_authtok_type = obfuscated_password with sss_obfuscate (sssd-tools) only hides it from a casual glance; it is not encryption. |
ldap_id_use_start_tls = true | Use StartTLS for the identity connection. The sssd-ldap(5) page of 2.13.1 lists the default as true; write it explicitly so an older or different default cannot surprise you. |
ldap_tls_cacert | The CA file used to verify the server. |
ldap_tls_reqcert = demand | The server must present a certificate that verifies. SSSD’s default is hard, the same as demand. Never use never or allow to make an error go away. |
min_id = 10000 | SSSD ignores users and groups below this number, so a clash with local accounts cannot happen and LDAP cannot hand out a low UID. The default is 1. |
cache_credentials = true | Store a salted hash of the password after each successful online login so the user can log in while LDAP is unreachable. The default is false. A stolen cache file allows offline guessing, so keep /var/lib/sss/db readable by root only (the default). |
enumerate = false | Do not download the whole directory into the cache. This is the default and the right choice for anything bigger than a lab. Single lookups still work. |
Step 4: Select the SSSD profile with authselect
SSSD only answers when the system asks it. authselect edits /etc/nsswitch.conf and the PAM stacks (system-auth, password-auth) and has a feature for home directories:
authselect select sssd with-mkhomedir
authselect current
If the files were edited by hand before, authselect refuses to overwrite them and tells you so; --force overrides that after you have looked at what would be lost. Do not edit those files by hand afterwards: the next authselect call would drop your changes.
What the profile puts in place, taken from the sssd profile shipped in authselect-libs-1.5.3-1.el10 with the with-mkhomedir feature enabled:
# /etc/nsswitch.conf (relevant lines)
passwd: files sss systemd
shadow: files systemd
group: files sss systemd
netgroup: files sss
services: files sss
# password-auth (sshd, login and sudo include it through their PAM files)
auth sufficient pam_sss.so forward_pass
account [default=bad success=ok user_unknown=ignore] pam_sss.so
password sufficient pam_sss.so use_authtok
session optional pam_oddjob_mkhomedir.so
session optional pam_sss.so
Local files come first, so root and local accounts keep working even if SSSD is down. The sshd that ships with AlmaLinux 10 has UsePAM yes (in /etc/ssh/sshd_config.d/50-redhat.conf) and its PAM file includes password-auth, so ssh logins use the same stack without any sshd change.
Step 5: Start the services
systemctl enable --now sssd oddjobd
systemctl status sssd --no-pager
Both must run: oddjobd creates the home directory, sssd does everything else. If the unit fails, the reason is in journalctl -u sssd and in /var/log/sssd/sssd.log (see the troubleshooting table).
Step 6: Verify identity and authentication
getent passwd jdoe
jdoe:*:10001:10001:John Doe:/home/jdoe:/bin/bash
id jdoe
uid=10001(jdoe) gid=10001(jdoe) groups=10001(jdoe),15001(sysadmins),15002(developers)
getent group developers
developers:*:15002:jdoe,asmith
- The password field is
*because SSSD never hands out hashes; the check happens through PAM. idshows the secondary groupssysadminsanddevelopersfrom thememberUidentries. If they are missing, the schema or group search base is wrong.- A name that does not exist prints nothing and the exit code is 2:
getent passwd nosuchuser; echo $?gives2. getent passwdwithout a name does not list LDAP users withenumerate = false. In the lab,getent passwd | grep -c jdoeprinted0even aftergetent passwd jdoehad worked. That is normal, not a fault.
Now test the password through PAM. sssctl user-checks runs the same pam_authenticate and pam_acct_mgmt calls as a login, for the PAM service you name (sshd on a real client, or login):
sssctl user-checks -a auth -s sshd jdoe
Password: (correct password)
pam_authenticate for user [jdoe]: Success
sssctl user-checks -a auth -s sshd jdoe
Password: (wrong password)
pam_authenticate for user [jdoe]: Authentication failure
sssctl user-checks -a acct -s sshd jdoe
pam_acct_mgmt: Success
Finally the real thing, from another machine:
ssh jdoe@client1
[jdoe@client1 ~]$ pwd
/home/jdoe
Not tested here: the ssh login itself and the automatic creation of /home/jdoe. The lab had no sshd, no oddjobd and no root privileges, so the checks above call SSSD through its NSS and PAM interfaces directly. The authselect output in step 4 is read from the profile files in the package, not from a run of authselect select.
Step 7: Prove the failover
The point of part 4 was that logins survive the loss of ldap1. Prove it from the client side. First stop slapd on ldap1 (systemctl stop slapd), then on client1 expire the cache so SSSD has to ask LDAP again, and look up users:
sss_cache -E
getent passwd bjones
bjones:*:10003:15002:Bob Jones:/home/bjones:/sbin/nologin
id asmith
uid=10002(asmith) gid=10002(asmith) groups=10002(asmith),15001(sysadmins),15002(developers)
sss_cache -E marks every cached user, group and netgroup as expired without deleting it. Both lookups succeeded with ldap1 stopped. The domain log shows what SSSD did (the lab ran its servers on ports 3890 and 3891, so those appear instead of 389):
# /var/log/sssd/sssd_LDAP.log (debug_level 4)
Marking port 3890 of server 'ldap1.example.lan' as 'not working'
Marking server 'ldap1.example.lan' as 'not working'
Marking server 'ldap2.example.lan' as 'resolving name'
Marking server 'ldap2.example.lan' as 'name resolved'
Marking port 3891 of server 'ldap2.example.lan' as 'working'
Marking server 'ldap2.example.lan' as 'working'
SSSD remembers that ldap1 failed and keeps using ldap2. After failover_primary_timeout seconds (default and minimum 31) it tries the primary again, so once ldap1 is back clients drift back to it on their own. Bringing ldap1 back and watching that happen was not part of the test.
Both servers down: the cache
Stop slapd on ldap2 as well and expire the cache again. The user information still comes out of the local cache, and because cache_credentials = true and jdoe had logged in successfully while SSSD was online, the password check works offline too:
sss_cache -E
getent passwd jdoe
jdoe:*:10001:10001:John Doe:/home/jdoe:/bin/bash
id jdoe
uid=10001(jdoe) gid=10001(jdoe) groups=10001(jdoe),15001(sysadmins),15002(developers)
sssctl user-checks -a auth -s sshd jdoe (correct password)
pam_authenticate for user [jdoe]: Success
sssctl user-checks -a auth -s sshd jdoe (wrong password)
pam_authenticate for user [jdoe]: Authentication failure
The log line that marks the change is Going offline. Running callbacks.. Notes on offline mode:
- A user who has never logged in on this client has no cached hash, so cached-credential login cannot work for them while LDAP is down. Log in each user once while online.
offline_credentials_expiration(default 0, no limit) limits how many days after the last online login cached passwords are accepted. Set it if policy requires offline access to expire.- SSSD retries an offline domain on its own and goes back online when a server answers. The retry interval was not measured here.
Step 8: Limit who may log in
With only id_provider and auth_provider configured, every LDAP user can log in to every client. In most environments that is not what you want. The simplest control is the simple access provider, which allows or denies by user and group name. Add two lines to [domain/LDAP] and restart SSSD:
access_provider = simple
simple_allow_groups = sysadmins
Tested result: jdoe and asmith (members of sysadmins) are allowed, bjones is not, even though the identity lookup still works for all three:
id bjones
uid=10003(bjones) gid=15002(developers) groups=15002(developers)
sssctl user-checks -a acct -s sshd jdoe
pam_acct_mgmt: Success
sssctl user-checks -a acct -s sshd bjones
pam_acct_mgmt: Permission denied
Remember that this check runs in the account phase. An ssh login with an SSH key skips the password check but still goes through the account phase, so the rule applies to key logins as well.
Alternatives, from the sssd-ldap(5) manual page (not tested here):
access_provider = ldapwithldap_access_filter = (employeeType=admin)evaluates an LDAP filter on the user entry only. If you useaccess_provider = ldapand do not set a filter, all users are denied. The man page points to the simple provider if you need group-based rules.access_provider = ldapwithldap_access_order = ppolicydenies users whosepwdAccountLockedTimesays they are locked. That connects to the password policy overlay in part 6. If your policy entry is not namedcn=ppolicy,ou=policies,<base>, also setldap_pwdlockout_dnto its DN; part 6 tested this combination and shows the denial.
Step 9: Password expiry on the client (optional)
ldap_pwd_policy defaults to none. Setting it to shadow makes SSSD evaluate the shadow(5) style attributes (shadowLastChange, shadowMax and related) of the user entries on the client side, which is why part 2 stored shadowLastChange. The man page asks you to also set ldap_chpass_update_last_change explicitly, so SSSD knows whether it has to update shadowLastChange after a password change (the server does not update it for you; part 2 showed that ldappasswd leaves it alone). The man page also notes that a server-side password policy always takes precedence, so with the ppolicy overlay from part 6 you will normally leave this at none. This option was not tested.
Managing the cache
| Command | Effect |
|---|---|
sss_cache -E | Expire all cached entries. They stay in the cache and are used offline, but the next lookup asks LDAP. Use after bulk changes in the directory. Tested. |
sss_cache -u jdoe | Expire a single user (-g for a group, -G for all groups). Tested, exit code 0. |
systemctl stop sssd; rm -f /var/lib/sss/db/* /var/lib/sss/mc/*; systemctl start sssd | Wipe the cache completely. This also removes cached password hashes, so users cannot log in offline until they have logged in once online. Use when the cache itself looks wrong. |
Without a manual expire, a change in LDAP (a new group member, a new shell) reaches the client after entry_cache_timeout (default 5400 seconds).
Debugging: turn up the log level
The default log level hides the details that matter. Add debug_level = 6 to [domain/LDAP] (and [nss] or [pam] sections when needed), restart SSSD, reproduce the problem and read /var/log/sssd/sssd_LDAP.log. Level 4 shows connection and failover decisions; level 6 adds the bind results and the exact searches. Switch it back afterwards, because the logs grow quickly.
For example, with a wrong password for sssd-bind, level 4 only says Failed to connect, going offline; level 6 shows the reason:
Bind result: Invalid credentials(49), no errmsg set
Executing simple bind as: cn=sssd-bind,ou=Services,dc=example,dc=lan
and with a wrong ldap_user_search_base level 6 shows both the search and the answer:
ldap_search_ext called: server: [127.0.0.1:3890] filter: [(&(uid=jdoe)(objectclass=posixAccount)(uid=*)(&(uidNumber=*)(!(uidNumber=0))))] base: [ou=Staff,dc=example,dc=lan]
Search result: No such object(32), no errmsg set
Copying that filter into ldapsearch and running it as the bind account is the fastest way to see what SSSD sees.
Troubleshooting
Each message below was produced in the lab by breaking the configuration on purpose, except the rows marked with an asterisk, which come from the manual pages or from general SSSD behaviour and were not reproduced.
| Symptom or log message | Cause | Fix |
|---|---|---|
sssd will not start: Can't read config: 'File ownership and permissions check failed'; sssd.log: Unexpected access to '/etc/sssd/sssd.conf' by other users | sssd.conf is readable by group or others (tested with mode 0644) | chown root:root /etc/sssd/sssd.conf; chmod 0600 /etc/sssd/sssd.conf |
getent passwd jdoe prints nothing, exit code 2; domain log ldap_install_tls failed: 'Connect error' ('TLS: hostname does not match name in peer certificate') | ldap_uri uses an IP address or a name that is not in the certificate SAN (tested with 127.0.0.1) | Use the FQDN from the certificate (part 3 SAN list) in ldap_uri; fix DNS or /etc/hosts instead of the URI |
Same empty answer; domain log ldap_install_tls failed: 'Connect error' ('(null)') | ldap_tls_cacert points to a file that does not exist or cannot be read (tested with a missing file). The message gives no path, so check it yourself. | ls -l the file; restorecon -v it; compare with openssl s_client -starttls ldap -connect ldap1.example.lan:389 -CAfile ... from part 3 |
Empty answer; level 4 log: Failed to connect, going offline (5 [Input/output error]) and getAccountInfo: Error [1432158212]: SSSD is offline; level 6: Bind result: Invalid credentials(49) | Wrong ldap_default_bind_dn or ldap_default_authtok | Test the same DN and password with ldapwhoami -x -ZZ; correct sssd.conf; restart sssd |
Empty answer, no error; level 6 log Search result: No such object(32) followed by Searching for users with base [...] | A search base that does not exist or is spelled wrongly (tested with ou=Staff) | Fix ldap_user_search_base or ldap_group_search_base; run the logged filter with ldapsearch |
User exists in LDAP but getent passwd shows nothing and no error, even with the correct search | UID below min_id (tested: with min_id = 10002, jdoe (10001) disappeared and asmith (10002) stayed) | Lower min_id or move the account into the managed UID range from part 2 |
getent passwd (no argument) does not list LDAP users | enumerate = false (tested) | Normal. Look up a name, or enable enumeration only on a small directory |
Password prompt appears, then Authentication failure for a correct password | Cached or LDAP password differs, or the user entry has no userPassword the client may bind with (tested: wrong password gives this result) | Check with ldapwhoami -x -ZZ -D uid=jdoe,ou=People,dc=example,dc=lan -W; fix the ACL or password in part 2 and part 6 |
pam_authenticate ... Authentication service cannot retrieve authentication info | PAM could not get an answer: SSSD is offline for a user without cached credentials, or sssd_pam is not running (seen in the lab while the PAM responder had crashed) | systemctl status sssd; read sssd_pam.log and the domain log; fix the LDAP side |
Permission denied from pam_acct_mgmt for a user who exists | The access provider denies the user (tested with simple_allow_groups) | Check simple_allow_groups, simple_deny_groups and ldap_access_filter |
Login works but /home/jdoe does not exist * | with-mkhomedir not selected, or oddjobd not running | authselect current; systemctl enable --now oddjobd |
| SSSD cannot connect and the audit log shows an SELinux denial * | Most often a non-standard LDAP port or a CA file with the wrong label | ausearch -m avc -ts recent; restorecon -v on the CA file; for a custom port check the labelled ports with semanage port -l | grep ldap |
| A change in LDAP does not show up on the client | The cached entry has not expired (entry_cache_timeout default 5400 s) | sss_cache -u jdoe or sss_cache -E |
Security notes
- Keep
ldap_tls_reqcert = demandandldap_id_use_start_tls = true. Without them the bind password and every user lookup cross the network in clear text, and anybody who can answer for ldap1 can hand out UIDs. - Give
sssd-bindread access only to what SSSD needs. The ACLs from part 1 already deny ituserPassword; part 6 tests that withslapacland adds rules for ou=Services and delegated password resets. - Every client holds the bind password. If a client is compromised, rotate it (part 2 shows
ldappasswd) and updatesssd.confeverywhere. - Use
simple_allow_groupsor a filter. An unrestricted directory login on a server is the usual cause of “why can that person log in here?”.
What was tested and what was not
For this post the AlmaLinux 10 SSSD packages (sssd-common, sssd-ldap, sssd-tools, libsss_* 2.13.1-3.el10_3) were unpacked and run as an unprivileged user on a test machine without systemd, together with the two OpenLDAP 2.6.13 servers from part 4 (StartTLS with the lab CA, ldap1 on port 3890 and ldap2 on 3891 instead of 389). SSSD ran in the foreground with the NSS and PAM responders, and getent and id were pointed at it. Everything shown in steps 2, 3 and 6 to 8, the cache commands and the error messages was run this way. The PAM checks used a small PAM service file with only pam_sss.so lines instead of sshd, so the service name differs from what you type on a real client.
Not tested: dnf install and the systemd units, authselect select (the profile contents were read from the package), oddjobd and home directory creation, a real ssh login, SELinux and firewalld, ldap_pwd_policy = shadow, the ldap_access_filter access option (the ppolicy access order was tested in part 6), sssctl domain-list and domain-status (they need D-Bus), changing a password with passwd (chpass_provider), and EL9 with SSSD 2.9. The sssctl output in this post shows only the lines that were captured; on a normal system sssctl user-checks prints more.
What is next
Part 6 closes the series: access control lists so that each account sees only what it should (including what sssd-bind may read), the ppolicy overlay for password length, history, lockout and expiry loaded on both servers, and backups with slapcat. Step 8 above already pointed to the one SSSD option, ldap_access_order = ppolicy, that connects to it. To go back, part 4 covers the replication that makes the failover in step 7 possible.
Next: part 6, OpenLDAP ACLs, password policy (ppolicy) and backups.
