この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
こんにちは。たかやまです。
今回はSecurityHubがインシデントを検知した場合に自動でBacklogに起票する方法をご紹介します。
イメージ図
Backlogのapi呼び出しにEventBridge API Destinationsが使えるためアーキテクチャはいたってシンプルになります。
Backlog起票時のイメージはこんな感じ。
やってみた
Backlog設定
まず、はじめにBacklogのAPIキーを発行していきます。
API キーの発行はBacklog公式手順をご参照ください。
APIキーが発行されたら、EventBridgeのエンドポイント設定で利用するためメモしておきます。
EventBridge設定
Security Hubのイベントパターンは重要度ラベルCRITICAL/HIGH
を対象にします。
設定内容の詳細についてはこちらのブログをご参考にしてください。
{
"detail-type": ["Security Hub Findings - Imported"],
"source": ["aws.securityhub"],
"detail": {
"findings": {
"Compliance": {
"Status": [{
"anything-but": "PASSED"
}]
},
"RecordState": ["ACTIVE"],
"Workflow": {
"Status": ["NEW"]
},
"Severity": {
"Label": ["CRITICAL", "HIGH"]
}
}
}
}
次にターゲットを設定していきます。
全体の設定は以下のとおりです。
各設定について説明していきます。
API送信先
ではBacklogの「課題の追加」APIを指定します。
Backlogのドキュメントを参考にPOST
メソッドとエンドポイント
を指定します。
エンドポイント設定時は、最初に発行したAPI キーを?apiKey=
の後ろにセットしていきます。
※このエンドポイントは機密情報として扱ってください。
パラメータについては後述する入力トランスフォーマーで設定していきます。
接続
では必ず認証タイプを設定する必要があるため、認証タイプでAPI キー
を選択しダミー情報を登録していきます。
ここでは dummy-key/dummy-value といった適当な値を入力しています。
追加設定では、入力トランスフォーマー
の設定をしていきます。
入力トランスフォーマーを設定
を選択すると、設定画面がポップアップで表示されます。
入力パス
にはBacklogに表示したいSecurity Hubの情報をkey-value形式で記述していきます。
Security Hubイベント通知例を参考に抽出したい情報を選んでください。
Security Hubイベント通知例
{
"version": "0",
"id": "CWE-event-id",
"detail-type": "Security Hub Findings - Imported",
"source": "aws.securityhub",
"account": "111122223333",
"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:111122223333:integtest/trigger/6294d71b927c41cbab915159a8f326a3/alert/f2893b211841"
],
"detail": {
"findings": [
{
"SchemaVersion": "2018-10-08",
"Id": "arn:aws:securityhub:ap-northeast-1:123456789012:subscription/aws-foundational-security-best-practices/v/1.0.0/EC2.19/finding/8bf42694-ad14-4ce8-abbe-f9337102aa37",
"ProductArn": "arn:aws:securityhub:ap-northeast-1::product/aws/securityhub",
"ProductName": "Security Hub",
"CompanyName": "AWS",
"Region": "ap-northeast-1",
"GeneratorId": "aws-foundational-security-best-practices/v/1.0.0/EC2.19",
"AwsAccountId": "123456789012",
"Types": [
"Software and Configuration Checks/Industry and Regulatory Standards/AWS-Foundational-Security-Best-Practices"
],
"FirstObservedAt": "2022-08-21T14:16:43.037Z",
"LastObservedAt": "2022-08-21T14:16:46.226Z",
"CreatedAt": "2022-08-21T14:16:43.037Z",
"UpdatedAt": "2022-08-21T14:16:43.037Z",
"Severity": {
"Product": 90,
"Label": "CRITICAL",
"Normalized": 90,
"Original": "CRITICAL"
},
"Title": "EC2.19 Security groups should not allow unrestricted access to ports with high risk",
"Description": "This control checks whether unrestricted incoming traffic for the security groups is accessible to the specified ports [3389, 20, 23, 110, 143, 3306, 8080, 1433, 9200, 9300, 25, 445, 135, 21, 1434, 4333, 5432, 5500, 5601, 22, 3000, 5000, 8088, 8888] that have the highest risk. This control passes when none of the rules in a security group allow ingress traffic from 0.0.0.0/0 for the listed ports.",
"Remediation": {
"Recommendation": {
"Text": "For directions on how to fix this issue, consult the AWS Security Hub Foundational Security Best Practices documentation.",
"Url": "https://docs.aws.amazon.com/console/securityhub/EC2.19/remediation"
}
},
"ProductFields": {
"StandardsArn": "arn:aws:securityhub:::standards/aws-foundational-security-best-practices/v/1.0.0",
"StandardsSubscriptionArn": "arn:aws:securityhub:ap-northeast-1:123456789012:subscription/aws-foundational-security-best-practices/v/1.0.0",
"ControlId": "EC2.19",
"RecommendationUrl": "https://docs.aws.amazon.com/console/securityhub/EC2.19/remediation",
"RelatedAWSResources:0/name": "securityhub-vpc-sg-restricted-common-ports-6651e1d2",
"RelatedAWSResources:0/type": "AWS::Config::ConfigRule",
"StandardsControlArn": "arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/EC2.19",
"aws/securityhub/ProductName": "Security Hub",
"aws/securityhub/CompanyName": "AWS",
"aws/securityhub/annotation": "Security group has a rule that allows all traffic.",
"Resources:0/Id": "arn:aws:ec2:ap-northeast-1:123456789012:security-group/sg-0dc53031d3d4fb993",
"aws/securityhub/FindingId": "arn:aws:securityhub:ap-northeast-1::product/aws/securityhub/arn:aws:securityhub:ap-northeast-1:123456789012:subscription/aws-foundational-security-best-practices/v/1.0.0/EC2.19/finding/8bf42694-ad14-4ce8-abbe-f9337102aa37"
},
"Resources": [
{
"Type": "AwsEc2SecurityGroup",
"Id": "arn:aws:ec2:ap-northeast-1:123456789012:security-group/sg-0dc53031d3d4fb993",
"Partition": "aws",
"Region": "ap-northeast-1",
"Details": {
"AwsEc2SecurityGroup": {
"GroupName": "all-inbound",
"GroupId": "sg-0dc53031d3d4fb993",
"OwnerId": "123456789012",
"VpcId": "vpc-0ca353a3f321fbf7c",
"IpPermissions": [
{
"IpProtocol": "-1",
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
]
}
],
"IpPermissionsEgress": [
{
"IpProtocol": "-1",
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
]
}
]
}
}
}
],
"Compliance": {
"Status": "FAILED"
},
"WorkflowState": "NEW",
"Workflow": {
"Status": "NEW"
},
"RecordState": "ACTIVE",
"FindingProviderFields": {
"Severity": {
"Label": "CRITICAL",
"Original": "CRITICAL"
},
"Types": [
"Software and Configuration Checks/Industry and Regulatory Standards/AWS-Foundational-Security-Best-Practices"
]
}
}
]
}
}
入力パス
{
"Description": "$.detail.findings[0].Description",
"Id": "$.detail.findings[0].Id",
"Label": "$.detail.findings[0].Severity.Label",
"Recommendation": "$.detail.findings[0].ProductFields.RecommendationUrl",
"Resource": "$.detail.findings[0].Resources[0].Id",
"Summary": "$.detail.findings[0].Title"
}
テンプレート
にはBacklog APIに渡すパラメータに対応する形で記述していきます。
各パラメータの設定内容は以下のとおりです。
パラメータ | 説明 |
---|---|
projectId | Backlogのプロジェクト。プロジェクト一覧の取得 |
summary | Backlogの課題の件名。ここではSecurityHub検出のTitle情報を設定 |
description | Backlogの本文。Backlogのテキスト整形ルールに合わせて記述する(例はMarkdown) |
issueTypeId | Backlogの種別。種別一覧の取得 |
priorityId | Backlogの優先度。 優先度一覧の取得 |
テンプレート
{
"projectId": "123456",
"summary": <Summary>,
"description": "Description:<br /><Description><br /><br />Severity:<br /><Label><br /><br />Resource:<br /><Resource><br /><br />Links:<br />[Security Hub](https://ap-northeast-1.console.aws.amazon.com/securityhub/home?region=ap-northeast-1#/findings?search=Id%3D%255Coperator%255C%253AEQUALS%255C%253A<Id>)<br />[Recommendation](<Recommendation>)",
"issueTypeId": "1234567",
"priorityId": "3"
}
descriptionはテンプレート記述の都合上、一行に圧縮されてわかりにくいため改行を入れた見やすくした内容を添えておきます。
descriptionを見やすくした内容
Description:<br />
<Description><br />
<br />
Severity:<br />
<Label><br />
<br />
Resource:<br />
<Resource><br />
<br />
Links:<br />
[Security Hub](https://ap-northeast-1.console.aws.amazon.com/securityhub/home?region=ap-northeast-1#/findings?search=Id%3D%255Coperator%255C%253AEQUALS%255C%253A<Id>)<br />
[Recommendation](<Recommendation>)
あとは、タグの設定をして問題なければ作成します。
動作確認
セキュリティグループのインバウンドを全開放にして[EC2.19]のイベントを検出してみます。
セキュリティグループ解放数分後、Backlogに登録されていることが確認できます。
最後に
EventBridge API Destinationsを利用することでLambdaなどを使わずローコードで自動起票の仕組みを実装することができます。API Destinationsを初めて使いましたが、サクッとAPIを叩く実装ができるのでとても可能性を感じる機能でした。
APIを利用する場面があれば、積極的にEventBridge API Destinationsを使えるか検討したいと思いました。
以上、たかやまでした。