AWS Security Hub オートメーションルールで特定のコントロールを自動抑制してみた

AWS Security Hub オートメーションルールで特定のコントロールを自動抑制してみた

Clock Icon2024.08.16

はじめに

Security Hub オートメーションルール(Automation Rules)を使用して、特定のコントロールの検出結果のステータスを自動的に抑制する方法を紹介します。

Security Hub オートメーションは、Security Hubの検出結果をほぼリアルタイムで自動的に更新できる機能です。

この機能は、Security Hubの委任管理アカウントのみが利用可能です。

本記事で想定する環境です。

  1. Security Hubの有効化状況
    • 管理アカウント(= Security Hubの委任管理アカウント):全リージョンで有効
    • メンバーアカウント:利用リージョン(東京リージョンとバージニアリージョン)のみで有効
  2. 中央設定
    • 利用していない
  3. Security Hubの通知設定
    • 管理アカウントの集約リージョン(東京リージョン)でEventBridgeルールで通知

上記の環境において、特定のSecurity Hubコントロールを通知対象外とするため、ステータスを「抑制済み」に更新するオートメーションルールを管理アカウントで作成します。

オートメーションルールは、ルールを作成したリージョンにて生成された検出結果に対してのみ適用されます。
そのため、リージョン集約を設定されている場合でも、東京リージョンでのみオートメーションルールを作成した場合、当該ルールはバージニアリージョンで生成された検出結果には適用されません。
リージョンごとに作成しましょう。

オートメーションルールの適用順序

Security Hubの検証結果が生成された際、オートメーションルールの適用順序は以下の通りです。

  1. 検出結果が生成される
  2. オートメーションルールがトリガーされ、検出結果が更新される
  3. 更新された検出結果がEventBridgeに送信される
  4. EventBridgeのルールが更新された検出結果に適用される

このように、オートメーションルールはEventBridgeルールよりも先に適用されます。

コントロールの無効化も検討する

AWSドキュメントでは、特定のコントロールを利用しない場合、コスト効率の面でコントロールの無効化を推奨しています。

Security Hub で特定のコントロールに関する検出結果の生成を停止したい場合は、自動化ルールを使用する代わりにコントロールを無効にすることをお勧めします。コントロールを無効にすると、Security Hub はそのコントロールに対するセキュリティチェックの実行を停止し、検出結果の生成を停止するため、そのコントロールに対する料金は発生しません。
https://docs.aws.amazon.com/ja_jp/securityhub/latest/userguide/automation-rules.html

ただし、以下のようなケースでは、オートメーションルールの方が適している場合があります。

  1. 各アカウントごとにコントロールの無効化を実行する必要があり、メンバーアカウントが多いと手間がかかる
    • オートメーションルールの場合、管理アカウントのリージョンごとに1つルールを作成するだけで済む
  2. 無効化したコントロールを有効化するよう変更になった場合、各アカウントごとに対応する必要があり、手間がかかる。
    • Security Hubのアップデートで、年々コントロールは増加しており、増えるたびに各アカウントにログインして実行するのは手間である。
    • オートメーションルールの場合、管理アカウントから、ルールを無効化し、特定のコントロールに対して各アカウントのステータスを抑制済みからNEWに一括変更するだけでよいで

また、Security Hubの中央設定を利用すると、全メンバーアカウントに特定のコントロールの無効化が実現できますが、今回は中央設定を利用していません。

https://dev.classmethod.jp/articles/aws-sh-organization-customize-standards-controls/

理由は、管理アカウントは全リージョン、メンバーアカウントは利用リージョンのみをSecurity Hubで集約する構成が容易にできないためです。詳細は、以下の記事をご参照ください。ただし、今回想定する環境では、Security Hub委任管理アカウントが管理アカウントになっており、これもベストプラクティスではありません。

https://dev.classmethod.jp/articles/aws-security-hub-central-configuration-admin-account/

コスト面と作業効率を考慮して、自身の環境に最適な方法をご選択ください。

オートメーションルールを作成

東京リージョンでオートメーションルールを作成します。今回は、コントロールID「EC2.17」と「EC2.18」を自動抑制させるルールにします。

Security Hubコンソールから「オートメーションルール」を選択し、「ルールの作成」をクリックします。

cm-hirai-screenshot 2024-08-14 10.17.26

ルール名やルールの説明には日本語を使用することができます。

  • ルール名:SH-特定のコントロールの検出結果を自動抑制
  • ルールの説明:SH-特定のコントロールの検出結果を自動抑制します

cm-hirai-screenshot 2024-08-14 10.24.26

ただし、ルール名の先頭文字は英文字である必要があります。

cm-hirai-screenshot 2024-08-13 9.26.47

ルールが適用される検出結果の条件を選択します。

  • ProductName:製品名
    • Security Hub
  • ComplianceSecurityControlId:コントロールID
    • EC2.17とEC2.18
  • RecordState:ステータス
    • ACTIVE

cm-hirai-screenshot 2024-08-14 10.49.46

条件に一致する検出結果のプレビューが確認できます。

cm-hirai-screenshot 2024-08-14 10.50.44

自動アクションでは、ワークフローステータスをSUPPRESSEDに設定します。
また、注 - オプション欄には、Security Hub 内で表示される Note の内容を記載します。この欄には日本語を使用することができます。

cm-hirai-screenshot 2024-08-14 10.41.25

ルールステータスは、デフォルトの有効にしました。

cm-hirai-screenshot 2024-08-14 10.42.44

これでオートメーションルールを作成します。

通知と抑制の確認

管理アカウントの集約リージョン(東京リージョン)に設定されたEventBridgeルールで通知を確認します。

メンバーアカウントの東京リージョンで、「EC2.18」「EC2.19」が検出されるようセキュリティグループを作成します。

cm-hirai-screenshot 2024-08-14 13.10.07

作成後、「EC2.19」については、EventBridgeルールがトリガーし通知されました。

「EC2.18」については、検出結果のステータスが抑制済みとなり、通知されませんでした。

cm-hirai-screenshot 2024-08-14 13.15.26

cm-hirai-screenshot 2024-08-14 13.15.35
以下が検出結果です。

{
  "AwsAccountId": "012345678901",
  "CompanyName": "AWS",
  "Compliance": {
    "Status": "FAILED",
    "SecurityControlId": "EC2.18",
    "AssociatedStandards": [
      {
        "StandardsId": "standards/aws-foundational-security-best-practices/v/1.0.0"
      }
    ],
    "SecurityControlParameters": [
      {
        "Value": [],
        "Name": "authorizedUdpPorts"
      },
      {
        "Value": ["80", "443"],
        "Name": "authorizedTcpPorts"
      }
    ]
  },
  "CreatedAt": "2024-08-14T02:14:50.595Z",
  "Description": "This control checks whether an Amazon EC2 security group permits unrestricted incoming traffic from unauthorized ports. The control status is determined as follows: If you use the default value for 'authorizedTcpPorts', the control fails if the security group permits unrestricted incoming traffic from any port other than ports 80 and 443; If you provide custom values for 'authorizedTcpPorts' or 'authorizedUdpPorts', the control fails if the security group permits unrestricted incoming traffic from any unlisted port; If no parameter is used, the control fails for any security group that has an unrestricted inbound traffic rule.",
  "FindingProviderFields": {
    "Types": [
      "Software and Configuration Checks/Industry and Regulatory Standards/AWS-Foundational-Security-Best-Practices"
    ],
    "Severity": {
      "Normalized": 70,
      "Label": "HIGH",
      "Product": 70,
      "Original": "HIGH"
    }
  },
  "FirstObservedAt": "2024-08-14T02:14:50.595Z",
  "GeneratorId": "aws-foundational-security-best-practices/v/1.0.0/EC2.18",
  "Id": "arn:aws:securityhub:ap-northeast-1:012345678901:subscription/aws-foundational-security-best-practices/v/1.0.0/EC2.18/finding/de2add97-455a-46b1-bb3e-37730ba38a25",
  "LastObservedAt": "2024-08-14T02:14:56.351Z",
  "Note": {
    "UpdatedBy": "sechub-automation",
    "Text": "オートメーションで自動的に抑制されました",
    "UpdatedAt": "2024-08-14T02:14:59.668Z"
  },
  "ProcessedAt": "2024-08-14T02:14:59.773Z",
  "ProductArn": "arn:aws:securityhub:ap-northeast-1::product/aws/securityhub",
  "ProductFields": {
    "StandardsArn": "arn:aws:securityhub:::standards/aws-foundational-security-best-practices/v/1.0.0",
    "StandardsSubscriptionArn": "arn:aws:securityhub:ap-northeast-1:012345678901:subscription/aws-foundational-security-best-practices/v/1.0.0",
    "ControlId": "EC2.18",
    "RecommendationUrl": "https://docs.aws.amazon.com/console/securityhub/EC2.18/remediation",
    "RelatedAWSResources:0/name": "securityhub-vpc-sg-open-only-to-authorized-ports-c7ec400d",
    "RelatedAWSResources:0/type": "AWS::Config::ConfigRule",
    "StandardsControlArn": "arn:aws:securityhub:ap-northeast-1:012345678901:control/aws-foundational-security-best-practices/v/1.0.0/EC2.18",
    "aws/securityhub/ProductName": "Security Hub",
    "aws/securityhub/CompanyName": "AWS",
    "aws/securityhub/annotation": "No tcp ['22'] port is authorized to be open, according to authorizedTcpPorts values ['80,443'] parameter.",
    "Resources:0/Id": "arn:aws:ec2:ap-northeast-1:012345678901:security-group/sg-0e209febfe1a9f83a",
    "aws/securityhub/FindingId": "arn:aws:securityhub:ap-northeast-1::product/aws/securityhub/arn:aws:securityhub:ap-northeast-1:012345678901:subscription/aws-foundational-security-best-practices/v/1.0.0/EC2.18/finding/de2add97-455a-46b1-bb3e-37730ba38a25"
  },
  "ProductName": "Security Hub",
  "RecordState": "ACTIVE",
  "Region": "ap-northeast-1",
  "Remediation": {
    "Recommendation": {
      "Text": "For information on how to correct this issue, consult the AWS Security Hub controls documentation.",
      "Url": "https://docs.aws.amazon.com/console/securityhub/EC2.18/remediation"
    }
  },
  "Resources": [
    {
      "Details": {
        "AwsEc2SecurityGroup": {
          "GroupName": "menber-account-ap-northeast-1",
          "OwnerId": "012345678901",
          "VpcId": "vpc-0e8a7ababbe73d146",
          "IpPermissions": [
            {
              "FromPort": 22,
              "ToPort": 22,
              "IpProtocol": "tcp",
              "IpRanges": [
                {
                  "CidrIp": "0.0.0.0/0"
                }
              ]
            }
          ],
          "IpPermissionsEgress": [
            {
              "IpProtocol": "-1",
              "IpRanges": [
                {
                  "CidrIp": "0.0.0.0/0"
                }
              ]
            }
          ],
          "GroupId": "sg-0e209febfe1a9f83a"
        }
      },
      "Id": "arn:aws:ec2:ap-northeast-1:012345678901:security-group/sg-0e209febfe1a9f83a",
      "Partition": "aws",
      "Region": "ap-northeast-1",
      "Type": "AwsEc2SecurityGroup"
    }
  ],
  "SchemaVersion": "2018-10-08",
  "Severity": {
    "Label": "HIGH",
    "Normalized": 70,
    "Original": "HIGH",
    "Product": 70
  },
  "Title": "EC2.18 Security groups should only allow unrestricted incoming traffic for authorized ports",
  "Types": [
    "Software and Configuration Checks/Industry and Regulatory Standards/AWS-Foundational-Security-Best-Practices"
  ],
  "UpdatedAt": "2024-08-14T02:14:50.595Z",
  "Workflow": {
    "Status": "SUPPRESSED"
  },
  "WorkflowState": "NEW"
}

Noteには、設定した通り「オートメーションで自動的に抑制されました」という記載があることが確認できます。

CLIで作成

AWS CLIでも作成可能です。CloudShellで以下を実行します。

aws securityhub create-automation-rule \
--rule-name "SH-特定のコントロールの検出結果を自動抑制-2" \
--description "SH-特定のコントロールの検出結果を自動抑制します" \
--rule-order 1 \
--rule-status "ENABLED" \
--criteria '{
  "ProductName": [{"Value": "Security Hub", "Comparison": "EQUALS"}],
  "ComplianceSecurityControlId": [
    {"Value": "EC2.17", "Comparison": "EQUALS"},
    {"Value": "EC2.18", "Comparison": "EQUALS"}
  ],  "RecordState": [{"Value": "ACTIVE", "Comparison": "EQUALS"}]
}' \
--actions '[{
  "Type": "FINDING_FIELDS_UPDATE",
  "FindingFieldsUpdate": {
    "Workflow": {"Status": "SUPPRESSED"},
    "Note": {
      "Text": "オートメーションで自動的に抑制されました",
      "UpdatedBy": "SecurityHub-AutomationRule"
    }
  }
}]'

{
    "RuleArn": "arn:aws:securityhub:ap-northeast-1:012345678901:automation-rule/d68bf547-cd21-4584-bb5b-c672e37c685d"
}

rule-order(順序)の値として1を指定しても、すでに順序1のルールが存在する場合は、自動的に2に調整されます。

cm-hirai-screenshot 2024-08-16 7.54.02

バージニアリージョンでも作成した場合の動作

オートメーションルールで更新された検出結果がEventBridgeに送信されると説明いたしました。

Security Hub 管理者アカウントの東京リージョンとバージニアリージョンの両方でオートメーションルールを作成した場合を考えてみます。
この状況で、メンバーアカウントのバージニアリージョンでオートメーションルールの条件にマッチする検出結果が生成された際には、以下のような一連の動作が発生します。

  1. 検出結果の生成

    • メンバーアカウントのバージニアリージョンで、Security Hubの検出結果が生成されます。
  2. オートメーションルールの適用

    • 生成された検出結果は、管理者アカウントのバージニアリージョンに設定されたオートメーションルールによって更新されます。
  3. 検出結果のレプリケーション
    更新された検出結果は、以下のアカウントとリージョンにレプリケートされます

    • メンバーアカウント:東京リージョン
    • 管理者アカウント:東京リージョンとバージニアリージョン
  4. EventBridgeへの送信
    更新された検出結果が以下のEventBridgeに送信されます。

    • メンバーアカウント:
      • 東京リージョンのEventBridge
      • バージニアリージョンのEventBridge
    • 管理者アカウント:
      • 東京リージョンのEventBridge
      • バージニアリージョンのEventBridge

参考

https://docs.aws.amazon.com/ja_jp/securityhub/latest/userguide/automation-rules.html
https://docs.aws.amazon.com/ja_jp/securityhub/latest/userguide/securityhub-cwe-integration-types.html
https://docs.aws.amazon.com/ja_jp/securityhub/latest/userguide/finding-aggregation.html

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.