「Git サーバー」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(新規作成)
 
(→‎全般: リンクを修正)
 
(2人の利用者による、間の16版が非表示)
1行目: 1行目:
 
[[Category:バージョン管理システム]]
 
[[Category:バージョン管理システム]]
 
[[Category:サーバー]]
 
[[Category:サーバー]]
[[en:Git Server]]
+
[[en:Git server]]
 
この記事では、[[Git]] サーバーをホストする方法について概要を説明します。より詳細な情報は、Pro Git book の [https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols Git on the Server chapter] の章を参照ください。
 
この記事では、[[Git]] サーバーをホストする方法について概要を説明します。より詳細な情報は、Pro Git book の [https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols Git on the Server chapter] の章を参照ください。
   
== Protocols ==
+
== プロトコル ==
   
Refer to [https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols Git on the Server - The Protocols] for a detailed description along with pros and cons.
+
詳細な説明と長所・短所は、[https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols Git on the Server - The Protocols] を参照してください。
   
=== General ===
+
=== 全般 ===
   
[https://miracoin.wordpress.com/2014/11/25/step-by-step-guide-on-setting-up-git-server-in-arch-linux-pushable/ Step by Step Guide on Setting Up git Server] describes setting up an unsecured server on Arch.
+
[https://miracoin.wordpress.com/2014/11/25/step-by-step-guide-on-setting-up-git-server-in-arch-linux-pushable/ Step by Step Guide on Setting Up git Server] では Arch での安全でないサーバーのセットアップを説明しています。
   
By default, the git user is expired ("Your account has expired; please contact your system administrator"). Use [[chage]] to remove the expiration condition, e.g. as follows:
+
デフォルトでは、git ユーザは期限切れになっています ("Your account has expired; please contact your system administrator") 有効期限切れの条件を解除するには、例えば、以下のように [[ユーザーとグループ#ユーザー管理の他の例|chage]] を使用します。
   
 
chage -E -1 git
 
chage -E -1 git
18行目: 18行目:
 
=== SSH ===
 
=== SSH ===
   
  +
[[OpenSSH|SSH サーバー]] を設置するだけです。
You only need to set up an [[SSH|SSH server]].
 
   
You are able to secure the SSH user account even more allowing only push and pull commands on this user account. This is done by replacing the default login shell by git-shell. Described in [https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server Setting Up the Server].
+
この SSH ユーザーアカウントでは、push pull のコマンドのみを許可することで、より安全性を確保することができます。これは、デフォルトのログインシェルを git-shell に置き換えることで実現します。[https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server Setting Up the Server] で説明しています。
   
  +
[[#全般]]の手順で作成した git サーバーをこの条項の手順 ([[#SSH]]) で保護する場合、Arch では以下の追加手順が必要です。
When securing the git server created using the instructions in [[#General]] with the instructions of this clause ([[#SSH]]), the following additional steps are needed on Arch:
 
   
;correct home directory: In order for ssh to be able to read /srv/git/.ssh/authorized_keys, the home directory for git in /etc/passwd needs to be changed from "/" to "/srv/git".
+
;正しいホームディレクトリ: ssh /srv/git/.ssh/authorized_keys を読めるようにするには、/etc/passwd git 用ホームディレクトリを "/" から "/srv/git" に変更する必要があります。
  +
;ホームディレクトリが修正された場合のベースパスの修正: git がリポジトリを提供するために、gitのホームディレクトリからリポジトリを提供する場合、"/usr/lib/systemd/system/git-daemon@.service" の --base-path を "/srv/git" へ変更する必要があります。
;correct base path when home directory is corrected: In order for git to serve the repositories, the --base-path in "/usr/lib/systemd/system/git-daemon\@.service" need to be changed to "/srv/git" if the repositories are served from git's home directory.
 
   
=== Smart HTTP ===
+
=== Dumb HTTP ===
   
  +
この文脈における "Dumb" とは、[[WebDAV]] のみが pull と push に関与することを意味します。
{{Expansion|There are many [[web server]]s with CGI support.}}
 
   
  +
==== nginx ====
The {{man|1|git-http-backend}} is a CGI program, allowing efficient cloning, pulling and pushing over HTTP(S).
 
  +
  +
nginx の基本的な WebDAV 手順に従います。WebDAV 経由の push にもロックが必要です。以下にブロック箇所の例を示します。
  +
  +
{{hc|1=/etc/nginx/nginx.conf|2=
  +
location /repos/ {
  +
auth_basic "Authorized Personnel Only!";
  +
auth_basic_user_file /etc/nginx/htpasswd;
  +
dav_methods PUT DELETE MKCOL COPY MOVE;
  +
dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
  +
dav_access user:rw group:rw all:r;
  +
dav_ext_lock zone=general;
  +
create_full_put_path on;
  +
client_body_temp_path /tmp;
  +
}
  +
}}
  +
  +
{{ic|dav_ext_lock zone}} に注目してください。指定したロックゾーンを設定の http セクションに追加します:
  +
  +
{{hc|1=/etc/nginx/nginx.conf|2=dav_ext_lock_zone zone=general:10m;}}
  +
  +
ここで、サーバーの git リポジトリを準備するときの通常の手順を実行します。
  +
  +
* {{ic|git clone --bare /path/to/myrepo myrepo.git}}
  +
* ベアリポジトリをサーバーにコピーします。
  +
* ベアリポジトリで {{ic|git update-server-info}} を実行します。
  +
* リポジトリを http:http によって所有されるようにchownします
  +
  +
HTTP ベーシック認証を追加した、htaccess ファイルにパスワードを入力した人は、誰でも push することができます。
  +
  +
これで、通常どおり clone を作成できます。
  +
  +
$ git clone <nowiki>https://www.example.com/repos/myrepo.git</nowiki>
  +
Cloning into 'myrepo'...
  +
$
  +
  +
いくつかの変更を加え、add、commit、push します。
  +
  +
$ git push origin main
  +
error: Cannot access URL <nowiki>https://www.example.com/repos/myrepo.git/</nowiki>, return code 22
  +
fatal: git-http-push failed
  +
error: failed to push some refs to '<nowiki>https://www.example.com/repos/myrepo.git</nowiki>'
  +
  +
実行しても PROPFIND は 401 Unauthorized とだけ報告します。nginx のエラーログには何もありません。どうやら git クライアントは、その後のすべてのリクエストでユーザー名とパスワードを渡すことに問題があるようです。git credential cache を実行しても解決しません。今のところうまくいっている唯一の解決策は、~/.netrc を編集することです (明らかに git は http に curl を使っています):
  +
  +
{{hc|1=~/.netrc|2=
  +
machine www.example.com
  +
login git
  +
password topsecret
  +
}}
  +
  +
$ > git push origin main
  +
Fetching remote heads...
  +
refs/
  +
refs/heads/
  +
refs/tags/
  +
updating 'refs/heads/main'
  +
from 03f8860418facfbecedd5e0a81b480131b31bcba
  +
to ec5536091e31ebf172a34c6d1ebddfc36e3bd3a6
  +
sending 3 objects
  +
done
  +
Updating remote server info
  +
To <nowiki>https://www.example.com/repos/myrepo.git</nowiki>
  +
0318860..ec55560 main -> main
  +
  +
clone URL を {{ic|<nowiki>https://username:password@www.example.com/repos/myrepo.git</nowiki>}} と指定することは考えないでください。これは最初のクローンでは動作しますが、その後の push ではエラーログに宛先 URL が別のリポジトリで処理されているというエラーメッセージが表示されます。
  +
  +
=== Smart HTTP ===
  +
  +
{{man|1|git-http-backend}} は CGI プログラムで、HTTP(S) で clone や pull, push を効率的に行うことができます。
   
 
==== Apache ====
 
==== Apache ====
   
The setup for this is rather simple as all you need to have installed is the [[Apache HTTP Server]], with {{ic|mod_cgi}}, {{ic|mod_alias}}, and {{ic|mod_env}} enabled) and of course, {{pkg|git}}.
+
[[Apache HTTP Server]] をインストールし、{{ic|mod_cgi}}, {{ic|mod_alias}}, {{ic|mod_env}} を有効にして、そしてもちろん {{pkg|git}} があれば、この設定はかなり簡単です。
   
  +
基本的なセットアップを実行したら、Apache の設定ファイルに以下を追加してください。
Once you have your basic setup running, add the following to your Apache configuration file, which is usually located at:
 
   
 
{{hc|/etc/httpd/conf/httpd.conf|
 
{{hc|/etc/httpd/conf/httpd.conf|
49行目: 118行目:
 
}}
 
}}
   
This assumes your Git repositories are located at {{ic|/srv/git}} and that you want to access them via something like: {{ic|<nowiki>http(s)://your_address.tld/git/your_repo.git</nowiki>}}.
+
ここでは、Git リポジトリが {{ic|/srv/git}} にあり、それにアクセスするために次のような方法をとるものとします。{{ic|<nowiki>http(s)://your_address.tld/git/your_repo.git</nowiki>}}.
   
  +
{{Note|Apache がリポジトリに対して読み書きができることを確認してください。}}
{{Note|Make sure that Apache can read and write to your repositories.}}
 
   
  +
より詳細なドキュメントについては、以下のリンクを参照してください。
For more detailed documentation, visit the following links:
 
 
* https://git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP
 
* https://git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP
 
* https://git-scm.com/docs/git-http-backend
 
* https://git-scm.com/docs/git-http-backend
59行目: 128行目:
 
=== Git ===
 
=== Git ===
   
  +
Git プロトコルは、暗号化も認証もされておらず、読み取りアクセスのみ許可します。
The Git protocol is not encrypted or authenticated, and only allows read access.
 
  +
  +
Git デーモン({{man|1|git-daemon}})は {{ic|git-daemon.socket}} で[[起動]]することができます.
   
  +
このサービスは {{ic|--export-all}} と {{ic|--base-path}} パラメータを使用して {{ic|,/srv/git/}} に置かれたすべてのリポジトリにサービスを提供します.
The Git daemon ({{man|1|git-daemon}}) can be [[start]]ed with {{ic|git-daemon.socket}}.
 
   
  +
== アクセスコントロール ==
The service uses the {{ic|--export-all}} and {{ic|--base-path}} parameters to serve all repositories placed in {{ic|/srv/git/}}.
 
   
  +
きめ細かなアクセス制御を行うために、以下のような解決策があります。
== Access control ==
 
   
  +
* {{App|[[Gitolite]]|Perl で書かれた、Git の上のアクセスコントロールレイヤー。|https://github.com/sitaramc/gitolite|{{Pkg|gitolite}}}}
For fine-grained access control, the following solutions are available:
 
  +
* {{App|[[Gitosis]]|Git リポジトリをホストするためのソフトウェア、Python で書かれています。|https://github.com/tv42/gitosis|{{AUR|gitosis-git}}}}
   
  +
もし、リポジトリにアクセスできるすべての人のための[[ユーザーアカウント]]を作成し、git オブジェクト(ブランチなど)のレベルでのアクセス制御を必要としない場合は、アクセス制御に標準的なファイルパーミッションを使用することもできますので、注意してください。[https://github.com/sitaramc/gitolite/blob/d74e58b5de8c78bddd29b009ba2d606f7fcb4f2d/doc/overkill.mkd]
* {{App|[[Gitolite]]|An access control layer on top of Git, written in Perl.|https://github.com/sitaramc/gitolite|{{Pkg|gitolite}}}}
 
* {{App|[[Gitosis]]|Software for hosting Git repositories, written in Python.|https://github.com/tv42/gitosis|{{AUR|gitosis-git}}}}
 
   
  +
== Web インターフェース ==
Note that if you are willing to create [[user account]]s for all of the people that should have access to the repositories and do not need access control at the level of git objects (like branches), you can also use standard [[file permissions]] for access control.[https://github.com/sitaramc/gitolite/blob/d74e58b5de8c78bddd29b009ba2d606f7fcb4f2d/doc/overkill.mkd]
 
   
  +
=== シンプルな Web アプリケーション ===
== Web interfaces ==
 
   
  +
* [[Gitweb]] — Git に付属するデフォルトの Web インターフェース。
=== Simple web applications ===
 
  +
* {{App|[[cgit]]|プレーン C で書かれた git 用の Web インターフェース。|https://git.zx2c4.com/cgit/|{{Pkg|cgit}}}}
   
  +
=== 高度な Web アプリケーション ===
* [[Gitweb]] — the default web interface that comes with Git
 
* {{App|[[cgit]]|A web interface for git written in plain C.|https://git.zx2c4.com/cgit/|{{Pkg|cgit}}}}
 
   
  +
* {{App|[[Gitea]]|無痛のセルフホスト型 GIT サービス。Gogs のコミュニティによるフォーク。|https://gitea.io|{{Pkg|gitea}}}}
=== Advanced web applications ===
 
  +
* {{App|[[GitLab]]|Ruby で書かれたプロジェクト管理とコードホスティングアプリケーション。|https://gitlab.com/gitlab-org/gitlab-ce|{{Pkg|gitlab}}}}
  +
* {{App|[[Gogs]]|Go で書かれたセルフホスティングの Git サービス。|https://gogs.io|{{AUR|gogs}}}}
   
  +
{{TranslationStatus|Git_server|2022-02-01|710469}}
* {{App|[[Gitea]]|Painless self-hosted Git service. Community managed fork of Gogs.|https://gitea.io|{{Pkg|gitea}}}}
 
* {{App|[[GitLab]]|Project management and code hosting application, written in Ruby.|https://gitlab.com/gitlab-org/gitlab-ce|{{Pkg|gitlab}}}}
 
* {{App|[[Gogs]]|Self Hosted Git Service, written in Go.|https://gogs.io|{{AUR|gogs}}}}
 

2023年11月13日 (月) 01:09時点における最新版

この記事では、Git サーバーをホストする方法について概要を説明します。より詳細な情報は、Pro Git book の Git on the Server chapter の章を参照ください。

プロトコル

詳細な説明と長所・短所は、Git on the Server - The Protocols を参照してください。

全般

Step by Step Guide on Setting Up git Server では Arch での安全でないサーバーのセットアップを説明しています。

デフォルトでは、git ユーザは期限切れになっています ("Your account has expired; please contact your system administrator") 有効期限切れの条件を解除するには、例えば、以下のように chage を使用します。

chage -E -1 git

SSH

SSH サーバー を設置するだけです。

この SSH ユーザーアカウントでは、push と pull のコマンドのみを許可することで、より安全性を確保することができます。これは、デフォルトのログインシェルを git-shell に置き換えることで実現します。Setting Up the Server で説明しています。

#全般の手順で作成した git サーバーをこの条項の手順 (#SSH) で保護する場合、Arch では以下の追加手順が必要です。

正しいホームディレクトリ
ssh が /srv/git/.ssh/authorized_keys を読めるようにするには、/etc/passwd の git 用ホームディレクトリを "/" から "/srv/git" に変更する必要があります。
ホームディレクトリが修正された場合のベースパスの修正
git がリポジトリを提供するために、gitのホームディレクトリからリポジトリを提供する場合、"/usr/lib/systemd/system/git-daemon@.service" の --base-path を "/srv/git" へ変更する必要があります。

Dumb HTTP

この文脈における "Dumb" とは、WebDAV のみが pull と push に関与することを意味します。

nginx

nginx の基本的な WebDAV 手順に従います。WebDAV 経由の push にもロックが必要です。以下にブロック箇所の例を示します。

/etc/nginx/nginx.conf
location /repos/ {
        auth_basic "Authorized Personnel Only!";
        auth_basic_user_file /etc/nginx/htpasswd;
        dav_methods PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
        dav_access user:rw group:rw all:r;
        dav_ext_lock zone=general;
        create_full_put_path on;
        client_body_temp_path /tmp;
    }

dav_ext_lock zone に注目してください。指定したロックゾーンを設定の http セクションに追加します:

/etc/nginx/nginx.conf
dav_ext_lock_zone zone=general:10m;

ここで、サーバーの git リポジトリを準備するときの通常の手順を実行します。

  • git clone --bare /path/to/myrepo myrepo.git
  • ベアリポジトリをサーバーにコピーします。
  • ベアリポジトリで git update-server-info を実行します。
  • リポジトリを http:http によって所有されるようにchownします

HTTP ベーシック認証を追加した、htaccess ファイルにパスワードを入力した人は、誰でも push することができます。

これで、通常どおり clone を作成できます。

$ git clone https://www.example.com/repos/myrepo.git
Cloning into 'myrepo'...
$

いくつかの変更を加え、add、commit、push します。

$ git push origin main
error: Cannot access URL https://www.example.com/repos/myrepo.git/, return code 22
fatal: git-http-push failed
error: failed to push some refs to 'https://www.example.com/repos/myrepo.git'

実行しても PROPFIND は 401 Unauthorized とだけ報告します。nginx のエラーログには何もありません。どうやら git クライアントは、その後のすべてのリクエストでユーザー名とパスワードを渡すことに問題があるようです。git credential cache を実行しても解決しません。今のところうまくいっている唯一の解決策は、~/.netrc を編集することです (明らかに git は http に curl を使っています):

~/.netrc
machine www.example.com
login git
password topsecret
$  > git push origin main
Fetching remote heads...
 refs/
 refs/heads/
 refs/tags/
updating 'refs/heads/main'
 from 03f8860418facfbecedd5e0a81b480131b31bcba
 to   ec5536091e31ebf172a34c6d1ebddfc36e3bd3a6
   sending 3 objects
   done
Updating remote server info
To https://www.example.com/repos/myrepo.git
  0318860..ec55560  main -> main

clone URL を https://username:password@www.example.com/repos/myrepo.git と指定することは考えないでください。これは最初のクローンでは動作しますが、その後の push ではエラーログに宛先 URL が別のリポジトリで処理されているというエラーメッセージが表示されます。

Smart HTTP

git-http-backend(1) は CGI プログラムで、HTTP(S) で clone や pull, push を効率的に行うことができます。

Apache

Apache HTTP Server をインストールし、mod_cgi, mod_alias, mod_env を有効にして、そしてもちろん git があれば、この設定はかなり簡単です。

基本的なセットアップを実行したら、Apache の設定ファイルに以下を追加してください。

/etc/httpd/conf/httpd.conf
<Directory "/usr/lib/git-core">
    Require all granted
</Directory>
 
SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

ここでは、Git リポジトリが /srv/git にあり、それにアクセスするために次のような方法をとるものとします。http(s)://your_address.tld/git/your_repo.git.

ノート: Apache がリポジトリに対して読み書きができることを確認してください。

より詳細なドキュメントについては、以下のリンクを参照してください。

Git

Git プロトコルは、暗号化も認証もされておらず、読み取りアクセスのみ許可します。

Git デーモン(git-daemon(1))は git-daemon.socket起動することができます.

このサービスは --export-all--base-path パラメータを使用して ,/srv/git/ に置かれたすべてのリポジトリにサービスを提供します.

アクセスコントロール

きめ細かなアクセス制御を行うために、以下のような解決策があります。

  • Gitolite — Perl で書かれた、Git の上のアクセスコントロールレイヤー。
https://github.com/sitaramc/gitolite || gitolite
  • Gitosis — Git リポジトリをホストするためのソフトウェア、Python で書かれています。
https://github.com/tv42/gitosis || gitosis-gitAUR

もし、リポジトリにアクセスできるすべての人のためのユーザーアカウントを作成し、git オブジェクト(ブランチなど)のレベルでのアクセス制御を必要としない場合は、アクセス制御に標準的なファイルパーミッションを使用することもできますので、注意してください。[1]

Web インターフェース

シンプルな Web アプリケーション

  • Gitweb — Git に付属するデフォルトの Web インターフェース。
  • cgit — プレーン C で書かれた git 用の Web インターフェース。
https://git.zx2c4.com/cgit/ || cgit

高度な Web アプリケーション

  • Gitea — 無痛のセルフホスト型 GIT サービス。Gogs のコミュニティによるフォーク。
https://gitea.io || gitea
  • GitLab — Ruby で書かれたプロジェクト管理とコードホスティングアプリケーション。
https://gitlab.com/gitlab-org/gitlab-ce || gitlab
  • Gogs — Go で書かれたセルフホスティングの Git サービス。
https://gogs.io || gogsAUR
翻訳ステータス: このページは en:Git_server の翻訳バージョンです。最後の翻訳日は 2022-02-01 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。