0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめてのHCP Vault Radar② GitHubのPull Requestをマージ前にスキャン/シークレット検出

Posted at

はじめに

前回の記事では、HCP Vault RadarとGitHubを連携して、自動でシークレット(パスワードやAPIキーなど)を検出する方法をご紹介しました。

はじめてのHCP Vault Radar① GitHub連携によるシークレット自動検出

今回は、HCP Vault Radarが提供するPull Request(PR)スキャン機能について動作検証を行いました。

image.png

1. PR Check機能がない場合の動作確認

1.新しくブランチを作成して、任意のファイルを追加します。

$ git checkout -b develop
Switched to a new branch 'develop'

$ cp .env .env2
$ vim .env2
const password = "hunter2V2";
const dbPassword = "supersecurepassword123V2";
$ git add .
$git commit -m "Add .env2"
$git push origin develop

2.「Compare & pull request」をクリックします。
image.png

3.「Create pull request」をクリックします。
image.png

4.Pull Request内にシークレットが含まれていても、PR Check機能がインストールされていない場合は、Merge pull requestでそのままマージが可能です。
image.png

2. PR Check機能のインストール

1.GitHubリポジトリの『Settings』ページを開き、『PR Checks』セクションを選択します。そこで、『Install the HashiCorp Vault Radar app for GitHub Checks』をクリックします。
image.png

2.HashiCorp Vault Radar Checks Appをインストールします。
image.png

3.インストール先を選択します、
image.png

4.リポジトリを選択して、「install」をクリックします。
image.png

5.アプリケーションが追加されました。
image.png

3. PR Check設定後の動作確認

1.先ほどのブランチに、任意のファイルを追加します。

$ git checkout develop
$ cp .env .env3
$ vim .env3
const password = "hunter2V3";
const dbPassword = "supersecurepassword123V3"; 
$ git add .
$git commit -m "Add .env3"
$git push origin develop

2.「Create pull request」をクリックします。
image.png

3.「Create pull request」をクリックします。
image.png

4.Pull Requestに対して、HashiCorp Vault Radar Secret Scanが動作します。
image.png

5.シークレットを検知し、Pull Requestが失敗しました。
image.png

6.右側の「・・・」ボタンをクリックすると、詳細情報が表示され、シークレット検知の旨が表示されていました。
image.png

7.この状態で、Merge pull requestを行うと、マージが成功してしまいました。
image.png

4. GitHubへclassic branch protection ruleルールの追加

GitHubの設定を変更し、HashiCorp Vault Radar Secret Scanが失敗した場合に、Pull Requestのマージを防ぐように設定を強化します。

1.「Settings」-「Branches」から、「Add classic branch protection rule」 をクリックします。
image.png

2.以下の通り設定し、設定を保存します。

  • Branch name pattern: main
  • Require a pull request before merging:チェック
  • Require status checks to pass before merging:チェック
  • Hashicorp Vault Radar Secret Scanを選択
  • Do not allow bypassing the above settings:チェック

image.png
image.png

5. PR Check設定/classic branch protection ruleルール追加後の動作確認

1.先ほどのブランチに、任意のファイルを追加します。

$ git checkout develop
$ cp .env .env4
$ vim .env4
const password = "hunter2V4";
const dbPassword = "supersecurepassword123V4"; 
$ git add .
$git commit -m "Add .env4"
$git push origin develop

2.「Create pull request」をクリックします。
image.png

3.「Create pull request」をクリックします。
image.png

4.シークレットを検知した結果、Pull Requestは失敗し、Merge pull requestボタンがグレーアウトされてマージが不可能になりました。
image.png

最後に

今回は、HCP Vault Radarで、GitHubのPull Request内にあるシークレット検出機能を試しました。
次回は、Vault Radarの『Radar Agent』を使用してGitHubリポジトリをスキャンする方法を検証します。Radar Agentを使用することで、より柔軟なスキャンが可能になる点に注目します。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?