Project

General

Profile

Repositories access control with apache mod dav svn and mod perl » History » Version 11

Shaun Mangelsdorf, 2009-04-30 03:57
Added a troubleshooting tip for people who manually create their SVN repositories.

1 7 Nicolas Chuche
h1. Repositories access control with apache mod dav svn and mod perl
2 1 Nicolas Chuche
3 2 Nicolas Chuche
{{>TOC}}
4
5 4 Jean-Philippe Lang
h2. Overview
6 1 Nicolas Chuche
7 3 Jean-Philippe Lang
In this documentation, we will configure apache to delegate authentication to mod_perl. It's tested on apache2 with mysql and postgresql but should work with allmost every databases for which there is a perl DBD module.
8 1 Nicolas Chuche
9 3 Jean-Philippe Lang
You need Redmine r860 or later. If your Redmine is older than r916, download "Redmine.pm":http://redmine.rubyforge.org/svn/trunk/extra/svn/Redmine.pm
10 1 Nicolas Chuche
11 4 Jean-Philippe Lang
You need a working apache on your SVN server and you must install some modules at least mod_dav_svn, mod_perl2, DBI and DBD::mysql (or the DBD driver for you database as it should work on allmost all databases).
12 1 Nicolas Chuche
13 11 Shaun Mangelsdorf
If the repositories are not created automatically by reposman.rb, it is important that the repository name is the same as the project identifier in Redmine, otherwise Redmine.pm will fail to authenticate users.
14
15 1 Nicolas Chuche
On Debian/ubuntu you must do :
16
17 5 Thomas Lecavelier
  aptitude install libapache2-svn libapache-dbi-perl libapache2-mod-perl2 libdbd-mysql-perl libdigest-sha1-perl
18 1 Nicolas Chuche
19 4 Jean-Philippe Lang
h2. Enabling apache modules
20 1 Nicolas Chuche
21
On debian/ubuntu :
22
23
<pre>
24
a2enmod dav
25
a2enmod dav_svn
26
a2enmod perl
27
</pre>
28
29 8 Nicolas Chuche
h2. Apache configuration for subversion repositories and redmine 0.7.X and before
30 1 Nicolas Chuche
31 4 Jean-Philippe Lang
You need to copy "Redmine.pm" on your SVN server and add something like that to your apache configuration (for example in @/etc/APACHE_DIR/conf.d/@)
32 1 Nicolas Chuche
33
You must change the Redmine.pm path and database informations to fit your needs.
34
35
<pre>
36
   PerlRequire /usr/local/apache/Redmine.pm
37
   <Location /svn>
38
     DAV svn
39
     SVNParentPath "/var/svn"
40
41
     AuthType Basic
42
     AuthName redmine
43
     Require valid-user
44
45
     PerlAccessHandler Apache::Authn::Redmine::access_handler
46
     PerlAuthenHandler Apache::Authn::Redmine::authen_handler
47
  
48
     ## for mysql
49
     PerlSetVar dsn DBI:mysql:database=databasename;host=my.db.server
50
     ## for postgres
51
     # PerlSetVar dsn DBI:Pg:dbname=databasename;host=my.db.server
52
53
     PerlSetVar db_user redmine
54
     PerlSetVar db_pass password
55
  </Location>
56
57 4 Jean-Philippe Lang
  # a private location in read only mode to allow Redmine browsing
58
  <Location /svn-private>
59
    DAV svn
60
    SVNParentPath "/var/svn"
61
    Order deny,allow
62
    Deny from all
63
    # only allow reading orders
64
    <Limit GET PROPFIND OPTIONS REPORT>
65
      Allow from redmine.server.ip
66
    </Limit>
67
  </Location>
68 1 Nicolas Chuche
</pre>
69
70 3 Jean-Philippe Lang
It will add add two Location directives, one @/svn@ with authentication and access control against the Redmine database for users and one @/svn-private@ in read-only with IP limitation for Redmine browsing.
71 1 Nicolas Chuche
72 3 Jean-Philippe Lang
And that's done. You can try to browse some public repository with:
73 1 Nicolas Chuche
<pre>
74
svn ls http://my.svn.server/svn/myproject
75
</pre>
76
77
If you try to browse some non public repository, it will ask you a password.
78 8 Nicolas Chuche
79
h2. Apache configuration for subversion repositories and redmine after 0.7.X 
80
81
There's some difference in Redmine.pm so configuration is different. Everything else in the previous part works.
82
83 9 Nicolas Chuche
You first need to copy or link Redmine.pm to /usr/lib/perl5/Apache/Redmine.pm, then you add this configuration to apache :
84 8 Nicolas Chuche
<pre>
85 9 Nicolas Chuche
   PerlLoadModule Apache::Redmine
86 8 Nicolas Chuche
   <Location /svn>
87
     DAV svn
88
     SVNParentPath "/var/svn"
89
90
     AuthType Basic
91
     AuthName redmine
92
     Require valid-user
93
94
     PerlAccessHandler Apache::Authn::Redmine::access_handler
95
     PerlAuthenHandler Apache::Authn::Redmine::authen_handler
96
  
97
     ## for mysql
98
     RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
99
     ## for postgres
100
     # RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
101
102
     RedmineDbUser "redmine"
103
     RedmineDbPass "password"
104
  </Location>
105
</pre>
106
107
h2. Apache configuration for after redmine 0.7.X and git access
108
109 10 Nicolas Chuche
Now that reposman.rb can create git repositories, you can use Redmine.pm to access them the same way than subversion. You first need to copy or link Redmine.pm to /usr/lib/perl5/Apache/Redmine.pm, then you add this configuration to apache : 
110 8 Nicolas Chuche
111
<pre>
112
Alias /git /var/git
113
114 9 Nicolas Chuche
PerlLoadModule Apache::Redmine
115 8 Nicolas Chuche
<Location /git>
116
  DAV on
117
118
  AuthType Basic
119
  Require valid-user
120
  AuthName "Git"
121
122
  PerlAccessHandler Apache::Authn::Redmine::access_handler
123
  PerlAuthenHandler Apache::Authn::Redmine::authen_handler
124
125
  RedmineDSN "DBI:mysql:database=redmine;host=localhost"
126
  RedmineDbUser "redmine"
127
  RedmineDbPass "password"
128
</Location>
129
130
Alias /git-private /var/git
131
132
<Location /git-private>
133
   Order deny,allow
134
   Deny from all
135
   <Limit GET PROPFIND OPTIONS REPORT>
136
      Options Indexes FollowSymLinks MultiViews
137
   Allow from 127.0.0.1
138
   </Limit>
139
</Location>
140
</pre>
141
142
To verify that you can access repository through Redmine.pm, you can use curl :
143
<pre>
144
% curl --netrc --location http://localhost/git/ecookbook/HEAD   
145
ref: refs/heads/master
146
</pre>