This method authenticates using Apache 2.0/2.2 and the LDAP authentication modules on Linux (supplied by default with most Linux distros) and an LDAP server. LDAP can be used to authenticate user accounts on Linux and other computer systems as well as web site logins.
Try this out with your Apache server authenticating to our open LDAP server using our Three Stooges example.
Apache LDAP modules: |
Note that the following configurations work if the LDAP modules are enabled:
These are turned on by default. See /etc/httpd/conf/httpd.conf
LoadModule ldap_module modules/mod_ldap.so LoadModule auth_ldap_module modules/mod_auth_ldap.so |
LoadModule ldap_module modules/mod_ldap.so LoadModule authnz_ldap_module modules/mod_authnz_ldap.so |
Apache Authentication Configuration: |
Authenticate to an Open LDAP server. (No bind name/password required to access LDAP server)
.. ... <Directory /var/www/html > AuthType Basic AuthName "Stooges Web Site: Login with email address" AuthLDAPURL ldap://ldap.yo-linux.com:389/o=stooges?mail require valid-user </Directory> ... .. |
AuthName "Stooges Web Site: Login with email address" AuthType Basic AuthLDAPURL ldap://ldap.your-domain .com:389/o=stooges?mail require valid-user |
Point your browser to http://localhost/
Login with the user id "[email protected]" and password "larrysecret".
You will be asked to use a user id (email address) and password to enter the site.
Bind with a bind DN: (password protected LDAP repository)
.. ... <Directory /var/www/html > AuthType Basic AuthName "Stooges Web Site: Login with email address" AuthLDAPEnabled on AuthLDAPURL ldap://ldap.your-domain .com:389/o=stooges?mail AuthLDAPBindDN "cn=StoogeAdmin,o=stooges" AuthLDAPBindPassword secret1 require valid-user </Directory> ... .. |
This example specified the use of the email address as a login id. If using user id's specify:
Authenticate using Apache httpd 2.2 AuthzLDAP:
User Authentication:
.. ... <Directory /var/www/html > AuthType Basic AuthName "Stooges Web Site: Login with user id" AuthBasicProvider ldap AuthzLDAPAuthoritative on AuthLDAPURL ldap://ldap.your-domain .com:389/o=stooges?uid?sub AuthLDAPBindDN "cn=StoogeAdmin,o=stooges" AuthLDAPBindPassword secret1 require ldap-user lary curley moe joe bob mary </Directory> ... .. |
There are two configurations for the directive AuthzLDAPAuthoritative :
AuthzLDAPAuthoritative on ... require ldap-user lary curley moe joe bob mary |
AuthzLDAPAuthoritative off
AuthzLDAPAuthoritative off ... require valid-user |
Group Authentication:
dn: cn=users,ou=group,o=stooges cn: users objectClass: top objectClass: posixGroup gidNumber: 100 memberUid: larry memberUid: moe |
Apache Configuration:
... <Directory /var/www/html > Order deny,allow Deny from All AuthType Basic AuthName "Stooges Web Site: Login with user id" AuthBasicProvider ldap AuthzLDAPAuthoritative on AuthLDAPURL ldap://ldap.your-domain .com:389/o=stooges?uid?sub AuthLDAPBindDN "cn=StoogeAdmin,o=stooges" AuthLDAPBindPassword secret1 AuthLDAPGroupAttribute memberUid AuthLDAPGroupAttributeIsDN off Require ldap-group cn=users,ou=group,o=stooges Require ldap-attribute gidNumber=100 Satisfy any </Directory> ... |
Concurrent File and LDAP authentication: |
Apache can use both File and LDAP authentication concurently. This is sometimes required to run cron jobs with a login where you do not want to use a system login or login managed by a directory server in another department.
<Directory /ABC> Order deny,allow Deny from All AuthType Basic AuthBasicProvider file ldap AuthName "Directory services login" AuthBasicAuthoritative off AuthUserFile /srv/htpasswd AuthGroupFile /dev/null AuthzLDAPAuthoritative off AuthLDAPURL "ldap://ldap.megacorp.com:389/ou=person,o=megacorp.com,c=us?uid?sub" # This user created for local cron jobs. It is not a system user and allows # the cron job to perform its task. # This user is not in the LDAP directory but in the password file /srv/htpasswd Require user cronuserjobx Require ldap-user usera userb </Directory> |
Debugging Apache Authentication: |
Set LogLevel debug when debugging authentication. This will log all the LDAP connection events and the LDAP attributes requested.
Authenticating with Microsoft Active directory using Microsoft's "Unix services for Windows":
Also note that encrypted connections will use the URL prefix "ldaps:// " and the added directives:
Restart Apache after editing the configuration file: service httpd restart for configuration changes to take effect.
See /var/log/httpd/error_log for configuration errors.