{"id":11830,"date":"2022-03-12T14:52:14","date_gmt":"2022-03-12T11:52:14","guid":{"rendered":"https:\/\/kifarunix.com\/?p=11830"},"modified":"2022-03-12T14:52:19","modified_gmt":"2022-03-12T11:52:19","slug":"how-to-enable-openldap-audit-logging","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-enable-openldap-audit-logging\/","title":{"rendered":"How to Enable OpenLDAP Audit Logging"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to enable OpenLDAP audit logging. OpenLDAP uses Auditlog <a href=\"https:\/\/www.openldap.org\/doc\/admin24\/overlays.html\" target=\"_blank\" rel=\"noreferrer noopener\">overlays<\/a> to record any changes made to the database to a specified log file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Enable OpenLDAP Audit Logging<\/h2>\n\n\n\n<p>To enable OpenLDAP audit logging, you need to of course have an OpenLDAP server running.<\/p>\n\n\n\n<p>You can check our previous articles on how to install and setup OpenLDAP server;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-openldap-server-on-ubuntu-22-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup OpenLDAP server on Ubuntu 22.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-openldap-server-on-debian-11\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup OpenLDAP Server on Debian 11<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-openldap-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup OpenLDAP on Rocky Linux 8<\/a><\/p>\n\n\n\n<p>Once you have an OpenLDAP server running, proceed to enable OpenLDAP Audit logging.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable OpenLDAP Audit Logging overlay Module<\/h3>\n\n\n\n<p>As already mentioned, OpenLDAP uses Auditlog overlay module to record all changes on a given backend database to a specified log file.<\/p>\n\n\n\n<p>As such, you need to have the Auditlog overlay module enabled.<\/p>\n\n\n\n<p>Check if the Auditlog overlay moduled is enabled by running this command on OpenLDAP server;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ldapsearch -LLL -Y EXTERNAL -H ldapi:\/\/\/ -b  cn=config -LLL -Q | grep -i module<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ndn: cn=module{0},cn=config\nobjectClass: olcModuleList\ncn: module{0}\nolcModulePath: \/usr\/libexec\/openldap\nolcModuleLoad: {0}back_mdb.la\nolcModuleLoad: {1}memberof.la\nolcModuleLoad: {2}refint.la\n...\n<\/code><\/pre>\n\n\n\n<p>From the output, the Auditlog overlay module is not enabled in my server.<\/p>\n\n\n\n<p>In my OpenLDAP server, the modules are stored under <strong><code>\/usr\/libexec\/openldap<\/code><\/strong> directory.<\/p>\n\n\n\n<p>The Auditlog overlay module is available on the path, <strong><code>\/usr\/libexec\/openldap\/auditlog.la<\/code><\/strong>.<\/p>\n\n\n\n<p>Thus, to enable Auditlog Overlay module on OpenLDAP server, you need to modify the modules configuration entry (<strong><code>dn: cn=module{0},cn=config<\/code><\/strong>) and add the Auditlog module by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/<\/code><\/pre>\n\n\n\n<p>When the command above runs, copy and paste the content below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dn: cn=module{0},cn=config\nchangetype: modify\nadd: olcModuleLoad\nolcModuleLoad: auditlog.la<\/code><\/pre>\n\n\n\n<p>Paste the content above and <strong>press<\/strong> <strong>ENTER<\/strong> <strong>twice<\/strong>.<\/p>\n\n\n\n<p>Next, press <strong>Ctrl+c<\/strong>.<\/p>\n\n\n\n<p>Sample command output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nldapadd -Y EXTERNAL -H ldapi:\/\/\/\nSASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\ndn: cn=module{0},cn=config\nchangetype: modify\nadd: olcModuleLoad\nolcModuleLoad: auditlog.la\n\nmodifying entry \"cn=module{0},cn=config\"\n\n^C\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add Auditlog Overlay to SLAPD Database Backend<\/h3>\n\n\n\n<p>Once you have enabled the Auditlog overlay module, you need to update <a href=\"https:\/\/www.openldap.org\/doc\/admin24\/backends.html\" target=\"_blank\" rel=\"noreferrer noopener\">SLAPD database backend <\/a>with Auditlog configuration options.<\/p>\n\n\n\n<p>In my OpenLDAP server setup, LMDB is the default database backend.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ldapsearch -LLL -Y EXTERNAL -H ldapi:\/\/\/ -b  cn=config olcDatabase -Q | grep olcDatabase:<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>olcDatabase: {-1}frontend\nolcDatabase: {0}config\n<strong>olcDatabase: {1}mdb<\/strong><\/code><\/pre>\n\n\n\n<p>Thus, to update the database with Audit logging configuration, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/<\/code><\/pre>\n\n\n\n<p>Once the command runs, copy and paste the content below. <strong>Be sure to replace the configs accordingly.<\/strong><\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ndn: olcOverlay=auditlog,olcDatabase={1}mdb,cn=config\nchangetype: add\nobjectClass: olcOverlayConfig\nobjectClass: olcAuditLogConfig\nolcOverlay: auditlog\nolcAuditlogFile: \/var\/log\/slapd\/slapd-audit.log\n<\/code><\/pre>\n\n\n\n<p>Paste the content above and <strong>press<\/strong> <strong>ENTER<\/strong> <strong>twice<\/strong>.<\/p>\n\n\n\n<p>Next, press <strong>Ctrl+c<\/strong>.<\/p>\n\n\n\n<p>Sample command output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nldapadd -Y EXTERNAL -H ldapi:\/\/\/\nSASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\ndn: olcOverlay=auditlog,olcDatabase={1}mdb,cn=config\nchangetype: add\nobjectClass: olcOverlayConfig\nobjectClass: olcAuditLogConfig\nolcOverlay: auditlog\nolcAuditlogFile: \/var\/log\/slapd\/slapd-audit.log\n\nadding new entry \"olcOverlay=auditlog,olcDatabase={1}mdb,cn=config\"\n<\/code><\/pre>\n\n\n\n<p>Ensure the logging directory is writable by the OpenLDAP user;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/var\/log\/slapd.d\/slapd-audit.ldif &amp;&amp; chown -R ldap: \/var\/log\/slapd.d\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Verify OpenLDAP Audit Logging<\/h3>\n\n\n\n<p>You are done with configuration. You can now test the audit logging by performing various ldap operations;<\/p>\n\n\n\n<p>For example, we have a user janedoe with the attributes;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ldapsearch -H ldapi:\/\/\/ -Y EXTERNAL -LLL -b \"dc=ldapmaster,dc=kifarunix-demo,dc=com\" uid=janedoe -LLL -Q<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\ndn: uid=janedoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: inetOrgPerson\nobjectClass: posixAccount\nobjectClass: shadowAccount\nuid: janedoe\ncn: jane\nsn: Doe\nloginShell: \/bin\/bash\nuidNumber: 10010\ngidNumber: 10010\nhomeDirectory: \/home\/janedoe\nshadowMax: 60\nshadowMin: 1\nshadowWarning: 7\nshadowInactive: 7\nshadowLastChange: 0\nuserPassword:: e1NTSEF9MTRhZ3FZQkZxbEw5SnY1dHF5ekozY1BIdUZJeng1Ujk=\n<\/code><\/pre>\n\n\n\n<p>lets try to update the home directory;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ldapadd -Y EXTERNAL -H ldapi:\/\/\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>dn: uid=janedoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nchangetype: modify\nreplace: homeDirectory\nhomeDirectory: \/home\/janed<\/code><\/pre>\n\n\n\n<p>When you have ran the command, check the logging file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>less \/var\/log\/slapd\/slapd-audit.log<\/code><\/pre>\n\n\n\n<p>You should see such entries;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ndn: uid=janedoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nchangetype: modify\nreplace: homeDirectory\nhomeDirectory: \/home\/janed\n-\nreplace: entryCSN\nentryCSN: 20220312110448.000680Z#000000#000#000000\n-\nreplace: modifiersName\nmodifiersName: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\n-\nreplace: modifyTimestamp\nmodifyTimestamp: 20220312110448Z\n-\n# end modify 1647083088\n<\/code><\/pre>\n\n\n\n<p>Similarly, you can run other operations and confirm the same on the database;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Audit Logging File Rotation<\/h3>\n\n\n\n<p>Ensure the file is rotated to avoid it growing to unmanageable sizes.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ncat > \/etc\/logrotate.d\/slapd-audit << 'EOL'\n\/var\/log\/slapd\/slapd-audit.log {\n    weekly\n    missingok\n    notifempty\n    sharedscripts\n    rotate 2\n    compress\n    delaycompress\n}\nEOL\n<\/code><\/pre>\n\n\n\n<p>And there you go. That is it on how to enable OpenLDAP Audit logging.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">More Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/setup-apache-guacamole-openldap-authentication\/\" target=\"_blank\" rel=\"noreferrer noopener\">Setup Apache Guacamole OpenLDAP Authentication<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-squid-proxy-openldap-authentication-on-pfsense\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure Squid Proxy OpenLDAP Authentication on pfSense<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-openldap-password-expiry-email-notification\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure OpenLDAP Password Expiry Email Notification<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to enable OpenLDAP audit logging. OpenLDAP uses Auditlog overlays to record any changes made to the database to<\/p>\n","protected":false},"author":1,"featured_media":11832,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121],"tags":[4683,4686,4685,4687,4684],"class_list":["post-11830","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-how-to-enable-openldap-audit-logging","tag-ldap-audit-modules","tag-ldap-audit-overlay","tag-ldap-auditing","tag-openldap-audit","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/11830"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=11830"}],"version-history":[{"count":2,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/11830\/revisions"}],"predecessor-version":[{"id":11833,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/11830\/revisions\/11833"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/11832"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=11830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=11830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=11830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}