Single Sign On with Active Directory

This will show how to install Plone on a fresh install of Debian 4.0r2 that will authenticate with Active Directory for a single sign on (SSO). This site will be an intranet with apache2 in front of the Plone site. Also I will show how to configure ssl for the site.

Purpose

Create an intranet for employees. This should be a SSO that way I will not hear employees complain about having to enter their passwords more than one time. The authentication is to a Windows 2003 Active Directory. 

Prerequisities

I will be using LDAPUserFolder, LDAPMultiPlugins, apachepas and mod_ntlm2.  My Debian station will have a static IP address of 192.168.1.5.  The name of the site is "project".

Install the following prior to installing Plone. You can use “Synaptic Package Manager” or “apt-get”

      • python-dev

      • readline: libreadline5, libreadline5-dev and readline-common

      • libssl and libssl-dev

      • libxml2 and libxml2-dev

      • wv

      • xpdf

      • PIL (Python Imaging Library)

      • libjpeg

      • zlib

      • libxml2-python

      • python-feedparser

Step by step

Installing Plone 3.1.4 with buildout

  • There is a more in-depth tutorial on buildouts.  Here is the link:

    1. http://plone.org/documentation/tutorial/buildout
  • Open a terminal. In the terminal type the following:

     wget http://peak.telecommunity.com/dist/ez_setup.py

     sudo apt-get install build-essential

     sudo python ez_setup.py

     sudo easy_install ZopeSkel

  • I am going to have Plone install at “/opt” directory in a folder called “Plone3”. In the terminal, type the following:

     mkdir /opt/Plone3

     cd /opt/Plone3

     sudo paster create -t plone3_buildout project

      ***Use the default settings when asked.  Basically hit enter.

     cd project

     sudo python bootstrap.py

     sudo /opt/Plone3/project/bin/buildout

  • At this point, Plone will be installing. When the installation is complete, we will create a new user called "plone" and couple other things to get it started. At the terminal, type:

     sudo adduser –disabled-login plone

  •  Now we need to edit “/opt/Plone3/project/buildout.cfg”. I am using gedit, use whatever you like. At the terminal, type: 

     sudo gedit /opt/Plone3/project/buildout.cfg

  • On "buildout.cfg" file, insert the following on line 52 between "http-address = 8080" and "#debug-mode = on".

     effective-user = plone

  • Now we need to change some permissions so we can start Plone. At the terminal, type:

     sudo chown -R plone /opt/Plone3/project/var/*

  • Redo the buildout. At the terminal, type:

     sudo /opt/Plone3/project/bin/buildout

  • With all that done, we can start Plone. At the terminal, type:

     sudo /opt/Plone3/project/bin/instance start

  • Give it about two minutes to kick in, then open your internet browser and type in the url: "http://localhost:8080/manage"

  • You should see a login window for Zope. When you have logged in, go to the drop-down menu and add a “Plone Site” and call it “project”. Our “project” site will be created and usable. Using you internet browser, type “http://localhost:8080/project”.

 

LDAP Authentication

  • Install “python-ldap”. You can use “Synaptic Package Manager” or “apt-get”

  • Open your internet browser and goto http://www.dataflake.org/software/ and download both “LDAPUserFolder” and “LDAPMultiPlugins”. Extract both archives and then copy both extracted folders to “/opt/Plone3/project/products/” folder.

  • Now restart Zope. Go to your terminal and type:

     sudo /opt/Plone3/project/bin/instance restart

  • When Zope has restarted goto "http://localhost:8080/manage", log in and navigate to your Plone site “project”. In your “project” site, click on “acl_users”. In the drop-down list, the very first listing should be “ActiveDirectory Multi Plugin” select “Add”.

  • “Add Active Directory Multi Plugin to the PluggableAuthService” section will come up. In the properties, insert/change the following:

 SSO_img-01

  • For "User Base DN" and "Group Base DN" use a LDAP browser for the information you need.  And for "Manager DN", you can use any user credentials.
  • Click the “Add” button
  • You will be sent back to the “acl_users” again. Select the AD plugin by the name you gave it ("AD_SSO"). On the functionality page, put a check mark by each (you can uncheck the ones you don't need later).  And then click the “Update” button.

  • Across the top of the page, you should see several tabs. Click the “Properties” tab. Change “groupid_attr” from “objectGUID” to “name” and then save changes.

  • Across the top. Click the “Contents” tab. There should be only one object there, click the “acl_users”

  • Change “User ID Attribute” to “Windows Login Name (sAMAccountName)” and click the “Apply Changes” button

  • Across the top, click the “Users” tab and do a quick search. You should see your users.

  • At this point you should be able to log into your Plone site with your AD credentials. Open a Internet browser and goto http://localhost:8080/project and enter your AD credentials.

Installing Apache2

  • You can use “Synaptic Package Manager” or “apt-get”.

  • After the installation of Apache2, install modules proxy_http, rewrite, and headers with “a2enmod”. Open a terminal and type:

     sudo a2enmod proxy_http

     sudo a2enmod rewrite

     sudo a2enmod headers

     sudo /etc/init.d/apache2 force-reload

  • We will edit the “default” file for apache2, but first let make a backup. Open a terminal and type:

     sudo cp /etc/apache2/sites-available/default /etc/apache2/default.original

     sudo gedit /etc/apache2/sites-available/default

  • I will be using the following IP address as the Apache2/Plone site: 192.168.1.5

  • With "default" still open, delete all the text and then insert the following:

NameVirtualHost 192.168.1.5:80 
<VirtualHost 192.168.1.5:80>
 
ServerSignature On 

   <IfModule mod_proxy.c> 
      <Proxy http://localhost:8080> 
         Order deny, allow 
         Deny from all 
         Allow from all 
      </Proxy> 
   </IfModule> 

   <IfModule mod_rewrite.c> 
      RewriteEngine On 
      RewriteLog /var/log/apache2/rewritelog 
      RewriteLogLevel 3 

      RewriteRule ^/(.*) \ 
         http://localhost:8080/VirtualHostBase/http/%{SERVER_NAME}:80/project/VirtualHostRoot/$1 [P,L] 
   </IfModule> 
</VirtualHost>
  • Goto your DNS server and add a new A & PTR record. IP address “192.168.1.5” and Name “project”.  Or locate your "hosts" file and enter the information.  In Windows, it is located in the "C:\Windows\system32\drivers\etc".
  • Now restart apache2.  Open a terminal and type:
  • sudo apache2 -k restart

  • Now you can use port 80 for the site on a workstation other than the Plone/Debian you are configuring right now. Open an Internet browser and type in the url your ServerName http://project. The Plone site should come up and you can still use your AD credentials.

 Creating the SSO

  • Installing mod_ntlm2
  1. Go to this website: http://mywheel.net/blog/index.php/mod_ntlm2-on-apache-22x/ and install per his instructions. But before doing the third part (compiling), edit “mod_ntlm.c”. Find every instance of “r->proxyreq” and replace with “r->proxyreq && 0”. When this is done, proceed with the rest of the installation. (I found this information at http://www.gossamer-threads.com/lists/zope/users/197385 )

  • Install apachepas 
  1. Download “apachepas” from Plone.org website. The current version is 1.2. In the “readme” file, it mentions “apachepas” does not work well with Plone3. You must use “AutoMemberMakerPasPlugin”. I tried without "AutoMemberMakerPasPlugin" and the Plone site seemed to work alright. 

  2. Install “apachepas” into “/opt/Plone3/project/products/” folder. Restart Zope. Go to your terminal and type:

     /opt/Plone3/project/bin/instance restart

  • Enter your Plone site as admin and goto “Site Setup” then click on “Add-on Products”. Install “apachepas”.

NameVirtualHost 192.168.1.5:80 
<VirtualHost 192.168.1.5:80>
 
ServerSignature On 

   <Location />
	   NTLMAuth on
	   NTLMAuthoritative on
	   NTLMDomain domain
	   NTLMServer AD-Server
	   NTLMBackup AD-Backup
	   NTLMLockfile /tmp/_mod_ntlm.lck
	   Require valid-user
	   AuthType NTLM
	   Satisfy all
	</Location>

   <IfModule mod_proxy.c> 
      <Proxy http://localhost:8080> 
         Order deny, allow 
         Deny from all 
         Allow from all 
      </Proxy> 
   </IfModule> 
   
   <IfModule mod_rewrite.c> 
      RewriteEngine On 
      RewriteLog /var/log/apache2/rewritelog 
      RewriteLogLevel 3 

	   RewriteCond %{LA-U:REMOTE_USER} (.+)
	   RewriteRule .* - [E=RU:%1]
	   
	   RequestHeader set X_REMOTE_USER %{RU}e

      RewriteRule ^/(.*) \ 
         http://localhost:8080/VirtualHostBase/http/%{SERVER_NAME}:80/project/VirtualHostRoot/$1 [L,P] 
   </IfModule> 
</VirtualHost>
  • Restart Apache2. Open a terminal and type:

    • sudo apache2 -k restart
  • Now you should be able to do a SSO from a workstation on your network (not this Debian station). On a workstation located on the network (Windows XP with a user in the acl_user), open “Internet Explorer” and navigate to your Plone site http://project. You should be sign on. If you prefer to use “firefox”, follow these instructions to configure http://sivel.net/2007/05/firefox-ntlm-sso/
    •  

      Installing SSL to the Plone site 

        cd /etc/apache2

        sudo mkdir ssl

        cd ssl

        sudo a2enmod ssl

        sudo /etc/init.d/apache2 force-reload

        sudo openssl genrsa -out site.key 1024

        sudo openssl req -new -key site.key -out site.csr 

      • When prompt, fill in the appropriate information. Remember when you are asked to fill in the “Common Name” use “project”.

         sudo openssl x509 -req -days 60 -in site.csr -signkey site.key -out site.crt

      • Edit “ports.conf” file in “/etc/apache2/”. Insert the following at the bottom:

         Listen 443

      • Edit “default” file in “/etc/apache2/sites-available/”. Insert the following after the first VirtualHost:

      NameVirtualHost 192.168.1.5:443 
      <VirtualHost 192.168.1.5:443>
       
      ServerSignature On 
      
         <Location />
      	   NTLMAuth on
      	   NTLMAuthoritative on
      	   NTLMDomain domain
      	   NTLMServer AD-Server
      	   NTLMBackup AD-Backup
      	   NTLMLockfile /tmp/_mod_ntlm.lck
      	   Require valid-user
      	   AuthType NTLM
      	   Satisfy all
      	</Location>
      
         <IfModule mod_proxy.c> 
            <Proxy http://localhost:8080> 
               Order deny, allow 
               Deny from all 
               Allow from all 
            </Proxy> 
         </IfModule> 
      
         SSLEngine On 
         SSLCertificateFile /etc/apache2/ssl/site.crt 
         SSLCertificateKeyFile /etc/apache2/ssl/site.key
      
      
         <IfModule mod_rewrite.c> 
            RewriteEngine On 
            RewriteLog /var/log/apache2/rewritelog 
            RewriteLogLevel 3 
      
      	   RewriteCond %{LA-U:REMOTE_USER} (.+)
      	   RewriteRule .* - [E=RU:%1]
      	   
      	   RequestHeader set X_REMOTE_USER %{RU}e
      
            RewriteRule ^/(.*) \ 
               http://localhost:8080/VirtualHostBase/https/%{SERVER_NAME}:443/project/VirtualHostRoot/$1 [L,P] 
         </IfModule> 
      </VirtualHost>
        • Restart Apache2. Open a terminal and type:

            sudo apache2 -k restart

        • Now you should be able to do a SSO from a workstation on your network (not this Debian station) using ssl. On a workstation located on the network (Windows XP with a user in the acl_user), open “Internet Explorer” and navigate to your Plone site https://project. You should be sign on using the certificate.

      Now that SSO against Active Directory is working, you should be able to create an extranet by creating another VirtualHost.

      Further information

      Here is a link to a document that shows other configurations for virtual hosting.  http://www.cps-project.org/static/doc/howto-virtual_hosts.html.

       

       

      X_REMOTE_USER = (null)

      Posted by Jonathan Riboux at Oct 21, 2008 08:18 AM
      I had troubles to make it work, but that was my mistake.
      I used the host IP instead of localhost in the proxy section and RewriteRule.
      NTLM authentication on Apache2.2 worked well, but the REMOTE_USER var was empty (and X_REMOTE_USER was "(null)").
      Changed to localhost, REMOTE_USER equals to the user name and the user gets successfully logged in Plone.

      Many thanks for your how-to.

      X_REMOTE_USER = (null)

      Posted by Josh Williams at Feb 24, 2009 01:00 AM
      I am having trouble with the username getting passed along. What exactly did you change?
      You stated "Changed to localhost, REMOTE_USER equals to the user name and the user gets successfully logged in Plone."
      Where is that change made?

      Everytime I go to the Plone site page it asks me for a username and password. I enter my credentials and it returns an Internal Server Error. I have double checked evrything.

      Thanks for your help

      Apache2.2 : RequestHeader instead of RewriteHeader

      Posted by Jonathan Riboux at Oct 21, 2008 08:22 AM
      On Apache2.2, I had to replace the RewriteHeader directive by RequestHeader.
      I don't know if it is a mistake in your how-to or a change in latest mod_headers.

      RequestHeader instead of RewriteHeader

      Posted by John Fugazi at Nov 19, 2008 07:03 PM
      Your right. I made a typo. thanks.

      Many many thanks

      Posted by NicolaBi at Feb 04, 2009 02:33 AM
      With this tutorial it's impossible don't get it! Congratulations for the great work and the explanations!

      What version of python should I use?

      Posted by Piotr L at Feb 11, 2009 02:49 PM
      Hi, I'm using python 2.5.2 on debian/lenny and having compile times errors and finally after:
      sudo /opt/Plone3/project/bin/instance start
      Traceback (most recent call last):
      .....
      NameError: name 'OverflowWarning' is not defined

      And that is the end of story. Wrong python or what?
      Regards
      P.

      What version of python should I use?

      Posted by John Fugazi at Feb 11, 2009 04:13 PM
      zope/plone uses python 2.4. download debian4.0 or use the unifiedinstaller which has the correct python. there is a how-to somewhere that explains how to install with different version of python.

      What version of python should I use?

      Posted by Piotr L at Feb 16, 2009 11:56 AM
      1)
      On debian/testing it was possible to make buildout with python 2.4x, just a soft link from default 2.5 python to 2.4. Second, I have used standard debian packages (plone, zope and python) not the buildout and it worked very well after a few checkups about AD schema. Why have you chosen to use buildouts against debs?

      2)
      Lets say we are at the step in this tutorial, where we can see AD users, so just before 'Installing Apache2'. From this point the password from plone to AD controller goes in clear text? I doubt a bit, but there is no ssl working yet. Hm I assume from my web browser to plone server in clear text, from plone server to AD controller crypted.

      3)
      The big picture. Why use apache in front of plone?

      Regards
      Piotr

      What version of python should I use?

      Posted by John Fugazi at Feb 16, 2009 02:03 PM
      1. it is fine to use the debs, but plone and packages are easier to install with buildout. at least for me, the buildout configuration is easier. i should updated this, because i use in my buildout config - PloneLDAP. i don't download and move LDAPUserFolder nor LDAPMultiPlugins anymore. PloneLDAP has both packages already.
      2. there is a way to connect plone to AD with SSL. i remember seeing this discussion in the forum (http://plone.org/support/forums#nabble-f293351).
      3. apache can authenticate with AD and send username/password to plone with WebServerAuth for a SSO. plus apache is the best for a web server.

      Setup on a Windows (2003) server

      Posted by Yusuf Tran at Mar 10, 2009 07:06 PM
      Advance apologies for my ignorance but would it be possible you can create a guide for windows servers?

      For the past week I've been all round the net and the irc channel and am still at a lost to get this working on a windows server :(, I'm confused with the variant add-ons mentioned in the various articles and get confused by the advice to Not use ones other the other.

      An updated guide for V3 on Windows would highly be appreciated, I'd like to roll this out to our various schools in the UK but need to get my head around configuring it with SSO in our office first.

      If anyone here whose had success with SSO on Server 2003 with Plone 3 would like point me in the right direction that would also be appreciated.

      Many thanks in advance

      Yusuf