내 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 콘솔을 연 다음 **스택 생성(Create Stack)**을 선택합니다.
참고: CloudFormation 스택은 미국 동부(버지니아 북부) 리전에 생성되어야 합니다.
3. [스택 만들기(Create stack)]를 선택한 다음 [새 리소스 사용(표준)(With new resources(standard))]을 선택합니다.
4. 템플릿 파일 업로드(Upload a template file), **다음(Next)**을 선택한 다음 **파일 선택(Choose file)**을 선택합니다.
5. 1단계에서 저장한 템플릿을 선택하고 **다음(Next)**을 선택합니다.
6. **스택 이름(Stack name)**에 Root-AWS-Console-Sign-In-CloudTrail와 같은 의미 있는 이름을 입력합니다.
7. **이메일 주소(EmailAddress)**에 이메일 주소를 입력하고 **다음(Next)**을 선택합니다.
참고: AWS에서 이 이메일 주소로 확인 이메일을 보냅니다.
8. **옵션(Options)**에서 **다음(Next)**을 선택하고 **생성(Create)**을 선택합니다.
9. 이메일 받은 편지함에서 AWS 확인 이메일을 확인하고 **구독 확인(Confirm subscription)**을 선택하여 SNS 구독 요청을 확인합니다. 구독이 확인되었습니다!(Subscription confirmed!) 메시지가 표시됩니다.
10. 알림을 테스트하려면 AWS 관리 콘솔에서 로그아웃합니다. 그런 다음 AWS 관리 콘솔에 AWS 루트 사용자 계정으로 로그인합니다.
11. 이메일 받은 편지함에서 AWS 알림 메시지를 확인합니다. 로그인 이벤트의 세부 정보가 포함된 CloudTrail 레코드 userIdentity, sourceIPAddress 및 MFAUsed를 확인합니다.
알림 수신을 중지하려면 2단계에서 생성한 CloudFormation 스택을 삭제합니다.
관련 정보
CloudFormation 콘솔에서 스택 생성
AWS 계정의 루트 액세스 키가 사용될 때 알림을 받는 방법
AWS 계정 루트 사용자 활동 모니터링 및 알림
CloudFormation 템플릿을 사용하여 CloudWatch 경보 생성