Configure squid for LDAP authentication using squid_ldap_auth helper

My last post was about Squid proxy authentication using ncsa_auth helper. This time I will show you how to configure squid for LDAP authentication.

The Lightweight Directory Access Protocol, (LDAP) is a networking protocol for querying and modifying directory services running over TCP/IP.

LDAP server (such as OpenLDAP or others) uses the Lightweight Directory Access Protocol. In order to use Squid LDAP authentication you need to tell which program to use with the auth_param option in squid.conf. You specify the name of the program, plus command line options.

Squid comes with squid_ldap_auth helper. This helper allows Squid to connect to a LDAP directory to validate the user name and password of Basic HTTP authentication. This helper is located at /usr/local/squid/libexec/ or /usr/lib/squid or /usr/lib64/squid/ directory.

Step # 1: Make sure squid can talk to LDAP server

Before configuring makes sure that the squid is working with LDAP auth. Type the following command:
# /usr/lib/squid/squid_ldap_auth -b "dc=nixcraft,dc=com" -f "uid=%s" ldap.nixcraft.com

Once you hit enter key you need to provide UID and password using following format:
USERID blankspace PASSWORD

If it was able to connect to LDAP server you will see "ok".

Step # 2: Configuration

Open your squid.conf file:
# vi /etc/squid/squid.conf

Next you need to add following code which specifies the base DN under where your users are located and the LDAP server name.
auth_param basic program /usr/lib/squid/squid_ldap_auth -b "dc=nixcraft,dc=com" -f "uid=%s" -h ldap.nixcraft.com
acl ldapauth proxy_auth REQUIRED
http_access allow ldapauth
http_access deny all

Save and close the file. Restart Squid to take effect.
# /etc/init.d/squid restart

Zimbra LDAP With Squid

You need to use it as follows
/usr/lib/squid/squid_ldap_auth -v 3 -b dc=zimbra,dc=example,dc=com -f "(&(uid=%s)(objectClass=zimbraAccount))" -h zimbra.example.com

Squid authentication against Microsoft's Active Directory

I have not used group_ldap_auth helper against Microsoft's Active Directory. But someone (user) pointed out the following solution. Add following configuration directive to squid.conf:

ldap_auth_program /usr/lib/squid/group_ldap_auth -b dc=my-domain,dc=de -h \
server.my-domain.de -p 636 -g distinguishedName -d CN=lookup,OU=Services,\
OU=Users,DC=my-domain,DC=de -w lookup -u cn -m member -o group -S -l \
/var/log/squid/ldaplog

acl ldap_backoffice ldap_auth static 'CN=BackOffice,OU=Groups,dc=my-domain,dc=de'
acl ldap_management ldap_auth static 'CN=Management,OU=Groups,dc=my-domain,dc=de'
acl ldap_it-service ldap_auth static 'CN=IT-Service,OU=Groups,dc=my-domain,dc=de'
acl ldap_development ldap_auth static 'CN=DEVELOPMENT,OU=Groups,dc=my-domain,dc=de'

http_access allow ldap_development
http_access allow ldap_backoffice
http_access allow ldap_management
http_access allow ldap_it-service
http_access deny all

Further readings

  • man squid_ldap_auth
  • man group_ldap_auth
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 7 comments… read them below or add one }

1 tt binda 03.27.08 at 10:33 am

Ehi! If you have any problem, start to try with -v 3 instead of ldap version 2.
I could bind to my ldap server in reason of this.
It is a good start this try:
# /usr/lib/squid/ldap_auth -b “dc=mydc” -D cn=admin,dc=mydc -w passwd -H ldap://ldapserver -v 3 -f “uid=%s”

when typed name and password you must see
OK. Be sure to have typed name and password with a blank separator.
byee

2 Deepak 03.31.08 at 5:13 am

IF i configured Active directory Ldap with Squid for authendication than ,how can i block internet access as per user ??? want to block internet access as per user.

3 John J. Martinez 12.13.08 at 8:46 pm

Excelente!!!
Muchas gracias!!
Excelent!!!
Very thanks!!

4 Paul 12.15.08 at 10:04 am

Excellent! I also had to specify version 3 before my query would work. Thanks.

5 rajkumar 12.16.08 at 2:39 pm

Hi Friends,

this is the first time i’m posting query.i need in help for configure squid proxy server . i.e, i want to block url and download by user based , not based on ip address. that while i’m trying to open IE (or) FIREFOX (or) OPERA , it have to ask for username and password , the permission will be granted accordimg to user. if any user can login in any system but proxy have to block according to their username and password. i need squid proxy based on user restriction not on ip address restricting. please try to solve my problem by sending configuration method to me. thank you friends

6 eder 12.22.08 at 2:21 pm

Hello.
I’m trying to auth against zimbra with this command :

/usr/lib64/squid/squid_ldap_auth -v 3 -b dc=zimbra,dc=mydomain,dc=com,dc=br -f “(&(uid=%s)(objectClass=zimbraAccount))” -h myserver.mydomain.com.br

after inserting user pass and user@domain I get this answer.

squid_ldap_auth: WARNING, LDAP search error ‘No such object’
ERR Success

could you help me, please?

7 Zied Fakhfakh 05.19.09 at 7:21 am

I got this error too,

and I’m pretty sure it’s a permission issue. As the LDAP server from LDAP won’t let you see (read) the userPassword Attribute.

Should we create a squid user on ldap, give him the permission to read userPassword and uid ?

any idea is welcome,
Zied.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , ,

Previous post: Download of the day: Fedora core live CD

Next post: VirtualBox virtualization product available for download