CloudTrailとは

出典: What Is AWS CloudTrail?

AWS CloudTrail is an AWS service that helps you enable operational and risk auditing, governance, and compliance of your AWS account. Actions taken by a user, role, or an AWS service are recorded as events in CloudTrail.

AWSアカウント内のAPIコールやイベントを記録するサービス 誰が、いつ、何をしたかを追跡できる


3つの記録方法

出典: What Is AWS CloudTrail?

CloudTrail provides three ways to record events: Event history, CloudTrail Lake, Trails

方法説明保存期間料金
イベント履歴自動記録される管理イベント90日無料
証跡S3に保存する設定無制限S3料金
CloudTrail LakeSQLでクエリ可能なデータレイク最大10年有料

イベント履歴

出典: Working with CloudTrail event history

The event history provides a record of the past 90 days of management events in an AWS Region, including activity made through the console, CLI, SDKs, and APIs. The event history is free to access

特徴:

  • 過去90日間の管理イベントを保持
  • 無料
  • 証跡を作成しなくても使える

制限:

  • 管理イベントのみ

出典: Working with CloudTrail event history

limitations include the inability to view data events, Insights events, or network activity events, a 90-day event retention period, a 200,000 event limit when downloading, and a limitation to a single AWS account and Region for event searches

  • データイベント、Insightsイベント、ネットワークアクティビティイベントは見れない
  • 90日を超えると消える
  • ダウンロードは200,000イベントまで
  • 単一リージョン・単一アカウントのみ検索可能

証跡

出典: What Is AWS CloudTrail?

Trails capture a record of AWS activities, delivering and storing these events in an Amazon S3 bucket, with optional delivery to CloudWatch Logs and Amazon EventBridge.

90日を超えて保存したい場合や、データイベントを記録したい場合は証跡を作成する

証跡を作成すると:

  • S3バケットにログファイルが保存される
  • 保存期間は無制限(S3のライフサイクルで管理)
  • Athenaでクエリ可能

証跡の料金

出典: AWS CloudTrail pricing

You can deliver one copy of your ongoing management events to your Amazon Simple Storage Service (S3) bucket for free by creating trails.

イベント種別料金
管理イベント(最初の1コピー)無料
管理イベント(追加コピー)$2.00 / 100,000イベント
データイベント$0.10 / 100,000イベント
ネットワークアクティビティイベント$0.10 / 100,000イベント

イベントの種類

出典: CloudTrail concepts

CloudTrail events include management events (control plane operations), data events (data plane operations), network activity events, and Insights events (unusual API call or error rate activity).

管理イベント(Management Events)

コントロールプレーン操作。リソースの作成・変更・削除など

例: EC2インスタンスの起動、IAMロールの作成、S3バケットの作成

デフォルトで有効

データイベント(Data Events)

出典: Logging data events

by default, trails and event data stores do not log data events, and additional charges apply for data events. Data events provide information about resource operations performed on or in a resource, also known as data plane operations.

データプレーン操作。リソース内のデータに対する操作

例: S3オブジェクトのGetObject/PutObject、Lambda関数の実行、DynamoDBのGetItem/PutItem

デフォルトで無効。有料

ネットワークアクティビティイベント

VPCエンドポイント経由のAPI呼び出しを記録

デフォルトで無効

Insightsイベント

異常なAPI呼び出しパターンを検出した際に生成される

出典: AWS CloudTrail pricing

CloudTrail Insights for management events: 0.03 per 100,000 events analyzed per insight type

デフォルトで無効。有料


証跡の配信先

出典: What Is AWS CloudTrail?

Trails capture a record of AWS activities, delivering and storing these events in an Amazon S3 bucket, with optional delivery to CloudWatch Logs and Amazon EventBridge.

配信先必須/オプション用途
S3バケット必須長期保存・アーカイブ
CloudWatch Logsオプションリアルタイム監視・アラート
EventBridgeオプションイベント駆動処理

S3は必須。CloudWatch Logsだけに保存する構成は不可


CloudWatch Logsとの連携

CloudWatch Logsに送ることで、特定のイベント発生時に通知を受け取れる

出典: Creating CloudWatch alarms for CloudTrail events: examples

Before creating the alarms, users must first create a CloudTrail trail and a log group, and grant CloudTrail the necessary permissions to create a CloudWatch Logs log stream and deliver events to it.

設定の流れ:

  1. 証跡でCloudWatch Logsを有効化
  2. CloudWatch Logsでメトリクスフィルタを作成
  3. CloudWatchアラームを設定
  4. SNSで通知

メトリクスフィルタの例

ルートユーザーのログイン検知:

{ $.userIdentity.type = "Root" && $.userIdentity.invokedBy NOT EXISTS && $.eventType != "AwsServiceEvent" }

セキュリティグループの変更検知:

{ $.eventName = AuthorizeSecurityGroup* || $.eventName = RevokeSecurityGroup* }

コンソールログイン失敗:

{ $.eventName = ConsoleLogin && $.errorMessage = "Failed authentication" }

CloudWatch Logs配信の料金

出典: AWS CloudTrail pricing

CloudTrail management and data events delivered to CloudWatch Logs group: $0.25/GB of events delivered to a CloudWatch Logs group

$0.25/GB(CloudWatch Logsの取り込み料金は別途発生)


証跡作成時のイベント選択

出典: Creating a trail for your organization in the console

Select the event types to log, including management events and data events. For data events, choose a resource type and use advanced event selectors to filter events.

コンソールで証跡を作成する際、ステップ2「ログイベントの選択」でイベントタイプを指定する

選択可能なイベント:

  • 管理イベント(デフォルトでオン)
  • データイベント(デフォルトでオフ)
  • ネットワークアクティビティイベント(デフォルトでオフ)
  • Insightsイベント(デフォルトでオフ)

データイベントを有効化する場合は、対象リソースを指定できる

  • すべてのS3バケット or 特定のバケット
  • すべてのLambda関数 or 特定の関数

AWS Organizationsとの統合

組織の証跡(Organization Trail)

出典: Creating a trail for an organization

An organization trail logs all events for all AWS accounts in the organization. The management account or a delegated administrator can create and manage organization trails.

Organizations環境では「組織の証跡」を作成できる 全メンバーアカウントのイベントを1つの証跡で記録

特徴:

  • 管理アカウントまたは委任管理者が作成・管理
  • 全メンバーアカウントに自動適用
  • メンバーアカウントは組織の証跡を変更・削除できない
  • 新しいアカウントが追加されると自動で証跡が適用される

作成方法: 証跡作成時に「Enable for all accounts in my organization」を選択

委任管理者(Delegated Administrator)

出典: Organization delegated administrator

A delegated administrator is an account within an organization that can manage the organization’s CloudTrail trails and event data stores on behalf of the organization.

管理アカウント以外のアカウントにCloudTrailの管理を委任できる

委任管理者ができること:

  • 組織の証跡の作成・更新・削除
  • 組織のイベントデータストアの管理

出典: Organization delegated administrator

An organization can have a maximum of three CloudTrail delegated administrators.

制限:

  • 組織あたり最大3つの委任管理者
  • 委任管理者の登録・削除は管理アカウントのみ可能

登録方法(CLI):

aws cloudtrail register-organization-delegated-admin --member-account-id="123456789012"

信頼されたアクセス

出典: AWS CloudTrail and AWS Organizations

When integration is enabled, an organization trail is created in the management account, which logs events for all accounts in the organization. The AWSServiceRoleForCloudTrail role is automatically created in the management account to allow CloudTrail to perform supported operations within member accounts.

OrganizationsとCloudTrailの統合を有効にすると:

  • 管理アカウントにAWSServiceRoleForCloudTrailロールが作成される
  • CloudTrailがメンバーアカウントで操作を実行できるようになる

出典: AWS CloudTrail and AWS Organizations

If trusted access is disabled, all organization trails for member accounts are deleted, and all management account organization trails and event data stores are converted to account-level trails and event data stores.

信頼されたアクセスを無効にすると:

  • メンバーアカウントの組織の証跡は削除される
  • 管理アカウントの組織の証跡はアカウントレベルの証跡に変換される

制限事項

出典: Sending events to CloudWatch Logs

CloudWatch Logs and EventBridge each allow a maximum event size of 256 KB, and CloudTrail does not send events larger than this size.

  • CloudWatch LogsとEventBridgeは最大256KBのイベントサイズ制限がある
  • 256KBを超えるイベントはCloudWatch Logsに送信されない

出典: Creating a trail for your organization in the console

The trail creation process may take up to 24 hours to complete in all enabled Regions and member accounts.

  • 組織の証跡の作成完了には最大24時間かかる場合がある