[FMS/jsii]: `IEMap` type is interpreted as an interface instead of a struct
The Firewall manager only has L1 Constructs, but even those doesn't seem to work. I fail to create a Shield Advanced policy. Nothing seems to implement IEMapProperty. The policy properties get incorrectly translated to strings. The minimal length for Shield Advanced is supposed to 0 (empty string), based on the AWS Documentation, but CDK expects min lenght eq 1.
Reproduction Steps
CDK Code:
fms.CfnPolicy(self,
'ShieldAdvancedPolicy',
policy_name='ShieldAdvancedPolicy',
remediation_enabled=False,
security_service_policy_data=policy_data,
include_map=core.CfnJson(self,
'IncludeMapAccounts',
value='{"ACCOUNT":"4321434134324234"}'
),
exclude_resource_tags=False,
resource_type='AWS::CloudFront::Distribution',
)
policy data:
{
"Type": "SHIELD_ADVANCED",
"ManagedServiceData": ""
}
What did you expect to happen?
Firewall Manager / Shield Advanced policy created
What actually happened?
Stack fails to deploy. Multiple properties get translated to strings. ManagedServiceData is incorrectly evaluated, it should be an empty string for Shield Advanced.
FirewallManagerStack539945: deploying...
[0%] start: Publishing 10e0d4bb29348023840238940e3351d41c9fd4487d0e005c1e18f2d50bf056b1608:current
[100%] success: Published 10e0d4bb29348023840238940e3351d41c9fd4487d0e005c1e18f2d50bf056b1608:current
FirewallManagerStack539945: creating CloudFormation changeset...
[██████████████████████████████████████▋···················] (4/6)
9:46:14 PM | CREATE_FAILED | AWS::FMS::Policy | FirewallManagerStack539945/Fire...ieldAdvancedPolicy
Model validation failed (#/ExcludeResourceTags: expected type: Boolean, found: String
#/SecurityServicePolicyData/ManagedServiceData: expected minLength: 1, actual: 0
#/RemediationEnabled: expected type: Boolean, found: String
#/IncludeMap: expected type: JSONObject, found: String)
9:46:15 PM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | FirewallManagerStack539945
The following resource(s) failed to create: [ShieldAdvancedPolicy]. Rollback requested by user.
9:46:15 PM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | FirewallManagerStack539945
The following resource(s) failed to create: [ShieldAdvancedPolicy]. Rollback requested by user.
Environment
- CDK CLI Version :1.64.1
- Framework Version:
- OS : MacOs Catalina
- Language (Version): Python 3.9.0
Other
It seems that nothing implements IEMapProperty, so I've used IResolvable (JSON to create IncludeMap).
Also, the error message says that ManagedServiceData is supposed to have min lenght 1, but the documentation says that for ShieldAdvanced this should be empty string: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-fms-policy.html#cfn-fms-policy-securityservicepolicydata
Also 2: although I've used Booleans as per the snippet above, considering the error messages complaining about type errors, something is perhaps translating them to Strings (is there any lambda on the background translating the data?).
This is :bug: Bug Report
include_map=core.CfnJson(self,
No need to use CfnJson there, just put the object that you want to use.
security_service_policy_data=policy_data,
Can't say anything about this without seeing the data that's in there.
The expected type: Boolean, found: String errors are strange.
@rix0rrr thank you for the quick reaction.
policy_data I've included in the report, it's the 2nd snippet from the top, but copy-pasting it here for your comfort:
{
"Type": "SHIELD_ADVANCED",
"ManagedServiceData": ""
}
Also, the error message says that ManagedServiceData is supposed to have min lenght 1, but the documentation says that for ShieldAdvanced this should be empty string:
It's not necessarily guaranteed that the documentation is correct by the way. If it isn't, that's an error you should file agains that particular documentation page. In this case, according to the error message the docs are wrong.
#/SecurityServicePolicyData/ManagedServiceData: expected minLength: 1, actual: 0
Looking at the output of your code snippet, I don't see why the booleans would be interpreted as strings:
ShieldAdvancedPolicy:
Type: AWS::FMS::Policy
Properties:
ExcludeResourceTags: false # <--- this seems fine
PolicyName: ShieldAdvancedPolicy
RemediationEnabled: false
ResourceType: AWS::CloudFront::Distribution
SecurityServicePolicyData:
Type: SHIELD_ADVANCED
ManagedServiceData: ""
IncludeMap:
Fn::GetAtt: # <--- forget this, this is due to the CfnJson.
- Bla7B35829F
- Value
You have stumbled on a jsii bug. Thanks for reporting!
It seems that the type of include_map is IEMap, which is interpreted as an interface/object, instead of a struct as it should be. That's why you can't pass a struct directly. That doesn't explain your other errors, but there's at least something wrong in the CDK with this construct.
We need to fix this first which may take a while.
In the mean time, you can work around by using CfnResource instead:
core.CfnResource(self, 'ShieldAdvancedPolicy2', type='AWS::FMS::Policy', properties=dict(
PolicyName='ShieldAdvancedPolicy',
RemediationEnabled=False,
ExcludeResourceTags=False,
ResourceType='AWS::CloudFront::Distribution',
SecurityServicePolicyData=dict(
Type='SHIELD_ADVANCED',
ManagedServiceData='',
),
IncludeMap=dict(
ACCOUNT='4321434134324234',
),
))
Alright as discussed with @rix0rrr offline, I believe the best way forward here is to add a feature in jsii that'll allow us to use those names while retaining the correct functionality... I've filed aws/jsii#2267 to this effect, and will be trying to get to this in the coming days.
@rix0rrr thank you very much for your update and for providing workaround information. I just tested it and unfortunately, there is still the type issue, where the booleans (and JSON arrays) are interpreted as strings:
XXStackFirewallManager6E394302
XXStackFirewallManager6E394302: deploying...
XXStackFirewallManager6E394302: creating CloudFormation changeset...
[··························································] (0/3)
7:55:32 PM | CREATE_FAILED | AWS::FMS::Policy | XXStack/Fire...eldAdvancedPolicy2
Model validation failed (#/ExcludeResourceTags: expected type: Boolean, found: String
#/SecurityServicePolicyData/ManagedServiceData: expected minLength: 1, actual: 0
#/RemediationEnabled: expected type: Boolean, found: String
#/IncludeMap/ACCOUNT: expected type: JSONArray, found: String)
7:55:32 PM | UPDATE_ROLLBACK_IN_P | AWS::CloudFormation::Stack | XXStackFirewallManager6E394302
The following resource(s) failed to create: [ShieldAdvancedPolicy2].
7:55:41 PM | UPDATE_ROLLBACK_COMP | AWS::CloudFormation::Stack | XXStackFirewallManager6E394302
this is with the code you posted earlier:
core.CfnResource(self, 'ShieldAdvancedPolicy2', type='AWS::FMS::Policy', properties=dict(
PolicyName='ShieldAdvancedPolicy2',
RemediationEnabled=False,
ExcludeResourceTags=False,
ResourceType='AWS::CloudFront::Distribution',
SecurityServicePolicyData=dict(
Type='SHIELD_ADVANCED',
ManagedServiceData='',
),
IncludeMap=dict(
ACCOUNT='234923840293480',
),
))
I updated to CDK 1.74.0, just in case, but the behavior is exactly the same.
I would suggest to look for a CloudFormation template fragment that achieves what you want to achieve, and then see the differences between that fragment and what CDK generates.
Apart from the obvious mistakes which you did not address in your code snippet:
#/SecurityServicePolicyData/ManagedServiceData: expected minLength: 1, actual: 0
#/IncludeMap/ACCOUNT: expected type: JSONArray, found: String)
I cannot tell you what the "expected Boolean found string" is about. I would suggest a ticket to CloudFormation, this seems to be a bug on their end.
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.