Debian 12 bookworm
Sponsored Link

Apache2 : Basic Authentication + LDAP2023/07/04

 
Configure [mod_ldap] to use LDAP directory users on httpd Basic authentication.
On this example, it uses Active Directory like following environment for it.
Domain Server : Windows Server 2022
Domain Name : srv.world
Hostname : fd3s.srv.world
NetBIOS Name : FD3S01
Realm : SRV.WORLD
[1]
Username and password are sent with plain text on Basic Authentication,
so Use secure connection with SSL/TLS setting, refer to here.
[2]
Create a user on Active Directory for binding Active Directory from Apache2.
On this example, it creates [ldapuser], it's OK to grant [Domain Users] rights only for it.
[3] Configure Basic authentication + LDAP.
For example, set Basic Authentication to the directory [/var/www/html/auth-ldap].
root@www:~#
vi /etc/apache2/sites-available/auth-ldap.conf
# create new
# on example below, it limits the range to search the directory only [Hiroshima] OU
# so only users under the [Hiroshima] OU can authenticate with this setting
# for [AuthLDAPBindDN] and [AuthLDAPBindPassword], specify the AD user for binding

<Directory "/var/www/html/auth-ldap">
    SSLRequireSSL
    AuthType Basic
    AuthName "LDAP Authentication"
    AuthBasicProvider ldap
    AuthLDAPURL "ldap://fd3s.srv.world:389/ou=Hiroshima,dc=srv,dc=world?sAMAccountName?sub?(objectClass=*)"
    AuthLDAPBindDN ldapuser@srv.world
    AuthLDAPBindPassword Password
    Require valid-user
</Directory>

root@www:~#
chgrp www-data /etc/apache2/sites-available/auth-ldap.conf

root@www:~#
chmod 640 /etc/apache2/sites-available/auth-ldap.conf

root@www:~#
a2ensite auth-ldap

Enabling site auth-ldap.
To activate the new configuration, you need to run:
  systemctl reload apache2

root@www:~#
a2enmod authnz_ldap

Considering dependency ldap for authnz_ldap:
Enabling module ldap.
Enabling module authnz_ldap.
To activate the new configuration, you need to run:
  systemctl restart apache2

root@www:~#
systemctl restart apache2

# create a test page

root@www:~#
mkdir /var/www/html/auth-ldap

root@www:~#
vi /var/www/html/auth-ldap/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for LDAP Authentication
</div>
</body>
</html>
[4] Access to the test page from any client computer with web browser. Then authentication is required as settings, answer with any AD user.
[5] That's OK if authentication is successfully passed and test page is displayed normally.
Matched Content