Tuesday, November 10, 2009

Subversion over https met basic authentificatie

  1. Subversion gedeelte

[bron http://odyniec.net/articles/ubuntu-subversion-server/ ]

Begin by installing the Subversion package:

$ sudo apt-get install subversion

You're going to need a directory for your repositories, as well as other Subversion-related files. Most people use /home/svn or /usr/local/svn for this purpose, and you can choose either. I personally prefer /usr/local/svn over /home/svn, as I like to keep /home for home directories of real users of the system.

$ sudo mkdir /usr/local/svn

Inside this directory, create another one to hold your repositories:

$ sudo mkdir /usr/local/svn/repos

Now, you need to set some access permissions on those directories. You only want to allow certain users of your system (that is, yourself and the other developers) to access the repositories, so add a new group for those users. Name the group svn.

$ sudo groupadd svn

Then, change the group ownership of /usr/local/svn/repos to the new group using the chgrp command:

$ sudo chgrp svn /usr/local/svn/repos

The members of the svn group also need write access to the repos directory, so use chmod to add the write permission for the group:

$ sudo chmod g+w /usr/local/svn/repos

Additionally, you need to make sure that all new files and directories created in the repos directory (in other words, anything committed to the repositories) will also be owned by the group. To accomplish this, use chmod again to set the set-group-ID bit on the directory, which causes any file created inside it to have the same group ownership as the directory itself. Effectively, everything in repos will belong to the svn group.

$ sudo chmod g+s /usr/local/svn/repos

OK, so you now have the repositories directory with proper permissions, ready to be used by the svn group. Go ahead and add yourself to the group:

$ sudo usermod -a -G svn michal

However, your new group membership will not be effective for the current session, so you need to log out and log back in. When you're back, you can verify that your account is recognized as a member of the svn group:

$ groups michal adm dialout cdrom plugdev lpadmin admin sambashare svn

If the other developers have user accounts on your server, add them to the group too:

$ sudo usermod -a -G svn jimmy $ sudo usermod -a -G svn craig

If they don't, they will still be able to access the repositories, but only using the basic svn protocol, not the secure svn+ssh method.

Creating a Test Repository

You can now create a repository. In the following steps, I'll demonstrate how to create a simple test repository containing one text file, and how to check out and commit files. If you're not familiar with Subversion, then this could be a good exercise to learn the basics. Otherwise, you can skip all the test checkouts and commits and just create the repository for your project.

The repository will be a subdirectory in the repos directory, and will have its group ownership set to svn (thanks to the chmod g+s you did earlier). However, that's not all – you also need to make sure the repository will be group writable, so that the other members of the svn group will be able to commit files. To do this, set the umask to 002:

$ umask 002

This command sets the new file mode creation mask which controls the default permissions of any new file that you create. The default value is 022 and it corresponds to read/write permissions for the file owner, and read permissions for the group and others. The new value, 002, also gives write permissions to the group, which is just what you need.

Create the repository using the svnadmin command:

$ svnadmin create /usr/local/svn/repos/test

And set back the default umask:

$ umask 022

So you now have an empty repository, waiting for you to commit something to it. But, before you do this, you need to check out the current version (i.e., the empty directory) to create a working copy.

$ svn checkout file:///usr/local/svn/repos/test Checked out revision 0.

The working copy has been checked out to a new directory named test. Go ahead and create a simple "hello world" text file in that directory:

$ cd test $ echo 'Hello, World!' > hello.txt

Then, add it to version control with the svn add command:

$ svn add hello.txt A hello.txt

Finally, commit it using svn commit:

$ svn commit -m "Added a 'hello world' text file." Adding hello.txt Transmitting file data . Committed revision 1.

The hello.txt file is now in the repository.

Apache configuratie

[bron: http://www.debuntu.org/2006/05/20/54-how-to-subversion-svn-with-apache2-and-dav ]

First of all we need to install the required packages:

apt-get install subversion libapache2-svn

Repository structure:

The projects are going to be hosted on /var/svn/repository. We need to create to directories and give full permission to the apache user:

mkdir /var/svn
mkdir /var/svn/repository

Now that the directory exist, we need to give write access to the apache user:

chown www-data:www-data -R /var/svn/repository
chmod 770 -R /var/svn/repository

Configuring Apache:

Now, we need to modify apache svn module configuration file, edit /etc/apache2/mods-available/dav_svn.conf and make sure the following argument are properly setted up:

...
SVNParentPath /var/svn/repository
#SVNPath /var/svn/repository
.....
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
...

In order to be able to track who modify the different files of the project, we need to create users. Create the first user (tester) and supply a password:

htpasswd2 -c /etc/apache2/dav_svn.passwd tester

Creating a first repository:
Get apache user access (so files and directories are created with proper rights:

su www-data

and create your first repository (example):

svnadmin create /var/svn/repository/example

import your project:

svn import /path/to/projectexample file:///var/svn/repository/example/examplev1 -m"initial import"

Now, get back to root user (Ctrl-D) and restart apache:

/etc/init.d/apache2 restart

Your project is now avalaible to the different user you will add in /etc/apache2/dav_svn.passwd .
User tester can now access the project at http://svnhostaddress/example and checkout a first copy to his computer, modify files and commit back his changes to the server.

No comments:

Post a Comment