{"id":321,"date":"2009-12-28T11:18:00","date_gmt":"2009-12-28T11:18:00","guid":{"rendered":"https:\/\/questy.org\/?p=321"},"modified":"2024-09-26T19:13:07","modified_gmt":"2024-09-26T19:13:07","slug":"ldap-administration-part-ii","status":"publish","type":"post","link":"https:\/\/questy.org\/index.php\/2009\/12\/28\/ldap-administration-part-ii\/","title":{"rendered":"LDAP Administration \u2013 Part II"},"content":{"rendered":"\n<p>Ok, so in our previous installment, we got LDAP all configured up from the client perspective. &nbsp;I\u2019ll cover some other client-based niceties such as extra PAM modules and security in our third installment. &nbsp;For now, back to the show!<\/p>\n\n\n\n<p><strong>The Server<\/strong><\/p>\n\n\n\n<p>The lightweight Directory Access Protocol (LDAP) gives us tons of things to use to help make the system login\/logout process easy to manage and maintain. &nbsp;The LDAP server runs over the Berkeley Database (BDB) as a data backend, and has a&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/LDAP\">long history<\/a>&nbsp;as a protocol\/standard.<\/p>\n\n\n\n<p>As we said last time, the server configuration consists of the contents of the \/etc\/openldap directory with the primary file of interest being the \/etc\/openldap\/slapd.conf file. &nbsp;The secondary file of interest will be the \/etc\/ldap.conf file, another server configuration file.<\/p>\n\n\n\n<p><strong>\/etc\/openldap\/slapd.conf<\/strong><\/p>\n\n\n\n<p>First, we will cover the ldap daemon (slapd) configuration file, \/etc\/openldap\/slapd.conf. &nbsp;This file is responsible for specifying information regarding what schemas to use, loggin parametwes, database specifications and locations, security, replication, and security grants.<\/p>\n\n\n\n<p>Let\u2019s start with a very simple slapd.conf file:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p># OpenLDAP Server Configuration <br># Primary Server Schemas <br>include \u00a0 \u00a0 \u00a0 \u00a0 \/etc\/openldap\/schema\/core.schema <br>include \u00a0 \u00a0 \u00a0 \u00a0 \/etc\/openldap\/schema\/cosine.schema <br>include \u00a0 \u00a0 \u00a0 \u00a0 \/etc\/openldap\/schema\/inetorgperson.schema <br>include \u00a0 \u00a0 \u00a0 \u00a0 \/etc\/openldap\/schema\/nis.schema <br>include \u00a0 \u00a0 \u00a0 \u00a0 \/etc\/openldap\/schema\/redhat\/autofs.schema <br><br># Logging<br> loglevel 0 <br>pidfile \u00a0 \u00a0 \u00a0\/var\/run\/openldap\/slapd.pid <br>argsfile \u00a0 \u00a0\/var\/run\/openldap\/slapd.args <br><br># bdb database definitions <br>database \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 bdb <br>suffix \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;dc=bob,dc=com&#8221; <br>rootdn \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;cn=admin,dc=bob,dc=com&#8221; <br>rootpw \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0secret <br>schemacheck \u00a0 \u00a0off <br><br># location of the data files <br>directory \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/var\/lib\/ldap <br><br># Indexes to help speed up queries <br>index objectClass,uid,uidNumber,gidNumber,memberUid \u00a0 \u00a0 <br>eq index cn,mail,surname,givenname \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<br>eq,subinitial <br><br># Grant users rights to change their own password <br>access to attrs=userPassword <br>  by self write <br>  by anonymous auth <br>  by dn.base=&#8221;cn=admin,dc=bob,dc=com&#8221; write <br>  by * noneaccess to * <br>  by self write by dn.base=&#8221;cn=admin,dc=bob,dc=com&#8221; write <br>  by * read<\/p>\n<\/blockquote>\n\n\n\n<p>This is a very basic slapd.conf file without TLS security information, without replication information, and without any frills at all. &nbsp;Recall that our primary goal here is to get a basic LDAP server running and working without any frills. &nbsp;We want the ting to work, and then we\u2019ll add features and security as time goes on.<\/p>\n\n\n\n<p><strong>\/etc\/ldap.conf<\/strong><\/p>\n\n\n\n<p>The \/etc\/ldap.conf file bills itself as the \u201cconfiguration file for the LDAP nameservice switch library and the LDAP PAM module\u201d. &nbsp;While we just configured the operation of the server, we must now put the \u201cglue\u201d in place so that PAM knows how to ask questions of the LDAP system to know if a user is allowed to login or not. &nbsp;Again, a very simple \/etc\/ldap.conf file:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p># ldap.conf &#8212; simple configuration # Distinguished name of the search base base dc=bob,dc=com # The distinguished name to bind to the server with binddn cn=admin,dc=bob,dc=com # Password to bind to the directory with bindpw secretpassword # Search TimeLimit timelimit 120 # bind\/connection timelimit bind_timelimit 120 # idle timelimit idle_timelimit 3600 # PAM password format pam_password md5 # Assume no supplemental groups for these named users nss_initgroups_ignoreusers root,ldap,named,avahi,haldaemon,dbus,radvd,tomcat,radiusd,news,mailman # Main LDAP configuration piece uri ldap:\/\/ldap.bob.com ssl no tls_cacertdir \/etc\/openldap\/cacerts<\/p>\n<\/blockquote>\n\n\n\n<p>A couple of notes here. &nbsp;First, the nss_initgroups_ignoreusers portion can most likely be left out. &nbsp;This is an artifact (as far as I am aware) of being on a RedHat system as several of these users are defaults on RedHat. &nbsp;Next: &nbsp;The timelimits are just sane numbers, nothing special. &nbsp;Should there be any need for tweaking this, it will be in your own experience across your own environment.<\/p>\n\n\n\n<p>Much like the earlier client configuration file, this serves somewhat the same purpose, but for the PAM system as a client rather than a system itself as a client.<\/p>\n\n\n\n<p><strong>Crank it Up!<\/strong><\/p>\n\n\n\n<p>At this point, you should be able to start up your server to begin configuring it for use. &nbsp;In RedHat-land, as many of you already know, this is typically a two-part process. &nbsp;First, you set the service to start at boot and then you start it up. &nbsp;First, run the command to set the runlevels in which you want ldap to start:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>chkconfig &#8211;level 2345 ldap on<\/p>\n<\/blockquote>\n\n\n\n<p>And then use the RedHat tools to start the service up:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\/sbin\/service ldap start<\/p>\n<\/blockquote>\n\n\n\n<p>At this point, you should have a fully functional LDAP server running with no particular schema or setup, ready to take data (in our case, POSIX compliant login information) and serve it out to your infrastructure.<\/p>\n\n\n\n<p><strong>Populating the Database<\/strong><\/p>\n\n\n\n<p>With the RedHat packages come a myriad of important tools you need to help migrate your current authentication information into the LDAP store. &nbsp;The location of these helpful perl scripts is: \/usr\/share\/openldap\/migration. &nbsp;Before you use these tools, make sure you edit the&nbsp;<strong><em>migrate_common.ph<\/em><\/strong>&nbsp;file in this location to match your environment like so:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>$DEFAULT_MAIL_DOMAIN = &#8220;bob.com&#8221; <br>$DEFAULT_BASE = &#8220;dc=bob,dc=com&#8221;<\/p>\n<\/blockquote>\n\n\n\n<p>This file is sourced by all the migration scripts resident in this directory, and will automagically insert these values where necessary.<\/p>\n\n\n\n<p>Next, let\u2019s do a trial-run of converting our passwd file in \u201cLDAP-ese\u201d. &nbsp;Since you\u2019ve already edited the migrate_common.ph, you can directly migrate your \/etc\/passwd and \/etc\/group files like so:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>_From the \/usr\/share\/openldap\/migration directory:_ .\/migrate_passwd.pl \/etc\/passwd .\/passwd.ldif _Similarly, convert your groups file as well:_ .\/migrate_group.pl \/etc\/group .\/group.ldif<\/p>\n<\/blockquote>\n\n\n\n<p>What these commands will do is convert your standard \/etc\/passwd and \/etc\/group file to&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/LDIF\">ldif<\/a>-formatted files for import into your LDAP store. &nbsp;Let\u2019s look at a record for an example:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>> > dn: uid=bin,ou=People,dc=best,dc=turner,dc=com > > > > uid: bin > > > > cn: bin > > > > objectClass: account > > > > objectClass: posixAccount > > > > objectClass: top > > > > objectClass: shadowAccount > > > > userPassword: {crypt}* > > > > shadowLastChange: 14251 > > > > shadowMax: 99999 > > > > shadowWarning: 7 > > > > loginShell: \/sbin\/nologin > > > > uidNumber: 1 > > > > gidNumber: 1 > > > > homeDirectory: \/bin > > > > gecos: bin > > dn: uid=bin,ou=People,dc=best,dc=turner,dc=comuid: bincn: binobjectClass: accountobjectClass: posixAccountobjectClass: topobjectClass: shadowAccountuserPassword: {crypt}*shadowLastChange: 14251shadowMax: 99999shadowWarning: 7loginShell: \/sbin\/nologinuidNumber: 1gidNumber: 1homeDirectory: \/bingecos: bin<br><strong><em>NOTE: Formatting Lost<\/em><\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>The LDIF format has a number of self-explanatory fields that you can see correlate to your \/etc\/passwd file. &nbsp;There are other fields here that LDAP needs, but are beyond our concern at this point. &nbsp;We\u2019ll come back to these later.<\/p>\n\n\n\n<p>I picked a system-default user just to illustrate the format of the ldif. &nbsp;This user generally has no password, and thus you cannot login using his credentials. &nbsp;In the userPassword line above, for a regular login user, you would normally see {crypt} followed by a rather large SHA encrypted string representing the user\u2019s hash.<\/p>\n\n\n\n<p>This brings about the question of how you wish to manage your users. &nbsp;Generally speaking, I allow the local \/etc\/passwd file manage root and all system-default users (bin, spool, lp, etc.) and all users I add post-installation get placed into LDAP. &nbsp;In that way, I manage the user centrally from the outset. &nbsp;I\u2019ll be covering how I limit what users are allowed to access what systems in a later article.<\/p>\n\n\n\n<p><strong>Importing the LDIF<\/strong><\/p>\n\n\n\n<p>Once you have your LDIF, you have some decisions\/edits to make. &nbsp;look through your dumped ldif file. &nbsp;Remove each stanza relating to the users you&nbsp;<em>do not&nbsp;<\/em>wish to manage via LDAP. &nbsp;The resulting LDIF file will be the one we import. &nbsp;Generally speaking, in a RedHat system I delete everything before UID 500 (which is usually me) and import everything else.<\/p>\n\n\n\n<p>Once your LDIF file is how you want it to look, it\u2019s time to import. &nbsp;Import it using the following command, modifying the search base and admin user to suit your configuration:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>_ldapadd -W -x -D &#8220;cn=admin,dc=bob,dc=com&#8221; -W -f passwd.lif_<\/p>\n<\/blockquote>\n\n\n\n<p>When you run this command, the LDAP server will churn for a moment (depending on how large your passwd file is) and then will return a clean shell with no errors.<\/p>\n\n\n\n<p><strong>Time to \u201cGet your GUI On\u201d<\/strong><\/p>\n\n\n\n<p>At this point, I usually point people toward the excellent Apache Directory Studio available at the&nbsp;<a href=\"http:\/\/directory.apache.org\/\">Apache Directory Project<\/a>. &nbsp;This is a gui directory administration tool that can browse and edit your entire store. &nbsp;The Apache Foundation describes it like so:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Apache Directory Studio is a complete directory tooling platform intended to be used with any LDAP server however it is particularly designed for use with the ApacheDS. It is an Eclipse RCP application, composed of several Eclipse (OSGi) plugins, that can be easily upgraded with additional ones. These plugins can even run within Eclipse itself.<\/p>\n<\/blockquote>\n\n\n\n<p>Apache Directory Studio is available for Windows, Linux, and Mac OSX and is a freely-available Apache 2.0 licensed product.<\/p>\n\n\n\n<p>Once you download and configure the Apache Directory Studio, you should be able to view, browse, edit, and manage all aspects of your LDAP store.<\/p>\n\n\n\n<p>Next time, we will tie PAM into LDAP, work with security and group-based access as well as cover a few \u201codds &amp; ends\u201d to help you use your LDAP store in a variety of different ways.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok, so in our previous installment, we got LDAP all configured up from the client perspective. &nbsp;I\u2019ll cover some other client-based niceties such as extra PAM modules and security in our third installment. &nbsp;For now, back to the show! The Server The lightweight Directory Access Protocol (LDAP) gives us tons of things to use to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[8],"tags":[],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-open-source"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/comments?post=321"}],"version-history":[{"count":1,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/321\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/media?parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/categories?post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/tags?post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}