{"id":311,"date":"2010-08-05T21:03:00","date_gmt":"2010-08-05T21:03:00","guid":{"rendered":"https:\/\/questy.org\/?p=311"},"modified":"2024-09-26T19:12:22","modified_gmt":"2024-09-26T19:12:22","slug":"ldap-authentication-iv-apache","status":"publish","type":"post","link":"https:\/\/questy.org\/index.php\/2010\/08\/05\/ldap-authentication-iv-apache\/","title":{"rendered":"LDAP Authentication IV &#8211; Apache"},"content":{"rendered":"\n<p>Once you\u2019ve got your handy LDAP server authenticating users for login throughout your environment, inevitably you find yourself getting around to the question of authentication for all your backend tools\/services machines. &nbsp;Can you authenticate from Apache to that same auth store to reduce administration burden across the environment?<\/p>\n\n\n\n<p>Yes you can.<\/p>\n\n\n\n<p>Recall from part I of this series that we have a server that is serving auth for our mythical \u201cBob.com\u201d environment. &nbsp;Recall also the important info regarding this environment:<\/p>\n\n\n\n<p>Internet domain name: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 bob.com <br>hostname of the server: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ldap.bob.com <br>LDAP Search base: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0dc=bob,dc=com<\/p>\n\n\n\n<p>File: \u00a0\/etc\/openldap\/ldap.conf<br>#<br># LDAP Defaults<br>#<\/p>\n\n\n\n<p>BASE dc=bob,dc=com <br>URI ldap:\/\/ldap.bob.com <br>TLS_CACERTDIR \/etc\/openldap\/cacerts<\/p>\n\n\n\n<p>Now, we add to the mix an Apache web server that has an area it wants to secure. &nbsp;Instead of using the old htpasswd method to create a disk-file containing usernames and password hashes, it would make much more sense to simply point Apache\u2019s authentication system at our shiny new LDAP server so we eliminate yet another user\/pass system we have to administer.<\/p>\n\n\n\n<p><strong>Apache<\/strong><\/p>\n\n\n\n<p>As many of you are already aware, Apache offers simple authentication to allow\/disallow access to specific shared directories over the web. &nbsp;The Apache Project has detailed documentation to help you get started&nbsp;<a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/howto\/auth.html\">here<\/a>.&nbsp;I\u2019ll cover the basics here.<\/p>\n\n\n\n<p>Traditionally, in Apache\u2019s config file(s) you specify a directory you wish to have secured via the \u201cDirectory\u201d directive like so:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>AllowOverride None <br>Options ExecCGI Includes<br>Order allow,deny<br>Allow from all<br>AuthUserFile \/secure\/passwd\/file\/location<br>AuthType Basic<br>AuthName &#8220;Cool Security Name&#8221;<br>Require valid-user<\/p>\n<\/blockquote>\n\n\n\n<p>You then create your passwd file for Apache with the htpasswd utility, make sure the above path points to it, bounce Apache, and you\u2019re authenticating locally. &nbsp;Problem with this is that every time you need to add a new user to your environment, every instance like this has to be touched individually and you have to add the user (whether by copy\/paste or otherwise is irrelevant) in each.<\/p>\n\n\n\n<p>Enter LDAP.<\/p>\n\n\n\n<p>Fortunately, the configuration for such a change is quite easy; Simple textual changes to the httpd.conf to repoint from the local disk file to the LDAP store is all you need. &nbsp;First, make sure that your LDAP modules are properly loaded into Apache:<\/p>\n\n\n\n<p>LoadModule ldap_module modules\/mod_ldap.so<\/p>\n\n\n\n<p>LoadModule authnz_ldap_module modules\/mod_authnz_ldap.so<\/p>\n\n\n\n<p>This tells the Apache core to load up these at startup so that the directives you supply in the Directory stanza will be understood. &nbsp;Next, let\u2019s add the appropriate info into the Directory section:<\/p>\n\n\n\n<p>AllowOverride None<br>Options ExecCGI Includes<br>Order deny,allow<br>Deny from all<br>AuthName \u201cCool Security Name\u201d<br>AuthType Basic<br>AuthBasicProvider ldap<br>AuthzLDAPAuthoritative Off<br>AuthLDAPURL ldap:\/\/cool.ldap.server\/dc=bob,dc=com?uid<br>AuthLDAPBindDN \u201ccn=admin,dc=bob,dc=com\u201d<br>AuthLDAPGroupAttribute memberUid<br>AuthLDAPGroupAttributeIsDN off<br>AuthLDAPBindPassword\u00a0<br>Satisfy any<\/p>\n\n\n\n<p>This simple change (after an Apache restart) should give your Apache server security over that directory, authenticating against LDAP. &nbsp;Since your LDAP store is POSIX compliant for login, you have a few other things you can leverage in there as well. &nbsp;Among those, are the \u201cGroup\u201d field. &nbsp;That\u2019s right, instead of going out and adding individuals and\/or preventing them, you can specify an entire class of people (say LDAP_Logins for instance) that if the user belongs to that group, suddenly they have access to anything that is authenticating against LDAP.<\/p>\n\n\n\n<p>To add that ability, you can add groups to the stanza above like so:<\/p>\n\n\n\n<p>Require ldap-group cn=mygroup,ou=Group,dc=bob,dc=com<br>Require ldap-attribute gidNumber=500<br><em>(you place your group number in place of the \u201c500\u201d above)<\/em><br><br>Now that you have the magic behind LDAP auth for Apache, you can add this to any Apache web server of the 2.x variety, and do your security centrally.<\/p>\n\n\n\n<p>The ease of addition for new users on your network is now as simple as adding the user to your LDAP store, placing them in the appropriate group. &nbsp;Once Apache was restarted the very first time to make this work, you never have to restart it for user additions. &nbsp;It will simply query LDAP, and LDAP will provide the credential response Apache needs to continue forward.<\/p>\n\n\n\n<p>Next time: &nbsp;Sudoers in LDAP!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once you\u2019ve got your handy LDAP server authenticating users for login throughout your environment, inevitably you find yourself getting around to the question of authentication for all your backend tools\/services machines. &nbsp;Can you authenticate from Apache to that same auth store to reduce administration burden across the environment? Yes you can. Recall from part I [&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-311","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\/311","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=311"}],"version-history":[{"count":1,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":312,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/311\/revisions\/312"}],"wp:attachment":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/tags?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}