使用Cloudformation创建多个规则的AWS WAF规则集

0

【以下的问题经过翻译处理】 我正在尝试使用Cloudformation配置AWS WAF WebACL。我已成功创建了一个包含在AWS :: WAFv2 :: WebACL规则语句中定义的单个规则的WebACL,但是一旦我尝试定义两个或多个规则,只有块中的最后一个规则会被创建。没有错误,但我只得到块中的最后一个规则。有没有人有一个部署多个规则的WebACL的示例?

所需的规则集是:

  1. 使用优先级0的IP拒绝规则和引用的IP集
  2. 使用优先级1的IP允许规则和引用的IP集
  3. 地理位置规则以限制为GB和允许

示例代码块:

“Rules”:[
            {
                “Name”:“IPSetDeny”,
                “Priority”:0,
                “Statement”:{
                    “IPSetReferenceStatement”:{“ARN”:{“Fn :: GetAtt”:[“SampleIPSetDeny”,“Arn”]}}
                },
                “Action”:{
                    “Block”:{}
                },
                “VisibilityConfig”:{
                    “SampledRequestsEnabled”:true,
                    “CloudWatchMetricsEnabled”:true,
                    “MetricName”:“aws-waf-logs-dev-inf”
                },
                “Name”:“IPSetAllow”,
                “Priority”:1,
                “Statement”:{
                    “IPSetReferenceStatement”:{“ARN”:{“Fn :: GetAtt”:[“SampleIPSetAllow”,“Arn”]}}
                },
                “Action”:{
                    “Allow”:{}
                },
                “VisibilityConfig”:{
                    “SampledRequestsEnabled”:true,
                    “CloudWatchMetricsEnabled”:true,
                    “MetricName”:“aws-waf-logs-dev-inf”
                },
                “Name”:“restrict-country”,
                “Priority”:2,
                “Statement”:{
                    “GeoMatchStatement”:{
                        “CountryCodes”:[
                          “GB”
                        ]
                    }
                },
                “Action”:{
profile picture
专家
已提问 5 个月前17 查看次数
1 回答
0

【以下的回答经过翻译处理】 你的描述仅描述了规则中的一个规则对象。尽管我们无法确定CloudFormation如何解释它,但最后一个块可能已经将其覆盖。

我认为你应该像下面这样在规则中编写多个规则数组。

"Rules": [
     {
         "Name": "IPSetDeny",
         "Priority": 0,
         "Statement": {
             "IPSetReferenceStatement": {
                 "ARN": {
                     "Fn::GetAtt": [
                         "SampleIPSetDeny",
                         "Arn"
                     ]
                 }
             }
         },
         "Action": {
             "Block": {}
         },
         "VisibilityConfig": {
             "SampledRequestsEnabled": true,
             "CloudWatchMetricsEnabled": true,
             "MetricName": "aws-waf-logs-dev-inf"
         }
     },
     {
         "Name": "IPSetAllow",
         "Priority": 1,
         "Statement": {
             "IPSetReferenceStatement": {
                 "ARN": {
                     "Fn::GetAtt": [
                         "SampleIPSetAllow",
                         "Arn"
                     ]
                 }
             }
         },
         "Action": {
             "Allow": {}
         },
         "VisibilityConfig": {
             "SampledRequestsEnabled": true,
             "CloudWatchMetricsEnabled": true,
             "MetricName": "aws-waf-logs-dev-inf"
         }
     },
     {
         "Name": "restrict-country",
         "Priority": 2,
         "Statement": {
             "GeoMatchStatement": {
                 "CountryCodes": [
                     "GB"
                 ]
             }
         },
         "Action": {
             "Allow": {}
         },
         "VisibilityConfig": {
             "SampledRequestsEnabled": true,
             "CloudWatchMetricsEnabled": true,
             "MetricName": "aws-waf-logs-dev-inf"
         }
     }
 ]
profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则