Apache Web Server and LDAP

Overview#

So many people have been asking about configuration of Apache Web Server with various LDAP servers, we put this How To page together to hopefully help.

Assumptions#

First, we assume that the Apache Web Server is version 2.0 or greater, if not, we recommend you upgrade. We also assume and will not go into details about how you would implement security once you have LDAP authentication configured as there are way too many methods to do this on Apache's Web Server.

What is Required#

The Basics#

The Apache Web Server Module, mod_authnz_ldap, provides authentication front-ends such as mod_auth_basic to authenticate users through an LDAP directory.

On many Apache Binaries will have the mod_authnz_ldap module compiled with the binary. Otherwise you may have to compile your Apache Web Server with one of the following LDAP SDKs:

LDAP Authentication#

The mod_authnz_ldap module provides LDAP Authentication by:

It is important security feature that the module performs a bind as any other method could bypass security features implemented within the LDAP server like:

Example Authentication#

In this example we will check the LDAP server to see if the user can successfully bind (LDAP term for login) and if the user can, we will let tell Apache he is "good-to-go".

Configuration in Apache#

Depending on where you put the mod_authnz_ldap configuration will determine which servers or locations are "protected". In this example we are protecting the Web URL "/private".
<Location /private>
	order allow,deny
	allow from all
	AuthName "AuthRequired"
        AuthType Basic
        AuthBasicProvider ldap
	AuthzLDAPAuthoritative on
	AuthLDAPURL "ldap://ldap.willeke.com:389/ou=People,dc=willeke,dc=com?cn?sub?(objectClass=inetOrgPerson)"
	AuthLDAPBindDN  "cn=apacheProxy,ou=administration,dc=willeke,dc=com"
	AuthLDAPBindPassword "secret"
	require valid-user
</Location>

Here is how the configuration breaks down:

LDAP Authorization#

In addtion to Authentication the integration of Apache Web Server with LDAP can provide Authorization.

In the example, we showed the directive of "require valid-user". Which in effect, says anyone is authorized.

We can specify other "require" directives that will require authorization requirements.

Authorization Examples#

As an example, if we configure a location as:
<Location /admin>
	order allow,deny
	allow from all
	AuthName "AuthRequired"
        AuthType Basic
        AuthBasicProvider ldap
	AuthzLDAPAuthoritative on
	AuthLDAPURL "ldap://ldap.willeke.com:389/ou=People,dc=willeke,dc=com?cn?sub?(objectClass=inetOrgPerson)"
	AuthLDAPBindDN  "cn=apacheProxy,ou=administration,dc=willeke,dc=com"
	AuthLDAPBindPassword "secret"
	Require ldap-attribute ldapRole=Admin
</Location>

The "Require ldap-attribute ldapRole=Admin" directive implies the user must pocess a value in the LDAP Attribute "ldapRole" of "Admin" or the user will receive a 403 Forbidden response.

Some other examples for Authorization:

More capabilities#

Yes there are more capabilities for the Apache Web Server and LDAP, Do we do not recommend you implement this module or LDAP pools until you get the basic LDAP Authentication working.

LDAP connection pool and an LDAP cache#

If you need LDAP pools and/or caching you will need to look at the the Apache Module mod_ldap.

Do not implement this module or LDAP pools until you get the basic LDAP Authentication working.

SSL or TLS for LDAP#

If you require support for LDAP over SSL (requires the Netscape SDK) or TLS (requires the OpenLDAP 2.x SDK or Novell LDAP SDK).

To implement SSL or TLS see the mod_ldap directives LDAPTrustedClientCert, LDAPTrustedGlobalCert|target='_blank'] and LDAPTrustedMode.

Do not implement these directives until you get the basic LDAP Authentication working.

More Information#

There might be more information for this subject on one of the following: