三歩あるけば物も忘れる

お腹のお肉がメタボックル

ユーザ用ツール

サイト用ツール


Aws:Organizations:Service-Config

サービス-Config

はじめに

アグリゲーターは、証跡取得ケースとは別の話でConsoleやCLIで、マルチアカウント/リージョンのConfigのコンプライアンス状況を集約する機能
証跡取得ケースも絡めて記載はしている。

・[②組織内の特定アカウントで証跡を集中管理]を例に設定例を記載します。
・組織全体を集中管理(全てのリージョン及び、将来の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用のロールを作成する

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の記録を有効化する

手順割愛

コメント

コメントを入力:
K X M X G
 
Aws/Organizations/Service-Config.txt · 最終更新: 2023/03/05 by 217.113.194.134