使用 Amazon CloudTrail 记录 API 调用 - Amazon WAF、Amazon Firewall Manager 和 Amazon Shield Advanced
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon CloudTrail 记录 API 调用

Amazon WAF、Amazon Shield Advanced, 和Amazon Firewall Manager与集成Amazon CloudTrail,该服务提供用户、角色或Amazon服务。CloudTrail 将对这些服务的一部分 API 调用作为事件捕获,包括来自Amazon WAF、防 Shield 高级控制台或 Firewall Manager 控制台中的代码调用Amazon WAF、防 Shield 高级或 Firewall Manager API。如果您创建跟踪,则可以使 CloudTrail 事件持续传送到 Amazon S3 存储桶(包括Amazon WAF”、“高级防 Shield” 或 “Firewall Manager”。如果您不配置跟踪,则仍可在 CloudTrail 控制台中的 Event history (事件历史记录) 中查看最新事件。通过使用 CloudTrail 收集的信息,您可以确定向这些服务发出了什么请求、发出请求的 IP 地址、何人发出的请求、请求的发出时间以及其他详细信息。

要了解有关 CloudTrail 的更多信息(包括如何对其进行配置和启用),请参阅《Amazon CloudTrail 用户指南》。

CloudTrail 已启用 Amazon Web Services 账户 创建账户时。当受支持的事件活动发生在Amazon WAF、Shield 火墙管理器或 Firewall Manager 中,则该活动将记录在 CloudTrail 事件中,并与其他Amazon中的服务事件事件历史记录. 您可以在 Amazon Web Services 账户 . 有关更多信息,请参阅使用 CloudTrail 事件历史记录查看事件

要持续记录在 Amazon Web Services 账户 ,包括Amazon WAF”、“高级 Shield” 或 “Firewall Manager”,创建跟踪。通过跟踪,CloudTrail 可将日志文件传送至 Amazon S3 存储桶。默认情况下,在控制台中创建跟踪时,此跟踪应用于所有区域。此跟踪记录来自 Amazon 分区中的所有区域的事件,并将日志文件传送至您指定的 Amazon S3 存储桶。此外,您可以配置其他 Amazon 服务,进一步分析在 CloudTrail 日志中收集的事件数据并采取行动。有关更多信息,请参阅下列内容:

Amazon CloudTrail 中的 Amazon WAF 信息

所有 Amazon WAF 操作由 Amazon CloudTrail 记录,并且在 Amazon WAF API 参考中正式记载。例如,对ListWebACLUpdateWebACL, 和DeleteWebACL在 CloudTrail 日志文件中生成条目。

每个事件或日志条目都包含有关生成请求的人员信息。身份信息可帮助您确定以下内容:

  • 请求是使用根用户凭证还是 IAM 用户凭证发出的

  • 请求是使用角色还是联合身份用户的临时安全凭证发出的

  • 请求是否由其他 Amazon 服务发出

有关更多信息,请参阅 CloudTrail userIdentity 元素

示例:Amazon WAF 日志文件条目

跟踪是一种配置,可用于将事件作为日志文件传送到您指定的 Amazon S3 存储桶。Amazon CloudTrail日志文件包含一个或多个日志条目。一个事件表示来自任何源的一个请求,包括有关请求的操作、操作的日期和时间、请求参数等方面的信息。CloudTrail 日志文件不是公用 API 调用的有序堆栈跟踪,因此它们不会按任何特定顺序显示。

下 CloudTrail 是Amazon WAFWeb ACL 操作。

示例:的 CloudTrail 日志条目CreateWebACL

{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole", "principalId": "principalId", "arn": "arn:aws:sts::112233445566:assumed-role/Admin", "accountId": "112233445566", "accessKeyId": "accessKeyId", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "principalId", "arn": "arn:aws:iam::112233445566:role/Admin", "accountId": "112233445566", "userName": "Admin" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2019-11-06T03:43:07Z" } } }, "eventTime": "2019-11-06T03:44:21Z", "eventSource": "wafv2.amazonaws.com", "eventName": "CreateWebACL", "awsRegion": "us-west-2", "sourceIPAddress": "10.0.0.1", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36", "requestParameters": { "name": "foo", "scope": "CLOUDFRONT", "defaultAction": { "block": {} }, "description": "foo", "rules": [ { "name": "foo", "priority": 1, "statement": { "geoMatchStatement": { "countryCodes": [ "AF", "AF" ] } }, "action": { "block": {} }, "visibilityConfig": { "sampledRequestsEnabled": true, "cloudWatchMetricsEnabled": true, "metricName": "foo" } } ], "visibilityConfig": { "sampledRequestsEnabled": true, "cloudWatchMetricsEnabled": true, "metricName": "foo" } }, "responseElements": { "summary": { "name": "foo", "id": "ebbcb976-8d59-4d20-8ca8-4ab2f6b7c07b", "description": "foo", "lockToken": "67551e73-49d8-4363-be48-244deea72ea9", "aRN": "arn:aws:wafv2:us-west-2:112233445566:global/webacl/foo/ebbcb976-8d59-4d20-8ca8-4ab2f6b7c07b" } }, "requestID": "c51521ba-3911-45ca-ba77-43aba50471ca", "eventID": "afd1a60a-7d84-417f-bc9c-7116cf029065", "eventType": "AwsApiCall", "apiVersion": "2019-04-23", "recipientAccountId": "112233445566" }

示例:的 CloudTrail 日志条目GetWebACL

{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole", "principalId": "AssumedRole", "arn": "arn:aws:sts::112233445566:assumed-role/Admin/admin", "accountId": "112233445566", "accessKeyId": "accessKeyId", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "AssumedRole", "arn": "arn:aws:iam::112233445566:role/Admin", "accountId": "112233445566", "userName": "Admin" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2019-11-06T19:17:20Z" } } }, "eventTime": "2019-11-06T19:18:28Z", "eventSource": "wafv2.amazonaws.com", "eventName": "GetWebACL", "awsRegion": "us-west-2", "sourceIPAddress": "10.0.0.1", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36", "requestParameters": { "name": "foo", "scope": "CLOUDFRONT", "id": "webacl" }, "responseElements": null, "requestID": "f2db4884-4eeb-490c-afe7-67cbb494ce3b", "eventID": "7d563cd6-4123-4082-8880-c2d1fda4d90b", "readOnly": true, "eventType": "AwsApiCall", "apiVersion": "2019-04-23", "recipientAccountId": "112233445566" }

示例:的 CloudTrail 日志条目UpdateWebACL

{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole", "principalId": "principalId", "arn": "arn:aws:sts::112233445566:assumed-role/Admin", "accountId": "112233445566", "accessKeyId": "accessKeyId", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "principalId", "arn": "arn:aws:iam::112233445566:role/Admin", "accountId": "112233445566", "userName": "Admin" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2019-11-06T19:17:20Z" } } }, "eventTime": "2019-11-06T19:20:56Z", "eventSource": "wafv2.amazonaws.com", "eventName": "UpdateWebACL", "awsRegion": "us-west-2", "sourceIPAddress": "10.0.0.1", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36", "requestParameters": { "name": "foo", "scope": "CLOUDFRONT", "id": "ebbcb976-8d59-4d20-8ca8-4ab2f6b7c07b", "defaultAction": { "block": {} }, "description": "foo", "rules": [ { "name": "foo", "priority": 1, "statement": { "geoMatchStatement": { "countryCodes": [ "AF" ] } }, "action": { "block": {} }, "visibilityConfig": { "sampledRequestsEnabled": true, "cloudWatchMetricsEnabled": true, "metricName": "foo" } } ], "visibilityConfig": { "sampledRequestsEnabled": true, "cloudWatchMetricsEnabled": true, "metricName": "foo" }, "lockToken": "67551e73-49d8-4363-be48-244deea72ea9" }, "responseElements": { "nextLockToken": "a6b54c01-7975-4e6d-b7d0-2653cb6e231d" }, "requestID": "41c96e12-9790-46ab-b145-a230f358f2c2", "eventID": "517a10e6-4ca9-4828-af90-a5cff9756594", "eventType": "AwsApiCall", "apiVersion": "2019-04-23", "recipientAccountId": "112233445566" }

示例:的 CloudTrail 日志条目DeleteWebACL

{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole", "principalId": "principalId", "arn": "arn:aws:sts::112233445566:assumed-role/Admin/sheqiang-Isengard", "accountId": "112233445566", "accessKeyId": "accessKeyId", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "principalId", "arn": "arn:aws:iam::112233445566:role/Admin", "accountId": "112233445566", "userName": "Admin" }, "webIdFederationData": {}, "attributes": { "mfaAuthenticated": "false", "creationDate": "2019-11-06T19:17:20Z" } } }, "eventTime": "2019-11-06T19:25:17Z", "eventSource": "wafv2.amazonaws.com", "eventName": "DeleteWebACL", "awsRegion": "us-west-2", "sourceIPAddress": "10.0.0.1", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36", "requestParameters": { "name": "foo", "scope": "CLOUDFRONT", "id": "ebbcb976-8d59-4d20-8ca8-4ab2f6b7c07b", "lockToken": "a6b54c01-7975-4e6d-b7d0-2653cb6e231d" }, "responseElements": null, "requestID": "71703f89-e139-440c-96d4-9c77f4cd7565", "eventID": "2f976624-b6a5-4a09-a8d0-aa3e9f4e5187", "eventType": "AwsApiCall", "apiVersion": "2019-04-23", "recipientAccountId": "112233445566" }

示例:Amazon WAF Classic 日志文件条目

Amazon WAF Classic 是 Amazon WAF 的以前版本。有关信息,请参阅 Amazon WAF Classic

日志条目演示了 CreateRuleGetRuleUpdateRuleDeleteRule 操作:

{ "Records": [ { "eventVersion": "1.03", "userIdentity": { "type": "IAMUser", "principalId": "AIDAIEP4IT4TPDEXAMPLE", "arn": "arn:aws:iam::777777777777:user/nate", "accountId": "777777777777", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "nate" }, "eventTime": "2016-04-25T21:35:14Z", "eventSource": "waf.amazonaws.com", "eventName": "CreateRule", "awsRegion": "us-west-2", "sourceIPAddress": "Amazon Internal", "userAgent": "console.amazonaws.com", "requestParameters": { "name": "0923ab32-7229-49f0-a0e3-66c81example", "changeToken": "l9434322-8685-4ed2-9c5b-9410bexample", "metricName": "0923ab32722949f0a0e366c81example" }, "responseElements": { "rule": { "metricName": "0923ab32722949f0a0e366c81example", "ruleId": "12132e64-6750-4725-b714-e7544example", "predicates": [ ], "name": "0923ab32-7229-49f0-a0e3-66c81example" }, "changeToken": "l9434322-8685-4ed2-9c5b-9410bexample" }, "requestID": "4e6b66f9-d548-11e3-a8a9-73e33example", "eventID": "923f4321-d378-4619-9b72-4605bexample", "eventType": "AwsApiCall", "apiVersion": "2015-08-24", "recipientAccountId": "777777777777" }, { "eventVersion": "1.03", "userIdentity": { "type": "IAMUser", "principalId": "AIDAIEP4IT4TPDEXAMPLE", "arn": "arn:aws:iam::777777777777:user/nate", "accountId": "777777777777", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "nate" }, "eventTime": "2016-04-25T21:35:22Z", "eventSource": "waf.amazonaws.com", "eventName": "GetRule", "awsRegion": "us-west-2", "sourceIPAddress": "Amazon Internal", "userAgent": "console.amazonaws.com", "requestParameters": { "ruleId": "723c2943-82dc-4bc1-a29b-c7d73example" }, "responseElements": null, "requestID": "8e4f3211"-d548-11e3-a8a9-73e33example", "eventID": "an236542-d1f9-4639-bb3d-8d2bbexample", "eventType": "AwsApiCall", "apiVersion": "2015-08-24", "recipientAccountId": "777777777777" }, { "eventVersion": "1.03", "userIdentity": { "type": "IAMUser", "principalId": "AIDAIEP4IT4TPDEXAMPLE", "arn": "arn:aws:iam::777777777777:user/nate", "accountId": "777777777777", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "nate" }, "eventTime": "2016-04-25T21:35:13Z", "eventSource": "waf.amazonaws.com", "eventName": "UpdateRule", "awsRegion": "us-west-2", "sourceIPAddress": "Amazon Internal", "userAgent": "console.amazonaws.com", "requestParameters": { "ruleId": "7237b123-7903-4d9e-8176-9d71dexample", "changeToken": "32343a11-35e2-4dab-81d8-6d408example", "updates": [ { "predicate": { "type": "SizeConstraint", "dataId": "9239c032-bbbe-4b80-909b-782c0example", "negated": false }, "action": "INSERT" } ] }, "responseElements": { "changeToken": "32343a11-35e2-4dab-81d8-6d408example" }, "requestID": "11918283-0b2d-11e6-9ccc-f9921example", "eventID": "00032abc-5bce-4237-a8ee-5f1a9example", "eventType": "AwsApiCall", "apiVersion": "2015-08-24", "recipientAccountId": "777777777777" }, { "eventVersion": "1.03", "userIdentity": { "type": "IAMUser", "principalId": "AIDAIEP4IT4TPDEXAMPLE", "arn": "arn:aws:iam::777777777777:user/nate", "accountId": "777777777777", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "nate" }, "eventTime": "2016-04-25T21:35:28Z", "eventSource": "waf.amazonaws.com", "eventName": "DeleteRule", "awsRegion": "us-west-2", "sourceIPAddress": "Amazon Internal", "userAgent": "console.amazonaws.com", "requestParameters": { "changeToken": "fd232003-62de-4ea3-853d-52932example", "ruleId": "3e3e2d11-fd8b-4333-8b03-1da95example" }, "responseElements": { "changeToken": "fd232003-62de-4ea3-853d-52932example" }, "requestID": "b23458a1-0b2d-11e6-9ccc-f9928example", "eventID": "a3236565-1a1a-4475-978e-81c12example", "eventType": "AwsApiCall", "apiVersion": "2015-08-24", "recipientAccountId": "777777777777" } ] }

Amazon Shield AdvancedCloudTrail 中的信息

Amazon Shield Advanced支持在 CloudTrail 日志文件中将以下操作记录为事件:

每个事件或日志条目都包含有关生成请求的人员信息。身份信息可帮助您确定以下内容:

  • 请求是使用根用户凭证还是 IAM 用户凭证发出的。

  • 请求是使用角色还是联合身份用户的临时安全凭证发出的。

  • 请求是否由其他 Amazon 服务发出。

有关更多信息,请参阅 CloudTrail userIdentity 元素

示例:Shield 高级日志文件条目

跟踪是一种配置,可用于将事件作为日志文件传送到您指定的 Amazon S3 存储桶。CloudTrail 日志文件包含一个或多个日志条目。一个事件表示来自任何源的一个请求,包括有关请求的操作、操作的日期和时间、请求参数等方面的信息。CloudTrail 日志文件不是公用 API 调用的有序堆栈跟踪,因此它们不会按任何特定顺序显示。

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了DeleteProtectionListProtections操作。

[ { "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "1234567890987654321231", "arn": "arn:aws:iam::123456789012:user/SampleUser", "accountId": "123456789012", "accessKeyId": "1AFGDT647FHU83JHFI81H", "userName": "SampleUser" }, "eventTime": "2018-01-10T21:31:14Z", "eventSource": "shield.amazonaws.com", "eventName": "DeleteProtection", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "aws-cli/1.14.10 Python/3.6.4 Darwin/16.7.0 botocore/1.8.14", "requestParameters": { "protectionId": "12345678-5104-46eb-bd03-agh4j8rh3b6n" }, "responseElements": null, "requestID": "95bc0042-f64d-11e7-abd1-1babdc7aa857", "eventID": "85263bf4-17h4-43bb-b405-fh84jhd8urhg", "eventType": "AwsApiCall", "apiVersion": "AWSShield_20160616", "recipientAccountId": "123456789012" }, { "eventVersion": "1.05", "userIdentity": { "type": "IAMUser", "principalId": "123456789098765432123", "arn": "arn:aws:iam::123456789012:user/SampleUser", "accountId": "123456789012", "accessKeyId": "1AFGDT647FHU83JHFI81H", "userName": "SampleUser" }, "eventTime": "2018-01-10T21:30:03Z", "eventSource": "shield.amazonaws.com", "eventName": "ListProtections", "awsRegion": "us-east-1", "sourceIPAddress": "Amazon Internal", "userAgent": "aws-cli/1.14.10 Python/3.6.4 Darwin/16.7.0 botocore/1.8.14", "requestParameters": null, "responseElements": null, "requestID": "6accca40-f64d-11e7-abd1-1bjfi8urhj47", "eventID": "ac0570bd-8dbc-41ac-a2c2-987j90j3h78f", "eventType": "AwsApiCall", "apiVersion": "AWSShield_20160616", "recipientAccountId": "123456789012" } ]

Amazon Firewall ManagerCloudTrail 中的信息

Amazon Firewall Manager支持在 CloudTrail 日志文件中将以下操作记录为事件:

每个事件或日志条目都包含有关生成请求的人员信息。身份信息可帮助您确定以下内容:

  • 请求是使用根用户凭证还是 IAM 用户凭证发出的。

  • 请求是使用角色还是联合身份用户的临时安全凭证发出的。

  • 请求是否由其他 Amazon 服务发出。

有关更多信息,请参阅 CloudTrail userIdentity 元素

示例:Firewall Manager 日志文件条目

跟踪是一种配置,可用于将事件作为日志文件传送到您指定的 Amazon S3 存储桶。CloudTrail 日志文件包含一个或多个日志条目。一个事件表示来自任何源的一个请求,包括有关请求的操作、操作的日期和时间、请求参数等方面的信息。CloudTrail 日志文件不是公用 API 调用的有序堆栈跟踪,因此它们不会按任何特定顺序显示。

下面的示例显示了一个 CloudTrail 日志条目,该条目说明了GetAdminAccount—> 操作。

{ "eventVersion": "1.05", "userIdentity": { "type": "AssumedRole", "principalId": "1234567890987654321231", "arn": "arn:aws:sts::123456789012:assumed-role/Admin/SampleUser", "accountId": "123456789012", "accessKeyId": "1AFGDT647FHU83JHFI81H", "sessionContext": { "attributes": { "mfaAuthenticated": "false", "creationDate": "2018-04-14T02:51:50Z" }, "sessionIssuer": { "type": "Role", "principalId": "1234567890987654321231", "arn": "arn:aws:iam::123456789012:role/Admin", "accountId": "123456789012", "userName": "Admin" } } }, "eventTime": "2018-04-14T03:12:35Z", "eventSource": "fms.amazonaws.com", "eventName": "GetAdminAccount", "awsRegion": "us-east-1", "sourceIPAddress": "72.21.198.65", "userAgent": "console.amazonaws.com", "requestParameters": null, "responseElements": null, "requestID": "ae244f41-3f91-11e8-787b-dfaafef95fc1", "eventID": "5769af1e-14b1-4bd1-ba75-f023981d0a4a", "eventType": "AwsApiCall", "apiVersion": "2018-01-01", "recipientAccountId": "123456789012" }