AWS Organizations の 組織単位 (OU) に Config Rules を CloudFormation StackSets でデプロイ

概要

やりたいこと

Config Rules を OU (Organizations Unit) ごとに反映したい。

サービスマネージド型 CloudFormation を利用した Config 有効化は以下で実施した。

委任管理者と CloudFormation StackSets の使い分け

今回は 組織単位 (OU) に Config Rules をデプロイしたいため、Organizations の CloudFormation StackSets を利用する。

ただし、Organizations の CloudFormation StackSets は OU 単位でしか設定反映ができず、AWS アカウント単位では設定反映ができない。

AWS Config も委任管理者にしたメンバーアカウントから Config を組織全体に管理できるようになっている。

CloudFormation StackSets

前提:Organizations で OU を作成していること。

Config Rules テンプレート作成

2 つの Config Rules を作成する CloudFormation テンプレートを作成。

vi config_rules.yaml
AWSTemplateFormatVersion: 2010-09-09
Description: Enables an AWS Config Rules

Resources:
  CheckS3PublicWritable:
    Type: 'AWS::Config::ConfigRule'
    Properties:
      ConfigRuleName: s3-bucket-public-write-prohibited
      Description: A Config rule that checks that your Amazon S3 buckets do not allow public write access. If an Amazon S3 bucket policy or bucket ACL allows public write access, the bucket is noncompliant.
      MaximumExecutionFrequency: TwentyFour_Hours
      Scope:
        ComplianceResourceTypes:
          - 'AWS::S3::Bucket'
      Source:
        Owner: AWS
        SourceIdentifier: S3_BUCKET_PUBLIC_WRITE_PROHIBITED

  CheckCloudTrailEnable:
    Type: 'AWS::Config::ConfigRule'
    Properties:
      ConfigRuleName: cloudtrail-s3-dataevents-enabled
      Description: >-
        A Config rule that checks whether at least one AWS CloudTrail trail is
        logging Amazon S3 data events for all S3 buckets. The rule is
        NON_COMPLIANT if trails that log data events for S3 buckets are not
        configured.
      MaximumExecutionFrequency: TwentyFour_Hours
      Scope:
        ComplianceResourceTypes: []
      Source:
        Owner: AWS
        SourceIdentifier: CLOUDTRAIL_S3_DATAEVENTS_ENABLED

サービスマネージド型 CloudFormation の実行

StackSet を作成。

aws cloudformation create-stack-set \
--profile organizations-test-lac \
--stack-set-name config-rules-organizations \
--template-body file://config_rules.yaml \
--permission-model SERVICE_MANAGED \
--auto-deployment Enabled=true,RetainStacksOnAccountRemoval=true

デプロイ対象の OU と regions を指定する。

aws cloudformation create-stack-instances \
--profile organizations-test-lac \
--stack-set-name config-rules-organizations \
--deployment-targets OrganizationalUnitIds="ou-xxxx-xxxxxxxx" \
--regions '["ap-northeast-1","ap-northeast-2", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "sa-east-1", "us-east-1", "us-east-2", "us-west-1", "us-west-2"]' \
--operation-preferences FailureToleranceCount=0,MaxConcurrentCount=1

指定した OU にのみ、Config Rules が追加されていることを確認。

参考

AWS Organizations の CloudFormation StackSets で AWS Config を有効化し別アカウントへログエクスポート

コメント

タイトルとURLをコピーしました