【Organizations】 主要なガバナンス・セキュリティサービスを組織で一括で有効化する

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

最近ランニングを始めたCI部2課の山﨑です。

今回はOrganizationsを用いたAWS環境を構成する上で、主要なセキュリティサービスを組織で一括で有効化する方法を整理しました。

はじめに

AWS Organizations を利用する場合は組織下のアカウント群のガバナンス・セキュリティの管理・統制について考慮する必要があります。AWSにおいてガバナンス・セキュリティに関連するサービスとしてよく取り上げられるサービスを以下に列挙します

  • AWS CloudTrail
  • AWS Config
  • Amazon Detective
  • IAM Access Analyzer
  • Amazon Macie
  • AWS Security Hub
  • Amazon GuardDuty

今回は上記のサービス群をOrganizations の組織下で効率よく有効化するための方法および手順を整理していきます。

Organizations組織への展開イメージ

セキュリティサービスの展開イメージは以下の通りです。

f:id:swx-yamasaki:20210825123640p:plain
展開イメージ

セキュリティサービスの設定方法一覧

有効化するAWSサービスによってはManagement Account から管理権限を委任できるサービスとそうでないサービスがあったりするため設定方法が異なります。以下、設定方法を一覧にして整理しました。

役割 Management Account Delegated Account Member Account New Account
AWS CloudTrail Organizations にて一括有効化 Organizations にて一括有効化 Organizations にて一括有効化 Organizations にて一括有効化
AWS Config CLI or Cloudformation で有効化 StackSets で有効化 StackSets で有効化 StackSets で有効化
AWS Config Aggregator CLIで委任後にDelegated Account にて手動設定 委任後に手動設定 Delegated Account の設定で自動有効化 Delegated Account の設定で自動有効化
Amazon Detective CLI で有効化 StackSets で有効化 StackSets で有効化 StackSets で有効化
IAM Access Analyzer Delegated Account のCLIに連動して有効化 委任後にCLIで有効化 Delegated Account のCLIに連動して有効化 Delegated Account の設定で自動有効化
Amazon Macie 委任後にDelegated Account にて手動設定 委任後に自動有効化 Delegated Accountより手動有効化 Delegated Account のAuto-Enable 設定で自動有効化
AWS Security Hub 委任後にDelegated Account にて手動設定 委任後に自動有効化 Delegated Accountより手動有効化 Delegated Account のAuto-Enable 設定で自動有効化
Amazon GuardDuty 委任後にDelegated Account にて手動設定 委任後に自動有効化 Delegated Accountより手動有効化 Delegated Account のAuto-Enable 設定で自動有効化

First Step

AWS CloudTrail

以下のブログに従い、Management Account/Delegated Account/Member Account の各リージョンに対してAWS CloudTrailを有効化しておきます。(GuardDuty のデータソースにCloudTrailが含まれているため先に有効化しておきます)

blog.serverworks.co.jp

AWS Config

Delegated Account でStackSets を利用する場合は先にManagement Account から委任が必要なので、以下のManagement Account でCloudShell を起動させて以下のコマンドを予め実行しておきます

aws organizations enable-aws-service-access --service-principal member.org.stacksets.cloudformation.amazonaws.com 

その上で以下のブログに従い、CloudFormation ならびに StackSets を使って Management Account/Delegated Account/Member Account の各リージョンに対してAWS Configを有効化しておきます。(Security Hub を有効化するにはAWS Config の有効化は必須条件です

blog.serverworks.co.jp

AWS Config Aggregator

以下のブログに従い、AWS Config Aggregator を有効化してDelegated Account にデータを集約します

blog.serverworks.co.jp

Second Step

Management Account にて委任ならびに自アカウントでのセキュリティサービスの有効化

Management Account のCloudShell で以下のCLI群をスクリプトにして実行します。委任先のAccounId となっている箇所は適宜修正した上でスクリプトをご利用ください。

スクリプト内で実行している処理は以下の通りです

  • AWS組織と各AWSサービスを統合
  • 委任先アカウントの各リージョンに対してGuardDuty/Security Hub/Macie/の権限委任

SecuritySettings.sh

#!/bin/bash

# AWS組織と各AWSサービスを統合
aws organizations enable-aws-service-access --service-principal guardduty.amazonaws.com 
aws organizations enable-aws-service-access --service-principal securityhub.amazonaws.com 
aws organizations enable-aws-service-access --service-principal config.amazonaws.com 
aws organizations enable-aws-service-access --service-principal config-multiaccountsetup.amazonaws.com 
aws organizations enable-aws-service-access --service-principal macie.amazonaws.com 
aws organizations enable-aws-service-access --service-principal access-analyzer.amazonaws.com 

# 委任先アカウントの各リージョンに対してGuardDutyの権限委任
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-2
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-3
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-south-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-southeast-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-southeast-2
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region ca-central-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-central-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-north-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-2
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-3
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region sa-east-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-east-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-east-2
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-west-1
aws guardduty enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-west-2

# 委任先アカウントの各リージョンに対してMacieの権限委任

aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-2
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-3
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-south-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-southeast-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-southeast-2
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region ca-central-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-central-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-north-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-2
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-3
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region sa-east-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-east-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-east-2
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-west-1
aws macie2 enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-west-2

# Managementアカウントの各リージョンに対してのMacieを有効化

aws macie2 enable-macie --region ap-northeast-1
aws macie2 enable-macie --region ap-northeast-2
aws macie2 enable-macie --region ap-northeast-3
aws macie2 enable-macie --region ap-south-1
aws macie2 enable-macie --region ap-southeast-1
aws macie2 enable-macie --region ap-southeast-2
aws macie2 enable-macie --region ca-central-1
aws macie2 enable-macie --region eu-central-1
aws macie2 enable-macie --region eu-north-1
aws macie2 enable-macie --region eu-west-1
aws macie2 enable-macie --region eu-west-2
aws macie2 enable-macie --region eu-west-3
aws macie2 enable-macie --region sa-east-1
aws macie2 enable-macie --region us-east-1
aws macie2 enable-macie --region us-east-2
aws macie2 enable-macie --region us-west-1
aws macie2 enable-macie --region us-west-2

# 委任先アカウントの各リージョンに対してSecurity Hubの権限委任

aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-2
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-northeast-3
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-south-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-southeast-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region ap-southeast-2
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region ca-central-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-central-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-north-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-2
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region eu-west-3
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region sa-east-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-east-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-east-2
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-west-1
aws securityhub enable-organization-admin-account --admin-account-id 委任先のAccounId --region us-west-2

Third Step

Management Account と Member Account でSecurity Hub を有効化

以下のブログに従ってAWSコンソール画面上からManagement Account と Member Account のSecurity Hubを有効化していきます。

blog.serverworks.co.jp

Management Account と Member Account でGuardDuty を有効化

Security Hub と同様にAWSコンソール画面からMember Account のGuardDutyを有効化していきます。基本的にはSecurity Hub と同様の手順でポチポチしていけばOKですが、多少異なる部分があるのでポチポチの流れを記載しておきます。

  • Delegated Account のGuardDuty のコンソール画面を開く
  • 左メニュー Accounts を開く
  • 画面上部に青枠でMember Account の同一リージョンでも有効化するといった趣旨のメッセージが表示されるので Enable を押下
  • コンソール画面上でMember Account のStatus が全てEnable になることを確認
  • Management Account はEnable にならないので手動でメンバー追加をしてEnable になることを確認 f:id:swx-yamasaki:20210820213154p:plain
  • 左メニュー S3 Protection を開く(S3 Protection については以下ドキュメントを参照) docs.aws.amazon.com
  • デフォルトではS3 Protection は有効化されていないので手動で有効化(Delegated Account と Member Account をそれぞれ有効化できるボタンがあるので両方とも有効化しておく。ちなみにSecond Step でManagement Account に対して実行したCLIではこれを有効化するオプションを設定しているためManagement AccountではS3 Protection はすでに有効化されています。)
  • 左メニュー Accounts を開く
  • Account リストの上部に Auto-Enable is という設定ボタンがあるので押下してGuardDuty と S3 Protection をそれぞれONにする(これにより新アカウントがOrganizationsに作成されても自動でGuardDuty を適用してくれる)

GuardDutyのFindings の結果をS3に出力する

Delegated Account の Findings export options を設定します。

コンソール画面から設定する場合

コンソール画面に従ってS3バケットとKMSのARNを記載します。これを各リージョンごとに1つずつ設定していきます。

※別アカウントのS3バケットを利用する場合はS3のプレフィックスが指定できません。

f:id:swx-yamasaki:20210820204004p:plain

Delegated Account で設定した後にMember Account の同一リージョンのGuardDuty を確認するとFindings export options が設定されていないように見えますが、実は裏側では設定が完了されておりDelegated Account の設定内容が全てのMember Account で反映されています。

f:id:swx-yamasaki:20210820202124p:plain
Member Account では出力設定がされていないように見える

CLIから設定する場合

CLIを実行するにあたり以下の3つの情報を予め用意しておきます。

  • 各リージョンのGuardDutyのdetector-id
  • 出力先のS3バケットのARN
  • 使用するKMSのARN

GuardDutyのdetector-idについては以下のCLIコマンドで確認可能です

# Delegatedアカウントの各リージョンのGuardDutyのdetector-idをリストアップ

aws guardduty aws guardduty list-detectors --region ap-northeast-1
aws guardduty aws guardduty list-detectors --region ap-northeast-2
aws guardduty aws guardduty list-detectors --region ap-northeast-3
aws guardduty aws guardduty list-detectors --region ap-south-1
aws guardduty aws guardduty list-detectors --region ap-southeast-1
aws guardduty aws guardduty list-detectors --region ap-southeast-2
aws guardduty aws guardduty list-detectors --region ca-central-1
aws guardduty aws guardduty list-detectors --region eu-central-1
aws guardduty aws guardduty list-detectors --region eu-north-1
aws guardduty aws guardduty list-detectors --region eu-west-1
aws guardduty aws guardduty list-detectors --region eu-west-2
aws guardduty aws guardduty list-detectors --region eu-west-3
aws guardduty aws guardduty list-detectors --region sa-east-1
aws guardduty aws guardduty list-detectors --region us-east-1
aws guardduty aws guardduty list-detectors --region us-east-2
aws guardduty aws guardduty list-detectors --region us-west-1
aws guardduty aws guardduty list-detectors --region us-west-2

面倒ですが、上記で取得したdetector-idをCLIオプションに追記してスクリプトを実行します

#!/bin/bash
# Delegatedアカウントの各リージョンに対してのGuardDutyのfindings出力を設定

aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 DestinationArn=string,KmsKeyArn=string --region ap-northeast-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 DestinationArn=string,KmsKeyArn=string --region ap-northeast-2
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region ap-northeast-3
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region ap-south-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region ap-southeast-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region ap-southeast-2
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region ca-central-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region eu-central-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region eu-north-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region eu-west-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region eu-west-2
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region eu-west-3
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region sa-east-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region us-east-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region us-east-2
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region us-west-1
aws guardduty create-publishing-destination --detector-id hogehoge123456789 --destination-type S3 --destination-properties  DestinationArn=string,KmsKeyArn=string --region us-west-2

Management Account と Member Account でMacie を有効化

Security Hub と同様にAWSコンソール画面からMember Account のMacieを有効化していきます。基本的にはSecurity Hub と同様の手順でポチポチしていけばOKですが、多少異なる部分があるのでポチポチの流れを記載しておきます。

  • Delegated Account のMacie のコンソール画面を開く
  • 左メニュー Accounts を開く
  • 有効化したいMember Account を選択して Actions から Add member を選択(添付画像はすでに有効化したものなのでグレーアウトしていますが有効化する際は選択可能です)
    f:id:swx-yamasaki:20210819172904p:plain
    有効化したいMember Account を選択してメンバー追加
  • EnableにしたいAccountを一括選択してもManagement Account はEnable にならないので手動でメンバー追加をしてEnable になることを確認 f:id:swx-yamasaki:20210820220535p:plain
  • Account リストの上部に Auto-Enable is という設定ボタンがあるので押下してONにする(これにより新アカウントがOrganizationsに作成されても自動でMacie を適用してくれる)

Delegated Account からCLI でIAM Access Analyzer を有効化

Delegated Account のCloudShell で以下のCLI群をスクリプトにして実行します。

有効化した後に、Delegated Account/Management Account 以外のMember Account にアクセスしてIAM Access Analyzerのコンソール画面を確認してもAnalyzerは表示されません。

Member Account のAnalyzerのFindingsを確認可能なアカウントはDelegated Account/Management Accountのみです。

Security Hubも同様にMember AccountではIAM Access Analyzer のFindingsは検出されずDelegated Account/Management Account のSecurity HubでのみFindings は確認可能です。

EnableIAMAccessAnalyzer.sh

#!/bin/bash

#Organizations内の各アカウント/各リージョンに対してIAM Access Analyzerを有効化

aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-ap-northeast-1   --region ap-northeast-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-ap-northeast-2   --region ap-northeast-2
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-ap-northeast-3   --region ap-northeast-3
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-ap-south-1 --region ap-south-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-ap-southeast-1   --region ap-southeast-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-ap-southeast-2   --region ap-southeast-2
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-ca-central-1  --region ca-central-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-eu-central-1   --region eu-central-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-eu-north-1   --region eu-north-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-eu-west-1  --region eu-west-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-eu-west-2   --region eu-west-2
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-eu-west-3  --region eu-west-3
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-sa-east-1  --region sa-east-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-us-east-1   --region us-east-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-us-east-2   --region us-east-2
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-us-west-1   --region us-west-1
aws accessanalyzer create-analyzer --type ORGANIZATION --analyzer-name Analyzer-us-west-2   --region us-west-2

Final Step

Delegated Account からStackSets で Detective を有効化

Detective はGuardDuty を有効化してから48時間経過後でないと有効化できないためThird Stepから2日後に実施します。

docs.aws.amazon.com

Delegated Account で以下のテンプレートをStackSets でOrganizations 組織に流します。

EnableDetective.yml

AWSTemplateFormatVersion: 2010-09-09
Description:
  "enable Detective"
Resources:
  DetectiveGraph:
    Type: AWS::Detective::Graph

Management Account のCloudShell で以下のCLI群をスクリプトにして実行します。

#!/bin/bash
# Managementアカウントの各リージョンに対してのDetectiveを有効化

aws detective create-graph --region ap-northeast-1
aws detective create-graph --region ap-northeast-2
aws detective create-graph --region ap-northeast-3
aws detective create-graph --region ap-south-1
aws detective create-graph --region ap-southeast-1
aws detective create-graph --region ap-southeast-2
aws detective create-graph --region ca-central-1
aws detective create-graph --region eu-central-1
aws detective create-graph --region eu-north-1
aws detective create-graph --region eu-west-1
aws detective create-graph --region eu-west-2
aws detective create-graph --region eu-west-3
aws detective create-graph --region sa-east-1
aws detective create-graph --region us-east-1
aws detective create-graph --region us-east-2
aws detective create-graph --region us-west-1
aws detective create-graph --region us-west-2

CLI を利用してDelegated Account にDetective を統合

Detective はOrganizations に統合されていないため管理アカウントから各アカウントを招待(Invitation)して、各アカウントで招待(Invitation)を受諾(Accept)する必要があります。今回はDelegated Account を管理アカウントとして統合を実施します。

AWSドキュメントではDetective を管理アカウントに統合する場合はGuardDutyとSecurity Hubの管理アカウントと同一アカウントに統合することを推奨しています。

If you are enrolled in GuardDuty and AWS Security Hub, we recommend that your account be an administrator account for those services.

Amazon Detective prerequisites and recommendations - Amazon Detective

AWSコンソール画面から各アカウントを招待することも可能ですが今回は以下の理由でAWS CLI を利用して統合します。

  • 複数のリージョンのDetective を統合したい場合はリージョンごとにコンソールを切替えるのが面倒
  • AWSコンソール画面からの招待では招待メールの送信を無効にできない

Delegated Account で各アカウントを招待する(Invitation)

CLIを実行するにあたり以下の3つの情報を予め用意しておきます。

  • 各リージョンのDetective のgraph-arn
  • 招待するAccount ID
  • 招待するAccount に関連付けられているEメールアドレス

Detective のgraph-arnについては以下のCLIコマンドで確認可能です

# Delegated Accountの各リージョンのDetectiveのgraph-arnをリストアップ

aws detective list-graphs --region ap-northeast-1
aws detective list-graphs --region ap-northeast-2
aws detective list-graphs --region ap-south-1
aws detective list-graphs --region ap-southeast-1
aws detective list-graphs --region ap-southeast-2
aws detective list-graphs --region ca-central-1
aws detective list-graphs --region eu-central-1
aws detective list-graphs --region eu-north-1
aws detective list-graphs --region eu-west-1
aws detective list-graphs --region eu-west-2
aws detective list-graphs --region eu-west-3
aws detective list-graphs --region sa-east-1
aws detective list-graphs --region us-east-1
aws detective list-graphs --region us-east-2
aws detective list-graphs --region us-west-1
aws detective list-graphs --region us-west-2

招待するAccount に関連付けられているEメールアドレスはOrganizationsのコンソール画面から確認可能です。

各アカウントに対応したEメールアドレスを後続のCLIのオプションで指定しないと処理が失敗します。

f:id:swx-yamasaki:20210830214551p:plain
Eメールアドレスの確認

ここまでの事前準備が完了したら上記で取得した情報を基にAWS CLIを作成してスクリプトを実行します

以下の項目について適宜変更してください。--accounts オプションは1つのCLIコマンドで複数指定が可能であるため一度に複数のAWSアカウントを招待することが可能です。

DetectiveInvitation.sh
#!/bin/bash
# Delegated Account から各アカウント/各リージョンへ統合の招待を行う(Invitation)

aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:ap-northeast-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region ap-northeast-1

aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:ap-northeast-2:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region ap-northeast-2


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:ap-south-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region ap-south-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:ap-southeast-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region ap-southeast-1

aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:ap-southeast-2:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region ap-southeast-2


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:ca-central-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region ca-central-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:eu-central-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region eu-central-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:eu-north-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region eu-north-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:eu-west-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region eu-west-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:eu-west-2:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region eu-west-2


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:eu-west-3:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region eu-west-3


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:sa-east-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region sa-east-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:us-east-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region us-east-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:us-east-2:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region us-east-2


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:us-west-1:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region us-west-1


aws detective create-members \
        --accounts AccountId=123456789123,EmailAddress=hoge@example.com  \
        AccountId=111122223333,EmailAddress=hogehoge@example.com \
        --graph-arn arn:aws:detective:us-west-2:333344445555:graph:detective0sample0arn \
        --disable-email-notification \
        --region us-west-2

各アカウントで招待を受諾する(Accept)

以下のようなAWS CLIを作成して各アカウントでスクリプトを実行します

AcceptDetectiveInvitation.sh
#!/bin/bash
# 各アカウントにてDelegated AccountからのInvitationをAccept

aws detective accept-invitation --graph-arn arn:aws:detective:ap-northeast-1:333344445555:graph:detective0sample0arn --region ap-northeast-1
aws detective accept-invitation --graph-arn arn:aws:detective:ap-northeast-2:333344445555:graph:detective0sample0arn  --region ap-northeast-2
aws detective accept-invitation --graph-arn arn:aws:detective:ap-south-1:333344445555:graph:detective0sample0arn  --region ap-south-1
aws detective accept-invitation --graph-arn arn:aws:detective:ap-southeast-1:333344445555:graph:detective0sample0arn  --region ap-southeast-1
aws detective accept-invitation --graph-arn arn:aws:detective:ap-southeast-2:333344445555:graph:detective0sample0arn  --region ap-southeast-2
aws detective accept-invitation --graph-arn arn:aws:detective:ca-central-1:333344445555:graph:detective0sample0arn  --region ca-central-1
aws detective accept-invitation --graph-arn arn:aws:detective:eu-central-1:333344445555:graph:detective0sample0arn  --region eu-central-1
aws detective accept-invitation --graph-arn arn:aws:detective:eu-north-1:333344445555:graph:detective0sample0arn  --region eu-north-1
aws detective accept-invitation --graph-arn arn:aws:detective:eu-west-1:333344445555:graph:detective0sample0arn  --region eu-west-1
aws detective accept-invitation --graph-arn arn:aws:detective:eu-west-2:333344445555:graph:detective0sample0arn  --region eu-west-2
aws detective accept-invitation --graph-arn arn:aws:detective:eu-west-3:333344445555:graph:detective0sample0arn  --region eu-west-3
aws detective accept-invitation --graph-arn arn:aws:detective:sa-east-1:333344445555:graph:detective0sample0arn  --region sa-east-1
aws detective accept-invitation --graph-arn arn:aws:detective:us-east-1:333344445555:graph:detective0sample0arn  --region us-east-1
aws detective accept-invitation --graph-arn arn:aws:detective:us-east-2:333344445555:graph:detective0sample0arn  --region us-east-2
aws detective accept-invitation --graph-arn arn:aws:detective:us-west-1:333344445555:graph:detective0sample0arn  --region us-west-1
aws detective accept-invitation --graph-arn arn:aws:detective:us-west-2:333344445555:graph:detective0sample0arn  --region us-west-2

まとめ

Organizations を利用する場合、セキュリティサービスをOrganizations 組織の全アカウント/全リージョンに導入するというニーズは出てくると思いますので、是非ご参考になれば幸いです。

山﨑 翔平 (Shohei Yamasaki) 記事一覧はコチラ

2019/12〜2023/2までクラウドインテグレーション部でお客様のAWS導入支援を行っていました。現在はIE(インターナルエデュケーション)課にて採用周りのお手伝いや新卒/中途オンボーディングの業務をしています。2023 Japan AWS Top Engineers/2023 Japan AWS Ambassadors