クラスメソッドに入社して個人検証用アカウントもらえたのでセキュリティ設定やっていく

うわさの個人検証用アカウントを手に入れたのでセキュリティ設定をやっていきます!
2021.10.25

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

2021/10に入社しました!IoT事業部のやまたつです。

IoT 事業部にジョインしましたやまたつです。

うわさの個人検証用アカウントを手に入れました!わーい!

目的

個人検証用アカウントを手に入れたのでセキュリティ設定をやっていきます!(以前個人アカウントで設定したら地味にお金かかったのでやめた。)

やっていく

ちなみに、AWS CloudTrailとAWS Configは個人検証アカウントを渡されたときから全リージョンで設定されています。さすが!

全リージョンでAWS Security Hubをenableにする

AWSの中の人もおすすめしてますし、言われるがままに。。。

aws securityhub enable-security-hub --region us-east-2
aws securityhub enable-security-hub --region us-east-1
aws securityhub enable-security-hub --region us-west-1
aws securityhub enable-security-hub --region us-west-2
aws securityhub enable-security-hub --region ap-south-1
aws securityhub enable-security-hub --region ap-northeast-3
aws securityhub enable-security-hub --region ap-northeast-2
aws securityhub enable-security-hub --region ap-southeast-1
aws securityhub enable-security-hub --region ap-southeast-2
aws securityhub enable-security-hub --region ap-northeast-1
aws securityhub enable-security-hub --region ca-central-1
aws securityhub enable-security-hub --region eu-central-1
aws securityhub enable-security-hub --region eu-west-1
aws securityhub enable-security-hub --region eu-west-2
aws securityhub enable-security-hub --region eu-west-3
aws securityhub enable-security-hub --region eu-north-1
aws securityhub enable-security-hub --region sa-east-1

全リージョンでAmazon GuardDutyをenableにする

公式ドキュメントでもおすすめしてますし、言われるがままに。。。

aws guardduty create-detector --enable --region us-east-2
aws guardduty create-detector --enable --region us-east-1
aws guardduty create-detector --enable --region us-west-1
aws guardduty create-detector --enable --region us-west-2
aws guardduty create-detector --enable --region ap-south-1
aws guardduty create-detector --enable --region ap-northeast-3
aws guardduty create-detector --enable --region ap-northeast-2
aws guardduty create-detector --enable --region ap-southeast-1
aws guardduty create-detector --enable --region ap-southeast-2
aws guardduty create-detector --enable --region ap-northeast-1
aws guardduty create-detector --enable --region ca-central-1
aws guardduty create-detector --enable --region eu-central-1
aws guardduty create-detector --enable --region eu-west-1
aws guardduty create-detector --enable --region eu-west-2
aws guardduty create-detector --enable --region eu-west-3
aws guardduty create-detector --enable --region eu-north-1
aws guardduty create-detector --enable --region sa-east-1

Guard Duty の通知設定

AWS Security Hubの通知は、すっごい通知くるので、とりあえずAmazon GuardDutyだけ設定します。

AWS CDKで設定します。理由は好きだから。。。
CDKのバージョンはv2を使ってます。もうRCなので、特に個人利用ならガンガン使っていくと良いと思います。package.jsonにあれこれ足さなくて済むので最高です!

import {
  App,
  Stack,
  StackProps,
  aws_chatbot,
  aws_sns,
  aws_events_targets,
  aws_events,
} from 'aws-cdk-lib';

type Props = StackProps & {
  slackWorkspaceId: string;
  slackChannelId: string;
};

export class SecurityAlertChatbot extends Stack {
  constructor(scope: App, id: string, props: Props) {
    super(scope, id, props);

    const topic = new aws_sns.Topic(this, 'GuardDutyTopic');

    const rule = new aws_events.Rule(this, 'GuardDutyNotificationRule', {
      ruleName: 'GuardDutyNotificationRule',
      description: 'Alert to SNS topic when find threats by Guardduty',
      eventPattern: {
        source: ['aws.guardduty'],
        detailType: ['GuardDuty Finding'],
      },
    });
    rule.addTarget(new aws_events_targets.SnsTopic(topic));

    new aws_chatbot.SlackChannelConfiguration(
      this,
      'SlackChannelConfiguration',
      {
        slackChannelConfigurationName: 'SecurityAlert',
        slackWorkspaceId: props.slackWorkspaceId,
        slackChannelId: props.slackChannelId,
        notificationTopics: [topic],
      },
    );
  }
}

余談1

細かい説明は端折りますが、AWS CDKのv2はv1のコードから自動で生成されています。なので、v1の更新は1週間ほどでv2に反映されます。怖いものなし!

余談2

悩み!Amazon GuardDutyの通知の確認したいけど、確認方法がわからない!?
後日、Slackに通知が来ました!「後日セキュリティ設定の追加を行います」と連絡があったのでそのための操作っぽいです。Rootユーザーが使えるならそれでログインすればAmazon GuardDutyもAWS Security Hubも通知の確認ができそうです。

加えて、公式からAmazon GuardDutyのテスターが提供されていたので、これも試せたらブログに書きたいと思います。

まとめ

とりあえず上記で簡単な設定はできたかと思います。ただAWS Security Hubは設定しただけではなんの意味もないのでこれから少しづつスコアを上げていこうと思います!その様子も書けたらブログに書こうかと思います!
ちなみに、いきおいでAmazon Detectiveも全リージョンenableにしようかと思ったのですが、そちらはコストを確認していきながらおいおい進めていこうと思います?

以上!やまたつでした!