AWS ルートユーザーアカウントが使用されたことを通知する EventBridge イベントルールを作成するにはどうすればよいですか?
最終更新日: 2021 年 12 月 8 日
AWS のルートユーザーアカウントが使用された際に通知を受け取る方法を教えてください。
解決方法
AWS CloudFormation スタックを起動して、Amazon Simple Notification Service (Amazon SNS) のトピックを作成します。次に、AWS マネジメントコンソールから userIdentity ルートログインをモニタリングするための Amazon EventBridge イベントルールを作成します。
重要: 開始する前に、EventBridge イベントの AWS CloudTrail Management 読み取り/書き込みイベントを [All] (すべて) または [Write-only] (書き込み専用) に設定して、ログインイベント通知をトリガーしてください。詳細については、「イベントの読み取りと書き込み」を参照してください。
1. この YAML テンプレートをコピーしてお好きなエディタツールに貼り付けてから保存します。
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AWSTemplateFormatVersion: '2010-09-09'
Description: ROOT-AWS-Console-Sign-In-via-CloudTrail
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Amazon SNS parameters
Parameters:
- Email Address
Parameters:
EmailAddress:
Type: String
AllowedPattern: "^[\\x20-\\x45]?[\\w-\\+]+(\\.[\\w]+)*@[\\w-]+(\\.[\\w]+)*(\\.[a-z]{2,})$"
ConstraintDescription: Email address required.
Description: Enter an email address you want to subscribe to the Amazon SNS topic
that will send notifications if your account's AWS root user logs in.
Resources:
RootActivitySNSTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: ROOT-AWS-Console-Sign-In-via-CloudTrail
Subscription:
- Endpoint:
Ref: EmailAddress
Protocol: email
TopicName: ROOT-AWS-Console-Sign-In-via-CloudTrail
EventsRule:
Type: AWS::Events::Rule
Properties:
Description: Events rule for monitoring root AWS Console Sign In activity
EventPattern:
detail-type:
- AWS Console Sign In via CloudTrail
detail:
userIdentity:
type:
- Root
Name:
Fn::Sub: "${AWS::StackName}-RootActivityRule"
State: ENABLED
Targets:
- Arn:
Ref: RootActivitySNSTopic
Id: RootActivitySNSTopic
DependsOn:
- RootActivitySNSTopic
RootPolicyDocument:
Type: AWS::SNS::TopicPolicy
Properties:
PolicyDocument:
Id: RootPolicyDocument
Version: '2012-10-17'
Statement:
- Sid: RootPolicyDocument
Effect: Allow
Principal:
Service: events.amazonaws.com
Action: sns:Publish
Resource:
- Ref: RootActivitySNSTopic
Topics:
- Ref: RootActivitySNSTopic
Outputs:
EventsRule:
Value:
Ref: EventsRule
Export:
Name:
Fn::Sub: "${AWS::StackName}-RootAPIMonitorEventsRule"
Description: Event Rule ID.
2. 米国東部 (バージニア北部) リージョンで CloudFormation コンソールを開き、[スタックの作成] を選択します。
注: CloudFormation スタックは、米国東部 (バージニア北部) リージョンで作成する必要があります。
3. [Create stack] (スタックの作成) を選択し、[With new resources (standard)] (新しいリソース (標準)) を選択します。
4. [テンプレートファイルのアップロード]、[次へ]、[ファイルの選択] の順に選択します。
5. 手順 1 で保存したテンプレートを選択し、[次へ] をクリックします。
6. [スタックの名前] に、わかりやすい名前 (Root-AWS-Console-Sign-In-CloudTrail など) を入力します。
7. [EmailAddress] フィールドに E メールアドレスを入力して、 [次へ] をクリックします。
注: この E メールアドレスに AWS から確認メールが送信されます。
8. [オプション] で [次へ] をクリックしてから、[作成] を選択します。
9. AWS から確認メールが届いたことを確認し、[サブスクリプションの確認] を選択して SNS のサブスクリプションリクエストを確認します。「Subscription confirmed!」というメッセージが表示されます。
10. 通知をテストするには、AWS マネジメントコンソールをサインアウトします。次に、AWS ルートユーザーアカウントで AWS マネジメントコンソールにサインインします。
11. AWS 通知メッセージが E メールで届いたことを確認します。ログインイベントの詳細を含む CloudTrail レコード の userIdentity、sourceIPAddress、MFAUsed をメモします。
通知の受信を停止するには、ステップ 2 で作成した CloudFormation スタックを削除します。