{"id":2014,"date":"2020-11-20T01:09:54","date_gmt":"2020-11-19T23:09:54","guid":{"rendered":"https:\/\/www.npcglib.org\/~stathis\/blog\/?p=2014"},"modified":"2020-11-20T01:16:09","modified_gmt":"2020-11-19T23:16:09","slug":"enable-access-logs-for-an-openldap-database","status":"publish","type":"post","link":"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/","title":{"rendered":"Enable access logs for an OpenLDAP database"},"content":{"rendered":"<p>Let&#8217;s assume you already have a database under <code>dn: olcDatabase={1}mdb,cn=config<\/code> and you would like to keep access logs. To achieve this, we will do (and assume) the following:<\/p>\n<ul>\n<li>Enable the AccessLog Module<\/li>\n<li>Create an AccessLog database, where the logs will be stored<\/li>\n<li>There is already an existing database for which we want to keep logs at: <code>dn: olcDatabase={1}mdb,cn=config<\/code><\/li>\n<\/ul>\n<p>Note that I use Gentoo linux, but with some modifications the following information should work on other distributions.<\/p>\n<h3>Enable the AccessLog Module<\/h3>\n<p>Ok, so first add the module to OpenLDAP:<\/p>\n<p>Ensure that the accesslog module is available on your system\/platform. In my case, it is in stored as <code>\/usr\/lib64\/openldap\/openldap\/accesslog.so<\/code>. Modify the following LDAP Data Interchange Format (LDIF) file accordingly if the shared object file is elsewhere.<\/p>\n<p>Create the file <code>load_AccessLogModule.ldif<\/code> and insert:<\/p>\n<pre>\r\ndn: cn=module{2},cn=config\r\nobjectClass: olcModuleList\r\ncn: module{2}\r\nolcModuleLoad: {0}accesslog.so\r\nolcModulePath: \/usr\/lib64\/openldap\/openldap\r\n<\/pre>\n<p>Add the content into the slapd server (you may have to restart the daemon):<\/p>\n<pre>\r\nldapmodify -a -D \"cn=config\" -w &lt;password&gt; -H ldap:\/\/ -f load_AccessLogModule.ldif\r\n<\/pre>\n<h3>Create an AccessLog database<\/h3>\n<p>Let&#8217;s now create the AccessLog database in which logs will be stored in:<\/p>\n<p>Create a file <code>create_AccessLogDatabase.ldif<\/code> and insert:<\/p>\n<pre>\r\ndn: olcDatabase={2}mdb,cn=config\r\nobjectClass: olcDatabaseConfig\r\nobjectClass: olcMdbConfig\r\nolcDatabase: mdb\r\nolcDbDirectory: \/var\/lib\/openldap-data\/accesslog\r\nolcSuffix: cn=accesslog\r\nolcRootDN: cn=admin,cn=accesslog\r\nolcRootPW: auditor_password\r\nolcDbIndex: default eq\r\nolcDbIndex: entryCSN,objectClass,reqEnd,reqResult,reqStart\r\n<\/pre>\n<p>Caution here, the olcDbDirectory <code>\/var\/lib\/openldap-data\/accesslog<\/code>, must exist and the system user owning the slapd process must be able to read\/write. On my system:<\/p>\n<pre>\r\n  mkdir -p \/var\/lib\/openldap-data\/accesslog\r\n  chown ldap:ldap \/var\/lib\/openldap-data\/accesslog\r\n<\/pre>\n<p>Of course you should also use a more secure password than the plain text <span style=\"color:red\">auditor_password<\/span> used, by utilizing the SHA or SSHA password scheme (see <a href=\"https:\/\/www.openldap.org\/faq\/data\/cache\/347.html\">https:\/\/www.openldap.org\/faq\/data\/cache\/347.html<\/a>).<\/p>\n<p>Add the content into the slapd server:<\/p>\n<pre>\r\n  ldapmodify -a -D \"cn=config\" -w &lt;password&gt; -H ldap:\/\/ -f create_AccessLogDatabase.ldif\r\n<\/pre>\n<h3>Add the AccessLog overlay to the &#8220;source&#8221; database<\/h3>\n<p>Recall, we have an existing database (with <code>dn: olcDatabase={1}mdb,cn=config<\/code>) we would like to log access for. We should create an overlay in that database and configure it to log into the AccessLog database we just created:<\/p>\n<p>Create a file <code>add_Overlay_to_Database.ldif<\/code> and insert:<\/p>\n<pre>\r\ndn: olcOverlay=accesslog,olcDatabase={1}mdb,cn=config\r\nobjectClass: olcOverlayConfig\r\nobjectClass: olcAccessLogConfig\r\nolcOverlay: accesslog\r\nolcAccessLogDB: cn=accesslog\r\nolcAccessLogOps: session\r\nolcAccessLogSuccess: TRUE\r\nolcAccessLogPurge: 07+00:00 01+00:00\r\n<\/pre>\n<p>Add the content into the slapd server: <\/p>\n<pre>\r\n  ldapmodify -a -D \"cn=config\" -w &lt;password&gt; -H ldap:\/\/ -f add_Overlay_to_Database.ldif\r\n<\/pre>\n<p>Now, whenever a session abandon, bind or unbind action happens for the <code><span style=\"color:darkcyan\"><strong>olcDatabase={1}mdb<\/strong><\/span>,cn=config<\/code> database, a log entry will be created in <code>dn: <span style=\"color:brown\"><strong>olcDatabase={2}mdb<\/strong><\/span>,cn=config<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s assume you already have a database under dn: olcDatabase={1}mdb,cn=config and you would like to keep access logs. To achieve this, we will do (and assume) the following: Enable the AccessLog Module Create an AccessLog database, where the logs will be stored There is already an existing database for which we want to keep logs [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[48,5],"tags":[96,94,95,92,97,93],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"stathis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/#website\",\"url\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/\",\"name\":\"sigmoid\",\"description\":\"..oo..oo..oo..oo..oo..oo..\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/#webpage\",\"url\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/\",\"name\":\"Enable access logs for an OpenLDAP database - sigmoid\",\"isPartOf\":{\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/#website\"},\"datePublished\":\"2020-11-19T23:09:54+00:00\",\"dateModified\":\"2020-11-19T23:16:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/#\/schema\/person\/508363c4ebd1fd6066edf00c94e37e41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Enable access logs for an OpenLDAP database\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/#\/schema\/person\/508363c4ebd1fd6066edf00c94e37e41\",\"name\":\"stathis\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/214f29f604ec7d8d2f1345c5fa617c09?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/214f29f604ec7d8d2f1345c5fa617c09?s=96&d=mm&r=g\",\"caption\":\"stathis\"},\"url\":\"https:\/\/www.npcglib.org\/~stathis\/blog\/author\/stathis\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/","twitter_misc":{"Written by":"stathis","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/#website","url":"https:\/\/www.npcglib.org\/~stathis\/blog\/","name":"sigmoid","description":"..oo..oo..oo..oo..oo..oo..","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.npcglib.org\/~stathis\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/#webpage","url":"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/","name":"Enable access logs for an OpenLDAP database - sigmoid","isPartOf":{"@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/#website"},"datePublished":"2020-11-19T23:09:54+00:00","dateModified":"2020-11-19T23:16:09+00:00","author":{"@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/#\/schema\/person\/508363c4ebd1fd6066edf00c94e37e41"},"breadcrumb":{"@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/2020\/11\/20\/enable-access-logs-for-an-openldap-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.npcglib.org\/~stathis\/blog\/"},{"@type":"ListItem","position":2,"name":"Enable access logs for an OpenLDAP database"}]},{"@type":"Person","@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/#\/schema\/person\/508363c4ebd1fd6066edf00c94e37e41","name":"stathis","image":{"@type":"ImageObject","@id":"https:\/\/www.npcglib.org\/~stathis\/blog\/#personlogo","inLanguage":"en-US","url":"http:\/\/2.gravatar.com\/avatar\/214f29f604ec7d8d2f1345c5fa617c09?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/214f29f604ec7d8d2f1345c5fa617c09?s=96&d=mm&r=g","caption":"stathis"},"url":"https:\/\/www.npcglib.org\/~stathis\/blog\/author\/stathis\/"}]}},"_links":{"self":[{"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/posts\/2014"}],"collection":[{"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/comments?post=2014"}],"version-history":[{"count":20,"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/posts\/2014\/revisions"}],"predecessor-version":[{"id":2036,"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/posts\/2014\/revisions\/2036"}],"wp:attachment":[{"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/media?parent=2014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/categories?post=2014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.npcglib.org\/~stathis\/blog\/wp-json\/wp\/v2\/tags?post=2014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}