Pages

Thursday, October 9, 2014

Sub version in Linux

Subversion is a free/open source version control system (VCS). That is, Subversion manages files and directories, and the changes made to them, over time. This allows you to recover older versions of your data or examine the history of how your data changed.

In this article we will see how we can configure a Sub version in Linux.

1. In order for the sub version to work we need a couple of tools to be available. Install the tools using yum install -y subversion mod_dav_svn

2. Once the tools are installed, We need to make changes to the svn configuration file. The file exists in /etc/httpd/conf.d/ subversion.conf. The final version of this file after making changes looks as

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

<Location /svn>
   DAV svn
   SVNParentPath /var/www/svn
   AuthType Basic
   AuthName "subversion repositories"
   AuthUserFile /etc/svn-auth-users
   Require valid-user
</Location>

I added the modules to be loaded and also user file.

3. Create a user “sk” for the svn repo using

[root@localhost conf.d]# htpasswd -cm /etc/svn-auth-users sk
New password:
Re-type new password:
Adding password for user sk

4. Once the user is created, we need to create a repository where we push the file. Use the following commands to create the directory structure

[root@localhost conf.d]# mkdir /var/www/svn
[root@localhost conf.d]# cd /var/www/svn/

Once the directory structure is created, we need to create a repository using the svnadmin command as
[root@localhost svn]# svnadmin create test_repo
Now the test_repo svn is created.We need to change the permissions using
[root@localhost svn]# chown -R apache.apache test_repo/

Now if we check the files available, we will see
[root@localhost svn]# ll
drwxr-xr-x. 6 apache apache 4096 Oct  9 17:41 test_repo

5. The next thing is we need to change the security level for the svn. We can do this using
[root@localhost svn]# chcon -R -t httpd_sys_content_t /var/www/svn/test_repo/
[root@localhost svn]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/test_repo/

6. Make sure the port 80 is accepted in the Iptables. For this make changes as below

[root@localhost svn]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT
COMMIT

Add the bold lines to the file.

7. Once the changes to security is changes, restart the iptables using
[root@localhost svn]# service iptables restart
iptables: Flushing firewall rules:                                             [  OK  ]
iptables: Setting chains to policy ACCEPT: nat mangle filte          [  OK  ]
iptables: Unloading modules:                                                [  OK  ]
iptables: Applying firewall rules:                                                      [  OK  ]

8. Restart Apache using
Service httpd restart

9. Test the subversion using

The url will ask for a User name and password. For this we will use the sk and the password created in step 3

Disable anonymous access
In order to disable anonymous access to users, we can change the setting in the svnserve.conf file. For this go to the test_rpm location

[root@localhost test_repo]# ll
drwxr-xr-x. 2 apache apache 4096 Oct  9 17:41 conf
drwxr-sr-x. 6 apache apache 4096 Oct  9 17:41 db
drwxr-xr-x. 2 apache apache 4096 Oct  9 17:41 hooks
drwxr-xr-x. 2 apache apache 4096 Oct  9 17:41 locks
-rw-r--r--. 1 apache apache  229 Oct  9 17:41 README.txt
-r--r--r--. 1 apache apache    2 Oct  9 17:41 format

[root@localhost test_repo]# cd conf/
[root@localhost conf]# ll
-rw-r--r--. 1 apache apache 1080 Oct  9 17:41 authz
-rw-r--r--. 1 apache apache  309 Oct  9 17:41 passwd
-rw-r--r--. 1 apache apache 2279 Oct  9 17:41 svnserve.conf

Un comment the lines in the svnserve.conf location as

anon-access = read
auth-access = write

Import Sample content
Once the configuration of SVN is done, we need to import some files to the repository. For this create a sample directory structure as

mkdir subversion-test
cd subversion-test
mkdir subversion-test/updates
mkdir subversion-test/fix
mkdir subversion-test/softwares

Now import the files using
[root@localhost dump]# svn import -m 'First Test Import' subversion-test/ http://localhost/svn/test_repo
Authentication realm: <http://localhost:80> subversion repositories
Password for 'root':
Authentication realm: <http://localhost:80> subversion repositories
Username: sk
Password for 'sk':
Adding         subversion-test/updates
Adding         subversion-test/fix
Adding         subversion-test/softwares

Committed revision 1.

More to Come, Happy learning J

No comments :

Post a Comment