On vous demande de donner à Authentik (ou Keycloak, ou Vaultwarden) un vrai annuaire de support, pour que le cycle de vie des comptes ne soit pas prisonnier d’un seul produit. Le README de LLDAP est court — un binaire Rust unique, SQLite embarqué, une interface web pour les groupes — vous le branchez sur Authentik via ldap://127.0.0.1:3890, le SSO fonctionne, vous remettez ça à l’équipe d’exploitation. Six mois plus tard, le port LDAP écoute en 0.0.0.0:3890, le mot de passe administrateur est resté à la valeur de bascule, chaque relying party parle à LDAP en clair parce que LDAPS n’a jamais été configuré, et l’annuaire qui ancre chaque utilisateur de l’entreprise est la VM la plus facile à énumérer sur le réseau.
Ce qui se passe
Un déploiement LLDAP réellement prêt pour la production demande beaucoup plus que ./lldap run. L’écouteur ldap:// en clair doit binder sur 127.0.0.1 uniquement — tout ce qui rejoint l’annuaire vit soit sur la même VM, soit entre via ldaps:// à travers une terminaison TLS nginx en mode stream. L’interface d’administration web doit s’asseoir derrière nginx qui termine TLS avec un vrai certificat Let’s Encrypt. Le mot de passe administrateur de bascule et les identifiants de bind qu’utilisent vos relying parties doivent être rotés hors des valeurs par défaut et stockés dans votre gestionnaire de secrets. Le base DN et les groupes initiaux doivent être réglés avant que la première relying party ne les lise — changer un base DN après que les applications sont branchées, c’est un nettoyage de plusieurs jours. SSH doit avoir l’authentification par mot de passe désactivée tout en gardant l’accès clé root. Aucune de ces étapes n’est individuellement critique — sautez-les et l’annuaire qui ancre chacun des autres systèmes d’identité devient le maillon le plus faible.
Comment vérifier
Après installation, les écouteurs sur l’hôte doivent être :
ss -lntp | grep -E ':(80|443|636|3890|17170)\b'
# 127.0.0.1:3890 lldap (LDAP en clair)
# 127.0.0.1:17170 lldap (interface admin HTTP)
# 0.0.0.0:80 nginx
# 0.0.0.0:443 nginx (interface admin)
# 0.0.0.0:636 nginx stream (LDAPS pour les relying parties hors hôte)
Si :3890 apparaît en 0.0.0.0, LLDAP diffuse du LDAP en clair — corrigez ldap_host dans la configuration. Confirmez un bind anonyme sur LDAPS :
ldapsearch -H ldaps://dir.example.com -x -b "dc=example,dc=com" -s base
# retourne "namingContexts: dc=example,dc=com"
curl -fsS https://dir.example.com/ | head -5
# doit retourner le HTML de l'interface admin LLDAP
Ensuite vérifiez TLS :
echo | openssl s_client -servername dir.example.com -connect dir.example.com:636 2>/dev/null \
| openssl x509 -noout -dates
Si LDAPS échoue à négocier ou si le certificat approche l’expiration, chaque relying party qui cache cette connexion LDAPS va commencer à échouer en silence.
Le correctif
Enregistrez le script ci-dessous sous /root/setup-lldap-ubuntu22.sh, puis exécutez-le. Il déroule l’installation sur une VM Ubuntu 22.04 fraîche : mise à jour de base, ajustement noyau, limites de fichiers, UFW (SSH + HTTP + HTTPS + LDAPS uniquement), durcissement SSH, unattended-upgrades, le binaire LLDAP officiel épinglé à une version, un utilisateur système lldap, une configuration avec l’écouteur LDAP lié à 127.0.0.1, JWT secret, mot de passe admin et key_seed aléatoires écrits dans /etc/lldap/lldap_config.toml (mode 640), une unité systemd avec LimitNOFILE=64000, nginx qui sert l’interface d’administration en HTTPS Let’s Encrypt, un bloc nginx stream qui expose LDAPS sur :636 qui passe vers l’écouteur local :3890, et une boucle d’attente qui valide :3890 puis :636 avant de déclarer succès.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 LLDAP clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs and configures LLDAP + nginx + Let's Encrypt + LDAPS
### No local backups; assumes VM-level backup
### Reboot remains manual
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
: "${LLDAP_DOMAIN:?Set LLDAP_DOMAIN=dir.example.com}"
: "${LLDAP_EMAIL:?Set LLDAP_EMAIL=ops@example.com for Let's Encrypt}"
: "${LLDAP_BASE_DN:?Set LLDAP_BASE_DN=dc=example,dc=com}"
LLDAP_VERSION="${LLDAP_VERSION:-v0.6.1}"
LLDAP_ADMIN_PASSWORD="${LLDAP_ADMIN_PASSWORD:-$(openssl rand -base64 24 | tr -d '\n=' | head -c 24)}"
LLDAP_JWT_SECRET="${LLDAP_JWT_SECRET:-$(openssl rand -hex 32)}"
LLDAP_KEY_SEED="${LLDAP_KEY_SEED:-$(openssl rand -hex 32)}"
echo
echo "========================================"
echo "LLDAP Ubuntu 22.04 Setup"
echo "========================================"
echo
echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
echo "==> Installing base packages"
apt-get -y install \
vim curl wget ca-certificates gnupg2 \
chrony fail2ban unattended-upgrades \
ufw lsof tcpdump dnsutils tar gzip \
iproute2 net-tools openssl jq ldap-utils \
software-properties-common
echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true
echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-lldap.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL
modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
echo "==> Setting file limits"
cat > /etc/security/limits.d/99-lldap.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS
echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 636/tcp
ufw --force enable
echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1"
local value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart ssh
echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Configuring unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG
echo "==> Creating lldap user"
if ! id -u lldap >/dev/null 2>&1; then
useradd --system --home-dir /var/lib/lldap --shell /sbin/nologin lldap
fi
mkdir -p /opt/lldap /var/lib/lldap /etc/lldap /var/log/lldap
echo "==> Downloading LLDAP ${LLDAP_VERSION}"
cd /opt/lldap
if [[ ! -x /opt/lldap/lldap ]]; then
wget -q "https://github.com/lldap/lldap/releases/download/${LLDAP_VERSION}/amd64-lldap-linux-static-musl.tar.gz" -O lldap.tar.gz
tar -xzf lldap.tar.gz --strip-components=1
rm -f lldap.tar.gz
fi
chmod +x /opt/lldap/lldap
chown -R lldap:lldap /opt/lldap /var/lib/lldap /var/log/lldap
echo "==> Writing LLDAP configuration"
cat > /etc/lldap/lldap_config.toml <<CONF
ldap_host = "127.0.0.1"
ldap_port = 3890
http_host = "127.0.0.1"
http_port = 17170
http_url = "https://${LLDAP_DOMAIN}"
ldap_base_dn = "${LLDAP_BASE_DN}"
ldap_user_dn = "admin"
ldap_user_email = "admin@${LLDAP_DOMAIN}"
ldap_user_pass = "${LLDAP_ADMIN_PASSWORD}"
jwt_secret = "${LLDAP_JWT_SECRET}"
key_seed = "${LLDAP_KEY_SEED}"
database_url = "sqlite:///var/lib/lldap/users.db?mode=rwc"
verbose = false
[smtp_options]
enable_password_reset = false
CONF
chown root:lldap /etc/lldap/lldap_config.toml
chmod 640 /etc/lldap/lldap_config.toml
echo "==> Writing systemd unit"
cat > /etc/systemd/system/lldap.service <<'UNIT'
[Unit]
Description=LLDAP
After=network.target
[Service]
Type=simple
User=lldap
Group=lldap
Environment=LLDAP_CONFIG_FILE=/etc/lldap/lldap_config.toml
ExecStart=/opt/lldap/lldap run
WorkingDirectory=/opt/lldap
Restart=on-failure
RestartSec=10
LimitNOFILE=64000
[Install]
WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable --now lldap
echo "==> Waiting for LLDAP on 127.0.0.1:3890 and 127.0.0.1:17170"
for i in {1..60}; do
if ss -lntp | grep -q '127.0.0.1:3890' && ss -lntp | grep -q '127.0.0.1:17170'; then
break
fi
sleep 2
done
if ! ss -lntp | grep -q '127.0.0.1:3890'; then
echo "LLDAP failed to listen on 127.0.0.1:3890"
journalctl -u lldap -n 200 --no-pager || true
exit 1
fi
echo "==> Installing nginx and certbot"
apt-get -y install nginx libnginx-mod-stream certbot python3-certbot-nginx
cat > /etc/nginx/sites-available/lldap <<NGINX
server {
listen 80;
listen [::]:80;
server_name ${LLDAP_DOMAIN};
return 301 https://\$host\$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ${LLDAP_DOMAIN};
client_max_body_size 10M;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
location / {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:17170;
}
}
NGINX
ln -sf /etc/nginx/sites-available/lldap /etc/nginx/sites-enabled/lldap
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl enable --now nginx
systemctl reload nginx
echo "==> Requesting Let's Encrypt certificate for admin UI"
certbot --nginx --non-interactive --agree-tos \
-m "${LLDAP_EMAIL}" -d "${LLDAP_DOMAIN}" --redirect
systemctl enable --now certbot.timer
echo "==> Configuring nginx stream for LDAPS on :636"
mkdir -p /etc/nginx/streams-available /etc/nginx/streams-enabled
cat > /etc/nginx/streams-available/ldaps <<STREAM
upstream lldap_ldap {
server 127.0.0.1:3890;
}
server {
listen 636 ssl;
listen [::]:636 ssl;
ssl_certificate /etc/letsencrypt/live/${LLDAP_DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${LLDAP_DOMAIN}/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
proxy_pass lldap_ldap;
}
STREAM
ln -sf /etc/nginx/streams-available/ldaps /etc/nginx/streams-enabled/ldaps
if ! grep -q 'streams-enabled' /etc/nginx/nginx.conf; then
cat >> /etc/nginx/nginx.conf <<'STREAMCONF'
stream {
include /etc/nginx/streams-enabled/*;
}
STREAMCONF
fi
nginx -t
systemctl reload nginx
echo "==> Waiting for LDAPS on :636"
for i in {1..30}; do
if ss -lntp | grep -q ':636'; then
break
fi
sleep 1
done
echo "==> Final package update"
apt-get -y upgrade
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r
echo
echo "SSH effective settings:"
sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication) ' || true
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|636|3890|17170)\b' || true
echo
echo "Services:"
systemctl is-active lldap nginx fail2ban chrony || true
echo
echo "LDAPS reachability test:"
ldapsearch -H "ldaps://${LLDAP_DOMAIN}" -x -b "${LLDAP_BASE_DN}" -s base 2>&1 | grep -E '^(namingContexts|result)' || true
echo
echo "Admin UI:"
echo "https://${LLDAP_DOMAIN}/"
echo
echo "Admin login:"
echo " Username: admin"
echo " Password: ${LLDAP_ADMIN_PASSWORD}"
echo
echo "Bind DN for Authentik/Keycloak/Vaultwarden:"
echo " uid=admin,ou=people,${LLDAP_BASE_DN}"
echo
echo "Final step:"
echo "Sign in to the admin UI, create per-app groups (admins, users, vaultwarden_users, etc.), then in each relying party configure LDAP backend pointing at ldaps://${LLDAP_DOMAIN}:636. Rotate the admin password from the wizard, store it in your secrets manager."
Rendez-le exécutable et lancez-le :
chmod 700 /root/setup-lldap-ubuntu22.sh
LLDAP_DOMAIN=dir.example.com LLDAP_EMAIL=ops@example.com LLDAP_BASE_DN="dc=example,dc=com" \
/root/setup-lldap-ubuntu22.sh
Le mot de passe administrateur est affiché à la fin — enregistrez-le dans votre gestionnaire de secrets. Connectez-vous à https://dir.example.com/, changez le mot de passe administrateur, créez les groupes dont vous avez réellement besoin avant qu’une relying party ne se connecte (admins, users, plus des groupes par application comme vaultwarden_users ou grafana_admins), et ajoutez-vous à admins. Ensuite, dans Authentik, Keycloak ou Vaultwarden, configurez le backend LDAP qui pointe sur ldaps://dir.example.com:636 avec le bind DN uid=admin,ou=people,dc=example,dc=com. Les sauvegardes au niveau hôte ne sont pas configurées ici ; /var/lib/lldap/users.db et /etc/lldap/lldap_config.toml doivent être couverts par votre politique de snapshots VM — perdre le key_seed vous coûte l’annuaire.
Quand l’annuaire qui ancre chaque autre système d’identité doit rester correct à travers les rotations LDAPS, les changements de schéma et une escalade sur appel à 3 h du matin, ça relève du service de calcul cloud en plan infogéré — ou réservez une revue d’infrastructure rapide.