Bash-based SSSD LDAP authentication client for Ubuntu/Debian systems. Integrates with theta42/sso-manager-node for centralized user management, group-based access control, and SSH key distribution.
This script automates the configuration of SSSD (System Security Services Daemon) to provide:
- LDAP authentication against a central directory
- Group-based access control (only authorized users can log in)
- SSH public key retrieval from LDAP for key-based authentication
- Automatic home directory creation for LDAP users
- Optional automatic registration of the host into the SSO Manager Directory Graph API
Note on sudo: group-based login access is enforced by SSSD's
ldap_access_filter. Group-based sudo via LDAP groups is not enforced by this client today -- SSSD's native LDAP sudo provider and the per-hostsudoRolescoping it depends on are both deferred (design-gap D5). A host joined with this script honors only/etc/sudoers/files sudo rules, not LDAP_admingroups. See Sudo integration below.
- Ubuntu or Debian system with root access
- Network connectivity to your LDAP server (LDAPS on port 636)
- LDAP service account credentials
- CA certificates for LDAP TLS validation
- (Optional) SSO Manager instance for group API registration
git clone https://github.com/theta42/ldap-client.git
cd ldap-clientCopy the template configuration file:
cp ldap.vars.template ldap.varsEdit ldap.vars with your environment settings:
# LDAP server settings
export ldap_host="ldap.internal.example.com"
export ldap_base_dn="dc=example,dc=com"
# Service account for LDAP binds (a plain user, not the admin DN --
# see sso-manager-node's docs/ldap.md "Direct-bind service accounts")
export ldap_bind_dn="cn=ldapclient,ou=People,$ldap_base_dn"
export ldap_bind_password="your-service-account-password"
# SSO Manager integration (optional)
export sso_url="https://sso.example.com"
export sso_token="your-api-token"
# Location identifier for group naming (optional) -- e.g. a site or
# datacenter name if you run this against more than one location
export ldap_location="mylocation"| Variable | Required | Description |
|---|---|---|
ldap_host |
Yes | LDAP server hostname |
ldap_base_dn |
Yes | Base DN for LDAP searches |
ldap_bind_dn |
Yes | DN of the service account for LDAP binds |
ldap_bind_password |
Yes | Password for the service account |
sso_url |
No | Base URL of the SSO Manager API |
sso_token |
No | API authentication token for SSO Manager |
ldap_location |
No | Location prefix for group names (e.g., nyc, dc1) if you run this against more than one site. If omitted, the group names fall back to unprefixed _access/_admin (see Group naming below) |
Login access and sudo are both group-based, using one consistent naming
scheme across files/sssd.conf.mo (the actual enforcement — SSSD's
ldap_access_filter / ldap_sudo_search_filter), files/ldap-ssh-key.sh
(which SSH keys get served), and the groups index.sh auto-creates via the
SSO Manager API:
<location>_access— grants login access to all hosts in this location<location>_host_<hostname>_access— grants login access only to<hostname><location>_admin— grants sudo on all hosts in this location<location>_host_<hostname>_admin— grants sudo only on<hostname>app_super_admin— the cross-app super admin group (also admin in the SSO manager/proxy/jump-host web UIs) grants login access to every host, regardless of location or per-host groups. Sudo is not yet extended to super admins (see the sudo caveat below).
e.g. with ldap_location="mylocation" on a host named webserver01:
mylocation_access, mylocation_host_webserver01_access, mylocation_admin,
mylocation_host_webserver01_admin.
ldap_access_groups in ldap.vars (used only by ldap-ssh-key.sh, to decide
who gets an SSH key served) must use this same scheme plus app_super_admin
— the template already does. If ldap_location is left empty, the filters
fall back to _access / _host_<hostname>_access / etc. (no location
prefix) — set ldap_location for anything beyond a single-location setup.
sudo ./index.shThe script will:
- Install required packages (sssd, sssd-ldap, libnss-sss, libpam-sss, ldap-utils, libsss-sudo)
- Generate and deploy the SSSD configuration
- Configure NSS to use SSS for passwd, group, and sudoers lookups
- Enable automatic home directory creation via PAM
- Deploy the SSH AuthorizedKeysCommand script
- Configure SSHD to retrieve keys from LDAP
- (Optional) Register host-specific groups with the SSO Manager API
- Start and enable the SSSD service
getent passwd <ldap-username>getent group <group-name>sudo -l -U <ldap-username>/usr/local/bin/ldap-ssh-key <ldap-username>systemctl status sssd
journalctl -u sssd -fsu - <ldap-username>ldap-client/
index.sh # Main installation script
ldap.vars.template # Configuration template (copy to ldap.vars)
files/
sssd.conf.mo # SSSD configuration template (Mustache) -- also
# configures SSSD's native LDAP sudo provider
ldap-ssh-key.sh # SSH AuthorizedKeysCommand script
lib/
mo # Mustache template processor
- User attempts to log in via SSH or console
- PAM/SSSD queries LDAP for user credentials
- If user is in an authorized access group, authentication proceeds
- Home directory is created automatically on first login (via pam_mkhomedir)
- SSHD calls
/usr/local/bin/ldap-ssh-keywith the username - The script queries LDAP for the user's
sshPublicKeyattribute - Keys are returned to SSHD for authentication
- This allows SSH key management through the central directory
Group-based sudo via LDAP groups is not configured by this client
(design-gap D5). The native SSSD LDAP sudo_provider and the sssd-sudo.socket
are intentionally not enabled: the directory does not scope sudoRole per-host,
so enabling them would grant every account sudoHost/sudoCommand ALL/ALL --
universal root (H12). A host joined with this script therefore honors only
local /etc/sudoers (files) sudo rules, not LDAP _admin groups.
The commented-out ldap_sudo_search_filter block remains in
files/sssd.conf.mo as a reference for when a scoped sudoRole mechanism lands.
When sso_token is configured, the script automatically creates host-specific groups in the SSO Manager:
<location>_host_<hostname>_access- for login access<location>_host_<hostname>_admin- for sudo privileges
This allows you to manage host-specific access through the SSO Manager web interface.
Check the configuration syntax:
sssd --genconf-onlyReview logs:
journalctl -u sssd -f-
Verify LDAP connectivity:
ldapsearch -H ldaps://<ldap_host> -b "<ldap_base_dn>" -D "<bind_dn>" -W
-
Check group membership in LDAP
-
Verify the
ldap_access_filterin/etc/sssd/sssd.conf
-
Test the key retrieval script directly:
/usr/local/bin/ldap-ssh-key <username>
-
Verify
sshPublicKeyattribute exists in LDAP -
Check SSHD configuration:
sshd -T | grep authorizedkeys
-
Check sudo provider configuration in
/etc/sssd/sssd.conf -
Verify sudo rules exist in LDAP with correct host and group filters
-
Force SSSD refresh:
sssctl cache-expire --group systemctl restart sssd
- The LDAP bind password in
ldap.varsshould have restricted filesystem permissions - SSSD configuration (
/etc/sssd/sssd.conf) is set to mode 600 - LDAPS (TLS) is required for LDAP connections
- The SSH key script runs as the
nobodyuser for minimal privilege
- theta42/sso-manager-node — Centralized SSO and LDAP management. See its Connecting a 3rd-party app or container docs if you just need one application to bind LDAP, rather than full host login/SSH/sudo.
MIT License — see LICENSE.