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?

Trivyを使ったTerraformコードのセキュリティスキャン入門

Posted at

trivyとは

Aqua Security社が開発しオープンソースの脆弱性スキャナーです。
trivyは、Terraformに焦点を当てているが、コンテナイメージ、ファイルシステム、Gitリポジトリなどさまざまな対象をスキャンすることが可能です。

tfsecとは

terraformのコードをセキュリティ上の問題や一般的なベストプラクティスに基づいてスキャンしてくれる静的解析ツール。
開発終了してるのでtrivyの方を使う方が良いです。最新のものにも対応しています。

インストール

Macでtrivyを使用してみようと思うので以下のコマンドでtrivyをインストール

% brew install trivy

trivy実行方法

スキャンしたい対象のディレクトリに移動して以下のコマンドを実行する。

trivy config .

実行結果

AVD-AWS-0132 (HIGH): Bucket does not encrypt data with a customer managed key.
═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Encryption using AWS keys provides protection for your S3 buckets. To increase control of the encryption and manage factors like rotation use customer managed keys.


See https://avd.aquasec.com/misconfig/avd-aws-0132
─────────────────────────────────────────────────────────────────────────────────path/to/my_s3_module/main.tf:4-10 via project/env/dev/main.tf:4-12 (module.my_s3_bucket) ───────────────────────────────────────────────────────────────────────────── 4   4 ┌ resource "aws_s3_bucket" "example-bucket" {
   5 │   bucket = var.bucket_name
   6 │ 
   7 │   tags = {
   8 │     Environment = var.environment
   9 │   }
  10 └ }

上の結果を例に挙げて考えてみます。
S3バケットが、AWS管理のデフォルトキー(SSE-S3)ではなく、顧客管理キー(CMK)を使って暗号化されていない」という重大度(HIGH)の警告が出ています。

🤔どう言うことか?

S3の暗号化には、大きく分けて2つの方法が存在しています。

  1. SSE-S3(AWSが管理してくれるキー)
      ・S3バケットのデフォルトの暗号化
      ・AWSがキーの作成から管理、ローテーションまで全てやってくれる。
      ・設定は簡単、ただユーザ側でキーの制御はできない。
  2. SSE-KMS(KMSキーを使った暗号化)
      ・AWS KMSを使ってキー作成・管理
      ・KMSキーには、2種類存在する。
       ・AWSがKMS内で管理するキー
       ・顧客がKMS内で管理するキー(CMK)

今回のTrivyの警告は、SSE-S3を使うのではなく、CMKを使いなさいって言う指摘
公式ドキュメント見たい場合、警告文にSeeでリンクが記載されてるので確認することができる。

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?