

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# git-secrets を使用して Git リポジトリに機密情報やセキュリティ上の問題がないかスキャンする
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets"></a>

*Saurabh Singh、Amazon Web Services*

## 概要
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets-summary"></a>

このパターンでは、 AWS Labs のオープンソースの [git-secrets](https://github.com/awslabs/git-secrets) ツールを使用して Git ソースリポジトリをスキャンし、ユーザーパスワードや AWS アクセスキーなどの機密情報が含まれる可能性のあるコード、またはその他のセキュリティ上の問題があるコードを検索する方法について説明します。

`git-secrets` は、コミット、コミットメッセージ、マージをスキャンして、シークレットなどの機密情報が Git リポジトリに追加されないようにします。例えば、コミット、コミットメッセージ、またはマージ履歴のコミットが、設定済みで禁止されている正規表現パターンのいずれかに一致した場合、そのコミットは拒否されます。

## 前提条件と制限事項
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets-prereqs"></a>

**前提条件**
+ アクティブな AWS アカウント
+ セキュリティスキャンが必要な Git リポジトリ
+ Git クライアント (バージョン 2.37.1 以降) がインストールされていること

## アーキテクチャ
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets-architecture"></a>

**ターゲットアーキテクチャ**
+ Git
+ `git-secrets`

![\[git-secrets ツールを使用して、Git ソースリポジトリで機密情報をスキャンします。\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/4a18e0c8-0935-4ee2-86bf-c1dfcfbc1bcb/images/e4813a76-83c2-4254-b5f4-aafe2b8f2127.png)


 

## ツール
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets-tools"></a>
+ [git-secrets](https://github.com/awslabs/git-secrets) は、機密情報を Git リポジトリにコミットすることを防ぐツールです。
+ [Git](https://git-scm.com/) はオープンソースの分散型バージョン管理システムです。

## ベストプラクティス
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets-best-practices"></a>
+ 必ず、すべてのリビジョンを含めて Git リポジトリをスキャンしてください。

  ```
  git secrets --scan-history
  ```

## エピック
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets-epics"></a>

### EC2 インスタンスに接続する
<a name="connect-to-an-ec2-instance"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| SSH を使用して EC2 インスタンスに接続する。 | SSH とキーペアファイルを使用して、Amazon Elastic Compute Cloud (Amazon EC2) インスタンスに接続します。ローカルマシンでリポジトリをスキャンする場合は、このステップをスキップできます。 | AWS 全般 | 

### Git をインストールする
<a name="install-git"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Git をインストールする。 | 次のコマンドを使用して Git をインストールします。<pre>yum install git -y</pre>ローカルマシンを使用している場合は、特定の OS バージョンの Git クライアントをインストールできます。詳細については、[Git Web サイト](https://git-scm.com/downloads/guis)を参照してください。 | AWS 全般 | 

### ソースリポジトリをクローンして git-secrets をインストールします
<a name="clone-the-source-repository-and-install-git-secrets"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Git ソースリポジトリをクローンする。 | スキャンする Git リポジトリを複製するには、ホームディレクトリから **Git clone** コマンドを選択します。 | AWS 全般 | 
| git-secrets をクローンする。 | `git-secrets` git リポジトリをクローンします。<pre>git clone https://github.com/awslabs/git-secrets.git</pre>`git-secrets` の実行時に Git がそれを取得できるように、`PATH ` のどこかに `git-secrets` を配置します。 | AWS 全般 | 
| git-secrets をインストールする。 | **Unix およびバリアント (Linux/MacOS) の場合:**`Makefile` (`git-secrets` リポジトリに用意されている) `install` のターゲットを使用してツールをインストールできます。`PREFIX` および `MANPREFIX` 変数を使用してインストールパスをカスタマイズできます。<pre>make install</pre>**Windows の場合:**`git-secrets` リポジトリで提供されている PowerShell `install.ps1` スクリプトを実行します。このスクリプトは、インストールファイルをインストールディレクトリ (`%USERPROFILE%/.git-secrets` デフォルト) にコピーし、そのディレクトリを現在のユーザー `PATH` に追加します。<pre>PS > ./install.ps1</pre>**Homebrew (macOS ユーザー) の場合:**以下を実行します:<pre>brew install git-secrets</pre> | AWS 全般 | 

### git コードリポジトリをスキャンする
<a name="scan-git-code-repository"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| ソースリポジトリに移動する。 | スキャンする Git リポジトリのディレクトリに切り替えます。<pre>cd my-git-repository</pre> | AWS 全般 | 
| AWS ルールセット (Git フック) を登録する。 | 各コミットで Git リポジトリをスキャンするように `git-secrets` を設定するには、以下のコマンドを実行します。<pre>git secrets --register-aws</pre> | AWS 全般 | 
| リポジトリをスキャンする。 | 次のコマンドを実行して、リポジトリのスキャンを開始します。<pre>git secrets -–scan</pre> | AWS 全般 | 
| 出力ファイルを確認する。 | Git リポジトリに脆弱性が見つかると、ツールは出力ファイルを生成します。例えば、次のようになります。<pre>example.sh:4:AWS_SECRET_ACCESS_KEY = *********<br /><br />[ERROR] Matched one or more prohibited patterns<br /><br />Possible mitigations:<br />- Mark false positives as allowed using: git config --add secrets.allowed ...<br />- Mark false positives as allowed by adding regular expressions to .gitallowed at repository's root directory<br />- List your configured patterns: git config --get-all secrets.patterns<br />- List your configured allowed patterns: git config --get-all secrets.allowed<br />- List your configured allowed patterns in .gitallowed at repository's root directory<br />- Use --no-verify if this is a one-time false positive</pre> | AWS 全般 | 

## 関連リソース
<a name="scan-git-repositories-for-sensitive-information-and-security-issues-by-using-git-secrets-resources"></a>
+ [git-secrets ツール](https://github.com/awslabs/git-secrets)