1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Security Hub → EventBridge → SNS → Chatbot → Slack

Last updated at Posted at 2021-06-03

#Security Hub から Slack に通知させる#

SecurityHubで評価 >> Event Bridge をトリガーに SNSトピックに通知 >> SNSトピックに設定されているChatbotに情報送信 >> ChatbotがSlackに通知

というのを CloudFormation でデプロイしていこうと思います。

##Security Hubの有効化##

こちらの手順で、Security Hub を有効化する。
基本的に有効化するだけですので、手順はドキュメントに任せます。

なお、AWS Security Hub の概要については下記の記事でも纏めているので参考程度に。

##Security Hub、EventBridge、SNS、Chatbot(Cloudformatinスタック)##

EventBridge のカスタムルールは以下の記事のもの採用する。

例3: 「通知済み」にしたものは除外する

ポイントは評価に失敗したものは、何度も通知させないようにすることである!
テンプレートは、重要度が「重要」もしくは「高」のものかつ、ワークフローステータスが「新規(NEW)」のものだけを通知する。
「新規(NEW)」で通知されたものは、「通知済み(NOTIFIED)」もしくは「(抑制済み(SUPPRESSED)」に変更しておくことで、失敗し続ける項目を何度も通知させないようにすることが可能である。

  • 重要度

  • ワークフローステータス

SecurityHub.yaml
AWSTemplateFormatVersion: 2010-09-09
Description:Slack notifications for security hub

Parameters: 
  SnsTopicName:
    Type: String
    Default: SecurityHubTopic
  SlackWorkspaceId:
    Type: String
    Default: XXXXXXXXX
  SlackChannelId:
    Type: String
    Default: YYYYYYYYY

Resources:
#SNS#
  SNST:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: SecurityHubTopic
  SNSTP:
    Type: AWS::SNS::TopicPolicy
    Properties:
      PolicyDocument:
        Id: default_policy_ID
        Version: "2012-10-17"
        Statement:
        - Sid: default_statement_ID
          Effect: Allow
          Principal:
            AWS: "*"
          Action:
            - "SNS:GetTopicAttributes"
            - "SNS:SetTopicAttributes"
            - "SNS:AddPermission"
            - "SNS:RemovePermission"
            - "SNS:DeleteTopic"
            - "SNS:Subscribe"
            - "SNS:ListSubscriptionsByTopic"
            - "SNS:Publish"
            - "SNS:Receive"
          Resource: !Ref SNST
          Condition:
            StringEquals:
              "AWS:SourceOwner": !Ref "AWS::AccountId"
        - Sid: AWSEvents_SecurityHubFindings_Id123
          Effect: Allow
          Principal:
            Service:
            - "events.amazonaws.com"
          Action: "sns:Publish"
          Resource: !Ref SNST
      Topics:
      - !Ref SNST

#EventBridge#
  ER:
    Type: AWS::Events::Rule
    Properties:
      Name: SecurityHubFindings
      EventPattern: {
                      "source": [
                        "aws.securityhub"
                      ],
                      "detail-type": [
                        "Security Hub Findings - Imported"
                      ],
                      "detail": {
                        "findings":
                          {
                            "Compliance": {
                              "Status": [
                                {
                                 "anything-but": "PASSED"
                                }
                              ]
                            },
                            "Severity": {
                              "Label": [
                                 "CRITICAL",
                                 "HIGH"
                               ]
                            },
                            "Workflow": {
                              "Status": [
                                 "NEW"
                             ]
                            },
                            "RecordState": [
                              "ACTIVE"
                            ]
                          }
                      }
                    }
      State: ENABLED
      Targets:
        - Arn: !Ref SNST
          Id: SNST
      EventBusName: default

#Chatbot用 IAMロール
  SecurityHubIamRole: 
    Type: AWS::IAM::Role
    Properties: 
      RoleName: SecurityHubIamRole
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: "Allow"
            Action: "sts:AssumeRole"
            Principal:
              Service: "chatbot.amazonaws.com"
      Policies: 
        - PolicyName: SecurityHub-NotificationsOnly-Policy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Action:
                  - "cloudwatch:Describe*"
                  - "cloudwatch:Get*"
                  - "cloudwatch:List*"
                Effect: "Allow"
                Resource: "*"

#Chatbot
  SecurityHubConfiguration:
    Type: AWS::Chatbot::SlackChannelConfiguration
    Properties: 
      ConfigurationName: SecurityHub-Chatbot-SlackChanel
      IamRoleArn: !GetAtt SecurityHubIamRole.Arn
      LoggingLevel: ERROR
      SlackChannelId: !Ref SlackChannelId
      SlackWorkspaceId: !Ref SlackWorkspaceId
      SnsTopicArns: 
        - !Sub 'arn:aws:sns:ap-northeast-1:${AWS::AccountId}:${SnsTopicName}' 
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?