Project

General

Profile

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

TaeKyeong Wang, 2009-10-09 04:44
for sqlite3

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 14 TaeKyeong Wang
for sqlite, patch 234 line in Redmine.pm
36
37 1 Nicolas Chuche
<pre>
38 14 TaeKyeong Wang
- "SELECT * FROM projects WHERE projects.identifier=? and projects.is_public=true;"
39
+ "SELECT * FROM projects WHERE projects.identifier=? and projects.is_public='t';"  
40
</pre>
41
42
<pre>
43 1 Nicolas Chuche
   PerlRequire /usr/local/apache/Redmine.pm
44
   <Location /svn>
45
     DAV svn
46
     SVNParentPath "/var/svn"
47
48
     AuthType Basic
49
     AuthName redmine
50
     Require valid-user
51
52
     PerlAccessHandler Apache::Authn::Redmine::access_handler
53
     PerlAuthenHandler Apache::Authn::Redmine::authen_handler
54
  
55
     ## for mysql
56
     PerlSetVar dsn DBI:mysql:database=databasename;host=my.db.server
57
     ## for postgres
58
     # PerlSetVar dsn DBI:Pg:dbname=databasename;host=my.db.server
59
60
     PerlSetVar db_user redmine
61
     PerlSetVar db_pass password
62
  </Location>
63
64 4 Jean-Philippe Lang
  # a private location in read only mode to allow Redmine browsing
65
  <Location /svn-private>
66
    DAV svn
67
    SVNParentPath "/var/svn"
68
    Order deny,allow
69
    Deny from all
70
    # only allow reading orders
71
    <Limit GET PROPFIND OPTIONS REPORT>
72
      Allow from redmine.server.ip
73
    </Limit>
74
  </Location>
75 1 Nicolas Chuche
</pre>
76
77 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.
78 1 Nicolas Chuche
79 3 Jean-Philippe Lang
And that's done. You can try to browse some public repository with:
80 1 Nicolas Chuche
<pre>
81
svn ls http://my.svn.server/svn/myproject
82
</pre>
83
84
If you try to browse some non public repository, it will ask you a password.
85 8 Nicolas Chuche
86
h2. Apache configuration for subversion repositories and redmine after 0.7.X 
87
88
There's some difference in Redmine.pm so configuration is different. Everything else in the previous part works.
89
90 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 :
91 8 Nicolas Chuche
<pre>
92 9 Nicolas Chuche
   PerlLoadModule Apache::Redmine
93 8 Nicolas Chuche
   <Location /svn>
94
     DAV svn
95
     SVNParentPath "/var/svn"
96
97
     AuthType Basic
98
     AuthName redmine
99
     Require valid-user
100
101
     PerlAccessHandler Apache::Authn::Redmine::access_handler
102
     PerlAuthenHandler Apache::Authn::Redmine::authen_handler
103
  
104
     ## for mysql
105
     RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
106
     ## for postgres
107
     # RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
108 14 TaeKyeong Wang
     ## for SQLite3
109
     # RedmineDSN "DBI:SQLite:dbname=database.db"
110 8 Nicolas Chuche
111
     RedmineDbUser "redmine"
112
     RedmineDbPass "password"
113
  </Location>
114
</pre>
115
116 12 Todd Nine
If you want to connect your LDAP authentication to Apache, you can install the Authen::Simple::LDAP perl module.  I found that connecting to my LDAP server to authenticate with every request can be quite slow.  I added the following to my configuration and had a significant performance increase.
117
118
<pre>
119
   PerlLoadModule Apache::Redmine
120
   <Location /svn>
121
     DAV svn
122
     SVNParentPath "/var/svn"
123
124
     AuthType Basic
125
     AuthName redmine
126
     Require valid-user
127
128
     PerlAccessHandler Apache::Authn::Redmine::access_handler
129
     PerlAuthenHandler Apache::Authn::Redmine::authen_handler
130
  
131
     ## for mysql
132
     RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
133
     ## for postgres
134
     # RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
135
136
     RedmineDbUser "redmine"
137
     RedmineDbPass "password"
138
     #Cache the last 50 auth entries
139
     RedmineCacheCredsMax 50
140
  </Location>
141
</pre>
142
143
144 8 Nicolas Chuche
h2. Apache configuration for after redmine 0.7.X and git access
145
146 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 : 
147 8 Nicolas Chuche
148
<pre>
149
Alias /git /var/git
150
151 9 Nicolas Chuche
PerlLoadModule Apache::Redmine
152 8 Nicolas Chuche
<Location /git>
153
  DAV on
154
155
  AuthType Basic
156
  Require valid-user
157
  AuthName "Git"
158
159
  PerlAccessHandler Apache::Authn::Redmine::access_handler
160
  PerlAuthenHandler Apache::Authn::Redmine::authen_handler
161
162
  RedmineDSN "DBI:mysql:database=redmine;host=localhost"
163
  RedmineDbUser "redmine"
164
  RedmineDbPass "password"
165
</Location>
166
167
Alias /git-private /var/git
168
169
<Location /git-private>
170
   Order deny,allow
171
   Deny from all
172
   <Limit GET PROPFIND OPTIONS REPORT>
173
      Options Indexes FollowSymLinks MultiViews
174
   Allow from 127.0.0.1
175
   </Limit>
176
</Location>
177
</pre>
178
179
To verify that you can access repository through Redmine.pm, you can use curl :
180
<pre>
181
% curl --netrc --location http://localhost/git/ecookbook/HEAD   
182
ref: refs/heads/master
183
</pre>
184 13 Thomas Pihl
185
h2. Gotchas
186
187
If you run this in Phusion Passenger, make sure you don't turn PassengerHighPerformance on. If you do, the rewrites to catch subversion dav will be bypassed with some interesting dump in the log as a result.
188
Example: 
189
> ActionController::RoutingError (No route matches "/svn/rm-code" with {:method=>:get}):
190
(if your repo are named rm-code)