Come posso creare una regola di un evento EventBridge per notificare che è stato utilizzato il mio account utente root AWS?

4 minuti di lettura
0

Come posso ricevere notifiche quando viene utilizzato il mio account utente root AWS?

Risoluzione

Avvia uno stack AWS CloudFormation per creare un argomento Amazon Simple Notification Service (Amazon SNS). Quindi, crea una regola di un evento Amazon EventBridge per monitorare gli accessi root userIdentity dalla Console di gestione AWS.

Importante: prima di iniziare, assicurati che gli eventi in lettura/scrittura di AWS CloudTrail Management siano impostati su All (Tutti) o Write-only (Solo scrittura) per gli eventi EventBridge per attivare la notifica dell'evento di accesso. Per ulteriori informazioni, consulta Eventi in lettura e scrittura.

1.    Copia e incolla questo modello YAML nel tuo strumento di editor preferito e poi salvalo.

# 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.    Apri la console CloudFormation nella regione Stati Uniti orientali (Virginia settentrionale) e scegli quindi Create Stack (Crea stack).

Nota: lo stack CloudFormation deve essere creato nella regione Stati Uniti orientali (Virginia settentrionale).

3.    Scegli Create stack (Crea stack) e scegli quindi With new resources (standard) (Con nuove risorse (standard)).

4.    Scegli Upload a template file (Carica un file di modello), Next (Avanti) e quindi Choose file (Scegli un file).

5.    Scegli il modello che hai salvato nel passaggio 1 e scegli quindi Next (Avanti).

6.    In Stack name (Nome stack), inserisci un nome che sia per te significativo, ad esempio Root-AWS-Console-Sign-in-CloudTrail.

7.    In EmailAddress (Indirizzo e-mail), inserisci il tuo indirizzo e-mail e scegli quindi Next (Avanti).

Nota: AWS invia l'e-mail di conferma a questo indirizzo e-mail.

8.    In Options (Opzioni), scegli Next (Avanti) e scegli quindi Create (Crea).

9.    Controlla nella tua casella di posta elettronica l'e-mail di conferma di AWS e scegli quindi Confirm subscription (Conferma sottoscrizione) per confermare la richiesta di abbonamento SNS. Riceverai il messaggio Subscription confirmed! (Sottoscrizione confermata!).

10.    Per testare le notifiche, esci dalla Console di gestione AWS. Quindi, accedi alla Console di gestione AWS con il tuo account utente root AWS.

11.    Controlla nella tua casella di posta elettronica se hai ricevuto un messaggio di notifica AWS. Nota che CloudTrail registra userIdentity, sourceIPAddress e MFAUsed contenenti i dettagli per l'evento di accesso.

Per interrompere la ricezione delle notifiche, elimina lo stack CloudFormation creato nel passaggio 2.


Informazioni correlate

Creazione di uno stack nella console CloudFormation

Come ricevere notifiche quando si utilizzano chiavi di accesso root del tuo account AWS

Monitoraggio e invio di notifiche sull'attività degli utenti root dell'account AWS

Creazione di allarmi CloudWatch con un modello di CloudFormation

AWS UFFICIALE
AWS UFFICIALEAggiornata 2 anni fa