~~NOCACHE~~ ~~DISCUSSION~~ ## サービス-Config ### はじめに アグリゲーターは、[[Aws:Organizations:TrailAcquisitionCase|証跡取得ケース]]とは別の話でConsoleやCLIで、マルチアカウント/リージョンのConfigのコンプライアンス状況を集約する機能 [[Aws:Organizations:TrailAcquisitionCase|証跡取得ケース]]も絡めて記載はしている。 {{:Aws:Organizations:pasted:20220518-093613.png?direct 600x0}} ・[②組織内の特定アカウントで証跡を集中管理]を例に設定例を記載します。 ・組織全体を集中管理(全てのリージョン及び、将来のAWSリージョンを含める) ## 設定概要 ### 組織のrootアカウント ・サービス-Configの信頼されたアクセスを有効にする ・組織内の特定アカウントにConfig Aggregatorを委任する ### 組織内の特定アカウント ・Config用のロールを作成する ・Config記録用のS3バケットを作成する ・Configの記録を有効化する ・アグリゲータ用のロールを作成する ・アグリゲータを有効化する ### 全てのメンバーアカウント ・Config用のロールを作成する ・Configの記録を有効化する ## 設定 ### 組織のrootアカウント CloudShellから以下を実行する。 # サービス-Configの信頼されたアクセスを有効にする aws organizations enable-aws-service-access --service-principal=config.amazonaws.com aws organizations enable-aws-service-access --service-principal config-multiaccountsetup.amazonaws.com #特定アカウントにConfig Aggregatorを委任する aws organizations register-delegated-administrator --account-id [委任アカウントID] --service-principal config.amazonaws.com aws organizations register-delegated-administrator --account-id [委任アカウントID] --service-principal config-multiaccountsetup.amazonaws.com #委任しているサービスと委任先のアカウントIDを確認するコマンド aws organizations list-delegated-administrators --query "DelegatedAdministrators[].[Name,Id]" --output text | while read line do echo $line aws organizations list-delegated-services-for-account --account-id $(echo $line | awk '{print $2}') \ --query "DelegatedServices[].[ServicePrincipal,DelegationEnabledDate]" --output text done ### 組織内の特定アカウント #### Config用のロールを作成する ##### 信頼関係 { "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": "sts:AssumeRole" } ] } ##### ポリシー %%以下のAWSConfigのマネージドポリシー(arn:aws:iam::aws:policy/service-role/AWS_ConfigRole)を許可%% CloudFormationで書くと下記のようになります。 AWSTemplateFormatVersion: 2010-09-09 Resources: ResConfigRole: Type: "AWS::IAM::Role" Properties: RoleName: AWSConfigRole AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: config.amazonaws.com Action: "sts:AssumeRole" ManagedPolicyArns: - "arn:aws:iam::aws:policy/service-role/AWS_ConfigRole" #### Config記録用のS3バケットを作成する { "Version": "2012-10-17", "Statement": [ { "Sid": "AWSConfigBucketPermissionsCheck", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": [ "s3:GetBucketAcl", "s3:ListBucket" ], "Resource": "arn:aws:s3:::[Config用S3バケット]" }, { "Sid": "AWSConfigBucketDelivery", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": "s3:PutObject", "Resource": [ "arn:aws:s3:::[Config用S3バケット]", "arn:aws:s3:::[Config用S3バケット]/*" ], "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control" } } }, { "Sid": "AWSConfigBucketDeliveryServiceLinkRole", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": [ "s3:PutObject", "s3:PutObjectAcl" ], "Resource": [ "arn:aws:s3:::[Config用S3バケット]", "arn:aws:s3:::[Config用S3バケット]/*" ], "Condition": { "StringEquals": { "aws:PrincipalOrgID": "[組織ID]" } } }, { "Sid": "Deny non SSL request", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": [ "arn:aws:s3:::[Config用S3バケット]", "arn:aws:s3:::[Config用S3バケット]/*" ], "Condition": { "Bool": { "aws:SecureTransport": "false" } } } ] } #### Configの記録を有効化する 手順割愛 #### アグリゲータ用のロールを作成する ##### 信頼関係 { "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": "config.amazonaws.com" }, "Action": "sts:AssumeRole" } ] } ##### ポリシー %%以下のAWSConfigRoleForOrganizationsのマネージドポリシー(arn:aws:iam::aws:policy/service-role/AWSConfigRoleForOrganizations)を許可%% CloudFormationで書くと下記のようになります。 AWSTemplateFormatVersion: 2010-09-09 Resources: ResAWSConfigRoleForOrganizations: Type: "AWS::IAM::Role" Properties: RoleName: AWSConfigRoleForOrganizations AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: config.amazonaws.com Action: "sts:AssumeRole" ManagedPolicyArns: - "arn:aws:iam::aws:policy/service-role/AWSConfigRoleForOrganizations" #### アグリゲータを有効化する AWSTemplateFormatVersion: 2010-09-09 Resources: ResConfigurationAggregator: Type: AWS::Config::ConfigurationAggregator Properties: ConfigurationAggregatorName: ConfigAggregator OrganizationAggregationSource: RoleArn: !GetAtt ResAWSConfigRoleForOrganizations.Arn AllAwsRegions: true ### 全てのメンバーアカウント #### Config用のロールを作成する [[Aws:Organizations:Service-Config#Config用のロールを作成する|Config用のロールを作成する]]に加え、以下のポリシーを追加する。 ※Configを有効化した後にポリシーを追加しないとConfigが有効にできない謎・・・ 追加しないとConfigWritabilityCheckFileの配信でS3AccessDeniedがでるし・・んもー!!! { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:PutObjectAcl" ], "Resource": [ "arn:aws:s3:::[別アカウントのS3バケット]", "arn:aws:s3:::[別アカウントのS3バケット]/*" ] } ] } #### Configの記録を有効化する 手順割愛 {{tag>AWS Config Organizations}}