Edited on jun, 21, 2009
The squid web cache include a authenticator for kerberos, it is simple to use, but the documentation is not very clear about how to make it work. Below some steps use by me to make Squid 3.0 Stable1 and Squid 2.6 Stable17 authenticate against Active Directory (Windows 2003 Directory Service) and also to make it make the authorization using Ldap. This setup was not used in production environment yet, so its possible to had some problems not seen by me or scalabilities issues.
Compilation
To achieve our objective:
- Authenticate using “Kerberos” (Negotiate);
- Authenticate using “Basic authentication”, with Ldap as back-end (for backward compatibility);
- Authorization using Ldap group membership;
we need to compile Squid with some specific parameters:
- –enable-auth=”basic negotiate”
- –enable-basic-auth-helpers=”LDAP”
- –enable-negotiate-auth-helpers=”squid_kerb_auth”
- –enable-external-acl-helpers=”ldap_group”
other parameters that you can need must be supplied at compilation time.
Authentication
In this article we’ll use two types of authentication: Negotiate (using Kerberos) and Basic (using Ldap).
To use Negotiate authentication method the web browser must be writed to understand it and configure correctly to do so, and the computer use need to be authenticated by the kerberos infra-structure and receive the appropriated key from the KDC (Key Distribution Center). I’m using Firefox for Linux 2.0 (authenticated with kerberos), Firefox for Windows 2.x and Internet Explorer 6/7, all worked very well.
The Basic authentication is present in any web browser, and we will use Ldap as back-end authentication provider.
Negotiate/kerberos authentication
This part is divided in two parts, one in Linux box other in Windows Domain Controlle, and was strongly based on http://www.grolmsnet.de/kerbtut/ article, that has Apache as a target but this steps works for Squid too.
Windows Step:
Create a user account, ex. squid.domain, and using ktpass command tool create a keytab file.
ktpass -princ HTTP/squid.domain@REALM -mapuser squid.domain -crypto rc4-hmac-nt pass squid-pass -ptype KRB5_NT_SRV_HST -out squid.domain.keytab
Transfer this file safely to the squid box.
Linux/Squid step:
Check that /etc/krb5.conf are correctly configured, example bellow (pay attention on bold lines):
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
default_realm = REALM
dns_lookup_realm = true
dns_lookup_kdc = true
ticket_lifetime = 24h
forwardable = yes
[realms]
EXAMPLE.COM = {
kdc = kerberos.example.com:88
admin_server = kerberos.example.com:749
default_domain = example.com
}
[domain_realm]
.example.com = EXAMPLE.COM
example.com = EXAMPLE.COM
[kdc]
profile = /var/kerberos/krb5kdc/kdc.conf
[appdefaults]
pam = {
debug = false
ticket_lifetime = 36000
renew_lifetime = 36000
forwardable = true
krb4_convert = false
}
Move the keytab file to some directory related to squid, like /etc/squid, and must change the permission like this:
chmod 400 /etc/squid/squid.domain.keytab
chown nobody /etc/squid/squid.domain.keytab
You can test is the squid box can use the keytab file using kinit command:
kinit -V -k -t squid.domain.keytab HTTP/squid.domain
klist
You need to put a line like this in squid startup script:
export KRB5_KTNAME=/etc/squid/squid.domain.keytab
In squid.conf you need set directives like this:
auth_param negotiate program /usr/local/squid/libexec/squid_kerb_auth -d
auth_param negotiate children 10
auth_param negotiate keep_alive on
acl AUTENTICADO proxy_auth REQUIRED
http_access allow AUTENTICADO
http_access deny all
Aditional reference about kerberos authentication for Squid:
- http://sourceforge.net/mailarchive/message.php?msg_id=11486457
- https://sourceforge.net/forum/message.php?msg_id=1853553
Check the /etc/hosts file to certify that the fqdn used on keytab file are associated to the correct address on hosts files, as well on DNS (A and PTR record). Dont associate the fqdn with loopback or other address.
Basic authentication
To make users not authenticated by a kerberos infra-structure keep using squid, you can use a Basic Authentication with many methods, I chose Ldap because the Samba/Winbind (that I already used) some times has problems of stability and a unknown timeouts of and refresh for password change and group membership.
To use this authentication, you can put this lines after the kerberos related lines (this is very important once that the order of method used to authenticated in browser is derived from this order, if you change this you’ll never get a negotiate authentication only basic):
auth_param basic program /usr/local/squid/libexec/squid_ldap_auth -b "CN=Users,dc=bc" -s sub -D "CN=user_to_bind_in_ldap,OU=Usuers,DC=bc" -w password -f "(&(objectClass=person)(sAMAccountName=%s))" -u sAMAccountName -P -v 3 -h ldap_server.domain
auth_param basic children 10
auth_param basic realm Proxy Authentication
auth_param basic credentialsttl 2 hours
Authorization
Sometimes you can control how access the Internet, sometimes you can control how can’t, or when they access, or yet where the peoples go. For achieve this you should use some directives from squid config file, like: ACL, External_ACL, http_access, http_reply_access, etc.
How we are doing the authentication with kerberos, the username (%LOGIN for squid external_acl) become like this: username@REALM. This is a problem for us once that we are trying to check the attribute sAMAccountName in Active Directory, that don’t include Realm, so we need to apply the patch bellow, and use the new parameter -K in squid_ldap_group to strip the Realm from username.
--- squid_ldap_group.c.original 2008-01-10 11:08:12.000000000 -0200
+++ squid_ldap_group.c 2008-01-04 19:35:09.000000000 -0200
@@ -215,6 +215,7 @@
int port = LDAP_PORT;
int use_extension_dn = 0;
int strip_nt_domain = 0;
+ int strip_kerberos_realm = 0;
int err = 0;
setbuf(stdout, NULL);
@@ -370,6 +371,9 @@
case 'S':
strip_nt_domain = 1;
break;
+ case 'K':
+ strip_kerberos_realm = 1;
+ break;
default:
fprintf(stderr, PROGRAM_NAME " ERROR: Unknown command line option '%c'\n", option);
exit(1);
@@ -424,6 +428,7 @@
#endif
fprintf(stderr, "\t-g\t\t\tfirst query parameter is base DN extension\n\t\t\t\tfor this query\n");
fprintf(stderr, "\t-S\t\t\tStrip NT domain from usernames\n");
+ fprintf(stderr, "\t-K\t\t\tStrip Kerberos realm from usernames\n");
fprintf(stderr, "\n");
fprintf(stderr, "\tIf you need to bind as a user to perform searches then use the\n\t-D binddn -w bindpasswd or -D binddn -W secretfile options\n\n");
exit(1);
@@ -470,6 +475,12 @@
if (u && u[1])
user = u + 1;
}
+ if (strip_kerberos_realm) {
+ char *u = strchr(user, '@');
+ if (u!=NULL) {
+ *u = '';
+ }
+ }
if (use_extension_dn) {
extension_dn = strtok(NULL, " \n");
if (!extension_dn) {
and
--- squid_ldap_group.8.original 2008-01-10 11:08:21.000000000 -0200
+++ squid_ldap_group.8 2008-01-07 11:36:45.000000000 -0200
@@ -152,6 +152,10 @@
Strip NT domain name component from user names (/ or \\ separated)
.
.TP
+.BI -K
+Strip Kerberos Realm component from user names (@ separated)
+.
+.TP
.BI -d
Debug mode where each step taken will get reported in detail.
Useful for understanding what goes wrong if the results is
To allow or deny some user with account in Active Directory based on they group membership, you can use Ldap to check the this using this lines on squid.conf:
external_acl_type ldapgroup %LOGIN /usr/local/squid/libexec/squid_ldap_group -b DC=bc -f
"(&(objectclass=person)(sAMAccountName=%v)(memberOf=cn=%a,OU=Security Groups,DC=REALM))" -D
CN=user_to_bind_in_ldap,CN=Users,DC=REALM -w password -h ldap-server.domain -v 3 -K
acl ldapgroup-access external ldapgroup @users_group
http_access allow all ldapgroup-access
Is possible to check other attributes as well, just change your Ldap query.
January 19, 2008 at 3:30 pm |
If you submit these patches via bugzilla (http://bugs.squid-cache.org/) then we’ll get them included. If they’re not already done, that is. :0
January 21, 2008 at 10:30 am |
It was already done. Thank you.
January 23, 2008 at 12:12 pm |
Thank you for your interesting scenario, it will help to implement without too much error
I have a question for you : Does your solution is working with proxy chaining like transparent proxy ?
Does the transparent proxy let the auth pass thru?
Best Regards
Marc Blanchard
http://marc-blanchard.com
January 23, 2008 at 12:22 pm |
No, I don’t try it on a transparent proxy, but I know that squid has problems with authentication and transparent proxy… If you try please let me know.
Klaubert
February 20, 2008 at 3:15 pm |
Great article.
I am hoping to move on to getting Squid and Kerberos working myself, but first I have the following problem.
While I have got squid_ldap_auth (and for that matter pam_auth) working, I am struggling with squid_ldap_group, maybe you or someone else can help. My server uses OpenLDAP.
My groups are in cn=groups,dc=example,dc=com my users are in cn=users,dc=example,dc=com and my LDAP server accepts anonymous searches. However I cannot get a command that works so that I can verify a user is a member of a specific group.
For example, I am trying to verify a user called ‘test’ is a member of the ‘internet’ group.
The internet group in this example would have a DN of cn=internet,cn=groups,dc=example,dc=com and membership would be a list of memberUid entries. A user would have a DN of uid=test,cn=users,dc=example,dc=com.
For your information the following squid_ldap_auth commands work for me
squid_ldap_auth -b “cn=users,dc=example,dc=com” -f “(uid=%s)” -h 127.0.0.1 -v 3
squid_ldap_auth -b “cn=users,dc=example,dc=com” -u cn -f “(cn=%s)” -h 127.0.0.1 -v 3
March 17, 2008 at 12:22 pm |
Negotiate authentication can’t be used by IE6 to authenticate with the proxy server. See Microsoft KB article here: http://support.microsoft.com/kb/321728/. I have confirmed via tcpdump on the server that IE6 doesn’t send ‘Proxy-Authorization: Negotiate’.
IE7 is OK.
April 4, 2008 at 3:05 am |
Thanks for the tips.
I’ve just spent like over a day trying to get this to work. After poring through C source code, trying to setup Kerberos with both Squid 2.6 and Apache2, etc and only getting “invalid token” errors, I finally have it working.
I discovered keytab (from Microsoft) which shows all the kerberos tickets on your XP computer and whether they were expired or not. It turns out that all my tickets were expired. After locking my screening and logging back in, the tickets got purged and reset and now I can auth to both Squid and Apache.
What a PITA. Anyways now I can proceed with my testing. Hopefully this ticket expiry thing won’t be a big problem in production.
June 19, 2008 at 9:43 pm |
Somehow i missed the point. Probably lost in translation
Anyway … nice blog to visit.
cheers, Primeval!
August 4, 2008 at 7:37 am |
Hi there
Very informative article, thanks very much!
Can I just ask a (perhaps) naive question though? Are there no dependencies on Samba in this solution? It’s just that I’ve been discussing this solution with colleagues and the opinion is that we need Samba4 installed to get Kerberos/negotiate to work. Your article seems to indicate otherwise, but I thought it best to check.
TAL
Pablo
August 4, 2008 at 12:04 pm |
Pablo,
the Samba 4 is not used in my setup, the kerberos authentication is squid native, and don’t has samba as a dependency.
Klaubert
August 27, 2008 at 6:40 am |
Hi folks,
after testing squid_kerb_auth i always get strength mesage :
#squid_kerb_auth: gss_accept_sec_context() failed: Invalid token was supplied. No error
BH gss_accept_sec_context() failed: Invalid token was supplied. No error
#squid_kerb_auth: User not authenticated
It should mean, that keytab and user match together, but windows doesn’t want to replay…????
How i can get thru this????
Petr
October 6, 2008 at 10:30 pm |
[...] Squid kerberos authentication and ldap authorization in Active Directory « Klaubert’s Blog [...]
October 20, 2008 at 11:56 pm |
great article, are there any builds of squid currently that already have kerberos support (squid_kerb_auth) compiled in with it. I am using v. 2.6 that comes with cent os 5.1 and it does not seem to include it.
October 21, 2008 at 12:18 am |
IG,
a guy from RedHat (Mnagy) has the pre-release packages hosted here: http://people.redhat.com/mnagy/squid/, it come with squid_kerb_auth but, at least currently (squid-2.6.STABLE20-1.el5 ), no squid_ldap_group patched (my patch was included in squid main source). I already use the rpm package, but compile myself the ldap_group authorization module.
Klaubert
October 24, 2008 at 12:39 pm |
please let me know how do I patch squid_ldap_group for stripe kerberos realm
thanks a lot,
Dario
October 24, 2008 at 2:32 pm |
Houston,
you don’t need to patch it any more, it was merged in squid source. The lasts stable releases include it.
Klaubert
October 28, 2008 at 10:34 pm |
I had problems with the squid_ldap_group module, so made my own. It uses the ldapsearch script, so no patching compiling is necessary. This is tested and working on Debian Etch (stable).
Usage in squid.conf:
external_acl_type LDAP ttl=60 children=5 concurrency=1 %LOGIN /usr/local/bin/squid-group-plugin.sh
Then map your AD groups to a Squid ACL:
acl StudentGroup external LDAP Students
# this will send the user and “Students” to the
# plugin to see if user is in AD “Students” group
here are the contents of the plugin:
BASE=”dc=mydomain,dc=ca”
HOST=”controller.mydomain.ca”
BIND=”squid@mydomain.ca”
PASS=”bindpass”
REALM=”MYDOMAIN.CA” # strip this off.
TIMELIMIT=1 # seconds
LOG=”/tmp/squid-groups.log”
IFS=” ”
while read IGNORE S_USER S_GROUP; do
S_USER=`echo $S_USER | sed -e s/@${REALM}//g`
QUERY=”(&(objectClass=person)(sAMAccountName=$S_USER)(memberOf=CN=$S_GROUP,CN=Users,DC=MYDOMAIN,DC=CA))”
FOUND_NAME=`ldapsearch -L -L -L -l $TIMELIMIT -b “$BASE” -h $HOST -D “$BIND” -w $PASS -x $QUERY ‘name’ |grep ^name 2>/dev/null`
if [ "$LOG" != "" ] ; then
echo `date` [$$] “u=$S_USER g=$S_GROUP f=$FOUND_NAME” >> $LOG
fi
if [ $? != 0 ] ; then
echo “ERR”
elif [ "$FOUND_NAME" != "" ] ; then
# found the name of user in AD.
echo “OK”
else
# couldn’t find name or some other problem.
echo “ERR”
fi
done
October 28, 2008 at 10:35 pm |
Sorry – I said that ldapsearch is a script but it’s actually a compiled binary.
October 28, 2008 at 10:37 pm |
I also forgot to mentioned that I had to recompile the Debian Squid package to enable the negotiate support. If anybody needs the steps for it, let me know
December 3, 2008 at 2:30 pm |
I wonder if you need the user enters the username and password, each time the user opens the browser he must inform the login and password?
March 30, 2009 at 8:19 am |
Hi,
thanks for this tutorial ! I’ve set up a Squid 2.7 on OpenBSD 4.4 and all works like a charm when trying to access with Firefox 3.0.7 to HTTP and HTTPS web sites: no authentication is asked to the users that have already opened their Windows session. But if i try a ftp request in Firefox like ftp://ftp.openbsd.org for example, Squid asks to authenticate again and again, however i can acces the ftp server.
Any idea why the kerberos ticket is not used in this case ?
Thanks
March 30, 2009 at 10:01 am |
Hi Morgan,
I actually don’t remember to try access for ftp, so I can’t answer you now. If I can try this lather I’ll let you now.
Klaubert
June 9, 2009 at 8:48 am |
I think you have not mentioned how to create a keytab file for linux. Or I failed to understand? I don’t know. I am a complete n00b for Kerberos. I will be thankful to you if you let me know how to create keytab for linux.
June 9, 2009 at 1:49 pm |
Actually I do! In the post is the “Windows Step:”, this step is done in Windows, but the file generated on it is used on Linux.
June 15, 2009 at 9:03 am |
OK.. But there must be a way to create that file on gnu/linux machine. I want to create same file using gnu/linux and not Windows. Please let me know. I googled it but couldn’t find anything helpful.
June 15, 2009 at 10:09 am |
Hi,
its not exactly an option to make this file on windows, its mandatory, once that you will need to associate this the Windows User, that you create on AD, to be used on Squid. This, off course, if you want to use Windows AD as a Kerberos authentication.
But if you want to use other Kerberos system (like MIT or Heimdal) you’ll need to make an similar process there, but for now I can’t help you on this.
Best regards,
Klaubert
June 16, 2009 at 4:36 am |
no problem, thanks
September 16, 2009 at 10:23 am |
Its very helpful, thanx
October 6, 2009 at 3:17 am |
greenmango0
You can create the keytab on linux if you integrate samba using net commando, for example:
# net ads keytab CREATE
# net ads keytab ADD HTTP
November 5, 2009 at 11:53 pm |
Nice tutor… thanks..