Configure Squid LDAP Authentication
This procedure has been tested with OpenLDAP on CentOS. Basically we are going to authenticate to our squid proxy server using OpenLDAP for http requests.
Squid hands the user name and password the browser sends to an external helper program. The LDAP helper looks the user up in the directory and tries to bind as that user; if the bind works, Squid lets the request through.
Prerequisites
- A working Squid proxy that clients are already configured to use.
- An OpenLDAP server with user entries that have a
uidattribute and a password. - The base DN of your users, for example
dc=domain,dc=local.
1) Install the LDAP helper
Login, and su to root

Install the LDAP Squid Module

On CentOS 6 the squid_ldap_auth helper ships inside the squid package (in /usr/lib64/squid/ on 64-bit), so yum -y install squid openldap-clients covers it; openldap-clients adds ldapsearch for testing.
2) Back up and edit squid.conf
from here make a backup of the squid configuration file

now let’s go ahead, and edit the configuration file

add the following:

auth_param basic program /usr/lib64/squid/squid_ldap_auth -b "dc=domain,dc=local" -f "uid=%s" -h ldap1.domain.local
auth_param basic children 5
auth_param basic realm Web-Proxy
auth_param basic credentialsttl 1 minute
acl ldap-auth proxy_auth REQUIRED
http_access allow ldap-auth
http_access allow localhost
http_access deny all
** If you are using a 64-bit system, be sure to udate the path of /usr/lib/squid to /usr/lib64/squid
What the lines do: -b is the search base, -f "uid=%s" the filter used to find the user, -h the LDAP server. children is how many helper processes run, realm is the text shown in the login box, and credentialsttl is how long Squid caches a good login. The proxy_auth REQUIRED ACL matches any authenticated user. Squid stops at the first matching http_access line, so the allow must come before http_access deny all.
If your directory does not allow anonymous searches, add a bind account with -D "cn=proxy,dc=domain,dc=local" -W /etc/squid/ldap.pass (the file holds only the password; make it readable by squid only).
3) Test the helper, then restart Squid
Run the helper by hand and type a user name and password separated by a space. It answers OK or ERR:
/usr/lib64/squid/squid_ldap_auth -b "dc=domain,dc=local" -f "uid=%s" -h ldap1.domain.local
jsmith Secret123
OK
Check the config syntax with squid -k parse.
once completed, remember to restart the squid service

4) Test from a client
from here test it from the computer you have already setup and connected to the proxy

BAM! it works! That’s it!
The user name now appears in /var/log/squid/access.log next to each request.
Troubleshooting
- Login box keeps coming back: test the helper by hand; ERR means wrong base DN, filter or password. Use
ldapsearch -x -h ldap1.domain.local -b "dc=domain,dc=local" uid=jsmithto confirm the user is found. - Squid will not start: run
squid -k parse; a wrong helper path is the usual cause. - Passwords in clear text: Basic authentication only base64-encodes the password (the browser warning says so). Keep the proxy on a trusted network, and use LDAPS or StartTLS between Squid and the LDAP server (
-H ldaps://ldap1.domain.localor-ZZ).
RHEL, AlmaLinux and Rocky 9/10
Install with dnf install squid openldap-clients. Newer Squid versions renamed the helper to basic_ldap_auth (/usr/lib64/squid/basic_ldap_auth) with the same options. Restart with systemctl restart squid, or apply changes with squid -k reconfigure, and open the proxy port with firewall-cmd --permanent --add-port=3128/tcp then firewall-cmd --reload.
Hosted Linux Servers at www.zwiegnet.com/go
Related guides: Load Balance Squid Reverse Proxy | Configure LDAP Server on CentOS 6

2 Comments