Tag Archives: OpenLDAP Log

Enable the production of Openldap Log file

Goal: In this 3rd part of the «OpenLDAP tutorial», we will enable the production of Log. To do that we must change default configuration of the server. The production of OpenLDAP log is very important for supervision and the proper use of this server. Prerequisite: The OpenLDAP server is installed with its default configuration. The installation has been done on GNU/Linux Debian, Ubuntu OS or compliant system. cf. part 1 and part 2 of this «OpenLDAP tutorial» series.

1. Enable the production of server Logs

sudo ldapsearch -Y external -H ldapi:/// -b cn=config "(objectClass=olcGlobal)" olcLogLevel -LLL > slapdlog.ldif
This command creates the slapdlog.ldif file whose content is the result of the LDAP query executed by ldapsearch utility:
dn: cn=config
olcLogLevel: none
The first line contains the DN (distinguished name) who is the unique identifier of the entry. The second line contains the unique attribute requested by the query with value: none. The production of log files is disabled by default. Modify that file so that its content becomes:
dn: cn=config
changeType: modify
replace: olcLogLevel
olcLogLevel: stats
Now, this LDIF (Lightweight data interchange format) contains a modify command: the second line says we want to change the entry, the third line indicates that it is a replacement of the content of the olcLogLevel attribute and the fourth shows the new value of this attribute. stats level allow generate logs of connections, operations and results. This is perfect for daily monitoring. To run the command file on the server, we use:
sudo ldapmodify -Y external -H ldapi:/// -f slapdlog.ldif
If we get the message: modifying entry “cn=config”, the operation was successful. To check the result:
sudo ldapsearch -Y external -H ldapi:/// -b cn=config "(objectClass=olcGlobal)" olcLogLevel
This new setting is immediately considered by the server and no reboot is required. The server sends the produced Logs, to the system log management mechanism. This is rsyslog for recent versions of Debian / Ubuntu OS.

2. Consideration of OpenLDAP log in rsyslog

Create a configuration file in the folder /etc/rsyslog.d/choose any name10-slapd.conf for example. The number in the name classifies files in this folder. This file contains those settings:
$template slapdtmpl,"[%$DAY%-%$MONTH%-%$YEAR% %timegenerated:12:19:date-rfc3339%] %app-name% %syslogseverity-text% %msg%\n"
local4.*    /var/log/slapd.log;slapdtmpl
The chosen name slapdtmpl, refers to a presentation format of the contents of the log file. For details on the template creations for rsyslog consult the manual:
man rsyslog.conf
See, in particular the section TEMPLATES. Finally you must restart rsyslog for the new settings to take effect.
service rsyslog restart

3. Test this functionality of the OpenLDAP server

Start a query and view the contents of the file /var/log/slapd.log :
sudo ldapsearch -Y external -H ldapi:/// -b dc=ldaptuto,dc=net
sudo cat /var/log/slapd.log
You should have a fairly significant content that show the work done by the OpenLDAP server to produce the query result..]]>

Activer le Log OpenLDAP

Objectif: Cette 3eme partie de la série OpenLDAP tutorial a pour objectif d’activer le log OpenLDAP. Pour atteindre cet objectif il faut paramétrer l’installation du serveur d’annuaire OpenLDAP. Cette production est très importante, voire indispensable pour la surveillance et l’utilisation correcte de ce serveur. Pré-requis: OpenlDAP est installé et pré-configuré sur une machine Debian, Ubuntu ou compatibles. cf. la partie 1 et la partie 2 de cette série OpenLDAP Tutorial.

1. Activer les fichiers journaux (Log) du serveur OpenLDAP

sudo ldapsearch -Y external -H ldapi:/// -b cn=config "(objectClass=olcGlobal)" olcLogLevel -LLL > slapdlog.ldif
Cette commande crée le fichier slapdlog.ldif dont le contenu est le résultat de la requête LDAP exécutée par l’utilitaire ldapsearch:
dn: cn=config
olcLogLevel: none
La première ligne contient le DN (distinguished name) qui est l’identifiant unique de l’entrée. La deuxième ligne contient l’unique attribut demandée par la requête avec comme valeur: none. La génération de log est désactivée par défaut. Modifier ce fichier pour que son contenu devienne:
dn: cn=config
changeType: modify
replace: olcLogLevel
olcLogLevel: stats
Maintenant ce fihier LDIF (Lightweight data interchange format) contient une commande de modification: la deuxième ligne déclare qu’on veut modifier l’entrée, la troisième indique qu’il s’agit d’un remplacement de contenu de l’attribut olcLogLevel de cette entrée et la troisième indique la nouvelle valeur de cet attribut. stats permet de générer les logs des connexions, des opérations et de leurs résultats ce qui est parfait pour une surveillance quotidienne. Pour exécuter la commande de ce fichier sur le serveur, on utilise:
sudo ldapmodify -Y external -H ldapi:/// -f slapdlog.ldif
Si on obtient le message: modifying entry “cn=config”, l’opération a réussi. Pour vérifier:
sudo ldapsearch -Y external -H ldapi:/// -b cn=config "(objectClass=olcGlobal)" olcLogLevel
Normalement la prise en compte par le serveur est immédiate et aucun redémarrage n’est nécessaire. Le serveur envoi les logs produits au mécanisme de gestion des logs système. Il s’agit de rsyslog pour les versions récentes.

2. Prise en compte des log OpenLDAP par rsyslog

Créer un fichier de configuration dans dans le dossier /etc/rsyslog.d/, choisir un nom quelconque: 10-slapd.conf par exemple. Le chiffre dans le nom permet de classer les fichiers dans ce dossier. Ce fichier contient l’unique ligne:
local4.*    /var/log/slapd.log;slapdtmpl
slapdtmpl est un nom au choix qui désigne un format de présentation du contenu de ce fichier de log. Il s’agit donc de créer ce format, cela se fait dans le fichier de configuration de rsyslog:
sudo vi /etc/rsyslog.conf
Dans l’éditeur ajouter ce qui suit, en dessous de la première ligne à partir du début qui commence par $template:
$template slapdtmpl,"[%$DAY%-%$MONTH%-%$YEAR% %timegenerated:12:19:date-rfc3339%] %app-name% %syslogseverity-text% %msg%\n"
Pour plus de détails sur la créations de format pour rsyslog consulter le manuel:
man rsyslog.conf
Voir, notamment, le paragraphe TEMPLATES. Enfin il faut redémarrer rsyslog pour que le nouveau paramétrage soit pris en compte:
service rsyslog restart

3. Tester cette fonctionnalité du serveur OpenLDAP

Lancer une requête et consulter le contenu du fichier /var/log/slapd.log:
sudo ldapsearch -Y external -H ldapi:/// -b dc=ldaptuto,dc=net
sudo cat /var/log/slapd.log
Normalement, on doit avoir un contenu assez significatif de ce qui a été exécuté par le serveur OpenLDAP.]]>