Project

General

Profile

HowTo configure Redmine for advanced git integration » History » Version 19

Mr. DTTH, 2013-08-08 04:44

1 1 Felix Schäfer
h1. HowTo configure Redmine for advanced git integration
2
3 3 Felix Schäfer
{{>TOC}}
4
5 1 Felix Schäfer
h2. Scope
6
7 17 Mr. DTTH
This HowTo explains how to serve git repositories on apache through the http-based "git-smart-http protocol":http://progit.org/2010/03/04/smart-http.html introduced in git 1.6.6. 
8 1 Felix Schäfer
9 17 Mr. DTTH
The git-smart-http offers various advantages over ssh or git-based access: you can use redmine access control as-is, no need for extra ssh keys or whatnot, you can secure it through SSL as needed, and there's generally less problems with firewalls and https/https ports than exist with ssh and git ports. git-smart-http also doesn't have some of the drawbacks of its "dumb" predecessor, as it doesn't require any complex DAV setup.
10 1 Felix Schäfer
11 17 Mr. DTTH
This HowTo is mainly written from memory and was conducted on a setup which was already serving [[Repositories_access_control_with_apache_mod_dav_svn_and_mod_perl|svn repositories integrated with redmine]], so it might be possible that I forgot some things or take them for granted. 
12
13
This is a wiki page, feel free to correct or amend anything you find lacking :-) You can also "drop me a line":/users/3866.
14
15 7 Felix Schäfer
Another option to integrate grack with redmine is the "modified grack+redmine plugin":http://github.com/friflaj/redmine_grack or "any other grack modified for redmine":http://github.com/search?q=grack&type=Everything&repo=&langOverride=&start_value=1, though those ones lack documentation and I haven't tried them, so I can't say much about those.
16 1 Felix Schäfer
17
h2. Prerequisites
18
19
* Apache with mod_perl (access control)
20
* git (version at least 1.6.6)
21
* A way to serve git-smart-http
22 10 Hallison Vasconcelos Batista
** mod_cgi (or mod_cgid) if you want to use the stock "git-http-backend":http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html
23 1 Felix Schäfer
** a rack server if you want to use "grack":http://github.com/schacon/grack (basically a rack wrapper around the right git commands) or
24 10 Hallison Vasconcelos Batista
"git-webby":http://git.io/BU7twg (another implementation based on grack but written in Sinatra).
25 1 Felix Schäfer
26 17 Mr. DTTH
You should already have a rack server to run redmine, and that's why I chose grack as the backend and which I will describe in this tutorial. 
27 1 Felix Schäfer
28 17 Mr. DTTH
Using the stock git-http-backend should be quite straightforward though (skip the [[HowTo_configure_Redmine_for_advanced_git_integration#Install-grack|grack installation]] part and get your install with the git-http-backend going (the "git-http-backend manpage":http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html has some examples), when that's done go on with the [[HowTo_configure_Redmine_for_advanced_git_integration#Access-control|access control]] part).
29
30 2 Felix Schäfer
h2. Install grack
31 1 Felix Schäfer
32 3 Felix Schäfer
h3. Get the sources
33 2 Felix Schäfer
34 19 Mr. DTTH
Fetch grack from its "github repository":http://github.com/schacon/grack, I checked out mine to @/var/www/grack@
35 1 Felix Schäfer
36 19 Mr. DTTH
<pre><code class="bash">
37
cd /var/www
38
git clone http://github.com/schacon/grack.git
39
</code></pre>
40 1 Felix Schäfer
41 18 Mr. DTTH
And create a directory for repositories :
42
43
<pre><code class="bash">
44
mkdir /opt/repositories
45
mkfir /opt/repositories/git
46
chown -R apache:apache /opt/repositories/git
47
</code></pre>
48
49 2 Felix Schäfer
h3. Configuration
50
51
Edit the @config.ru@ file and adapt it to your local configuration. @project_root@ must contain the path to the directory containing your git repositories, @git_path@ must obviously contain the path to the git, mine looks like this (on gentoo):
52
53
<pre><code class="ruby">$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
54 1 Felix Schäfer
55 2 Felix Schäfer
use Rack::ShowExceptions
56 1 Felix Schäfer
57 18 Mr. DTTH
require 'grack'
58 1 Felix Schäfer
59 18 Mr. DTTH
require 'git_adapter'
60
61 2 Felix Schäfer
config = {
62 18 Mr. DTTH
  :project_root => "/opt/repositories/git",
63
  :git_path => '/usr/bin/git',
64 2 Felix Schäfer
  :upload_pack => true,
65
  :receive_pack => true,
66 1 Felix Schäfer
}
67
68
run GitHttp::App.new(config)</code></pre>
69 3 Felix Schäfer
70 1 Felix Schäfer
h3. Integrate with Apache
71 17 Mr. DTTH
72 1 Felix Schäfer
You could obviously use any rack server you like at this point, but the access control mechanism @Redmine.pm@ is written for apache with mod_perl, so you will at least need to reverse proxy your rack server through apache. 
73 17 Mr. DTTH
74 1 Felix Schäfer
My rack server of choice is "passenger":http://modrails.com/ (solid performance, apache module, mostly simple configuration) and it is already configured on my system. 
75 17 Mr. DTTH
76
As passenger installation and configuration is not within the scope of this HowTo, please refer to the "passenger documentation":http://modrails.com/documentation.html or to the passenger installation guide from your distribution.
77
78
There's a little more work to do here to get passenger to work with this, you will need to create the directories @public@ and @tmp@ in the grack directory. 
79
80
Please also be aware that in the standard configuration, passenger will run the grack application with the same user and group owning the @config.ru@ file. This user must have read- and write-access as needed to the git repositories!
81 2 Felix Schäfer
82
The last step is to configure an apache vhost to serve the application:
83
84
<pre><code class="apache"><VirtualHost yo.ur.i.p:80>
85
    ServerName git.myhost.com
86
87
    ServerAdmin root@myhost.com
88
    DocumentRoot "/var/www/git.myhost.com/public"
89
90
    <Directory "/var/www/git.myhost.com/public">
91
        Options None
92
        AllowOverride None
93
        Order allow,deny
94
        Allow from all
95
    </Directory>
96
</VirtualHost></code></pre>
97 1 Felix Schäfer
98 10 Hallison Vasconcelos Batista
At this point, if you have a repository in @/var/git/git.myhost.com/myrepo@, you should be able to access it through @http://git.myhost.com/myrepo@, for example @git ls-remote http://git.myhost.com/myrepo@ should show you some information about the repository.
99
100
h2. Install git-webby
101 3 Felix Schäfer
102
Follow the instructions available in "repository page":http://git.io/BU7twg that use basically the same instructions described above.
103
104
h2. Access control
105
106
You now have a working git server, albeit with no access control. Currently, the shipped perl module for access control @Redmine.pm@ (in @extra/svn/@ in your redmine directory) does not support access control for the git-smart-http protocol, the patch in #4905 aims to implement that.
107
108 11 Gregory Bartholomew
h3. Applying the patch
109 1 Felix Schäfer
110 3 Felix Schäfer
Download the latest (or better: correct) version of the patch from #4905 to your redmine directory. In the redmine directory, apply the patch: @patch -p1 < the-patch-file.patch@ should work (if it tells you stuff about being unable to apply a hunk, the patch is incompatible with your @Redmine.pm@ version, if it says other stuff, try @patch -p0 < the-patch-file.patch@ or @patch Redmine.pm < the-patch-file.patch@, if it still borks, ask for advice on #4905).
111 1 Felix Schäfer
112
-You will possibly still need to edit the file from here, because the current version of the patch only works for repositories served from @http://git.myhost.com/git/myrepo@ though the above example uses @http://git.myhost.com/myrepo@.- This step isn't needed anymore, the patch has been updated to take the information from the @Location@ block from apache into account.
113 8 Felix Schäfer
114 3 Felix Schäfer
h3. Configuring Apache
115 17 Mr. DTTH
116 3 Felix Schäfer
You now have to make Apache aware of your new authentication module (if you already had done this step for subversion integration, you can go to the @Location@ directives directly). 
117 17 Mr. DTTH
118
Copy or link @Redmine.pm@ (from your @extra/svn/@ directory) to @/usr/lib/perl5/Apache/Redmine.pm@ (ubuntu) or wherever your distribution puts its apache perl modules (e.g. gentoo puts them in @/usr/lib64/perl5/vendor_perl/5.8.8/Apache/@, fedora puts them in @/usr/lib64/perl5/vendor_perl/Apache/@).
119 3 Felix Schäfer
120
Having done that, reload apache to make sure everything in the patching phase went well (if not, remove the link or the file create in the step just before and restart apache to get apache back up, try to find the error in your Redmine.pm file). Now edit your vhost configuration to look somewhat like (same as above but with more stuff):
121
122
<pre><code class="apache"><VirtualHost yo.ur.i.p:80>
123
    ServerName git.myhost.com
124
125
    ServerAdmin root@myhost.com
126
    DocumentRoot "/var/www/git.myhost.com/public"
127
128
    PerlLoadModule Apache::Redmine
129
130
    <Directory "/var/www/git.myhost.com/public">
131
        Options None
132
        AllowOverride None
133
        Order allow,deny
134
        Allow from all
135
    </Directory>
136
137
    <Location "/">
138
        AuthType Basic
139
        AuthName "Redmine git repositories"
140
        Require valid-user
141
142
        PerlAccessHandler Apache::Authn::Redmine::access_handler
143
        PerlAuthenHandler Apache::Authn::Redmine::authen_handler
144
145
        ## for mysql
146
        RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
147
        ## for postgres
148
        # RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
149
        ## for SQLite3
150
        # RedmineDSN "DBI:SQLite:dbname=database.db"
151
152
        RedmineDbUser "redmine"
153
        RedmineDbPass "password"
154 1 Felix Schäfer
        RedmineGitSmartHttp yes
155 3 Felix Schäfer
    </Location>
156 1 Felix Schäfer
</VirtualHost></code></pre>
157
158 3 Felix Schäfer
Reload your apache, and everything should be good and well :-)
159
160
h2. Known issues
161 17 Mr. DTTH
162 1 Felix Schäfer
If you are using the stock git-http-backend directly under apache and you are finding errors like "Request not supported: '/git/your-git-repo'" in your apache error log, you may need to add "SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER" to the to the list of environment variables that you are setting in your apache configuration.  
163 17 Mr. DTTH
164
Unfortionately, this setting may cause redmine to borke.  If so, you will need to set the variable for only the requests that are passed through git-http-backend.  One way to accomplish this is with mod_rewrite.  Below is a sample apache configuration from a Fedora 17 system that uses git-http-backend and mod_rewrite.
165 13 Gregory Bartholomew
166
In httpd.conf:
167
168
<pre><code class="apache">Listen xxx.xxx.xxx.xxx:80
169
<VirtualHost xxx.xxx.xxx.xxx:80>
170
   DocumentRoot /var/www/redmine/public
171
   ServerName servername.domain:80
172
   Include conf/servername.conf
173
</VirtualHost>
174
175
Listen xxx.xxx.xxx.xxx:443
176
<VirtualHost xxx.xxx.xxx.xxx:443>
177
   DocumentRoot /var/www/redmine/public
178
   ServerName servername.domain:443
179
   Include conf/servername.conf
180
   Include conf/ssl.conf
181
</VirtualHost></code></pre>
182
183
In servername.conf:
184
185
<pre><code class="apache">PerlLoadModule Apache::Authn::Redmine
186
187
SetEnv GIT_PROJECT_ROOT /git-1/repositories
188
SetEnv GIT_HTTP_EXPORT_ALL
189
190
<IfModule mod_rewrite.c>
191
   RewriteEngine On
192
193
   RewriteCond %{HTTPS} ^off$
194
   RewriteCond %{REQUEST_URI} !^/git-private/
195
   RewriteRule ^.*$ https://servername.domain$0 [R=301,L]
196
   RewriteRule ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /git-1/repositories/$1 [L]
197
   RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /git-1/repositories/$1 [L]
198
   RewriteRule ^/git/(.*)$ /usr/libexec/git-core/git-http-backend/$1 [E=REMOTE_USER:$REDIRECT_REMOTE_USER,H=cgi-script,L]
199
</IfModule>
200
201 15 Gregory Bartholomew
<Directory /usr/libexec/git-core>
202
   <Files "git-http-backend">
203
      Options +ExecCGI
204 13 Gregory Bartholomew
   </Files>
205
</Directory>
206
207
<Location /git>
208
   AuthType Basic
209
   AuthName "CAMPUS"
210
   AuthBasicProvider external
211
   AuthExternal pwauth
212
   Require valid-user
213
214
   PerlAccessHandler Apache::Authn::Redmine::access_handler
215
   PerlAuthenHandler Apache::Authn::Redmine::authen_handler
216
 
217
   RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
218 14 Gregory Bartholomew
   RedmineDbUser "redmine" 
219 13 Gregory Bartholomew
   # RedmineDbPass "password"
220
   RedmineGitSmartHttp yes
221
</Location>
222
223
Alias /git-private /git-1/repositories
224
225
<Location /git-private>
226
   Order deny,allow
227
   Deny from all
228
   <Limit GET PROPFIND OPTIONS REPORT>
229
      Options Indexes FollowSymLinks MultiViews
230
      Allow from 127.0.0.1
231
      Allow from localhost
232
   </Limit>
233
</Location>
234
235
<Directory "/var/www/redmine/public">
236
   RailsEnv production
237
   RailsBaseURI /
238
239
   Options -MultiViews
240
   AllowOverride All
241
</Directory></code></pre>
242
243
In conf/ssl.conf:
244
245
<pre><code class="apache">LogLevel warn
246
SSLEngine on
247
SSLProtocol all -SSLv2
248
SSLCipherSuite RC4-SHA:AES128-SHA:ALL:!ADH:!EXP:!LOW:!MD5:!SSLV2:!NULL
249
SSLCertificateFile /etc/pki/tls/certs/your-server.crt
250
SSLCertificateKeyFile /etc/pki/tls/private/your-server.key
251
SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
252
SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
253
254
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
255
    SSLOptions +StdEnvVars
256
</Files>
257
<Directory "/var/www/cgi-bin">
258
    SSLOptions +StdEnvVars
259
</Directory>
260
261
SetEnvIf User-Agent ".*MSIE.*" \
262
         nokeepalive ssl-unclean-shutdown \
263
         downgrade-1.0 force-response-1.0
264
</code></pre>
265
266
In conf.d/ssl.conf:
267
268
<pre><code class="apache">LoadModule ssl_module modules/mod_ssl.so
269 1 Felix Schäfer
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
270
SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
271
SSLSessionCacheTimeout  300
272 13 Gregory Bartholomew
SSLMutex default
273
SSLRandomSeed startup file:/dev/urandom  256
274
SSLRandomSeed connect builtin
275
SSLCryptoDevice builtin
276
</code></pre>
277 17 Mr. DTTH
278
You will also need to have the perl modules Net::LDAP, Authen::Simple, and Authen::Simple::LDAP installed.  The first two are available in Fedora's default package repositories.  
279
280 13 Gregory Bartholomew
The third must be installed after the other two and it must be obtained directly from cpan.  Below are the commands that I used to install these packages on Fedora 17.
281 15 Gregory Bartholomew
282 13 Gregory Bartholomew
yum -y install gcc make perl-LDAP perl-Authen-Simple
283
cpan
284 1 Felix Schäfer
cpan> install Authen::Simple::LDAP