Repositories access control with apache mod dav svn and mod perl
Version 39 (Lluís Vilanova, 2012-01-22 21:03)
| 1 | 16 | Jean-Philippe Lang | h1. Repositories access control with apache, mod_dav_svn and mod_perl |
|---|---|---|---|
| 2 | 1 | Nicolas Chuche | |
| 3 | 2 | Nicolas Chuche | {{>TOC}} |
| 4 | 2 | Nicolas Chuche | |
| 5 | 4 | Jean-Philippe Lang | h2. Overview |
| 6 | 1 | Nicolas Chuche | |
| 7 | 23 | Eric Davis | In this documentation, we will configure apache to delegate authentication to mod_perl. It's tested on apache2 (@apache2-mpm-prefork@) with mysql and postgresql but should work with allmost every databases for which there is a perl DBD module. Apache2 with the high speed thread model might not load Perl correctly (@apache2-mpm-worker@). |
| 8 | 1 | Nicolas Chuche | |
| 9 | 1 | Nicolas Chuche | 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). |
| 10 | 4 | Jean-Philippe Lang | |
| 11 | 15 | Jean-Philippe Lang | On Debian/ubuntu you can do : |
| 12 | 11 | Shaun Mangelsdorf | |
| 13 | 37 | Mischa The Evil | sudo aptitude install libapache2-svn libapache-dbi-perl libapache2-mod-perl2 libdbd-mysql-perl libdigest-sha1-perl libauthen-simple-ldap-perl |
| 14 | 1 | Nicolas Chuche | |
| 15 | 37 | Mischa The Evil | 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. For example, if the path to the repository is @/path/to/repository/foo-bar@, then the project Identifier on the Settings page must be @foo-bar@. |
| 16 | 1 | Nicolas Chuche | |
| 17 | 1 | Nicolas Chuche | h2. Enabling apache modules |
| 18 | 1 | Nicolas Chuche | |
| 19 | 1 | Nicolas Chuche | On debian/ubuntu : |
| 20 | 1 | Nicolas Chuche | |
| 21 | 1 | Nicolas Chuche | <pre> |
| 22 | 15 | Jean-Philippe Lang | sudo a2enmod dav |
| 23 | 21 | Marko Roeder | sudo a2enmod dav_svn # if you want to use svn |
| 24 | 21 | Marko Roeder | sudo a2enmod dav_fs # if you want to use git |
| 25 | 15 | Jean-Philippe Lang | sudo a2enmod perl |
| 26 | 4 | Jean-Philippe Lang | </pre> |
| 27 | 1 | Nicolas Chuche | |
| 28 | 15 | Jean-Philippe Lang | h2. Apache configuration for Subversion repositories |
| 29 | 1 | Nicolas Chuche | |
| 30 | 1 | Nicolas Chuche | You first need to copy or link @Redmine.pm@ to @/usr/lib/perl5/Apache/Redmine.pm@ |
| 31 | 37 | Mischa The Evil | * Redmine.pm can be found in $REDMINE_DIR/extra/svn/Redmine.pm |
| 32 | 37 | Mischa The Evil | * In the Debian install, it is found /usr/share/redmine/extra/svn/Redmine.pm |
| 33 | 37 | Mischa The Evil | |
| 34 | 15 | Jean-Philippe Lang | Then add the following Location directives to your apache configuration (for example in @/etc/APACHE_DIR/conf.d/@): |
| 35 | 1 | Nicolas Chuche | |
| 36 | 17 | Joachim Fritschi | * the old how-to which suggested two separate locations for with @/svn@ and @/svn-private@ can be avoided |
| 37 | 17 | Joachim Fritschi | * with the @Satisfy any@ keyword from Apache you can define different authentication policies |
| 38 | 17 | Joachim Fritschi | * read access from the redmine-server or any validated user |
| 39 | 17 | Joachim Fritschi | * write access only validated users |
| 40 | 15 | Jean-Philippe Lang | |
| 41 | 17 | Joachim Fritschi | |
| 42 | 15 | Jean-Philippe Lang | <pre> |
| 43 | 1 | Nicolas Chuche | # /svn location for users |
| 44 | 1 | Nicolas Chuche | PerlLoadModule Apache::Redmine |
| 45 | 1 | Nicolas Chuche | <Location /svn> |
| 46 | 1 | Nicolas Chuche | DAV svn |
| 47 | 19 | Joachim Fritschi | SVNParentPath "/var/svn" |
| 48 | 17 | Joachim Fritschi | Order deny,allow |
| 49 | 17 | Joachim Fritschi | Deny from all |
| 50 | 17 | Joachim Fritschi | Satisfy any |
| 51 | 1 | Nicolas Chuche | |
| 52 | 1 | Nicolas Chuche | PerlAccessHandler Apache::Authn::Redmine::access_handler |
| 53 | 1 | Nicolas Chuche | PerlAuthenHandler Apache::Authn::Redmine::authen_handler |
| 54 | 17 | Joachim Fritschi | AuthType Basic |
| 55 | 18 | Joachim Fritschi | AuthName "Redmine SVN Repository" |
| 56 | 17 | Joachim Fritschi | |
| 57 | 17 | Joachim Fritschi | #read-only access |
| 58 | 17 | Joachim Fritschi | <Limit GET PROPFIND OPTIONS REPORT> |
| 59 | 19 | Joachim Fritschi | Require valid-user |
| 60 | 17 | Joachim Fritschi | Allow from redmine.server.ip |
| 61 | 17 | Joachim Fritschi | # Allow from another-ip |
| 62 | 17 | Joachim Fritschi | Satisfy any |
| 63 | 17 | Joachim Fritschi | </Limit> |
| 64 | 17 | Joachim Fritschi | # write access |
| 65 | 17 | Joachim Fritschi | <LimitExcept GET PROPFIND OPTIONS REPORT> |
| 66 | 17 | Joachim Fritschi | Require valid-user |
| 67 | 17 | Joachim Fritschi | </LimitExcept> |
| 68 | 17 | Joachim Fritschi | |
| 69 | 17 | Joachim Fritschi | |
| 70 | 1 | Nicolas Chuche | ## for mysql |
| 71 | 1 | Nicolas Chuche | RedmineDSN "DBI:mysql:database=databasename;host=my.db.server" |
| 72 | 4 | Jean-Philippe Lang | ## for postgres |
| 73 | 1 | Nicolas Chuche | # RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server" |
| 74 | 4 | Jean-Philippe Lang | ## for SQLite3 |
| 75 | 1 | Nicolas Chuche | # RedmineDSN "DBI:SQLite:dbname=database.db" |
| 76 | 1 | Nicolas Chuche | |
| 77 | 1 | Nicolas Chuche | RedmineDbUser "redmine" |
| 78 | 1 | Nicolas Chuche | RedmineDbPass "password" |
| 79 | 1 | Nicolas Chuche | </Location> |
| 80 | 1 | Nicolas Chuche | |
| 81 | 1 | Nicolas Chuche | </pre> |
| 82 | 1 | Nicolas Chuche | |
| 83 | 17 | Joachim Fritschi | h3. Testing the configuration: |
| 84 | 1 | Nicolas Chuche | |
| 85 | 17 | Joachim Fritschi | After reloading apache conf, you can try to browse some repository with: |
| 86 | 17 | Joachim Fritschi | |
| 87 | 1 | Nicolas Chuche | <pre> |
| 88 | 1 | Nicolas Chuche | svn ls http://my.svn.server/svn/myproject |
| 89 | 4 | Jean-Philippe Lang | </pre> |
| 90 | 1 | Nicolas Chuche | |
| 91 | 17 | Joachim Fritschi | Any non-public repository should ask for a username and password. |
| 92 | 4 | Jean-Philippe Lang | |
| 93 | 17 | Joachim Fritschi | To test the authentication that allows you redmine server to read all repositories: |
| 94 | 1 | Nicolas Chuche | |
| 95 | 17 | Joachim Fritschi | Reading a private repository: |
| 96 | 3 | Jean-Philippe Lang | <pre> |
| 97 | 17 | Joachim Fritschi | svn ls http://my.svn.server/svn/myproject |
| 98 | 17 | Joachim Fritschi | </pre> |
| 99 | 17 | Joachim Fritschi | Try writing to the repository: |
| 100 | 17 | Joachim Fritschi | <pre> |
| 101 | 17 | Joachim Fritschi | svn mkdir http://my.svn.server/svn/myproject/testdir |
| 102 | 17 | Joachim Fritschi | </pre> |
| 103 | 17 | Joachim Fritschi | This should fail and ask for a password. |
| 104 | 17 | Joachim Fritschi | |
| 105 | 17 | Joachim Fritschi | |
| 106 | 17 | Joachim Fritschi | h3. optional LDAP Authentication |
| 107 | 17 | Joachim Fritschi | |
| 108 | 17 | Joachim Fritschi | 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. If you have configured an encrypted connection to the LDAP server you will need the IO::Socket::SSL module. |
| 109 | 17 | Joachim Fritschi | |
| 110 | 20 | Stefan Stefansson | > *NOTE: the above wording is a little confusing. I attempt to clear up the issues I had with this in the following paragraph.* |
| 111 | 20 | Stefan Stefansson | > |
| 112 | 1 | Nicolas Chuche | > First of all, make sure that you have the Net::LDAP module installed as well. I installed Authen::Simple::LDAP through CPAN and found that nothing worked. Eventually I figured out that this was because the Authen::Simple::LDAP did not require the Net::LDAP module as a dependency but it is needed for our purpose here. I did this on CentOS and it seems that the Net::LDAP module can be installed via yum (@yum install perl-LDAP@) but the Authen::Simple::LDAP had to be installed via CPAN since there's no RPM for it in the CentOS repositories. |
| 113 | 1 | Nicolas Chuche | > |
| 114 | 37 | Mischa The Evil | |
| 115 | 37 | Mischa The Evil | To install the Authen::Simple::LDAP using CPAN use commands: |
| 116 | 37 | Mischa The Evil | <pre> |
| 117 | 37 | Mischa The Evil | cpan |
| 118 | 37 | Mischa The Evil | cpan> install Authen::Simple::LDAP |
| 119 | 37 | Mischa The Evil | </pre> |
| 120 | 37 | Mischa The Evil | if the installation failed due to some dependencies, resolve the dependencies first. |
| 121 | 37 | Mischa The Evil | |
| 122 | 20 | Stefan Stefansson | > My second point is related to the below Apache config. The @PerlLoadModule Authen::Simple::LDAP@ is actually not required for having users authenticated via LDAP. It will happen automatically if both of the above modules are installed. So there really is no difference between the config snippet below and the one above except for the @RedmineCacheCredsMax 50@ line which is probably a good idea although it can result in users that have been deleted or removed in redmine still getting access to the repositories, at least for a little while. |
| 123 | 20 | Stefan Stefansson | |
| 124 | 17 | Joachim Fritschi | <pre> |
| 125 | 8 | Nicolas Chuche | PerlLoadModule Apache::Redmine |
| 126 | 17 | Joachim Fritschi | PerlLoadModule Authen::Simple::LDAP |
| 127 | 17 | Joachim Fritschi | # PerlLoadModule IO::Socket::SSL |
| 128 | 12 | Todd Nine | <Location /svn> |
| 129 | 12 | Todd Nine | DAV svn |
| 130 | 12 | Todd Nine | SVNParentPath "/var/svn" |
| 131 | 12 | Todd Nine | |
| 132 | 12 | Todd Nine | AuthType Basic |
| 133 | 12 | Todd Nine | AuthName redmine |
| 134 | 12 | Todd Nine | Require valid-user |
| 135 | 12 | Todd Nine | |
| 136 | 12 | Todd Nine | PerlAccessHandler Apache::Authn::Redmine::access_handler |
| 137 | 12 | Todd Nine | PerlAuthenHandler Apache::Authn::Redmine::authen_handler |
| 138 | 12 | Todd Nine | |
| 139 | 12 | Todd Nine | ## for mysql |
| 140 | 12 | Todd Nine | RedmineDSN "DBI:mysql:database=databasename;host=my.db.server" |
| 141 | 12 | Todd Nine | ## for postgres |
| 142 | 12 | Todd Nine | # RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server" |
| 143 | 12 | Todd Nine | |
| 144 | 1 | Nicolas Chuche | RedmineDbUser "redmine" |
| 145 | 12 | Todd Nine | RedmineDbPass "password" |
| 146 | 12 | Todd Nine | #Cache the last 50 auth entries |
| 147 | 12 | Todd Nine | RedmineCacheCredsMax 50 |
| 148 | 15 | Jean-Philippe Lang | </Location> |
| 149 | 12 | Todd Nine | </pre> |
| 150 | 36 | neil johnson | |
| 151 | 1 | Nicolas Chuche | h2. Apache configuration for Git repositories |
| 152 | 38 | Lluís Vilanova | |
| 153 | 38 | Lluís Vilanova | *TODO*: This should probably be moved into [[HowTo configure Redmine for advanced git integration]] |
| 154 | 15 | Jean-Philippe Lang | |
| 155 | 1 | Nicolas Chuche | Now that reposman.rb can create git repositories, you can use Redmine.pm to access them the same way than subversion. |
| 156 | 1 | Nicolas Chuche | |
| 157 | 1 | 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 : |
| 158 | 1 | Nicolas Chuche | |
| 159 | 1 | Nicolas Chuche | <pre> |
| 160 | 1 | Nicolas Chuche | |
| 161 | 37 | Mischa The Evil | PerlLoadModule Apache::Authn::Redmine |
| 162 | 1 | Nicolas Chuche | |
| 163 | 37 | Mischa The Evil | SetEnv GIT_PROJECT_ROOT /path/to/git/repos |
| 164 | 37 | Mischa The Evil | SetEnv GIT_HTTP_EXPORT_ALL |
| 165 | 37 | Mischa The Evil | |
| 166 | 37 | Mischa The Evil | ScriptAlias /git/ /usr/bin/git-http-backend/ |
| 167 | 37 | Mischa The Evil | |
| 168 | 37 | Mischa The Evil | <Location /git> |
| 169 | 8 | Nicolas Chuche | AuthType Basic |
| 170 | 8 | Nicolas Chuche | Require valid-user |
| 171 | 1 | Nicolas Chuche | AuthName "Git" |
| 172 | 8 | Nicolas Chuche | |
| 173 | 8 | Nicolas Chuche | PerlAccessHandler Apache::Authn::Redmine::access_handler |
| 174 | 8 | Nicolas Chuche | PerlAuthenHandler Apache::Authn::Redmine::authen_handler |
| 175 | 1 | Nicolas Chuche | |
| 176 | 8 | Nicolas Chuche | RedmineDSN "DBI:mysql:database=redmine;host=localhost" |
| 177 | 8 | Nicolas Chuche | RedmineDbUser "redmine" |
| 178 | 8 | Nicolas Chuche | RedmineDbPass "password" |
| 179 | 37 | Mischa The Evil | RedmineGitSmartHttp yes |
| 180 | 8 | Nicolas Chuche | </Location> |
| 181 | 8 | Nicolas Chuche | |
| 182 | 8 | Nicolas Chuche | Alias /git-private /var/git |
| 183 | 8 | Nicolas Chuche | |
| 184 | 8 | Nicolas Chuche | <Location /git-private> |
| 185 | 8 | Nicolas Chuche | Order deny,allow |
| 186 | 8 | Nicolas Chuche | Deny from all |
| 187 | 8 | Nicolas Chuche | <Limit GET PROPFIND OPTIONS REPORT> |
| 188 | 8 | Nicolas Chuche | Options Indexes FollowSymLinks MultiViews |
| 189 | 8 | Nicolas Chuche | Allow from 127.0.0.1 |
| 190 | 8 | Nicolas Chuche | </Limit> |
| 191 | 8 | Nicolas Chuche | </Location> |
| 192 | 8 | Nicolas Chuche | </pre> |
| 193 | 8 | Nicolas Chuche | |
| 194 | 8 | Nicolas Chuche | To verify that you can access repository through Redmine.pm, you can use curl : |
| 195 | 8 | Nicolas Chuche | <pre> |
| 196 | 8 | Nicolas Chuche | % curl --netrc --location http://localhost/git/ecookbook/HEAD |
| 197 | 13 | Thomas Pihl | ref: refs/heads/master |
| 198 | 13 | Thomas Pihl | </pre> |
| 199 | 13 | Thomas Pihl | |
| 200 | 22 | Diego Oliveira | h2. Apache configuration for Mercurial repositories |
| 201 | 22 | Diego Oliveira | |
| 202 | 39 | Lluís Vilanova | *TODO*: This should probably be moved into [[HowTo configure Redmine for advanced Mercurial integration]] |
| 203 | 39 | Lluís Vilanova | |
| 204 | 22 | Diego Oliveira | Create a file caled "hgweb.config" in the same folder as "hgwebdir.cgi". This foder will be the root repository folder. Then edit the "hgweb.config" with something like this: |
| 205 | 22 | Diego Oliveira | |
| 206 | 22 | Diego Oliveira | <pre> |
| 207 | 22 | Diego Oliveira | [paths] |
| 208 | 22 | Diego Oliveira | /=/path/to/root/repository/** |
| 209 | 22 | Diego Oliveira | |
| 210 | 22 | Diego Oliveira | [web] |
| 211 | 22 | Diego Oliveira | allow_push = * |
| 212 | 22 | Diego Oliveira | allowbz2 = yes |
| 213 | 22 | Diego Oliveira | allowgz = yes |
| 214 | 22 | Diego Oliveira | allowzip = yes |
| 215 | 22 | Diego Oliveira | |
| 216 | 22 | Diego Oliveira | </pre> |
| 217 | 22 | Diego Oliveira | |
| 218 | 22 | Diego Oliveira | Follows the instructions to install Redmine.pm as described and configure your apache like this. |
| 219 | 22 | Diego Oliveira | |
| 220 | 22 | Diego Oliveira | <pre> |
| 221 | 22 | Diego Oliveira | RewriteEngine on |
| 222 | 22 | Diego Oliveira | PerlLoadModule Apache2::Redmine |
| 223 | 22 | Diego Oliveira | PerlLoadModule Authen::Simple::LDAP |
| 224 | 22 | Diego Oliveira | ScriptAliasMatch ^/hg(.*) /path/to/the/hgwebdir.cgi/$1 |
| 225 | 22 | Diego Oliveira | <Location /hg> |
| 226 | 22 | Diego Oliveira | AuthType Basic |
| 227 | 22 | Diego Oliveira | AuthName "Mercurial" |
| 228 | 22 | Diego Oliveira | Require valid-user |
| 229 | 1 | Nicolas Chuche | |
| 230 | 1 | Nicolas Chuche | #Redmine auth |
| 231 | 1 | Nicolas Chuche | PerlAccessHandler Apache::Authn::Redmine::access_handler |
| 232 | 1 | Nicolas Chuche | PerlAuthenHandler Apache::Authn::Redmine::authen_handler |
| 233 | 1 | Nicolas Chuche | RedmineDSN "DBI:mysql:database=redmine;host=localhost" |
| 234 | 1 | Nicolas Chuche | RedmineDbUser "DB_USER" |
| 235 | 1 | Nicolas Chuche | RedmineDbPass "DB_PASSWD" |
| 236 | 1 | Nicolas Chuche | </Location> |
| 237 | 37 | Mischa The Evil | |
| 238 | 37 | Mischa The Evil | # Note: Do not use hg-private as the rewrite rule above will cause strange things to occur. |
| 239 | 37 | Mischa The Evil | Alias /private-hg /path/to/hg/repos |
| 240 | 37 | Mischa The Evil | |
| 241 | 37 | Mischa The Evil | <Location /private-hg> |
| 242 | 37 | Mischa The Evil | Order deny, allow |
| 243 | 37 | Mischa The Evil | Deny from all |
| 244 | 37 | Mischa The Evil | <Limit GET PROPFIND OPTIONS REPORT> |
| 245 | 37 | Mischa The Evil | Options Indexes FollowSymLinks MultiViews |
| 246 | 37 | Mischa The Evil | Allow from 127.0.0.1 |
| 247 | 37 | Mischa The Evil | </Limit> |
| 248 | 37 | Mischa The Evil | </Location> |
| 249 | 37 | Mischa The Evil | |
| 250 | 22 | Diego Oliveira | |
| 251 | 1 | Nicolas Chuche | </pre> |
| 252 | 22 | Diego Oliveira | |
| 253 | 22 | Diego Oliveira | h2. Gotchas |
| 254 | 13 | Thomas Pihl | |
| 255 | 13 | Thomas Pihl | 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. |
| 256 | 13 | Thomas Pihl | Example: |
| 257 | 1 | Nicolas Chuche | > ActionController::RoutingError (No route matches "/svn/rm-code" with {:method=>:get}): |
| 258 | 1 | Nicolas Chuche | (if your repo are named rm-code) |
| 259 | 27 | Bill Dieter | |
| 260 | 37 | Mischa The Evil | When using @Authen::Simple::LDAP@ for authentication, it is not sufficient to have the Administrator role to access a repository. The user must have a role with that specifically allows the user to browse, read, or write the repository. |