プロジェクト

全般

プロフィール

SubversionにRedmineの認証を連携する » 履歴 » リビジョン 3

リビジョン 2 (Hidehisa Matsutani, 2015/11/27 23:42) → リビジョン 3/7 (Hidehisa Matsutani, 2015/11/27 23:44)

h1. SubversionにRedmineの認証を連携する 

 SubversionとRedmineの認証連携ができると、Redmineのユーザ/パスワードでSubversionにコミットできます。 
 いろいろと試行錯誤した結果、無事連携できたので、ノウハウをまとめておきます。 

 h2. 前提条件 

 * Bitnami Redmine を利用 
 * サーバはCentOS 
 * Bitnamiのインストールフォルダは/opt/redmine-3.0.3-0 


 h2. mod_auth_mysqlのインストール 

 <pre> 
     # yum install mod_auth_mysql 
 </pre> 

 h2. Redmine に同梱されている Redmine.pm を Perl の実行パスへシンボリックリンク 

 <pre> 
     # mkdir -p /opt/redmine-3.0.3-0/perl/lib/site_perl/5.16.3/x86_64-linux-thread-multi/Apache/Authn 
     # ln -s /opt/redmine-3.0.3-0/apps/redmine/htdocs/extra/svn/Redmine.pm /opt/redmine-3.0.3-0/perl/lib/site_perl/5.16.3/x86_64-linux-thread-multi/Apache/Authn 
 </pre> 

 h2. デフォルトの権限設定を記述 

 <pre> 
     # vi /opt/redmine-3.0.3-0/repos/svnauthz 
 </pre> 

 <pre> 
 # common settings 
 [/] 
 admin = rw 
 * = rw 
 guest = r 
 </pre> 

 h2. httpd.confに以下を追加 

 <pre> 
     # vi /opt/redmine-3.0.3-0/apache2/conf/httpd.conf 
 </pre> 

 <pre> 
 Include conf/extra/httpd-svn.conf 
 </pre> 


 h2. mod_auth_mysql.so の作り直し 

 


 h3. BitNami Redmine Stack に同梱されている Apache 2.4 では API がいくつか変更されたらしいので、パッチをあてます がいくつか変更されたらしいので、パッチをあてます。 

 https://osdn.jp/projects/sfnet_modauthmysql/ 
 から、mod_auth_mysql-3.0.0.tar.gzをダウンロードします。 

 http://sourceforge.net/p/modauthmysql/patches/13/ 
 のパッチを当てて、mod_auth_mysql.so を作り直します。 
 この作業では gcc がインストールされている必要があります。 

 <pre> 
     # tar xzvf mod_auth_mysql-3.0.0.tar.gz 
     # patch -p0 < mod_auth_mysql_3.0.0_patch_apache2.4.diff 
     # cd mod_auth_mysql-3.0.0/ 
     # /opt/redmine-3.0.3-0/use_redmine 
     # apxs -c -L/opt/redmine-3.0.3-0/mysql/lib -I/opt/redmine-3.0.3-0/mysql/include -lmysqlclient -lm -lz mod_auth_mysql.c 
     # apxs -i mod_auth_mysql.la 
 </pre> 

 

 h3. ユーザテーブルにsaltが追加されたが、mod_auth_mysqlがRedmineのsaltの掛け方に対応していないので、パッチをあてます 

 (参考) http://d.hatena.ne.jp/vmi/20111102/p1  
 パッチは http://www.redmine.org/boards/2/topics/24386?r=25722#message-25722 からダウンロードします。 

 <pre> 
     # patch -p0 < mod_auth_mysql-3.0.0-redmine.patch 
     # cd mod_auth_mysql-3.0.0/ 
     # /opt/redmine-3.0.3-0/use_redmine 
     # apxs -c -L/opt/redmine-3.0.3-0/mysql/lib -I/opt/redmine-3.0.3-0/mysql/include -lmysqlclient -lm -lz mod_auth_mysql.c 
     # apxs -i mod_auth_mysql.la 
 </pre> 

 h2. httpd-svn.confを作成 

 * Subversion に WebDAV 経由でアクセスできるようにします 

 * access_handler にバグがあるらしいのでコメントアウトしています。 
 (参考) http://sc1h5r.cswiki.jp/index.php?Subversion%E3%81%AEApache%E7%B5%8C%E7%94%B1%E3%82%A2%E3%82%AF%E3%82%BB%E3%82%B9%E3%81%AE%E8%A8%AD%E5%AE%9A 

 * http://d.hatena.ne.jp/vmi/20111102/p1 
 によりユーザテーブルにsaltが追加されたことの設定を追加しています。 

 * {DB_password}{port}は適宜インストール環境に合わせて読み替えてください。 

 <pre> 
     # vi /opt/redmine-3.0.3-0/apache2/conf/extra/httpd-svn.conf 
 </pre> 

 <pre> 
 LoadModule perl_module modules/mod_perl.so 
 PerlLoadModule Apache::Authn::Redmine 

 <Location /svn> 
   DAV svn 
   SVNParentPath "/var/svn" 
   AuthType Basic 
   AuthName Subversion 
   Require valid-user 
   AuthUserFile /dev/null 
   AuthBasicAuthoritative Off 
   AuthMySQLAuthoritative On 
 # my.cnfの設定に合わせて変更 
   AuthMySQLSocket /opt/redmine-3.0.3-0/mysql/tmp/mysql.sock 
 # Redmineのdatabase.ymlの設定に合わせて変更 
   AuthMySQLHost localhost 
   AuthMySQLUser bitnami 
   AuthMySQLPassword {DB_password} 
   AuthMySQLDB bitnami_redmine 
 ### Redmineのテーブルとの紐付け 
 # Redmineのユーザテーブル 
   AuthMySQLNoPasswd Off 
   AuthMySQLUserTable users 
   AuthMySQLNameField login 
   AuthMySQLPasswordField hashed_password 
   AuthMySQLSaltField salt 
   AuthMySQLPwEncryption sha1-rm 
 # グループの設定。プロジェクト識別子をグループとして扱う 
   AuthMySQLGroupTable "users, members, projects" 
   AuthMySQLGroupCondition "users.id = members.user_id and projects.id = members.project_id" 
   AuthMySQLGroupField "projects.identifier" 

   AuthzSVNAccessFile /opt/redmine-3.0.3-0/repos/svnauthz 
   #PerlAccessHandler Apache::Authn::Redmine::access_handler 
   PerlAuthenHandler Apache::Authn::Redmine::authen_handler 

   RedmineDSN "DBI:mysql:database=bitnami_redmine;host=localhost:{port};mysql_socket=/opt/redmine-3.0.3-0/mysql/tmp/mysql.sock" 
   RedmineDbUser "bitnami" 
   RedmineDbPass "{DB_password}" 
 </Location> 

 </pre> 

 h2. Redmineを再起動します。 

 <pre> 
 # /opt/redmine-3.0.3-0/ctlscript.sh restart 
 </pre> 

 h2. Redmineのユーザ/パスワードでSubversionのコミットができれば成功です。