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④ Vault Radar CLIでのシークレット検出

Posted at

はじめに

前回の記事では、HCP Vault Radar Agent経由のスキャンを試しました。

はじめてのHCP Vault Radar③ Vault Radar Agent 経由でのシークレット自動検出

HCP Vault Radarでは、いくつかのスキャン方式を提供しています。
以下は、HCP Vault Radarが提供するスキャン方式の一覧です。

# カテゴリ 説明
1 HCP Vault Radar Scan SaaSからの直接スキャン、トライアル環境で設定可能。
2 Vault Radar Agent Scan Agent経由のスキャン、トライアル環境で設定可能。Agentは1つまで構成可能
3 Vault Radar CLI Scan CLIでのスキャン。マニュアルに「Contact your customer success manager to enable HCP Vault Radar or for a license to run the CLI in offline mode.」と記載あるので一部利用できない可能性あり。

今回は、#3 Vault Radar CLI Scan 方式のスキャンを試してみました。

1.事前準備

1.Vault Radar Agentを稼働させる際にインストールしたVault Radar CLIを利用します。
CLIのインストールについては、以下を参照ください。

はじめてのHCP Vault Radar③ Vault Radar Agent 経由でのシークレット自動検出

2.次に、ガイドに従い、Vault Radar CLI User ロールを持つService Principalを登録します。

Service principals require the Vault Radar CLI User role in the Vault Radar service.

3.Vault Radarからプロジェクト画面に移動し、「Access Control(IAM)」をクリックします。
image.png

4.「Serive Principals」-「Create service principal」をクリックします。
image.png

5.Vault Radar CLI ロールを割り当てて、「Create service principal」をクリックします。
image.png

6.Service Principalが登録されたら、「Keys」タブをクリックします。
image.png

7.「Generate Key」をクリックします。
image.png

8.登録されたClient IDとClient Secretをメモします。
image.png

9.ProjectIDを取得するために、「Project Settings」をクリックします。
image.png

10.表示されたプロジェクトIDをメモします。
image.png

2. Vault Radar CLIによるスキャン

Vault Radar CLIによるscanコマンドで提供されているBeta版の機能を含め、いくつかのコマンドを試してみます。

image.png

2.1. scan fileコマンド(Beta版)

1.環境変数を設定します。

export HCP_PROJECT_ID=<プロジェクトID>
export HCP_CLIENT_ID=<クライアントID>
export HCP_CLIENT_SECRET=<クライアントシークレット>

2.任意のファイルをスキャンします。

$ vault-radar scan file -p ./config.js2 -o scantest.csv
Scan completed

Summary:
   New secrets found: 2
   Baseline secrets found: 0

3.検出されたシークレットを確認します。

$ cat scantest.csv
category,description,created_at,author,severity,is_historic,deep_link,path,value_hash,fingerprint,textual_context,activeness,tags,managed_location,managed_location_is_latest,total_managed_locations
secret,Password assignment,,,low,,stream:///config.js2:1:19,config.js2,s4dFTSb78qnGvlaDJWV0woldQSx5XaUev5m6jaj1dfE,17da4e431950fea55fc1ff2d3d3b32250fd6d6d6ed8342f899614f9bd2cb8288,"const password = ""***"";",unknown,low_entropy,,,0
secret,Password assignment,,,low,,stream:///config.js2:2:21,config.js2,f7zSZMX7WEfB1F95J3RbXSKtClcl6rhT1m6mH0sCAiA,9930ed88f2c1a49cd1670cf7fb9f1d6d139c85db7db7d87610c6a6e61c8e9c1f,"const dbPassword = ""***"";",unknown,low_entropy,,,0

現時点で連携できるデータソースは以下の3つのみです。
このため、scan fileコマンドの結果は、HCPクラウドには反映されていませんでした。

image.png

4.次にHCP クラウド接続を必要とせずにスキャン行うための「--offline」フラグを使ってみました。
マニュアルに記載の通り、別途ライセンスファイルが必要で、トライアル環境では動作しませんでした。

環境変数が設定されていないことを確認
$ env |grep HCP*

オフラインモードで同じファイルをスキャン
$ vault-radar scan file -p ./config.js2 -o scantest_offline.csv --offline
unable to get license key: unable to stat license file: stat /home/ubuntu/.hashicorp/vault-radar/vault-radar.hclic: no such file or directory

Please make sure to either set VAULT_RADAR_LICENSE or VAULT_RADAR_LICENSE_PATH environment variable or create a license file under ~/.hashicorp/vault-radar/vault-radar.hclic

2.2. scan fileコマンド(Beta版)

1.任意のフォルダをスキャンします。

$ vault-radar scan folder -p ./vault-radar-demo/ -o scantest2.csv
Scan completed

Summary:
  Folders scanned: 1
  Files scanned: 8
  New secrets found: 8
  Baseline secrets found: 0

2.検出されたシークレットを確認します。

$ cat scantest2.csv
category,description,created_at,author,severity,is_historic,deep_link,path,value_hash,fingerprint,textual_context,activeness,tags,managed_location,managed_location_is_latest,total_managed_locations
secret,Password assignment,,,medium,,file://<computername>/home/ubuntu/vault-radar-demo/configjs:1:19,configjs,U7KG9CYzEcon+JLpedfy9gEVEPP2i/PL4xxcS4lahOc,17fd29b616b9e2fde96c277d45e7d6795d0675ff860432dda331990f398062f7,"const password = ""***"";",unknown,common_secret,,,0
secret,Password assignment,,,low,,file://<computername>g/home/ubuntu/vault-radar-demo/.env4:1:19,.env4,1MunxfMJLAbhWlqR6VSmO2S05xslU3mcBvqh4zGL9hI,e1419f354e2354a15ff2a53115f27cffddc3e29480d32fe5ba4d687d674b9567,"const password = ""***"";",unknown,low_entropy,,,0
~割愛~

2.3. scan repoコマンド

このコマンドは、HCPクラウドへのデータアップロードがサポートされているコマンドです。

1.GitHubの任意のリポジトリをスキャンします。
GitHubで発行したパーソナルアクセストークンを環境変数に設定します。

export VAULT_RADAR_GIT_TOKEN=<Token>

2.任意のリポジトリをスキャンします。

$ vault-radar scan repo -u https://github.com/xxx/vault-radar-cli-demo
Scan completed

Summary:
   Tip files scanned: 1
   Commits scanned: 1
   New secrets found: 2
   Baseline secrets found: 0

3.HCPクラウドで確認すると、データソースが追加され、スキャン結果も確認できるようになっていました。
image.png

image.png

最後に

今回は、『Vault Radar CLI』 を使って、いくつかのソースをスキャンしてみました。
次回は、『Integration機能を使ってSlackへ通知』する方法を試してみます。この機能を活用すると、セキュリティイベントをリアルタイムで共有することが可能になります。

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?