Configure Squid LDAP Authentication

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 uid attribute 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

Root shell prompt on the squid proxy server

Install the LDAP Squid Module

cp /etc/squid/squid.conf /etc/squid/squid.conf.bk backup copy

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

Same screenshot: cp squid.conf to squid.conf.bk before editing

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

vi /etc/squid/squid.conf

add the following:

squid.conf auth_param basic program squid_ldap_auth with proxy_auth ACL and http_access rules
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

service squid restart, Stopping and Starting squid OK

4) Test from a client

from here test it from the computer you have already setup and connected to the proxy

Browser on the proxy client prompting for an LDAP user name and password

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=jsmith to 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.local or -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

Leave a Reply

Your email address will not be published. Required fields are marked *