0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS日記31 (CloudTrail)

Last updated at Posted at 2021-09-30

はじめに

今回は AWS CloudTrail を試します。
アカウントアクティビティのログを記録し、Amazon SNSを組み合わせて通知するよう設定します。

設定

今回は CloudFormation を利用し、設定しました。
使用したテンプレートはGithubに。

AWS SAM テンプレート作成

AWS SAM テンプレートで S3, SNS, CloudTrail の設定をします。

[参考資料]
AWS SAM テンプレートを作成する

S3の設定は以下の部分

  SampleBucket:
    Type: AWS::S3::Bucket
    Properties:
      AccessControl: LogDeliveryWrite
      BucketEncryption:
        ServerSideEncryptionConfiguration:
        - ServerSideEncryptionByDefault:
            SSEAlgorithm: AES256
      PublicAccessBlockConfiguration:
        BlockPublicAcls: True
        BlockPublicPolicy: True
        IgnorePublicAcls: True
        RestrictPublicBuckets: True
      LifecycleConfiguration:
        Rules:
        - Id: 30days
          Status: Enabled
          ExpirationInDays: 30
          NoncurrentVersionExpirationInDays: 30
    DeletionPolicy: Retain
  SampleBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
      Bucket: !Ref SampleBucket
      PolicyDocument:
        Version: 2012-10-17
        Statement:
        - Sid: SampleBucketCloudTrailAclCheck
          Effect: Allow
          Principal:
            Service: cloudtrail.amazonaws.com
          Action: s3:GetBucketAcl
          Resource: !Sub "arn:aws:s3:::${SampleBucket}"
        - Sid: SampleBucketCloudTrailWrite
          Effect: Allow
          Principal:
            Service: cloudtrail.amazonaws.com
          Action: s3:PutObject
          Resource: !Sub "arn:aws:s3:::${SampleBucket}/AWSLogs/${AWS::AccountId}/*"
          Condition:
            StringEquals:
              s3:x-amz-acl: bucket-owner-full-control

SNSの設定は以下の部分

  TrailSNSTopic:
    Type: AWS::SNS::Topic
  TrailSNSTopicPolicy:
    Type: AWS::SNS::TopicPolicy
    Properties:
      PolicyDocument:
        Version: 2012-10-17
        Statement:
        - Sid: SampleSNSCloudTrailWrite
          Effect: Allow
          Principal:
            Service: cloudtrail.amazonaws.com
          Action: sns:Publish
          Resource: !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:*"
      Topics:
        - !Ref TrailSNSTopic
  TrailSNSSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Endpoint: !Ref TrailSNSMailAddress
      Protocol: email
      TopicArn: !Ref TrailSNSTopic

CloudTrailの設定は以下の部分

  SampleTrail:
    Type: AWS::CloudTrail::Trail
    Properties:
      S3BucketName: !Ref SampleBucket
      SnsTopicName: !GetAtt TrailSNSTopic.TopicName
      IsLogging: true
      TrailName: !Ref TrailName

イベント履歴の確認

  • CloudTrail コンソール から イベント履歴の確認

CloudTrail2_.jpg

終わりに

CloudTrail を試しました。
異常なアクティビティを警告する、 CloudTrail Insights も今後試してきたいと思います。

参考資料
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?