Amazon Primeにドはまり中のCI部2課の山﨑です。
前回はConfig Rule のConformance Packs(適合パック)を単一アカウント上でデプロイしましたが、今回Organizationsでマルチアカウント/マルチリージョンに展開してみます
事前準備
1. 以下のブログに従い、CloudFormation StackSetsを使ってマルチアカウント/マルチリージョンでAWS Configを有効化しておきます。今回は東京リージョンとシドニーリージョンを有効化しておきました。
2. 今回デプロイするテンプレートは以下のブログでも使用したS3のデフォルト暗号化チェックならびに修復を行うConfig Ruleと修復アクションが記載されたものを利用します。
Organizations組織への展開イメージ
デプロイイメージは以下の通りです。

検証
1. SSM Automation で必要なIAMロールを作成
CloudFormation もしくは CloudFormation StackSetsを使ってSSM Automation で必要なIAMロールを作成するテンプレートをConformance Pack(適合パック)をデプロイする各アカウントに流しておきます。前回のブログでもご紹介させて頂きましたが、以下改めてテンプレートを載せておきます。
Parameters:
S3TargetBucketNameForEnableLogging:
Description: Create IAM Role for SSM Automation
Type: String
Conditions:
GlobalServiceDeployRegion: !Equals [!Ref AWS::Region, ap-northeast-1]
Resources:
S3OperationsAutomationsExecutionRole:
Type: AWS::IAM::Role
Condition: GlobalServiceDeployRegion
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ssm.amazonaws.com
Action:
- sts:AssumeRole
Path: /
RoleName: "S3OperationsAutomationsExecutionRole"
EbsRemediationPassPolicy:
DependsOn: S3OperationsAutomationsExecutionRole
Type: AWS::IAM::ManagedPolicy
Condition: GlobalServiceDeployRegion
Properties:
ManagedPolicyName: S3OperationsAutomationsExecutionPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:PutEncryptionConfiguration
- s3:GetEncryptionConfiguration
- s3:ListBucket
- s3:GetBucketAcl
Resource:
- "*"
Roles:
- !Ref S3OperationsAutomationsExecutionRole
2. Conformance Packs(適合パック)をデプロイ
Management Account のCloudShellで以下のテンプレートを記述したファイル(S3template.yml)を作成して保存します。
S3template.yml
AWSTemplateFormatVersion: 2010-09-09
Description: Enable AWS Config S3 Conformance Pack
Resources:
S3BucketServerSideEncryptionEnabled:
Type: "AWS::Config::ConfigRule"
Properties:
ConfigRuleName: S3BucketServerSideEncryptionEnabled
Description: "Checks that your Amazon S3 bucket either has S3 default encryption enabled or that the S3 bucket policy explicitly denies put-object requests without server side encryption."
Scope:
ComplianceResourceTypes:
- "AWS::S3::Bucket"
Source:
Owner: AWS
SourceIdentifier: S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED
S3BucketServerSideEncryptionEnabledRemediation:
DependsOn: S3BucketServerSideEncryptionEnabled
Type: 'AWS::Config::RemediationConfiguration'
Properties:
ConfigRuleName: S3BucketServerSideEncryptionEnabled
ResourceType: "AWS::S3::Bucket"
TargetId: "AWS-EnableS3BucketEncryption"
TargetType: "SSM_DOCUMENT"
TargetVersion: "1"
Parameters:
AutomationAssumeRole:
StaticValue:
Values:
- arn:aws:iam::"コマンドを実行するAccountのID":role/S3OperationsAutomationsExecutionRole
BucketName:
ResourceValue:
Value: "RESOURCE_ID"
SSEAlgorithm:
StaticValue:
Values:
- "AES256"
ExecutionControls:
SsmControls:
ConcurrentExecutionRatePercentage: 10
ErrorPercentage: 10
Automatic: True
MaximumAutomaticAttempts: 10
RetryAttemptSeconds: 600
Conformance Packを複数リージョンにデプロイするためにCLIを記述したスクリプトを作成して実行します。
※2021年8月11日現在、Conformance Packsがサポート対象しているリージョンは16リージョンのみです。例えば大阪リージョンはConformance Packs(適合パック)のサポート対象外です。
multideploy.sh
#!/bin/bash aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region ap-northeast-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region ap-northeast-2 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region ap-south-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region ap-southeast-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region ap-southeast-2 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region ca-central-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region eu-central-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region eu-north-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region eu-west-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region eu-west-2 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region eu-west-3 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region sa-east-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region us-east-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region us-east-2 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region us-west-1 aws configservice put-organization-conformance-pack --organization-conformance-pack-name="S3Test" --template-body="file://S3template.yml" --region us-west-2
スクリプトが実行されたらOrganizationConformancePackArn が返り値として表示されます。

Management Account
各リージョンでデプロイが完了したことを確認

Member Account
各リージョンでデプロイが完了したことを確認

[おまけ] Member Account に管理を委任
Management AccountからMember Account にAWS Configとアグリゲーターの管理委任を行う場合、まずはManagement AccountでCloudShellを起動して以下のCLIコマンドを実行してAWSサービス(ServicePrincipalによって指定されたサービス)とAWS組織の統合状態を確認します。
aws organizations list-aws-service-access-for-organization --output text
config-multiaccountsetup.amazonaws.com と config.amazonaws.com の2つの設定が有効化されていなければ、CLIコマンドで有効化します。
$ aws organizations enable-aws-service-access --service-principal config-multiaccountsetup.amazonaws.com $ aws organizations enable-aws-service-access --service-principal config.amazonaws.com
有効化されていることを確認したら以下のコマンドでMember Accountに委任を行います。
$ aws organizations register-delegated-administrator --service-principal config-multiaccountsetup.amazonaws.com --account-id "委任先AWSアカウントID" $ aws organizations list-delegated-services-for-account --account-id "委任先AWSアカウントID"
委任設定ができたかどうかはManagement Account で以下のCLIコマンドを実行することで確認できます。
$ aws organizations list-delegated-services-for-account --account-id "委任先AWSアカウントID" --output text
まとめ
CloudFormation StackSets を使ってマルチアカウント/マルチリージョンでAWS Configを有効化
Config Rule のConformance Packs(適合パック)を単一アカウント/単一リージョンにデプロイ
Config Rule の Conformance Packs(適合パック)をOrganizationsでマルチアカウント/マルチリージョンにデプロイ
AWS Configについて上記の3つを検証してみましたが率直な感想としてはConformance Packs(適合パック)の導入はしんどかったです。私があまりAWS Configの機能に触れてこなかったという側面もありますが学習コストや運用コストを考えると個人的にはオススメできません。Trusted AdvisorやSecurity Hub等のAWSマネージドサービスを利用してコンプライアンス統制を行ってみて、それでも不足していると判断した場合に導入するのはアリかと思います(修復アクションなしでただデプロイするだけであれば多少はラクです)。本当にこの機能を使いこなしたいのであればCloudFormation/SSM Document/Lambda 等をある程度マスターした状態で挑戦しましょう。
山﨑 翔平 (Shohei Yamasaki) 記事一覧はコチラ
カスタマーサクセス部所属。2019年12月にインフラ未経験で入社し、AWSエンジニアとしてのキャリアを始める。2023 Japan AWS Ambassadors/2023-2024 Japan AWS Top Engineers