Agile Development Tools Server Part 1 - Subversion

Wednesday, 5th January 2011 - Michael Halls-Moore - 3 Comments

Creating an agile development tools server is possibly the biggest time saver for a developer when beginning a startup. Frantically running a manual deployment process, hacking together code from five developers without version control or breaking code without running unit tests are common scenarios which can be eliminated via the proper use of agile tools, in particular an agile tools server.

This is Part #1 of a series of tutorials which will show you how to build a highly robust server that you can use for version control, project management, continuous integration and full stack monitoring. In the first part we will cover setting up a version control repository using the open source Subversion (SVN) agile tool on the Ubuntu Server 10.04 LTS operating system.

The first step is to obtain yourself a fresh Ubuntu LTS machine (virtual or physical!). If you are just trying out some agile development tools and wish to give SVN a go, I recommend following my other tutorial on setting up a web development environment with VirtualBox and stop when you reach "Configuring the Virtual Machine". Alternatively, you can start a micro server instance in Amazon EC2 with one of the Canonical AMIs. I outline the basics of how to do that in my other tutorial on Desktop Ubuntu in Amazon EC2 - The Right Way. You can follow everything up until "Desktop Installation".

We will set up the tools box up by installing the Apache2 webserver, using it to serve SVN across SSL so that we have a secure encrypted connection to our repository. This stops others sniffing our packets and stealing our prized code! In addition we will enforce user read/write privileges so that we can choose who can modify our codebase.

Let's begin by updating and upgrading our server so that it has the latest security updates. Log onto the server and type:

sudo apt-get update
sudo apt-get upgrade

I generally install some "admin packages". These include my favourite text editor Emacs 2.3, htop (a much more usful version of top), screen (multiple terminals in one terminal!) and build-essential for all any compilation via source that may be required:

sudo apt-get install build-essential emacs23 htop screen

The next step is to install all of the packages that Subversion requires in order to run. We install Apache and SVN, then the Python Module for Apache and Python-Subversion which is used to communicate with your repository via Python, funnily enough!

sudo apt-get install apache2 subversion libapache2-svn \
libapache2-mod-python python-subversion

We are now going to create a permanent location for your repository. I tend to create my repos outside of the home directory as I may need to change usernames at a later date. Let's put our repo in /var/lib/svn. To achieve this we run a subversion command, svnadmin, which populates the repo directory with all of the necessary configuration and storage files:

sudo mkdir /var/lib/svn
sudo svnadmin create /var/lib/svn/repo

We need to make sure that Apache has access to this repo, so let's change the ownership recursively (-R) to the www-data user for the svn directory:

sudo chown -R www-data:www-data svn

We now need to create a skeleton codebase to import into our new repository. You may already have a codebase in use that you wish to you add, in which case you should add the code underneath the /tmp/myproject/trunk directory below, otherwise follow the proceeding steps to create a new codebase:

sudo mkdir -p /tmp/myproject/branches
sudo mkdir /tmp/myproject/tags
sudo mkdir /tmp/myproject/trunk
sudo svn import /tmp/myproject \
file:///var/lib/svn/repo/myproject -m "Initial import"

The next step involves configuring Apache to make use of the encryption provided by a Secure Socket Layer (SSL). SSL makes use of public-private key encryption. The "plaintext" is encrypted via the public key and decrypted via the private key. In order to employ SSL with Apache it is necessary to use a signed certificate which usually involves authenticating our identity against a third party. In this instance we will use a self-signed certificate as there is no need to prove to third parties (i.e. website users) that we are, indeed, who we say we are. Let's install SSL:

sudo apt-get install openssl

Now we need to generate our keys and certificates. We are going to use the genrsa command to create an RSA-based DES3 key (of 1024-bit strength) for our Certificate Signing Request (CSR):

openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr

You will be prompted for a challenge password. It is convenient, but highly insecure, to leave this blank. I recommend you do not leave it blank.

Note: Upon rebooting the server once all of this installation is complete, apache2 will initialise and prompt you for this passphrase. On my VM I did not yet have keyboard access to the TTY and hence I was unable to enter it. The only way I could (immediately) find around this problem was to create an insecure key without a passphrase. I wasn't fussed as this was a test VM. On a live server I would have to spend longer thinking through the issue. Any suggestions would be greatly appreciated in the comments!

Now that we have created our key for our signing request, it is time to actually self-sign our certificate. We input our signing request and our key and output the SSL certificate file. Then we copy the files to Ubuntu's SSL directory. Finally, we enable the SSL Apache module with the shortcut a2enmod:

openssl x509 -req -days 365 -in server.csr \
-signkey server.key -out server.crt
sudo cp server.crt /etc/ssl/certs
sudo cp server.key /etc/ssl/private
sudo a2enmod ssl

It's time to configure Apache to serve our SVN repository over SSL. We need to create a basic authentication htaccess password file so that any random Joe who points their web browser at https://svn.yourproject.com/ is not allowed to view your codebase. Run the htpasswd command to create a new user myuser. You will be prompted for a password:

sudo htpasswd -cm /etc/apache2/svn.passwd myuser

In addition, we need to tell Apache to listen to port 443 (the default HTTP SSL port) so let's open up the virtual host configuration file and add in a NameVirtualHost for that port:

sudo emacs /etc/apache2/conf.d/virtual.conf

Add the following lines in the appropriate place:

NameVirtualHost *:80
NameVirtualHost *:443

Now we need to create the configuration for the SVN virtual host itself. I've called it svn-myproject but you are free to call it anything that does not clash with another virtual host. We're going enforce SSL encryption and basic auth. The listing below should be reasonably self-explanatory regarding your own server information:

sudo emacs /etc/apache2/sites-available/svn-myproject

Now add the following in the file, replacing the ServerAdmin and ServerName attributes as necessary:

<VirtualHost *:443>
  ServerAdmin youremail@myproject.com
  ServerName svn.myproject.com
  DocumentRoot /var/www/myproject
  SSLEngine on
  SSLOptions +StrictRequire
  SSLCertificateFile /etc/ssl/certs/server.crt
  SSLCertificateKeyFile /etc/ssl/private/server.key
 
  <Location />
    DAV svn
    SVNPath /var/lib/svn/repo
    AuthType Basic
    AuthName "My Project SVN Server"
    AuthUserFile /etc/apache2/svn.passwd
    Require valid-user
  </Location>
</VirtualHost>

Let's create the web root to stop Apache throwing a warning about non-existent directories:

sudo mkdir /var/www/myproject

Enable the site and reboot Apache:

sudo a2ensite svn-myproject
sudo /etc/init.d/apache2 restart

You can test that your repository is working by visiting your repo (don't forget to prefix with HTTPS) in your browser with the IP/domain configured as for your virtual host configuration above. It is quite handy to be able to browse the structure over a web connection sometimes!

Currently this will give any user who passes the basic auth test full read/write access to your repository. To allow more fine-grained access, you can edit the /var/lib/svn/repo/conf/authz file and add usernames with read and write privileges ("r", "w" or "rw"). This is particularly useful if you are working in a team or wish to share your repo over the internet and only want to allow the masses read access.

In the next set of agile tools development server tutorials I will outline how to install Trac for project management, continuous integration and monitoring tools as well as off-site backup strategies.

I'd love to hear about other setups being used - perhaps Git or Bazaar with alternative project management tools. If there's anything you think I've left out, please let me know - I want the tutorial to be as accurate as possible!

3 comments ... read them below or add one
  • 6th January 2011
    5:47 am

    We use git, gitosis, and viewgit for our version control. I'm writing a web frontend to gitosis so that its easier to add/change permissions. Looking forward to see about trac and CI :)

  • 6th January 2011
    6:48 am

    Hi Nigel, thanks for stopping by.

    I tried using git for a while but I never quite got the hang of it. I'm not currently in a multiple developer environment so I haven't really had a chance to try it properly. I've heard many good things though. I will probably use it on my next hobby project (whatever that may be!). Gitosis presumably makes hosting easier?

    I'll be very keen to see the web front end when it's done. Have you got a link to a beta version?

    Mike.

  • Cata
    11th April 2011
    3:12 pm

    Hello. Perfect article for me!

    I set up all, but when I SVN Checkout from Tortoise it's telling me:
    Error: OPTIONS of 'https://ip': Server certificate was missing commonName
    Error: attribute in subject name (https://ip)

    What I am doing wrong?
    Thanks!