AWS Control Towerのカスタマイズソリューション(CfCT)

記事タイトルとURLをコピーする

AWS Control TowerのカスタマイズソリューションとしてAWSから提供されているCustomize for Control Tower(CfCT)をご紹介します。

まずはAWSから公開されているラボを通じて解説し、後半では弊社の技術ブログで公開しているCloudFormationテンプレートと連携させてみます。

概要

Control Towerはメンバーアカウントや組織に対して、AWSベストプラクティスの設定を自動でセットアップしてくれる大変便利なサービスですが、デフォルトの状態ではセットアップ内容のカスタマイズの自由度は高くありません。

CfCTを利用することで、Control Towerのランディングゾーンに対してユーザー独自のカスタマイズが可能になります。仕組みとしては、カスタマイズの内容を記載した定義ファイルを元に、SCPやStackSetsが自動で展開されるというソリューションです。

Control Towerのコンソールから設定する部分は特に無く、CI/CDを活用してSCPやStackSetsの展開を自動化することで疑似的にControl Towerをカスタマイズします。

CfCTの利用の流れは下記の通りです。

  1. カスタマイズを自動で展開する仕組み(CI/CD)を構築
  2. カスタマイズ内容を記載したyamlファイル(およびSCPのjsonやCloudFormationのテンプレート)をソースリポジトリにプッシュして、カスタマイズを展開する

ラボでそれぞれ実施します。 より詳細な内容についても下記で触れています。

ラボ

controltower.aws-management.tools

カスタマイズを自動で展開する仕組み(CI/CD)を構築

本項目で構築するアーキテクチャはこちらです。

このアーキテクチャが展開されていれば、どのOUにどのCloudFormationテンプレートを適用するかを定義ファイルに記載してCodeCommitリポジトリにpushすることで、OU配下のアカウントに自動でCloudFormationスタックが作成されます。Control Towerでのアカウントのライフサイクルとも統合されているため、Control Towerでのアカウント登録やOU移動時にも同期的に対応できるようになります。

また、定義ファイルではSCPも指定することができます。

このアーキテクチャを構築するためのCloudFormationテンプレートがAWSから提供されているので、ここではそれを流すだけです。

これでカスタマイズを自動で展開する仕組みが構築できました。

カスタマイズの展開

CodeCommitのリポジトリにリモート接続する

今回はCloud9で実行しました。

  • まずはCloud9にて実行環境を作成し、Openします。
  • ここからはCloud9のShell上での操作です。gitパッケージをインストールします。
sudo yum install git -y
  • CodeCommitコンソールでURLをコピーします。

  • CodeCommitリポジトリをクローンします。

git clone (コピーしたリンクを貼り付け)
  • クローンできました。

カスタマイズの展開

  • カスタマイズを展開していきます。リポジトリのルートにあるmanifest.yamlを下記に置き換えます。
    • ホームリージョンおよびresource_fileのURLで指定しているリージョンはap-northeast-1(東京)リージョンとしています。
    • デプロイ先のリージョンも適宜修正が必要です。
---
# Home region for CodePipeline, StepFunctions, Lambda, SSM, StackSets
region: ap-northeast-1  # Control Tower Home Region
version: 2021-03-15

resources:
# ControlTower Custom SCPs - Additional Preventive Guardrails
- name: test-preventive-guardrails
  description: Prevent deleting or disabling resources in member accounts
  resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/preventive-guardrails.json
  deploy_method: scp
  # Apply to the following OU(s)
  deployment_targets:
    organizational_units:
      # New Essential OU names since ControlTower v2.7 16 April 2021.
      # Observe the names of your existing OUs and comment out or uncomment below to match yours.
      - Security # Foremerly Core
      - Sandbox # Formerly Custom
      #- Core
      #- Custom

# ControlTower Custom CFN Resources - Create Additional IAM Role
- name: create-iam-role
  resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/describe-regions-iam-role.template
  deploy_method: stack_set
  deployment_targets:
    organizational_units:
      # New Essential OU names since ControlTower v2.7 16 April 2021.
      # Observe the names of your existing OUs and comment out or uncomment these to match yours.
      - Security # Foremerly Core
      - Sandbox # Formerly Custom
      #- Core
      #- Custom
  regions:
    - ap-northeast-1

# ControlTower Config Rule - Additional Detective Guardrails
- name: rotate-access-keys-guardrail
  resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/access_keys_rotated.template
  parameters:
    - parameter_key: maxAccessKeyAge
      parameter_value: '24'
  deploy_method: stack_set
  deployment_targets:
    organizational_units:
      # New Essential OU names since ControlTower v2.7 April 16.
      # Observe the names of your existing OUs and comment out or uncomment these to match yours.
      - Security # Foremerly Core
      - Sandbox # Formerly Custom
      #- Core
      #- Custom
  regions:
    - ap-northeast-1
    - us-east-1

※ラボのmanifest.yamlをコピーしてそのまま進めたらインデントがズレていて以降の操作でエラーが出ました。インデントにはご注意を。

  • 上記のmanifest.yamlをリポジトリにpushすることで、前項の自動化の仕組みが動き、既存の環境にSCPおよびStackSetsが構築されます。下記のコマンドを実行してpushしていきます。
cd <Your-local-CodeCommit-Repository>
git status
git add -A 
git commit -m 'Initial checkin'
git push 
  • pushした後はCodePipelineやCodeDeployのコンソールからデプロイの進捗が確認できます。

確認

StackSets

  • メンバーアカウントにてCloudFormationのテンプレートが作成されています。

SCP

  • 管理アカウントではSCPが作成されています。

SecurityHubの設定カスタマイズ

  • 弊社末廣の技術ブログで、SecurityHubの重大度スコア「中」以下のコントロールを定期的に無効化するlambdaをCFnで作成するというブログがありましたので、これをCfCT上で展開してみます。

blog.serverworks.co.jp

  • まずはテンプレートファイルをディレクトリに配置します。テンプレートの中身は上記ブログをご参照ください。

  • 続いてmanifest.ymlを修正して、前述のテンプレートを指定のOU配下のアカウントの指定のリージョンに流すように追記します。

# Home region for CodePipeline, StepFunctions, Lambda, SSM, StackSets
region: ap-northeast-1  # Control Tower Home Region
version: 2021-03-15

resources:
# ControlTower Custom SCPs - Additional Preventive Guardrails
- name: test-preventive-guardrails
  description: Prevent deleting or disabling resources in member accounts
  resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/preventive-guardrails.json
  deploy_method: scp
  # Apply to the following OU(s)
  deployment_targets:
    organizational_units:
      # New Essential OU names since ControlTower v2.7 16 April 2021.
      # Observe the names of your existing OUs and comment out or uncomment below to match yours.
      - Security # Foremerly Core
      - Sandbox # Formerly Custom
      #- Core
      #- Custom

# ControlTower Custom CFN Resources - Create Additional IAM Role
- name: create-iam-role
  resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/describe-regions-iam-role.template
  deploy_method: stack_set
  deployment_targets:
    organizational_units:
      # New Essential OU names since ControlTower v2.7 16 April 2021.
      # Observe the names of your existing OUs and comment out or uncomment these to match yours.
      - Security # Foremerly Core
      - Sandbox # Formerly Custom
      #- Core
      #- Custom
  regions:
    - ap-northeast-1

# ControlTower Config Rule - Additional Detective Guardrails
- name: rotate-access-keys-guardrail
  resource_file: s3://marketplace-sa-resources-ct-ap-northeast-1/ctlabs/access_keys_rotated.template
  parameters:
    - parameter_key: maxAccessKeyAge
      parameter_value: '24'
  deploy_method: stack_set
  deployment_targets:
    organizational_units:
      # New Essential OU names since ControlTower v2.7 April 16.
      # Observe the names of your existing OUs and comment out or uncomment these to match yours.
      - Security # Foremerly Core
      - Sandbox # Formerly Custom
      #- Core
      #- Custom
  regions:
    - ap-northeast-1
    # - us-east-1

# ↓↓↓追記部分

# ControlTower Custom CFN Resources - SecurityHub Control Lambda
- name: create-lambdafunction
  resource_file: security_hub_control.template
  parameters:
    - parameter_key: ResourceName
      parameter_value: securityhub-from-lambda
  deploy_method: stack_set
  deployment_targets:a
    organizational_units:
      # New Essential OU names since ControlTower v2.7 16 April 2021.
      # Observe the names of your existing OUs and comment out or uncomment these to match yours.
      - Security # Foremerly Core
      - Sandbox # Formerly Custom
      #- Core
      #- Custom
  regions:
    - ap-northeast-1
  • 変更をpushします。
git status
git add -A 
git commit -m 'SecurityHub Control'
git push 
  • スタックが作成されました!

まとめ

今回はCfCTを紹介しました。 StackSetsをControlTowerと連携して利用することで自由度がかなり高くなって便利です。

2022/11/28のアップデートでAFC(Account Factory Customization)というカスタマイズ機能も出ましたのでAFCについてもいずれ紹介しようと思います。

関連ドキュメント

docs.aws.amazon.com docs.aws.amazon.com