Skip to content

Commit 938892d

Browse files
authored
Merge pull request #507 from dbarzin/dev
Add LDAPRecord v2 Support
2 parents 5614db5 + 41923fd commit 938892d

File tree

11 files changed

+642
-92
lines changed

11 files changed

+642
-92
lines changed

.env.example

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1+
##################################################
2+
# Application
3+
##################################################
14
APP_NAME=Deming
25
APP_ENV=production
3-
APP_KEY=
46
APP_FORCE_HTTPS=false
5-
APP_DEBUG=false
7+
APP_KEY=
8+
APP_DEBUG=true
69
APP_URL=http://deming.yourdomain.com
710
APP_TIMEZONE='Europe/Paris'
11+
APP_EDITOR=pulsar
812

13+
##################################################
14+
# Database
15+
##################################################
916
DB_CONNECTION=mysql
1017
DB_HOST=127.0.0.1
1118
DB_PORT=3306
1219
DB_DATABASE=deming
1320
DB_USERNAME=deming_user
1421
DB_PASSWORD=demPasssword-123
15-
DB_ROOTPASSWORD=root
1622

1723
LOG_CHANNEL=stack
1824

@@ -22,6 +28,9 @@ QUEUE_CONNECTION=sync
2228
SESSION_DRIVER=file
2329
SESSION_LIFETIME=120
2430

31+
##################################################
32+
# Mail
33+
##################################################
2534
MAIL_HOST='smtp.localhost'
2635
MAIL_PORT=2525
2736
MAIL_AUTH=true
@@ -35,6 +44,38 @@ MAIL_PASSWORD=
3544
# MAIL_DKIM_SELECTOR = 'default'; # Match your DKIM DNS selector
3645
# MAIL_DKIM_PASSPHRASE = ''; # Only if your key has a passphrase
3746

47+
##################################################
48+
# LDAP
49+
##################################################
50+
# - If LDAP_ENABLED=true => try LDAP; on success, log the mapped local user in.
51+
# - If LDAP fails and LDAP_FALLBACK_LOCAL=true => try local DB credentials.
52+
# - If LDAP_ENABLED=false => only local DB credentials.
53+
54+
LDAP_ENABLED=false
55+
LDAP_FALLBACK_LOCAL=true
56+
LDAP_AUTO_PROVISION=false
57+
58+
# Config
59+
LDAP_LOGGING=true
60+
LDAP_CONNECTION=default
61+
LDAP_HOST=127.0.0.1
62+
LDAP_USERNAME="cn=admin,dc=example,dc=org"
63+
LDAP_PASSWORD=admin
64+
LDAP_PORT=389
65+
LDAP_BASE_DN="dc=example,dc=org"
66+
LDAP_TIMEOUT=5
67+
LDAP_SSL=false
68+
LDAP_TLS=false
69+
70+
# Candidate attributes to identify the username entered in the form
71+
# Order matters: the first match wins.
72+
# OpenLDAP: uid, cn, mail ; AD: sAMAccountName, userPrincipalName, mail
73+
LDAP_LOGIN_ATTRIBUTE="uid,cn,mail,sAMAccountName,userPrincipalName"
74+
75+
##################################################
76+
# Socialite
77+
##################################################
78+
3879
# List of socialite providers separated by a space. Possible value : keycloak, oidc
3980
SOCIALITE_PROVIDERS=""
4081

@@ -62,3 +103,4 @@ OIDC_CLIENT_ID=deming
62103
OIDC_CLIENT_SECRET=deming
63104
OIDC_BASE_URL=http://auth.lan
64105
OIDC_REDIRECT_URI=${APP_URL}auth/callback/oidc
106+
APP_VERSION=2025.08.13

INSTALL.fr.md

Lines changed: 122 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,23 @@ Pour importer un référentiel et générer des données de test, allez dans "Co
132132
Il est également possible de faire démarrer l'application en tant que service `systemd`. Pour cela, créez un nouveau fichier de définition du service :
133133

134134
su root -c "vi /etc/systemd/system/deming.service"
135-
135+
136136
Ajoutez les lignes suivantes:
137137

138138
[Unit]
139139
Description=Deming
140140
After=network.target
141141
After=mariadb.service
142142
After=apache2.service
143-
143+
144144
[Service]
145145
Type=simple
146146
ExecStart=/usr/bin/php artisan serve --host 127.0.0.1 --port 8000
147147
User=www-data
148148
Group=www-data
149149
WorkingDirectory=/var/www/deming
150150
KillMode=mixed
151-
151+
152152
[Install]
153153
WantedBy=multi-user.target
154154

@@ -204,21 +204,21 @@ Ajouter les lignes suivantes :
204204

205205
<VirtualHost *:80>
206206
ServerName deming.local
207-
207+
208208
RewriteEngine On
209209
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1
210210
</VirtualHost>
211-
211+
212212
<VirtualHost *:443>
213213
ServerName deming.local
214214
DocumentRoot /var/www/deming/public
215-
215+
216216
Protocols h2 h2c http/1.1
217-
217+
218218
<Directory /var/www/deming>
219219
AllowOverride All
220220
</Directory>
221-
221+
222222
ProxyPass / http://127.0.0.1:8000/
223223
ProxyPassReverse / http://127.0.0.1:8000/
224224
ProxyPreserveHost On
@@ -227,10 +227,10 @@ Ajouter les lignes suivantes :
227227
#<FilesMatch \.php$>
228228
# SetHandler "proxy:unix:/var/run/php/php8.3-fpm.sock|fcgi://localhost/"
229229
#</FilesMatch>
230-
230+
231231
ErrorLog ${APACHE_LOG_DIR}/error.log
232232
CustomLog ${APACHE_LOG_DIR}/access.log combined
233-
233+
234234
<IfModule mod_headers.c>
235235
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
236236
Header always set Referrer-Policy "no-referrer"
@@ -240,7 +240,7 @@ Ajouter les lignes suivantes :
240240
Header always set X-Frame-Options "SAMEORIGIN"
241241
Header edit Set-Cookie ^(.*)$ "$1;HttpOnly;Secure;SameSite=Strict"
242242
</IfModule>
243-
243+
244244
SSLEngine on
245245
SSLCertificateFile /etc/apache2/ssl/deming.local.crt
246246
SSLCertificateKeyFile /etc/apache2/ssl/deming.local.key
@@ -283,10 +283,119 @@ Vous pouvez également configurer DKIM :
283283
MAIL_DKIM_SELECTOR = 'default'; // Match your DKIM DNS selector
284284
MAIL_DKIM_PASSPHRASE = ''; // Only if your key has a passphrase
285285

286-
Don't forget to [configure](https://dbarzin.github.io/deming/config/#notifications) the content and frequency of your emails.
287-
288286
N'oubliez pas de [configurer](https://dbarzin.github.io/deming/config.fr/#notifications) le contenu et la fréquence d'envoi des mails.
289287

288+
## LDAP / LDAPRecord configuration (optional)
289+
290+
Cette section te permet d’activer l’authentification LDAP dans Deming avec **LDAPRecord v2**. Elle fonctionne indifféremment avec **Active Directory** *ou* **OpenLDAP**, et peut cohabiter avec l’authentification locale (base de données).
291+
292+
### Prérequis
293+
294+
Prérequis : l’extension PHP LDAP doit être installée et active.
295+
296+
```bash
297+
sudo apt-get install php-ldap
298+
sudo systemctl restart php8.3-fpm || sudo systemctl restart apache2
299+
```
300+
### Environnement
301+
302+
Ajouter / adapter les variables suivantes :
303+
304+
```dotenv
305+
# Activation LDAP dans Deming (mode hybride)
306+
LDAP_ENABLED=true # Active l’authentification LDAP
307+
LDAP_FALLBACK_LOCAL=true # Si LDAP échoue, tenter l’auth locale
308+
LDAP_AUTO_PROVISION=false # Créer automatiquement l’utilisateur local après bind LDAP OK
309+
310+
# Connexion au serveur LDAP
311+
LDAP_HOST=ldap.example.org
312+
LDAP_PORT=389 # 389 (StartTLS) ou 636 (LDAPS)
313+
LDAP_BASE_DN=dc=example,dc=org
314+
LDAP_USERNAME=cn=admin,dc=example,dc=org # Compte de service pour la recherche
315+
LDAP_PASSWORD=********
316+
LDAP_TLS=true # StartTLS (recommandé si port 389)
317+
LDAP_SSL=false # true si tu utilises ldaps:// sur 636
318+
LDAP_TIMEOUT=5 # (optionnel)
319+
320+
# Attributs candidats pour identifier l’utilisateur saisi dans le formulaire
321+
# L’ordre a de l’importance : le premier qui matche est utilisé.
322+
# OpenLDAP: uid, cn, mail ; AD: sAMAccountName, userPrincipalName, mail
323+
LDAP_LOGIN_ATTRIBUTES=uid,cn,mail,sAMAccountName,userPrincipalName
324+
```
325+
326+
**Exemples**
327+
328+
* OpenLDAP (DN utilisateur typique : `uid=jdupont,ou=people,dc=example,dc=org`) :
329+
330+
```dotenv
331+
LDAP_TLS=true
332+
LDAP_SSL=false
333+
LDAP_LOGIN_ATTRIBUTES=uid,cn,mail
334+
```
335+
* Active Directory (UPN : `[email protected]`, sAM : `jdupont`) :
336+
337+
```dotenv
338+
LDAP_TLS=true
339+
LDAP_SSL=false
340+
LDAP_LOGIN_ATTRIBUTES=sAMAccountName,userPrincipalName,mail,cn
341+
LDAP_USERNAME=EXAMPLE\\svc_ldap # ou DN complet du compte de service
342+
```
343+
344+
Après modification du `.env` :
345+
346+
```bash
347+
php artisan config:clear
348+
php artisan optimize:clear
349+
```
350+
351+
### Certificats
352+
353+
**Certificats** : si tu utilises StartTLS/LDAPS avec un CA interne, ajoute le CA au trust store de ta distribution (ex. `/usr/local/share/ca-certificates` + `update-ca-certificates`).
354+
355+
### Comment ça marche côté Deming
356+
357+
Le contrôleur d’authentification :
358+
359+
* recherche l’entrée LDAP via une **OR**-query sur les attributs listés dans `LDAP_LOGIN_ATTRIBUTES` ;
360+
* récupère le **DN** ;
361+
* tente un **bind** avec le mot de passe saisi ;
362+
* si OK, il connecte l’utilisateur applicatif local correspondant (et peut **auto-provisionner** s’il n’existe pas, selon `LDAP_AUTO_PROVISION`).
363+
364+
### Test rapide
365+
366+
Avant de tester via l’UI, valide la connexion en CLI :
367+
368+
```bash
369+
php artisan tinker
370+
```
371+
372+
Puis dans Tinker :
373+
374+
```php
375+
use LdapRecord\Container;
376+
377+
$dn = 'uid=jdupont,ou=people,dc=example,dc=org'; // ou cn=..., ou DN AD
378+
Container::getConnection()->auth()->attempt($dn, 'MOT_DE_PASSE', true);
379+
// => true attendu si l’authentification réussit
380+
```
381+
382+
### Dépannage express
383+
384+
* **PHP LDAP manquant** : `php -m | grep ldap` doit renvoyer `ldap`. Sinon `sudo apt-get install php-ldap`, puis redémarrage PHP/Apache.
385+
* **Mauvais DN** : ajoute les `ou=...` corrects (ex. `ou=people`).
386+
* **TLS/SSL** : StartTLS = `LDAP_TLS=true` (389). LDAPS = `LDAP_SSL=true` (636). Ne laisse pas en clair en prod.
387+
* **Certificat non approuvé** : ajoute le CA au système (voir ci-dessus).
388+
* **Recherche impossible** : vérifie `LDAP_USERNAME` / `LDAP_PASSWORD` (compte de service) et les ACL de l’annuaire.
389+
* **Attribut de login** : aligne `LDAP_LOGIN_ATTRIBUTES` avec ce que tes utilisateurs saisissent réellement (uid ? UPN ? email ?).
390+
391+
### Sécurité – à faire, pas à discuter
392+
393+
* Utilise **TLS/LDAPS**. Point.
394+
* Restreins les droits du **compte de service** au strict nécessaire (lecture des attributs requis).
395+
* Évite de logger des mots de passe ou DN complets côté application.
396+
* Si tu actives l’**auto-provisioning**, stocke un mot de passe aléatoire côté base (pas un duplicat du LDAP) et applique tes politiques de rôles/profils.
397+
398+
290399
## Configuration de Keycloak (optionnel)
291400

292401
Pour configurer [Keycloak](https://www.keycloak.org), suivez ces étapes :

0 commit comments

Comments
 (0)