【问题标题】:Multiple RedactedFields in AWS WAFv2 put-logging-configuration commandAWS WAFv2 put-logging-configuration 命令中的多个 RedactedFields
【发布时间】:2020-10-01 14:24:18
【问题描述】:

我正在尝试使用 WAFv2 在我们的 Web ACL 上设置日志记录。 我可以使用一个“RedactedField”成功运行put-logging-configuration 命令,但是在第一个之后添加更多标题时遇到问题。

这是有问题的documentation——我无法完全理解它:

您希望 AWS WAF 检查的 Web 请求部分。根据类型,包括您要检查的单个 FieldToMatch 类型,并根据需要提供其他规范。您在 FieldToMatch 中为每个需要它的规则语句指定一个请求组件。要检查 Web 请求的多个组件,请为每个组件创建单独的规则语句。

这是我的有效命令:

 aws --region="us-west-2" wafv2 put-logging-configuration \
 --logging-configuration ResourceArn=${MY_WEB_ACL_ARN},LogDestinationConfigs=${MY_FIREHOSE_DELIVERY_STREAM_ARN},RedactedFields={SingleHeader={Name="cookie"}}

这给出了以下结果:

{
    "LoggingConfiguration": {
        "ResourceArn": "{My arn}",
        "LogDestinationConfigs": [
            "{My firehose log stream arn}"
        ],
        "RedactedFields": [
            {
                "SingleHeader": {
                    "Name": "cookie"
                }
            }
        ]
    }
}

我还希望编辑“授权”标题。

我在--logging-configuration 的“RedactedFields”部分尝试了以下内容:

1) Two SingleHeader statements within brackets
RedactedFields={SingleHeader={Name="cookie"},SingleHeader={Name="cookie"}}
(Results in 'Unknown options' error.)

2) Two sets of brackets with comma
RedactedFields={SingleHeader={Name="cookie"}},{SingleHeader={Name="authorization"}}
Error parsing parameter '--logging-configuration': Expected: '=', received: '{' for input:

3) Two sets of brackets, no comma 
RedactedFields={SingleHeader={Name="cookie"}}{SingleHeader={Name="authorization"}}
Error parsing parameter '--logging-configuration': Expected: ',', received: '{' for input: 

4) Two SingleHeader statements within brackets, no comma
RedactedFields={SingleHeader={Name="cookie"}{SingleHeader={Name="authorization"}}
Error parsing parameter '--logging-configuration': Expected: ',', received: '{' for input:

5) One SingleHeader statement, two headers (Isn't really a SingleHeader anymore, is it?)
RedactedFields={SingleHeader={Name="cookie", "authorization"}}
Unknown options: authorization}}

我在这里做错了什么?我尝试了许多其他方法,包括[] 方括号、“名称”的多个实例、“RedactedFields”的多个实例——完全没有用。

【问题讨论】:

    标签: amazon-web-services amazon-waf


    【解决方案1】:

    要通过简写语法将多个 SingleHeaders 添加到 RedactedFields,我必须

    • 为每个 SingleHeader 提供自己的一组括号
    • 在每个括号集之间添加一个逗号
    • 用方括号将所有集合括起来
    • 将所有内容用单引号括起来。

    例如,如果我想要两个 SingleHeader,一个用于“cookie”,一个用于“授权”,我需要将以下内容用于--logging-configurationRedactedFields 部分:

    RedactedFields='[{SingleHeader={Name="cookie"}},{SingleHeader={Name="authorization"}}]'
    

    总之,如果我们将它添加到 put-logging-configuration,整个命令将是:

    aws --region=${MY_REGION} wafv2 put-logging-configuration \
    --logging-configuration ResourceArn=${MY_WEB_ACL_ARN},LogDestinationConfigs=${MY_FIREHOSE_DELIVERY_STREAM_ARN},RedactedFields='[{SingleHeader={Name="cookie"}},{SingleHeader={Name="authorization"}}]'
    

    给出以下结果:

    {
        "LoggingConfiguration": {
            "ResourceArn": "{my acl arn}",
            "LogDestinationConfigs": [
                "{my firehose log stream arn}"
            ],
            "RedactedFields": [
                {
                    "SingleHeader": {
                        "Name": "cookie"
                    }
                },
                {
                    "SingleHeader": {
                        "Name": "authorization"
                    }
                },
            ]
        }
    }
    

    此格式可用于任何其他 FieldToMatch,例如 SingleQueryArgument、AllQueryArguments、QueryString、UriPath、Body 等。

    【讨论】:

      猜你喜欢
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 2013-08-31
      相关资源
      最近更新 更多