# Git - SSHでコミットに署名

![](/files/pAo3Ey6vusNnajuniGKz)

## 概説 <a href="#about" id="about"></a>

Gitのコミットに署名することは重要です。署名により、作成者の確認、コミット内容の整合性の確保、なりすましの防止、否認防止が可能になります。秘密鍵による暗号署名は、貢献の真正性とセキュリティへの取り組みを示し、共同作業者間の信頼を築き、リポジトリを改ざんや悪意のあるコードから保護します。

本連携では、開発者がKeeperボルト（Keeperシークレットマネージャー経由）で保護されたSSHキーを使用してGitコミットに署名できます。

{% hint style="info" %}
[**最新のgit-ssh-signバイナリをダウンロード**](https://github.com/Keeper-Security/git-ssh-sign/releases)
{% endhint %}

## 機能 <a href="#features" id="features"></a>

* Keeperボルトに保存されたSSHキーを使用してGitコミットに署名
* ディスク上のSSHキーが不要なセキュアなDevOpsワークフロー
* Windows、macOS、Linuxで動作
* ソースコードは[GitHub](https://github.com/Keeper-Security/git-ssh-sign)で公開

## 要件 <a href="#prerequisites" id="prerequisites"></a>

本ページでは、git-ssh-signによるGitコミット署名について取り扱います。本連携を利用するには、以下が必要です。

* Keeperシークレットマネージャーへのアクセス（[クイックスタートガイド](/jp/keeperpam/secrets-manager/quick-start-guide.md)をご参照ください）
  * Keeperのサブスクリプションでシークレットマネージャーアドオンが有効になっていること
  * シークレットマネージャーポリシーが有効なロールに所属していること
* SSHキーが共有されているKeeper[シークレットマネージャーアプリケーション](/jp/keeperpam/secrets-manager/about/terminology.md#application)
  * アプリケーションの作成手順については、[クイックスタートガイド](https://newdocs.keeper.io/jp/keeperpam/secrets-manager/integrations/pages/-MeRAVfQmDBzKQBC0f_c#2.-create-an-application)をご参照ください
* 初期化済みのKeeper[シークレットマネージャー構成](/jp/keeperpam/secrets-manager/about/secrets-manager-configuration.md)
  * 本連携ではJSON形式の構成のみ使用可能
* Git 2.34.0以降がインストールされていること

## 設定 <a href="#setup" id="setup"></a>

### 1. シークレットマネージャー構成 <a href="#id-1.-secrets-manager-configuration" id="id-1.-secrets-manager-configuration"></a>

* Keeperウェブボルトまたはデスクトップアプリにログイン
* 共有フォルダを作成（例: 「Git SSH Keys」）
* 共有フォルダにSSHキーレコードを追加
* SSHキーレコードでSSHキーを生成

ボルトからSSHキーを取得するには、ゼロ知識型のKeeperシークレットマネージャーを使用します。

すべてのシステムで、ユーザーのホームディレクトリ内の `.config/keeper/ssh-sign.json` にシークレットマネージャー構成ファイルを配置します。見つからない場合は、バックアップとして `ssh-sign.json` も確認します。**シークレットマネージャーアプリケーションは、SSHキーが保存されている共有フォルダにアクセスできる必要があります**。

アプリケーションの設定と構成ファイルの取得については、[構成ドキュメント](/jp/keeperpam/secrets-manager/about/secrets-manager-configuration.md#creating-a-secrets-manager-configuration)をご参照ください。

### 2. Git構成 <a href="#id-2.-git-config" id="id-2.-git-config"></a>

シークレットマネージャーの構成が完了したら、コミットに自動的に署名するようGitを設定できます。ローカルまたはグローバルに設定できます。

構成には以下の4つの情報が必要です。

1. すべてのコミットに署名する
2. デフォルトのGPG署名ではなくSSH署名を使用する
3. 本連携の実行可能ファイルの場所（[こちらからダウンロード](https://github.com/Keeper-Security/git-ssh-sign/releases)）
4. 署名に使用するSSHキーのUID

以下のコマンドで、ローカルGitリポジトリに設定できます（グローバルに設定する場合は `--global` フラグを追加）。

```shell
git config commit.gpgsign true
git config gpg.format ssh
git config gpg.ssh.program <path to this binary>
git config user.signingkey <SSH Key UID>
```

Git構成には以下の属性が含まれます。

```ini
[commit]
	gpgsign = true
[gpg]
	format = ssh
[user]
	signingKey = <SSH Key UID>
[gpg "ssh"]
	program = path/to/ssh-sign
```

### 3. GitHub / GitLabにキーを追加 <a href="#id-3.-add-keys-to-github-gitlab" id="id-3.-add-keys-to-github-gitlab"></a>

#### GitHubのセットアップ <a href="#id-3.1-setup-github" id="id-3.1-setup-github"></a>

**GitHub**でコミット署名を検証するには、SSHキーの公開鍵をGitHubアカウントにアップロードする必要があります。GitHubはこの公開鍵で署名を検証し、UIに `verified` タグが表示されます。

公開鍵をアカウントに追加する手順の詳細は、[GitHubの公式ドキュメント](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account?tool=webui\&platform=linux)をご参照ください。

{% hint style="warning" %}
キーの種類は必ず「signing key」（署名キー）に設定してください。
{% endhint %}

#### GitLabのセットアップ <a href="#id-3.2-setup-gitlab" id="id-3.2-setup-gitlab"></a>

**GitLab**でコミット署名を検証するには、SSHキーの公開鍵をGitLabアカウントにアップロードする必要があります。GitLabはこの公開鍵で署名を検証し、UIに `verified` タグが表示されます。

公開鍵をアカウントに追加する手順の詳細は、[GitLabの公式ドキュメント](https://docs.gitlab.com/ee/user/ssh.html#add-an-ssh-key-to-your-gitlab-account)をご参照ください。

{% hint style="warning" %}
キーの種類は必ず「signing key」（署名キー）または「Authentication and signing」（認証と署名）に設定してください。
{% endhint %}

## 署名の検証 <a href="#verify-signatures" id="verify-signatures"></a>

ターミナルでもIDEでも、すべてのコミットに自動的に署名されます。コミット時の `-S` フラグも不要です。

ターミナルで `git show --pretty=raw` を実行すると、コミットが署名されていることを確認できます。

### GitHubとGitLab <a href="#github-and-gitlab" id="github-and-gitlab"></a>

コミットに署名してGitHubまたはGitLabにプッシュすると、Git履歴のコミット横に `verified` タグが自動的に表示されます。追加の作業は不要です。

![](/files/rvBurV893QbJF9p0rbh0)

### ローカル検証 <a href="#local-verification" id="local-verification"></a>

リポジトリが自社データセンターにある場合、コマンドラインでコミットをローカル検証できます。そのためには、承認済み署名キーを登録する `allowed_signers` ファイルを作成します。

通常、このファイルはホームディレクトリの `.ssh/allowed_signers` に保存するか、リポジトリ内の `.git/allowed_signers` に保存します。ファイルへのパスを `.gitconfig` または `.git/config` に追加します。

```shell
git config gpg.ssh.allowedSignersFile path/to/file
```

`allowed_signers` ファイルの各行は、承認済み署名キーのプリンシパルです。公開鍵に関連付けられたメールアドレスから始め、スペースで区切ります。以下に例を示します。

```
test@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEQvSrBv28KLAjYO7pD91prhlenrm3hZ4B7DdcB/4/H+
```

{% hint style="info" icon="pencil-line" %}
`allowed_signers` ファイルの形式の詳細は[こちら](https://www.man7.org/linux/man-pages/man1/ssh-keygen.1.html)をご参照ください。
{% endhint %}

1つの公開鍵に複数のメールアドレスを関連付ける構文は有効ですが、推奨されず、現時点では利用できません。

Git履歴を検証するには、以下を実行します。

```shell
# Verify all commits in the repo
git log --show-signature

# Verify the last commit in the repo
git log --show-signature -1
```

## ソース <a href="#source" id="source"></a>

本連携のソースコードはオープンソースで、[GitHub](https://github.com/Keeper-Security/git-ssh-sign)で公開されています。問題は[こちら](https://github.com/Keeper-Security/git-ssh-sign/issues)から報告できます。

## 類似連携 <a href="#similar-integrations" id="similar-integrations"></a>

Keeper SSH Agentを使用してGit認証とコミット署名を行うこともできます。

* [Keeper SSH Agent](/jp/keeperpam/privileged-access-manager/ssh-agent.md)について
* [Gitとの統合](/jp/keeperpam/privileged-access-manager/ssh-agent/integration-with-git.md)について


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://newdocs.keeper.io/jp/keeperpam/secrets-manager/integrations/git-sign-commits-with-ssh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
