23May

Single Sign-On with Apache and Active Directory - Part 1

HowTo, Linux

Part 1 | Part 2

This HowTo will describe how to setup single sign-on authentication with Apache and Microsoft Active Directory. Most of you are probably aware that there is no default/built-in support for automatically authenticating to an Apache web server using the NTLM header information passed from the web browser (in most cases Microsoft Internet Explorer) to the Web Server. Microsoft IIS of course supports this out of the box but who wants to use IIS? There are as I have found 3 major solutions for achieving this and I will outline which I picked and why.

First I’ll start by explaining which solution I selected and why. There are 3 major solutions for this which are mod_ntlm, mod_auth_kerb and Apache2:AuthenNTLM. I have chosen Apache2:AuthenNTLM. Now as for the why…I bypassed mod_auth_kerb instantly after reading that it required a working winbind setup. Keep in mind that I am looking for an easy quick setup, and configuring winbind first does not fall into that realm of a quick and easy setup. Next I tried mod_ntlm which seemed to be very easy to setup and worked well. But there was one catch…If the browser did not send the NTLM information or correct NTLM information1 the user had to login with the username in the form of DOMAIN\username. In my experience with applications already in place they did not require this form of DOMAIN\username. This could be resolved if you could specify the default domain in mod_ntlm which you cannot. Reading the documentation for Apache2:AuthenNTLM you could specify the default domain as well as many other options that are not available in mod_ntlm. Configuration proved to be a little tricky, but if it weren’t I wouldn’t be writing this HowTo. Now as you may have noticed from the naming syntax of Apache2:AuthenNTLM that it is indeed a perl module. Now as we are using Apache2:AuthenNTLM it will require mod_perl2 which is not included with CentOS4 or RHEL4.

Now for the HowTo:

1) Start by installing Apache and mod_perl by issuing the following commands:

shell> yum install httpd
shell> wget http://sivel.net/repo/i386/mod_perl-2.0.3-1.el4.sn.i386.rpm
shell> rpm -Uvh mod_perl-2.0.3-1.el4.sn.i386.rpm

2) Next we need to install the Apache2:AuthenNTLM module

shell> wget http://sivel.net/repo/i386/perl-Apache2-AuthenNTLM-0.02-1.el4.sn.i386.rpm
shell> rpm -Uvh perl-Apache2-AuthenNTLM-0.02-1.el4.sn.i386.rpm

3) Now we need to configure Apache to use Apache2:AuthenNTLM

shell> cd /etc/httpd/conf.d
shell> touch ntlm.conf
shell> vi ntlm.conf

  • Add the following information:
<location /directory> # Change this to the directory you wish to protect.  Can be /
PerlAuthenHandler Apache2::AuthenNTLM
AuthType ntlm,basic
AuthName Basic
require valid-user
#                    domain  pdc  bdc
PerlAddVar ntdomain "DOMAIN  dc1  dc2" # Change DOMAIN to the netbios name of your domain.  Change dc1 and dc2 to the hostnames of the domain controllers for your domain.  dc2 is not required if your setup does not have a dc2.
PerlSetVar defaultdomain DOMAIN # Change DOMAIN to the netbios name of your domain
PerlSetVar splitdomainprefix 1
</location>

shell> vi /etc/httpd/conf/httpd.conf
Find ‘KeepAlive Off’ and change it to ‘KeepAlive On’

4) Now we need to modify /etc/resolv.conf

shell> vi /etc/resolv.conf

  • We need to make sure that it looks like the following:

search domain.lan
nameserver 10.0.0.1
nameserver 10.0.0.2

  • Where domain.lan is your Active Directory domain name and the nameservers are the name servers for your Active Directory (usually the domain controllers)

5) Let’s start Apache

shell> /etc/init.d/httpd start

6) Let’s setup a simple test page that will utilize the server environment variable that AuthenNTLM sets.

shell> cd /path/set/in/step/3
shell> touch index.php
shell> vi index.php

  • Insert the following information:

<?php echo "You have logged in as <b>" . $_SERVER['REMOTE_USER'] . "</b>;"; ?>

  • If you do not see your username then you don’t have something in step 3 setup correctly. If you get a login prompt check the footnotes below.

Part 1 | Part 2

  1. Getting a login prompt can be caused by using Firefox with the default configuration, not being logged on in the domain that you are attempting to authenticate against, or not having the site listed in the Local Intranet security zone in Internet Explorer. Or worst of all you could have mis configured something in step 3. You can turn on debug information by adding ‘PerlSetVar ntlmdebug 2′ to step 3. Debugging will log to /var/log/httpd/error_log. []
7 comments

Comments

  1. Gravatar Posted by cs on Thursday 5th July

    Looks cool, but :
    [24809] AuthenNTLM: Authorization Header
    [Thu Jul 05 17:02:14 2007] [error] Bad/Missing NTLM/Basic Authorization Header for /

    I saw this message many times on google, but no answer. On my client, IE and also firefox are configured to do a NTLM negociation with my server.

  2. Gravatar Posted by cs on Thursday 5th July

    Problem solved ! :)

    I had a long domain name with dots in this variable :
    PerlAddVar ntdomain “DOMAIN.FOO.BAR PDC BDC”

    I replaced “DOMAIN.FOO.BAR” by the short domain name “DOMAIN” and now it works.

  3. Gravatar Posted by Adam Nielson on Tuesday 12th February

    Ok, I followed the directions, and I get:

    [error] Bad/Missing NTLM/Basic Authorization Header for /

    I am trying to access the index.html file I created as you suggested. It just loads up and says:

    ” . $_SERVER[’REMOTE_USER’] . “”; ?>

    I am trying to get this to work with OTRS.

  4. Gravatar Posted by Matt on Wednesday 13th February

    @Adam: The file should be index.php. The instructions above need to be fixed. And just to make sure that it is written correctly above the code should be:

    <?php
    echo "You have logged in as <b>" . $_SERVER['REMOTE_USER'] . "</b>";
    ?>

    I’ll fix the instructions above very soon.

    As for the error you will sometime get that even though this is working.

  5. Gravatar Posted by Adam Nielson on Wednesday 13th February

    Cool! Thank you very much! Its working now and the index.php file is reporting back properly!

    Now… any ideas how to get OTRS to work with it? :)

  6. Gravatar Posted by zerocool on Monday 17th March

    I have a problem setting this up, i get ==> You have logged in as ;

    this is my ntlm.conf file
    —————————–

    PerlAuthenHandler Apache2::AuthenNTLM
    AuthType ntlm,basic
    AuthName Basic
    require valid-user
    # domain pdc bdc
    PerlAddVar ntdomain “EXAMPLE server.EXAMPLE.COM″
    PerlSetVar defaultdomain server
    PerlSetVar splitdomainprefix 1

    (offtopic:I already tried working with mod_auth_kerb and mod_auth_ldap but i allways get the login prompt that keeps popping up, and if check the apache logs, it says cant find KDC?)

  7. Gravatar Posted by Stan on Friday 18th April

    I have the same issue as zerocool and IE keeps popping up login dialog

    logs show Bad/Missing NTLM/Basic Authorization Header for /test/viewlist.php

Pingbacks

Leave a reply