Redmine認証でgitを使う

嵌りまくった。

OS: CentOS release 5.9 (Final)
Apache: 2.2.3
Database: Mysql Ver 14.12
Redmine: 2.3.3 stable
Git: 1.8.2.1

gitのベアリポジトリを作成

Redmineでのリポジトリ識別子は何でも良い。
gitのリポジトリは「プロジェクト識別子.任意の文字列」という名前で作成という記事をよく見かけたけど、現行のRedmineだとプロジェクト識別子だけでも大丈夫な模様。

mkdir -p /var/www/git/test
chown -R apache:apache /var/www/git
cd /var/www/git/test.repos
git --bare init --shared
git config --file config http.reseivepack true
git config --system core.quotepath false
git update-server-info

Apacheの設定

Redmine.pm や多くの記事ではGitのバージョンが古いものなのか、scriptAliasが/usr/libexecなどのパスになっていた部分はerror_logを見るまで気が付かなかった。

PerlLoadModule Apache::Authn::Redmine

SetEnv GIT_PROJECT_ROOT /var/www/html/git
SetEnv GIT_HTTP_EXPORT_ALL
scriptAlias /git/ /usr/bin/git-http-backend/

<Location /git/>
  PerlAccessHandler Apache::Authn::Redmine::access_handler
  PerlAuthenHandler Apache::Authn::Redmine::authen_handler

  AuthType Basic
  AuthName Git
  Require valid-user

  RedmineDSN "DBI:mysql:database=Redmineデータベース名;host=localhost"
  RedmineDbUser "Redmine用DBユーザ名"
  RedmineDbPass "Redmine用DBユーザパスワード"
  RedmineGitSmartHttp yes
</Location>

Apache再起動。

接続先URLの指定はconfのLocationとgit上のリポジトリ名の組み合わせとなる。

http://hoge.com/git/test