(wafv2): change in CfnWebACL model validation & lack of associated documentation
:question: General Issue
I don't think this is a bug with CDK per se. I see differing CloudFormation behavior from just one day ago having to do with aws-wafv2.
cdk deploy previously resulted in completion of stack creation but now results in error message:
Model validation failed (#: extraneous key [true] is not permitted)
I identified that this is due to how the CfnWebAcl.props.defaultAction parameter were coded. Below is an example.
defaultAction: {
block: {
true: true,
}
},
It now must be
defaultAction: {
block: {}
},
Iterating to this point was not obvious. I tried different keys and values to no avail. Attempting block: true resulted in cdk exception:
block: true should be an 'object'.
Other similar patterns are problematic such as for CfnWebAcl.props.rules.action
In addition the language-specific api documentation for most (any?) is non existent. For example, https://docs.aws.amazon.com/cdk/api/latest/typescript/api/aws-wafv2/ruleactionproperty.html results in 404. This does not help with determining correct syntax.
The Question
I guess my question is what changed and where is the resource to figure out what the correct syntax is? I was even using the same ver cdk between behavior changes so I imagine this is a CloudFormation change in behavior.
Also, was I doing something incorrect originally? I remember having to try a couple different approaches to forming an object that worked - might have even seen an example of the idiom in the issue tracker.
Environment
- CDK CLI Version: 1.74.0 (build e86602f)
- Module Version: 1.74.0
- Node.js Version: v10.22.1
- OS: Ubuntu 20.04
- Language (Version): TypeScript 3.7.5
Other information
Having same problems. Tried variety of things, like custom classes and etc. Cant manage to make it work. Any idea? Im using csharp
@Pokis Don't know if this helps are is still current (from a syntax example):
DefaultAction = new CfnWebACL.DefaultActionProperty
{
Allow = new CfnWebACL.RuleActionProperty() { Allow = true }
}
ref: https://stackoverflow.com/questions/61136390/how-can-i-set-value-to-cfnwebacl-defaultactionproperty-allow-property-in-wafv2-f
@ekeyser This is exactly what I used before and it stopped working ;/ Leaning to downgrading packages
Edit: Latest package with the mentioned expression generates
DefaultAction:
Allow:
allow: true
And then it complains accordingly
"wafAcl Model validation failed (#: extraneous key [allow] is not permitted)".
Got it. Yeah I don't know C#. Sorry couldn't help.
highly appreciate the effort either way.
Last suggestion - maybe drop the Allow = true? Can you have empty constructors? Is that a constructor?
Nah mate, tried that and similar approaches. Current solution that I am going to do is: Generate cloudformation with synth -> substitute the required part with simple string substitute -> deploy the generated file
Adjusted the place where I need to substitute with: webAcl.AddPropertyOverride("DefaultAction.Allow", "CHANGE_THIS_WITH_BRACKETS"); so all I have to do is substitute that keyword. If I add brackets there btw, it just parses them as string, and json must be there, so cant do that directly apparently.
Is it possible to substitute cfnWebAcl.AddPropertyOverride("DefaultAction.Block", 'insert empty element here') as a workaround to achieve the result we need ? :
defaultAction: {
block: {}
}
What would we use as an empty element in C#?
Just FYI for anyone having issues with WAF the error is now returning the following:
2:11:49 PM | CREATE_FAILED | AWS::WAFv2::WebACL | waf
Internal Failure
new BookAwsCdkStack (redacted.ts:258:20)
\_ Object.<anonymous> (redacted.ts:7:1)
\_ Module._compile (internal/modules/cjs/loader.js:778:30)
\_ Module.m._compile (redacted.ts:858:23)
\_ Module._extensions..js (internal/modules/cjs/loader.js:789:10)
\_ Object.require.extensions.(anonymous function) [as .ts] redacted.ts:861:12)
\_ Module.load (internal/modules/cjs/loader.js:653:32)
\_ tryModuleLoad (internal/modules/cjs/loader.js:593:12)
\_ Function.Module._load (internal/modules/cjs/loader.js:585:3)
\_ Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
\_ main (redacted.ts:227:14)
\_ Object.<anonymous> (redacted.ts:513:3)
\_ Module._compile (internal/modules/cjs/loader.js:778:30)
\_ Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
\_ Module.load (internal/modules/cjs/loader.js:653:32)
\_ tryModuleLoad (internal/modules/cjs/loader.js:593:12)
\_ Function.Module._load (internal/modules/cjs/loader.js:585:3)
\_ Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
\_ findNodeScript.then.existing (redacted.ts:268:14)
Resolution is still the same as provided in the OP.
The WAFv2 documentation is certainly a bit light here. The official CloudFormation documentation notes the 'Allow' and 'Block' members are of a JSON type, but otherwise doesn't give any hints. The example on the same page does show an empty block. The official CreateWebACL API documentation likewise shows empty blocks but the individual member documentation are a bit light.
I guess my question is what changed and where is the resource to figure out what the correct syntax is?
It's quite possible something with the internal CloudFormation implementation changed; I can follow up internally and see if I can track that down. In the meantime, looking at the official CloudFormation and API docs is the best way to figure out the correct syntax for these CloudFormation-only modules.
To follow up on some of the other conversations in this thread, the correct syntax for .NET is:
DefaultAction = new CfnWebACL.DefaultActionProperty { Allow = { } },
Apologies for the poor experience here. This is the kind of thing that an L2 construct for WebACL would have helped to paper over, but since we don't (yet -- contributions welcome!) have one, the resolution is to work with the format that CloudFormation has provided.
I'm closing this out, as I don't think there's anything to be changed on the CDK here.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
For C# use this in your CDK code:
DefaultAction = new CfnWebACL.DefaultActionProperty { Allow = new JObject() }
Ran into this issue with a Java based CDK project as well. Fix was to use this code:
CfnWebACL.DefaultActionProperty.builder().allow(Collections.emptyMap()).build()