How to add a new user to SVN on Apache

Problem:

I’ve started working on an existing project and needed to add myself as a user to the repository. It proved kinda tricky. First I couldn’t get Tortoise to authenticate, then I couldn’t add myself as a user, and then I couldn’t work out how to put a password on my svn user.

Solution:

Tortoise won’t authenticate

The previous developer left me his username and password, but try as I might it didn’t seem to work. Turns out it does work, the problem is that if you don’t select the little “Save Authentication” option it asks you over and over and over for the authentication. You think it is not working even though it is…

So try selecting “Save Authentication” before concluding that the user/pass is wrong.

Add myself as a Subversion user

It just wouldn’t do to start updating the repository using someone else’s name. So I need to add myself as a user of the subversion repository.

First problem I had here was determining whether I was accessing SVN through “svnserve” or the apache module “mod_dav_svn”, both appeared to be installed and running. The answer is pretty obvious if you stop and look at the problem. If the URL you’re using includes a port number, like “:3630″ then you’re probably using svnserve. If the URL does not have a port and is something like “http://foobar/svn/project” then it is accessing through the apache mod.

Great so I’m looking for the authentication apache is using, now how do I add myself as a user?

I have access to the box so I find and look at the httpd.conf. In this case (FreeBSD) it was at “/usr/local/etc/apache22/httpd.conf”. In this instance it in turn pulled in another conf file at “/usr/local/etc/apache22/Include/httpd-vhosts.conf” which had this…


        <location /svn>
                DAV svn
                SVNParentPath /var/svn
                AuthType Basic
                AuthName "Subversion Repository"
                AuthUserFile /var/svn/svn-auth-file
                Require valid-user
        </location>

It tells me where the file is that provides authentication, namely “/var/svn/svn-auth-file”.

Now all the documentation I could find told me to run “htpasswd /path/to/file john” and we’d be done. But when I tried that it would prompt for a password and fail with


The file does not appear to be a valid passwd file

Now there was something about that file which confused me. It did not look like a standard passwd file. It has the groups in it as well… something like this:


[groups]
foo7group = bob, sally, bruce, john

[foo7:/]
@foo7group = rw

bob:$apr1$mp3HK/..$asfdaasfdaasfdaasfda
sally:$apr1$M4XB7...$asfda23lkkj2l3k3jl23k
bruce:$apr1$P5eCH/..$asfdowiuerowkerlk3lkj
john:

There was nothing about being able to include groups in the password file in the documentation. But to cut a long story short, clearly you can because when I edit this file and append myself without a password (as shown) I was able to access the repository, without a password!

Give myself a password

Ok, that’s progress, I at least know I’m on the right track, but obviously open access with my name is not ideal. I can’t get the htpasswd command to work on this file, so how do I add my password?!

I added it manually by using this to encrypt the password and appending it to the auth file thus. I managed to deduce that the encryption method everyone else was using is “apr1″ from the “$apr1$” prefix, so I’ve followed suit…


sudo openssl passwd -apr1 foobar >> /var/svn/svn-auth-file

Now clean it up with “vi” (Capital “J” to join lines) or editor of choice.

Ta-da. Now that was more work than expected, but finally I am a bona-fide contributor to the respository. I enter “john” and my password to tortoiseSVN, click “Save Authenication” and it all works as advertised.

This entry was posted in geek and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>