如何创建 EventBridge 事件规则,以通知我有人使用了 AWS 根用户账户?
我想在有人使用我的 AWS 根用户账户时收到通知。
解决方案
启动 AWS CloudFormation 堆栈以创建 Amazon Simple Notification Service(Amazon SNS)主题。然后,创建 Amazon EventBridge 事件规则来监控 AWS 管理控制台中的 userIdentity 根用户登录。
**重要信息:**在开始之前,请确保将 AWS CloudTrail 管理的读写事件设置为 All 或 Write-only。这将允许 EventBridge 事件初始化登录事件通知。有关更多信息,请参阅Read and write events。
-
将此 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 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.
-
在美国东部(弗吉尼亚州北部)区域打开 CloudFormation 控制台,然后选择创建堆栈。
**注意:**您必须在美国东部(弗吉尼亚州北部)区域创建 CloudFormation 堆栈。
-
选择创建堆栈,然后选择使用新资源(标准)。
-
依次选择上传模板文件、下一步、选择文件。
-
选择您在步骤 1 中保存的模板,然后选择下一步。
-
在堆栈名称中,输入对您有意义的名称,例如 Root-AWS-Console-Sign-In-CloudTrail。
-
在电子邮件地址中,输入您的电子邮件地址,然后选择下一步。
**注意:**AWS 将确认电子邮件发送到该电子邮件地址。 -
在选项中,选择下一步,然后选择创建。
-
在您的电子邮件收件箱中查看 AWS 确认电子邮件,然后选择确认订阅以确认 SNS 订阅请求。您将收到**订阅已确认!**消息。
-
要测试通知,请退出 AWS 管理控制台。然后,使用您的 AWS 根用户账户登录 AWS 管理控制台。
-
检查您的电子邮件收件箱,看看是否收到 AWS 通知消息。请注意,CloudTrail 记录包含登录事件详细信息的 userIdentity、sourceIPAddress 和 MFAUsed。
如果您不想收到通知,请删除您在步骤 2 中创建的 CloudFormation 堆栈。
相关信息
Creating a stack on the AWS CloudFormation console
How to receive notifications when your AWS account's root access keys are used
相关内容
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 个月前