aws-cdk: wafv2: CfnWebACL Rules property has incorrect CloudFormation schema
link to reference doc page: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-wafv2.CfnWebACL.html
I tried instantiating a simple WAF ACL with the following code:
const acl = new waf.CfnWebACL(this, 'ACL', {
defaultAction: {
allow: true,
},
scope: 'CLOUDFRONT',
visibilityConfig: {
cloudWatchMetricsEnabled: true,
metricName: 'waf', // TODO add a stage suffix
sampledRequestsEnabled: false,
},
rules: {
rules: [
{ name: 'AWS-AWSManagedRulesAmazonIpReputationList' },
{ name: 'AWS-AWSManagedRulesCommonRuleSet' },
{ name: 'AWS-AWSManagedRulesKnownBadInputsRuleSet' },
{ name: 'AWS-AWSManagedRulesSQLiRuleSet' },
{ name: 'AWS-AWSManagedRulesLinuxRuleSet' },
],
},
});
The code compiles but cdk deploy fails with an ACL Internal Failure that doesn’t provide any helpful context.
Can you update the document with a working starter example?
This is a 📕 documentation issue
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 32 (9 by maintainers)
I’ve discovered you get the error “Your statement has multiple values set for a field that requires exactly one value., field: RULE, parameter: Rule” is returned if you are missing the
OverrideActionon theManagedRuleGroupStatement. The field is needed even if you don’t want to override it, you specify “none” as per the docs.Clearly a CF issue because the cdk types can’t enforce this the way they are, but this GH Issue is the main result when searching for that error message so hopefully this helps someone.
Given this page is the first (and only, really) coming up in Google for the error
I would add to @tmo-trustpilot 's comment above:
overrideActionandactionHope this helps someone.
For everyone affected by this, using the Escape Hatch mechanism (which applies any time the CloudFormation template the CDK generates is not the one you would like to see) is probably your only solution to tide you over until this issue gets resolved upstream by CloudFormation and we import the new schema.
I’m sure it’s just something I’m doing, but now that the original error is resolved, is anyone getting the following error now when trying this in Python:
Wafdev Error reason: Your statement has multiple values set for a field that requires exactly one value., field: RULE, parameter: Rule (Service: Wafv2, Status Code: 400, Request ID: e558fb83-afa0-484c-9831-9f8b06ac6c2b)Code to create:
Which seems to output the correct JSON to the stack template:
(I’m using version 1.26 of all CDK packages, boto3 v1.12.8, and botocore v1.15.8)
I think this type of feature is better suited for the cdk-examples repository.
@rix0rrr - I was able to sync with a couple folks from the WAF team yesterday and they’re in the midst of amending the resource specification. I think we should hold off on putting in a patch unless there are delays in importing the updated spec
@SomayaB Please note that the question is about documentation, but the underlying issue is an unresolved bug (hence the bug report, which was flagged as a duplicate and got closed)
Thank you for the detailed steps. Manually uploading the modified output template to Cloudformation worked for me. I’ll wait for
@aws-cdk/aws-wafv2to be updated to switch to using CDK for this.@thibaut-singlefile I see the managed rules you wanted to put on the ACL, so I created one manually and reverse-engineered the config to CDK (I assume you use typescript). Please keep in mind that CDK has a bug that outputs the
Rules: { Rules: [] }wrapper, which caused your internal failure. I opened a bug report hereLike mentioned above, keep in mind that for the time being you need to fix the output manually.
You won’t be able to successfully run cdk commands with this anymore, because the synthesized template.json will put
Rules: { Rules: [] }back in whenever you rundeploy,synthordiffGo to cdk.output and edit the *.template.json file. Remove the
Rules { }wrapper around theRules: [ ]. Then go to the cloudformation console, and create a stack by uploading the *.template.json file. CDK and the CLI have some issues with Cloudfront being global. I tested this in us-east-1Take a look at the rule properties and the output it produces. You might want to tweak a few things.
@tmo-trustpilot This fixed my issue. Thank you very, very much!
I can also confirm that I was able to instantiate the WAF ACL with AWS CDK using 1.26. Here is the code that worked for me:
This is a hack, but maybe you’ll find it as an alternative to the escape hatch. This class rips through the generated cloudfront template and fixes the object array wrappers:
While it worked for my use case, your mileage might vary. Also, this is purely a hack until the underlying CF schema can be fixed.
@hoegertn I’m not sure if it’s related to spec errors. It seems that by removing the extra wrapped “Rules” property from the cdk.output I’m able to create the stack using the cdk.output file with the correct rule.
@thibaut-singlefile I reverse engineered the ACL configuration by creating one manually and downloading it has JSON (button on the top right of the ACL detail screen). I copy pasted one of the rules into the array and, like I said, edited the cdk.output file. Then it worked to recreate the exact ACL.
Scope set to CLOUDFRONT Still only works in us-east-1 though…
Edit: sorry, you’re right. Looks like most of the code is generated based on the AWS CloudFormation Resource Specification.
First, try to create a simple ACL and make sure you use @aws-cdk/aws-wafv2 and not @aws-cdk/aws-waf (this took me half an hour to figure out). I was able to create an ACL without rules.
However, I just found out that ACLs with the CLOUDFRONT scope need to be created in the us-east-1 region. Before I was getting errors on the scope property. When you create REGIONAL scoped ACLs it’s all fine, but CLOUDFRONT scope is global and somehow only works with us-east-1. This is quite a limitation because I can’t roll-out the stack containing this ACL in any other region.
To see it work, go to your bin folder. There should be a file which contains the following. In the stack properties is a property called region. Set that to us-east-1
I really hope this gets resolved soon but it seems like an underlying issue with cloudformation, not CDK (unless CDK can somehow reroute CLOUDFRONT scoped ACLs to use the us-east-1 region). I’m hoping to roll-out and duplicate an entire solution using CDK soon.
You might want to look at: https://twitter.com/hoegertn/status/1222960907929706499
There are some spec errors in the CFN spec for WAFv2
Once they are resolved, CDK will work.