LoginSignup
4
4

CloudTrail の管理イベントにおける API イベントとサービスイベントの違い

Last updated at Posted at 2023-06-01

はじめに

AWS CloudTrail には管理イベントとデータイベントという 2 種類の CloudTrail イベントがあることをご存じの方は多いと思います。

管理イベントでは AWS アカウント内のリソースに対して実行される管理オペレーションが証跡として記録されますが、管理イベントにもいくつかの種類があります。

管理イベントにおけるイベントタイプ

管理インベントのタイプは CloudTrail レコードの eventType で確認することができます。2023 年 6 月現在で 5 つのタイプが存在します。

eventType
Identifies the type of event that generated the event record. This can be the one of the following values:

  • AwsApiCall – An API was called.
  • AwsServiceEvent – The service generated an event related to your trail. For example, this can occur when another account made a call with a resource that you own.
  • AwsConsoleAction – An action was taken in the console that was not an API call.
  • AwsConsoleSignIn – A user in your account (root, IAM, federated, SAML, or SwitchRole) signed in to the AWS Management Console.
  • AwsCloudTrailInsight – If Insights events are enabled for the trail, CloudTrail generates Insights events when CloudTrail detects unusual operational activity such as spikes in resource provisioning or bursts of AWS Identity and Access Management (IAM) actions.

EventBrdige のイベントパターン設定時にハマった

eventType の違いを意識しておかないと、EventBrdige のイベントパターンの設定で意図通りにイベント発火せず、時間を浪費してしまう場合があります。(私です)

AWS アカウント作成時に発生する CreateAccount イベントと CreateAccountResult イベントを例にあげます。

CreateAccount (API イベント)

CreateAccount イベント は API イベント (eventType: AwsApiCall) です。AWS Organizations のCreateAccount API が呼び出された際に記録されます。

CreateAccount イベントの例 (クリックして展開)
CreateAccount Event
{
    "eventVersion": "1.05",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDAMVNPBQA3EXAMPLE:my-admin-role",
        "arn": "arn:aws:sts::111122223333:assumed-role/my-admin-role/my-session-id",
        "accountId": "111122223333",
        "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AIDAMVNPBQA3EXAMPLE",
                "arn": "arn:aws:iam::111122223333:role/my-admin-role",
                "accountId": "111122223333",
                "userName": "my-session-id"
            },
            "webIdFederationData": {},
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2020-09-16T21:16:45Z"
            }
        }
    },
    "eventTime": "2018-06-21T22:06:27Z",
    "eventSource": "organizations.amazonaws.com",
    "eventName": "CreateAccount",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "192.168.0.1",
    "userAgent":  "Mozilla/5.0 (Windows NT 10.0; Win64; x64)...",
    "requestParameters": {
        "tags": [],
        "email": "****",
        "accountName": "****"
    },
    "responseElements": {
        "createAccountStatus": {
            "accountName": "****",
            "state": "IN_PROGRESS",
            "id": "car-examplecreateaccountrequestid111",
            "requestedTimestamp": "Sep 16, 2020 9:20:50 PM"
        }
    },
    "requestID": "EXAMPLE8-90ab-cdef-fedc-ba987EXAMPLE",
    "eventID": "EXAMPLE8-90ab-cdef-fedc-ba987EXAMPLE",
    "eventType": "AwsApiCall",
    "recipientAccountId": "111111111111"
}

EventBridge ルールでイベントの発火を検知したい場合、設定するイベントパターンは以下のようになります。detail-type を AWS API Call via CloudTrail にするのがポイントです。

{
  "source": ["aws.organizations"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventName": ["CreateAccount"]
  }
}

CreateAccountResult (サービスイベント)

CreateAccountResult はサービスイベント (eventType: AwsServiceEvent) です。サービスイベントはその名の通り AWS サービスによって作成、記録されるため、特定の AWS API の呼び出しには紐づきません。

CreateAccountResult イベントはアカウント作成のバックグラウンドワークフローが完了した際に AWS Organizations によって記録されるサービスイベントです

CreateAccountResult イベントの例 (クリックして展開)
CreateAccountResult Event
{
  "eventVersion": "1.05",
  "userIdentity": {
    "accountId": "111122223333",
    "invokedBy": "..."
  },
  "eventTime": "2020-09-16T21:20:53Z",
  "eventSource": "organizations.amazonaws.com",
  "eventName": "CreateAccountResult",
  "awsRegion": "us-east-1",
  "sourceIPAddress": "192.0.2.0",
  "userAgent": "....",
  "requestParameters": null,
  "responseElements": null,
  "eventID": "EXAMPLE8-90ab-cdef-fedc-ba987EXAMPLE",
  "readOnly": false,
  "eventType": "AwsServiceEvent",
  "recipientAccountId": "111122223333",
  "serviceEventDetails": {
    "createAccountStatus": {
      "id": "car-examplecreateaccountrequestid111",
      "state": "SUCCEEDED",
      "accountName": "****",
      "accountId": "444455556666",
      "requestedTimestamp": "Sep 16, 2020 9:20:50 PM",
      "completedTimestamp": "Sep 16, 2020 9:20:53 PM"
    }
  }
}

EventBridge ルールでイベントの発火を検知したい場合、設定するイベントパターンは以下のようになります。detail-type を AWS Service Event via CloudTrail にするのがポイントです。

{
  "source": ["aws.organizations"],
  "detail-type": ["AWS Service Event via CloudTrail"],
  "detail": {
    "eventName": ["CreateAccountResult"],
   }
}

誤って AWS API Call via CloudTrail にしてしまうとイベントが発火しないので、CloudTrail のイベントを EventBridge で検知する際は eventType も意識しておこうというお話でした。

簡単ですが以上です。
参考になれば幸いです。

4
4
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
4
4