LoginSignup
1
0

マルチアカウントxマルチリージョンSecurity HubとConfig設定

Last updated at Posted at 2023-04-27

概要

以下の構成を作る。作業の殆どはCloudFormationテンプレートで記述済み。
image.png

前提条件

  • AWS ControlTowerが有効
  • rainをインストール済み(CFnテンプレートの反映に利用)
  • getoptionsをインストール済み(登場するスクリプトが利用)

ControlTowerは必須ではない。ControlTowerが有効な場合、メンバーアカウントへのConfig設定が省略できる。
今回の記事でも触れない。

構築

テンプレートのgit pull

$ git pull https://github.com/kotatsu360/cfn-templates
$ cd cfn-templates

権限の取得

# マネージメントアカウントの管理者権限
$ aws sso login --profile mgmt-admin

# Auditアカウントの管理者権限
$ aws sso login --profile audit-admin

マネージメントアカウント:Configの有効化

【存在する場合は省略可】StackSets用のIAMロールとConfig用のServiceLinkedRoleを作成

$ rain deploy -p mgmt-admin -r ap-northeast-1 iam/cloudformation-stacksets.yaml iam-cloudformation-stacksets-mgmt

$ rain deploy -p mgmt-admin -r ap-northeast-1 iam/slr.yaml iam-slr-mgmt

有効なリージョンに対して、設定済みのConfig設定を使ってConfigを設定(前述のコマンドを含めたワンライナー)。

ControlTowerで複数リージョンを許可している or リージョンを制御していない場合
stacksets/config.yamlのIsAllowedRegionByControlTowerにリージョンを列挙してください
※テンプレート修正が不要な方法が見つかり次第、更新します

rain stackset deploy -p mgmt-admin -r ap-northeast-1 --accounts <YOUR_MANAGEMENT_ACCOUNT_ID> \
     --regions $(aws account list-regions \
                     --output text \
                     --query 'Regions|[?RegionOptStatus!=`DISABLED`].RegionName' \
                     --region ap-northeast-1 --profile mgmt-admin | tr -s '\t' ',') \
     --params $(aws configservice describe-delivery-channels \
                    --output yaml \
                    --query 'DeliveryChannels[0].{S3BucketName:s3BucketName,  SnsTopicARN:snsTopicARN, KmsKeyArn: s3KmsKeyArn, OrgId: s3KeyPrefix}' \
                    --region ap-northeast-1 --profile audit-admin | awk 'BEGIN{ FS=": "; OFS="="; ORS=","} {print $1,$2}') \
     stacksets/config.yaml stacksets-config-mgmt

ワンライナー中のaws cli呼び出しを個別に呼び出したときのサンプル

マネージメントアカウントで有効なリージョンを確認。

$ AWS_PAGER='' aws --profile mgmt-admin account list-regions --output json --query 'Regions|[?RegionOptStatus!=`DISABLED`].RegionName'
[
    "ap-northeast-1",
    "ap-northeast-2",
    "ap-northeast-3",
    "ap-south-1",
    "ap-southeast-1",
    "ap-southeast-2",
    "ca-central-1",
    "eu-central-1",
    "eu-north-1",
    "eu-west-1",
    "eu-west-2",
    "eu-west-3"
]

適当なAWSアカウント(ここでは後から使うAuditアカウント)で既存のConfig設定を確認。


$ AWS_PAGER='' aws configservice describe-delivery-channels --region ap-northeast-1 --profile audit-admin --output json --query 'DeliveryChannels[0].{S3BucketName:s3BucketName,  SnsTopicARN:snsTopicARN, KmsKeyArn: s3KmsKeyArn, OrgId: s3KeyPrefix}'
{
    "S3BucketName": " ... ",
    "SnsTopicARN": " ... ",
    "KmsKeyArn": null,
    "OrgId": " ... "
}

マネージメントアカウント:SecurityHubの有効化&移譲

$ rain stackset deploy -p mgmt-admin -r ap-northeast-1 --accounts <YOUR_MANAGEMENT_ACCOUNT_ID> \
     --regions $(aws account list-regions \
                     --output text \
                     --query 'Regions|[?RegionOptStatus!=`DISABLED`].RegionName' \
                     --region ap-northeast-1 --profile mgmt-admin | tr -s '\t' ',') \
     stacksets/securityhub.yaml stacksets-securityhub-mgmt

$ bash scripts/init_securityhub.sh --audit-account <AUDIT_ACCOUNT_ID> --mgmt-profile mgmt-admin --audit-profile audit-admin --enabled-regions <ControlTowerで許可しているリージョン> -r ap-northeast-1
# ex. $ bash scripts/init_securityhub.sh --audit-account 123456789098 --mgmt-profile mgmt-admin --audit-profile audit-admin --enabled-regions ap-northeast-1,us-east-1 -r ap-northeast-1

init_securityhub.shは冪等性があるように記述しているため、何回実行してもよい。

Auditアカウント:SecurityHubの有効化

Auditアカウントにて、init_securityhub.shの結果に表示されるURLを開き、以下の設定を行う。
※有効なリージョンごとに行う

image.png
image.png

終わり。

運用例

後編に分離。

  • AWS Config Conformance PackのOrg展開
  • 考慮すること:アカウントやリージョンの追加
1
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
1
0