Single Sign-on for Your Web Applications with Apache and Kerberos
Pages: 1, 2
Setting Up the Web Server
First, you'll have to create a service principal for the Apache server. This service
principal will be named HTTP/hostname@REALM. Our example will be for the host freebsd.wedgie.org, in the w2k.wedgie.org AD domain. The service principal in this case will be HTTP/freebsd.wedgie.org@W2K.WEDGIE.ORG (yes, HTTP needs to be capitalized, as this is the exact service principal that IE will request). This principal will be created in the Active Directory Users and Computers MMC snap-in and the keytab exported via the ktsetup program.
Because Windows usernames cannot contain slashes, you'll have to pick a username that will be mapped to the HTTP service principal. In this case, we will create a user named freebsdhttp. The password set for this account will become the service principal's key, so ensure that the password set for this account is a secure password.
Once the Windows user has been created, then you can map the user and
export a keytab through the ktpass program. ktpass is not installed by default; it
can be found inside of the support/tool subdirectory of the Windows 2000 Server
installation CD. The ktpass command line we will use for our example is:
ktpass -out http.keytab -princ
HTTP/freebsd.wedgie.org@W2K.WEDGIE.ORG -pass * -mapuser
freebsdhttp
Successfully mapped HTTP/freebsd.wedgie.org to freebsdhttp.
Type the password for HTTP/freebsd.wedgie.org:
Key created.
Output keytab to http.keytab:
Keytab version: 0x502
keysize 65 HTTP/freebsd.wedgie.org@W2K.WEDGIE.ORG ptype 1
(KRB5_NT_PRINCIPAL) vno 1 etype 0x1 (DES-CBC-CRC) keylength
8 (0xf253024517c75f80)
Account has been set for DES-only encryption.
The keytab can now be copied from the Windows machine to the Apache server through some secure means, such as secure copy or using a floppy. We will place the keytab into the directory /usr/local/apache/etc, but it can be placed anywhere in the file system. Since the contents of this file are sensitive, it should be readable only by the user the web server runs as.
Compiling the Apache Module
Now we're ready to install mod_auth_gss_krb5. While the instructions on the
SourceForge page show how to build the module statically inside of Apache at
compile time, most administrators prefer the management flexibility of loadable
Apache modules.
Let's step through how you can compile mod_auth_gss_krb5 as a shared
module.
First, you'll need spnegohelp, which is the mini-SPNEGO library that
Microsoft has released on its web site. This library is included with the module
distribution in the spnegohelp directory. Note that there is a pre-processor define
for __LITTLE_ENDIAN__ by default. Those running on processors with big-
endian byte order, such as PowerPC or Sparc, will have to remove this pre-
processor define from the makefile before building spnegohelp.
Now you're ready to compile the Apache module itself. Note that on the
FreeBSD test machine, I had to remove all references to the log() function in
mod_auth_gss_krb5.c. If these aren't removed, you will get unresolved
references to _log in the server's error log when you load the module .
We'll use apxs, the Apache extension tool, to do the dirty work for us. Assuming
that your Apache is installed into /usr/local/apache and MIT Kerberos has been
installed into /usr/local, then the following command will compile and install the
module into the appropriate location:
/usr/local/apache/bin/apxs -i -a -c -DEAPI_MM
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/local/include -L/usr/local/lib
../../../spnegohelp/spnegohelp.a -L/usr/local/lib
-lgssapi_krb5 -ldes425 -lkrb5 -lk5crypto -lcom_err
mod_auth_gss_krb5.c
Now that apxs has compiled and installed the module, we can add the
appropriate directives inside of our httpd.conf file to require authentication for
certain directories. Inside of a <directory> section, insert the following directives:
GssKrb5Keytab "/usr/local/apache/etc/httpd.keytab"
Krb5Keytab "/usr/local/apache/etc/httpd.keytab"
KrbAuthRealm W2K.WEDGIE.ORG
Krb5SaveCredentials Off
AuthType GSS
GssAuth On
AuthName "KRB5 Realm"
require valid-user
The paths to the keytab and the realm name should be changed, of course. Now start the Apache server.
Configuring the Clients
Our next step is to configure the Windows client. Internet Explorer must be set up to recognize that our new Apache server is in the Intranet zone, and instructed to use domain authentication with it. Open up the Internet Options dialog inside of Internet Explorer. The Security tab contains the security zones that Internet Explorer recognizes. Click Intranet and click the Sites button. Click Advanced in the next dialog box, and a third dialog is presented where we can add sites that will be added to the Intranet zone. Click Add and type in the name of your Apache server, in this case "freebsd.wedgie.org." Return to the Internet Options dialog, Security tab. Click the "Custom Level" button for the Intranet security zone. Ensure that "User authentication - Automatic logon only in intranet zone" is selected (at the bottom of the list). Click OK.
If you're using Internet Explorer 6 or above, one more setting must be tweaked. Inside of the Internet Options dialog box, Advanced tab, there is a setting named "Enable Integrated Windows Authentication" inside of the Security group. If this box is not checked, check the box, and restart the machine. More information on these browser settings can be found in the Microsoft MSDN library.
Now that everything is set up, it's time to see if everything works. Open IE and
go to the protected URL on the Apache server. If the page displays, then
congratulations! The full Kerberos username of the client will be inserted into the
REMOTE_USER environment variable on the Apache server side, for example
Administrator@W2K.WEDGIE.ORG. A simple PHP script or server-side include
page can be used to verify that the REMOTE_USER is now set.
Troubleshooting
What could go wrong?
First, let's take a look at what could happen on the client side. Ensure that you're
logged in to the Windows domain and have a valid Kerberos TGT. You can also
check to see if IE successfully acquired a service ticket for your Apache server
through kerbtray, included with the Windows Resource Kit.
Next, make sure that you aren't using a proxy to contact your Apache server. Unfortunately, the Negotiate authentication method does not work through web proxies. Ensure that if a proxy is set, that an exclusion is made for the Apache sever (assuming, of course, that the server is reachable directly).
If instead you're getting internal server errors from Apache, you should make
sure that the GssKrb5Keytab and Krb5Keytab directives give the correct path to
the keytab and that it is readable by the web server's user ID. If problems
persist, then there is probably something going wrong with your Kerberos
configuration.
If you're getting an error message such as :
[Wed Aug 27 01:05:21 2003] [notice] [client 192.168.1.23]
gss_acquire_cred() failed: No principal in keytab matches
desired name:
the GSSAPI libraries either can't read or find your keytab, or
your hostname or realm are misconfigured. Make sure that your hostname
is set correctly; both forward and reverse DNS should map to the correct
hostname. Test it out by doing nslookup queries on the Apache server itself. If
your hostname is configured correctly, then ensure that the AD server is
configured as your default_realm in the /etc/krb5.conf file.
Summary
After performing these steps, you now have an Apache web server that can interoperate with Internet Explorer clients in a Windows domain. Clients who access the protected area of your Apache web server will transparently pass their domain credentials to your web server through the use of Kerberos, with no separate username or password prompts.
O'Reilly & Associates recently released (August 2003) Kerberos: The Definitive Guide.
Chapter 5: "Troubleshooting," is available free online.
You can also look at the Table of Contents, the Index, and the full description of the book.
For more information, or to order the book, click here.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 14 of 14.
-
Nice article, but i still can't get it to work (on FC2)
2005-03-24 12:34:24 Morpheus4you [Reply | View]
I can't get it to work on Fedora Core 2.
The methode where apxs is used doesn't work either, i compile it with this command:
/usr/sbin/apxs -i -a -c -DEAPI_MM \
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
-I/usr/include -L/usr/lib -L/lib \
../../../spnegohelp/libspnegohelp.a -L/usr/lib -L/lib \
-lgssapi_krb5 -ldes425 -lkrb5 -lk5crypto -lcom_err \
mod_auth_gss_krb5.c
But unfortunately it fails with a lot of errors, starting with the next lines...
mod_auth_gss_krb5.c:32: error: syntax error before "gss_krb5_auth_module"
mod_auth_gss_krb5.c:32: warning: data definition has no type or storage class
mod_auth_gss_krb5.c:69: warning: initialization from incompatible pointer type
mod_auth_gss_krb5.c:70: error: syntax error before "gss_krb5_config_rec"
mod_auth_gss_krb5.c:70: error: initializer element is not constant
mod_auth_gss_krb5.c:70: error: (near initialization for `gss_krb5_cmds[0].cmd_data')
mod_auth_gss_krb5.c:71: error: initializer element is not constant
Can this module be build with Apache 2 anyway?
Could it be that the Kerberos implementation coming with Fedora Core 2 is not the right one? (like it requires MIT but FC2 has HEIMDAL)
Has anyone gotten this module to work with Fedora Core in some way?
-
Nice article, but i still can't get it to work (on FC2)
2005-03-28 19:57:26 jason_garman [Reply | View]
Hi, since I wrote the article, the mod_auth_kerb module has integrated support for GSSAPI. Have you tried that? You can find mod_auth_kerb at http://modauthkerb.sourceforge.net/
Thanks
-- Jason -
I'm almost there...
2005-03-29 23:20:01 Morpheus4you [Reply | View]
Thank you for pointing me to that module! I had seen it before, but overlooked it's capability for Negotiate support. btw, I liked your book. It is really helping me to understand how Kerberos works. If possible you should add more information about web authentication via the Negotiate protocol as you did in this article, but i'm confident you will do that ;)
Although transparent authentication via a winXP client with IE6, a webserver Apache 2 on Fedora Core2 and Windows 2003 Active directory as KDC doesn't work yet for me, i can succesfully do password authentication :)
The error that was left behind in Apache's error log for using the Negotiate method was:
[Wed Mar 30 08:44:34 2005] [error] [client 10.0.0.10] gss_accept_sec_context() failed: A token was invalid (Token header is malformed or corrupt)
When on the Fedora Core 2 machine, i try to authenticate using the keytab file, i get the following error:
[root@krbappserver conf.d]# kinit -k -t http.keytab
kinit(v5): Cannot find KDC for requested realm while getting initial credentials
However, this does work:
kinit http/krbappserver.kerberos.local
Password for http/krbappserver.kerberos.local@KERBEROS.LOCAL:
Shouldn't the authentication with the keytabe file just have worked?
-
SPNEGO implementation in Java
2004-04-23 02:26:36 bofriis [Reply | View]
Hi,
The header of the this forum kinda invited me to write about my SPNEGO implementation using nothing but JDK 1.4.
I have written code that can run on client side, either inside an applet or inside a (thick) java application. This code is capable of getting the TGT from either the java ticket cache or the native windows ticket cache. The output is a SPNEGO token.
I have also written server side code that can decode and validate the SPNEGO token coming from either the client side generated code (which in principle could run on Linux or Windows) or the Internet Explorer on windows.
I have tested it using win2k and XP on client side, win2kadv server on server side and the SPNEGO authentication has been tested running on Tomcat on top of JDK 1.4.
I have writtes some articles and a presentation on the subject which I have posted on my site.
/Bo
http://appliedcrypto.com
-
SPNEGO and JAVA
2003-10-24 02:01:22 anonymous2 [Reply | View]
I tried the microsoft spnego lib used in this article with java. I unwrap the spnego token and i pass the byte array to the GSSContext instance acceptSecContext. The error is:
java.lang.IllegalArgumentException: Authentication time of ticket cannot be null
at javax.security.auth.kerberos.KerberosTicket.init(KerberosTicket.java:279)
at javax.security.auth.kerberos.KerberosTicket.(KerberosTicket.java:222)
at sun.security.jgss.krb5.Krb5InitCredential.(Krb5InitCredential.java:118)
at sun.security.jgss.krb5.Krb5InitCredential.getInstance(Krb5InitCredential.java:198)
at sun.security.jgss.krb5.InitSecContextToken.(InitSecContextToken.java:107)
at sun.security.jgss.krb5.Krb5Context.acceptSecContext(Krb5Context.java:584)
at sun.security.jgss.GSSContextImpl.acceptSecContext(GSSContextImpl.java:300)
at sun.security.jgss.GSSContextImpl.acceptSecContext(GSSContextImpl.java:246)
at ifx.gssauth.GSSAuthFilter.doFilter(GSSAuthFilter.java:132)
It looks the context cannot build up its internal representation of the kerberos ticket from the kerberos token. Do you have any ideeas?
Thank you in advance.
-
module segmentation fault
2003-10-22 02:22:50 anonymous2 [Reply | View]
I have tested this module on both apache 1.3.26 and 1.3.27 and I've a segmentation fault of the httpd child process on all http request which use it.
-
Other options...
2003-09-22 21:07:04 anonymous2 [Reply | View]
There's an IETF draft for SASL over HTTP. Since GSSAPI works within SASL this may be a great option to pursue.
The draft is here:
http://www.ietf.org/internet-drafts/draft-nystrom-http-sasl-07.txt







Just thought I'd share a few observations when I used this great article as a launch pad into the SPNEGO universe. Almost all of them are tidbits of information that I gathered on the web in the process, so kudos to those who posted them.
- the SPNEGO stuff is also available in mod-auth-kerb, which happens to be available as a debian package both for apache and apache2 in unstable.
- The directives for the mod-auth-kerb are significantly different from the above, they are well documented on the modules homepage (http://modauthkerb.sourceforge.net/)
- when using the ktpass-tool, you have to specifiy the domain name in addtion to the username (ie. domainname\username) otherwise it bails with a rather obscure error message.
- I used a short php script (well, line) to read out the environment variable:
<?php echo $_SERVER['REMOTE_USER'] ; ?>
just to convince myself that it works.
cheers
okrams