Posted by wvreeven
on March 15, 2010 at 8:30 AM PDT
There are several ways to enable user authentication for web based applications, like .htaccess files, plain tekst files, databases, LDAP, etc. They all have their pros and cons. In case a central, flexible solution is needed, either a database or LDAP solution can be used.
I chose for an LDAP solution since it can be reused by many web and application servers and the applications that run on them while many LDAP solutions provide excellent tooling and easy configuration. Since Yenlo strongly focuses on GlassFish and other Sun tools, I chose OpenDS to authenticate against.The idea is to create a bunch of users and put them into one or more groups. Each group gets access to one specific Subversion repository and every user that needs access to a certain subversion repositoy needs to be in the corresponding group.
This blog describes the basic steps I took to get Basic HTTP authentication for Subversion using Apache2 and OpenDS.
Setting up the server
The server is running on Debian Etch, for which most of the required software is available via the Debian package repository. The packages I installed are
Apart form these packages I downloaded and installed the OpenDS 2.2 zip file from the OpenDS homepage . For this purpose I created a user and a group called “opends” and the directory /usr/local/opends which I gave both ownership and group “opends”. Next I logged in as user opends and extracted the zip file into that directory. Finally, as root, I created a start and stop script and used the update-rc.d script to make sure OpenDS is automatically started and stopped when the server is started and stopped.
Setting up Subversion
Let’s suppose that our organisation has decided to create a Subversion repository for each development project that we do. This means that we would get a directory structure like this, with the leaves being the root directories of each repository:
The repositories were created as root using these commands in the /usr/share/subversion directory
# svnadmin create repository1
# svnadmin create repository2
That’s all the configuration that was done to the Subversion repositories.
First, a basic setup of OpenDS needed to be done using the command
For more info about this, see Setting Up the Directory Server . Please note that if you are not running OpenDS as root user, it will listen on port 1389.
The next step was to configure OpenDS so it contains a few users and groups. The main configuration tool for OpenDS is called control-panel and, in my case, it can be started as user “opends” by issuing this command:
With this tool, among other things, you can manage the entries in the directory. For my purpose I created the next layout
base dn (dc=yenlo,dc=nl)
organisational unit (ou=devel)
user (uid=wouter1, password = wouter1)
user (uid=wouter2, password = wouter2)
user (uid=wouter3, password = wouter3)
group (cn=group1, uniqueMember=wouter1,wouter2)
group (cn=group2, uniqueMember=wouter2,wouter3)
which is a very simple layout but sufficient for now. Note that I created two Subversion repositories and therefore two LDAP groups, one for each Subversion repository.
Setting up Apache2 to get access to the Subversion repositories
First I configured Apache2 so the two repositories were accessible to anyone using e.g. a web browser. After libapache2-svn is installed, the module should be enabled in the Apache2 configuration files automatically. To verify this, check the
directory and make sure these symbolic links exist
dav.load -> ../mods-available/dav.load
dav_svn.conf -> ../mods-available/dav_svn.conf
dav_svn.load -> ../mods-available/dav_svn.load
If the first link is missing, create it as root using
# a2enmod dav
If the second and third are missing, create it as root using
# a2enmod dav_svn
To make sure the modules are loaded by Apache2, restart the server as root using
# /etc/init.d/apache2 restart
Now some modifications need to be made to the dav_svn configuration file
The idea is that there are two Subversion repositories that need to be configured individually. So, these two entries need to be put in the above mentioned configuration file
SVNReposName “Repository1 Subversion Repository”
SVNReposName “Repository2 Subversion Repository”
Now, if you point your browser to either http:///svn/repository1 or http:///svn/repository2 you should see the root of your repository.
Adding LDAP support using OpenDS
In order to use LDAP atuentication with Apache2, these two entries should be present in /etc/apache2/mods-enabled:
authnz_ldap.load -> ../mods-available/authnz_ldap.load
ldap.load -> ../mods-available/ldap.load
If they aren’t present, you can enable them as root with these commands
# a2enmod authnz_ldap
# a2enmod ldap
# /etc/init.d/apache2 restart
Now, each entry in /etc/apache2/mods-available/dav_svn.conf should be extended with these lines in order to get LDAP authentication working with OpenDS. Please note that you should pay attention to the group you assign to each subversion repository location. I am only showing the configuration addition for repository1 and leave it as an excercise to you to setup the second repository configuration. Also please note you make sure the correct password for the Directory Manager is provided. For more info about these configuration settings, please consult the OpenDS WIKI page on Apache Web Server .
AuthName “Repository1 Subversion Repository”
AuthLDAPBindDN “cn=Directory Manager”
Require ldap-group cn=repository1,ou=devel,o=yenlo,dc=yenlo,dc=nl
Issue a final
# /etc/init.d/apache2 restart
and you should be prompted for a username and password when you try to access either repository. Using the correct uid and password combination should grant you access to the repository.
The authentication mechanism we chose, Basic autentication, posts usernames and passwords in plain text, which potentially could be harmful in case someone sniffes the connection. I would strongly recommend to setup SSL based connections. Moreover, this blog post only shows how to secure one repository layout using LDAP. Both Subversion and Apache are sufficiently flexible that other layouts are possible. Those layouts most likely require tweaking of the Apache2 configuration options. Finally, I am not an LDAP expert so the directory structure I chose in OpenDS most likely can be much improved. However, following the steps in this article should get you on your way to using OpenDS incombination with Apache2.
This entry was originally posted on the Yenlo B.V. weblog .