如何将 AWS WAF 日志发送到位于集中式日志账户的 Amazon S3 桶中?

2 分钟阅读
0

我想将 AWS WAF 日志发送到位于其他账户或 AWS 区域的 Amazon Simple Storage Service (Amazon S3) 桶中。

解决方法

要将 AWS WAF 日志发送到位于集中式日志账户的 Amazon S3 桶中,请完成以下部分中的步骤。

在所选区域的集中式日志账户中创建 S3 桶

1.在所选 AWS 区域的集中式日志账户中创建 S3 桶

2.输入以前缀 aws-waf-logs- 开头的桶名称。例如,将您的桶命名为类似于 aws-waf-logs-example-bucket 这样的名称。

创建桶策略并将其添加到 S3 桶

将以下 S3 桶策略添加到您的 S3 桶:

重要事项:

  • aws:SourceAccount 中的账户 ID 替换为您要向此桶发送日志的源账户 ID 列表。
  • aws:SourceArn 中的 ARN 替换为您要向此桶发布日志的源资源的 ARN 列表。使用 arn:aws:logs:*:source-account-id:* 的格式。
  • 资源中的 S3 桶名称 aws-waf-logs-example-bucket 替换为您 S3 桶的名称。
{
  "Version": "2012-10-17",
  "Id": "AWSLogDeliveryWrite20150319",
  "Statement": [
    {
      "Sid": "AWSLogDeliveryWrite",
      "Effect": "Allow",
      "Principal": {
        "Service": "delivery.logs.amazonaws.com"
      },
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::aws-waf-logs-example-bucket/AWSLogs/*",
      "Condition": {
        "StringEquals": {
          "s3:x-amz-acl": "bucket-owner-full-control",
          "aws:SourceAccount": [
            "111111111111",
            "222222222222"
          ]
        },
        "ArnLike": {
          "aws:SourceArn": [
            "arn:aws:logs:*:111111111111:*",
            "arn:aws:logs:*:222222222222:*"
          ]
        }
      }
    },
    {
      "Sid": "AWSLogDeliveryAclCheck",
      "Effect": "Allow",
      "Principal": {
        "Service": "delivery.logs.amazonaws.com"
      },
      "Action": "s3:GetBucketAcl",
      "Resource": "arn:aws:s3:::aws-waf-logs-example-bucket",
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": [
            "111111111111",
            "222222222222"
          ]
        },
        "ArnLike": {
          "aws:SourceArn": [
            "arn:aws:logs:*:111111111111:*",
            "arn:aws:logs:*:222222222222:*"
          ]
        }
      }
    }
  ]
}

配置您的 Web ACL,将日志发送到所需的 S3 桶

**注意:**如果您在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请确保您使用的是最新版本的 AWS CLI

您必须配置您的 Web ACL,才能将 AWS WAF 日志发送到集中式日志账户的 S3 桶中。要配置 Web ACL,请从拥有 Web ACL 的账户运行 put-logging-configuration AWS CLI 命令。

重要事项:

  • ResourceArn 的值替换为您的网络 ACL ARN。
  • LogDestinationConfigs 的值替换为位于您集中式日志账户中的 S3 桶的 ARN。
  • 区域替换为您的 Web ACL 所在的 AWS 区域。
aws wafv2 put-logging-configuration --logging-configuration ResourceArn=arn:aws:wafv2:eu-west-1: 111111111111:regional/webacl/testing/b4a768c9-4895-4f35-9354-3049ab8acc29,LogDestinationConfigs=arn:aws:s3:::aws-waf-logs-example-bucket --region eu-west-1

**注意:**对于 CloudFront (Global) Region 中的 Web ACL,在前面的命令中使用 us-east-1 作为区域。

对您的每个 Web ACL 重复前面的 put-logging-configuration 命令。


相关信息

将日志发布到 Amazon S3 所需的权限

AWS 官方
AWS 官方已更新 1 年前