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?

EventBridgeの入力トランスフォーマーを用いてSecurity Hubのアラートメールを整形する

0
Posted at

はじめに

こんにちは、エンジニアの わた です。
皆さんはSecurity Hub でアラートメールを設定したにもかかわらず、膨大な英語の文字列が送られてきた経験はありますでしょうか。
僕はあります。
アラートメールを整形できることを知らず、しばらくはそのまま運用していました。

さて、今回はそんな見づらいアラートメールについて、EventBridge の「入力トランスフォーマー」を用いて見やすくしていきたいと思います。

構成図

image.png

やってみる

環境の構成については前回行ったこちらの記事を参考にしてください。
今回はEventBridgeの入力トランスフォーマーの部分のみ行います。

現在のアラートメールの確認

現在のアラートメールは以下のようになっております。
一部のみの抜粋ですがすごいことになっていますね、、、
image.png

Event Bridgeの入力トランスフォーマーの設定

作成したイベントパターンを選択します。
image.png

「編集」をクリックします。
image.png

ステップ3の「ターゲットを選択」を選びます。
image.png

「追加設定」から「入力トランスフォーマー」を選択します。
image.png

入力トランスフォーマーの設定について

入力トランスフォーマーの設定は大きく以下の3つに分かれます。

  • サンプルイベント
     実際にSecurity Hubが送ってくるイベントのフォーマット(json形式)です。
  • 入力パス
     サンプルイベントのjsonファイルにおける各項目を変数化して、この後のテンプレートで使用できるように定義します。
  • テンプレート
     実際に通知する内容をここで設定します。

今回のEventBridgeのイベントパターンは「Security Hub Findings - Inported」を使用しているため、同様のサンプルイベントを選択します。
image.png

サンプルイベント
{
 "version": "0",
 "id": "8e5622f9-d81c-4d81-612a-9319e7ee2506",
 "detail-type": "Security Hub Findings - Imported",
 "source": "aws.securityhub",
 "account": "123456789012",
 "time": "2019-04-11T21:52:17Z",
 "region": "us-west-2",
 "resources": ["arn:aws:securityhub:us-west-2::product/aws/macie/arn:aws:macie:us-west-2:123456789012:integtest/trigger/6294d71b927c41cbab915159a8f326a3/alert/f2893b211841"],
 "detail": {
   "findings": [{
     "SchemaVersion": "2018-10-08",
     "Id": "arn:aws:macie:us-west-2:123456789012:integtest/trigger/6214d71b927c41cbab015159a8f316a3/alert/f2893b211841467198cc1201e9031ee4",
     "ProductArn": "arn:aws:securityhub:us-west-2::product/aws/macie",
     "GeneratorId": "arn:aws:macie:us-west-2:123456789012:integtest/trigger/6214d71b927c41cbab015159a8f316a3",
     "AwsAccountId": "123456789012",
     "Types": ["Sensitive Data Identifications/Passwords/Google Suite Two-factor backup codes in S3"],
     "FirstObservedAt": "2019-04-11T21:52:15.900Z",
     "LastObservedAt": "2019-04-11T21:52:15.900Z",
     "CreatedAt": "2019-04-11T21:52:15.900Z",
     "UpdatedAt": "2019-04-11T21:52:15.900Z",
     "Severity": {
       "Product": 6,
       "Normalized": 15
     },
     "Confidence": 5,
     "Title": "Google Suite Two-Factor Backup Codes uploaded to S3",
     "Description": "Google Suite two-factor backup codes uploaded to S3....",
     "Remediation": {
       "Recommendation": {
         "Text": "v2 Release"
       }
     },
     "ProductFields": {
       "rule-arn": "arn:aws:macie:us-west-2:123456789012:trigger/6214d71b927c41cbab015159a8f316a3",
       "tags:0": "DATA_COMPLIANCE",
       "tags:1": "BASIC_ALERT",
       "themes:0/theme": "google_two_factor_backup",
       "themes:0/count": "1",
       "dlpRisk:0/risk": "8",
       "dlpRisk:0/count": "1",
       "owner:0/name": "vchin",
       "owner:0/count": "1",
       "aws/securityhub/FindingId": "arn:aws:securityhub:us-west-2::product/aws/macie/arn:aws:macie:us-west-2:123456789012:integtest/trigger/6214d71b927c41cbab015159a8f316a3/alert/f2893b211841467198cc1201e9031ee4",
       "aws/securityhub/SeverityLabel": "LOW",
       "aws/securityhub/ProductName": "Macie",
       "aws/securityhub/CompanyName": "Amazon"
     },
     "Resources": [{
       "Type": "AwsS3Bucket",
       "Id": "arn:aws:s3:::test-bucket-12",
       "Partition": "aws",
       "Region": "us-west-2"
     }],
     "RecordState": "ACTIVE",
     "WorkflowState": "NEW"
   }]
 }
}

この中で今回は「アラート送信元」「アカウントID」「発生日時」「アラート」「アラートの説明」を取り出したいので、入力パスは以下のようにします。
なお、入力パスの書き方は以下の通りです。

{"変数名": "$.<対象の項目>"}

image.png

入力パス
{
    "account": "$.account",
    "description": "$.detail.findings[0].Description",
    "resourceId": "$.detail.findings[0].Resources[0].Id",
    "source": "$.source",
    "time": "$.time",
    "title": "$.detail.findings[0].Title"
}

入力パスで変数化した項目を用いて以下のテンプレートで出力します。
テンプレートの書き方についてはAWSの公式ドキュメントを参考にしてください。

image.png

テンプレート
"<source> でアラートを検知しました。"

"・アカウントID:<account>"
"・検知日時:<time>"
"・アラート:<title>"
"・アラートの説明:<description>"
"・対象リソース:<resourceId>"

出力結果をテストすることもできます。
出力結果を出力し、問題なく出力できていることが確認できました。
image.png

その後受信されたアラートメールについても想定通りのフォーマットになっていました。
image.png

まとめ

今回はEventBridgeの入力トランスフォーマーを用いてアラートメールの整形を行いました。
ただ1つ注意があり、時刻についてはAWSの仕様でGMTになってしまうため、こちらについてはほかの方法で日本時間に変更する必要があります。
アラートメールの波に飲み込まれている人の助けになれば幸いです。
ではでは。

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?