cloudtools / cloudtools/troposphere

AWS FMS: SecurityServicePolicyData rendering entirely as JSON

Open
#1,834 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
4.9k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

By [AWS CloudFormation documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-fms-policy.html#aws-resource-fms-policy--examples), the YAML representation of the SecurityServicePolicyData has two child nodes... _Type_ and _ManagedServiceData_. They are represented in YAML as follows:

```yaml
PolicyWAFv2:
Type: AWS::FMS::Policy
Properties:
ExcludeResourceTags: false
PolicyName: Policy
RemediationEnabled: false
ResourceType: AWS::ElasticLoadBalancingV2::LoadBalancer
SecurityServicePolicyData:
Type: WAFV2
ManagedServiceData: !Sub '{"type":"WAFV2",
"preProcessRuleGroups":[{
"ruleGroupType":"RuleGroup",
"ruleGroupArn":"${RuleGroup.Arn}",
"overrideAction":{"type":"NONE"}}],
"postProcessRuleGroups":[],
"defaultAction":{"type":"BLOCK"}}'
```

The _ManagedServiceData_ property is the only item of the node that is supposed to be JSON based, but in the [FMS::Policy troposphere object](https://github.com/cloudtools/troposphere/blob/26d0663e7ad5ac632a5aeaee34d66ded8195a116/troposphere/fms.py#L31), the entire thing is coded/output as JSON, which results in outputs like this:

```yaml
BaseProtectionsIntPolicy:
Properties:
DeleteAllPolicyResources: true
ExcludeResourceTags: false
IncludeMap:
ACCOUNT:
- '123456789012'
ORGUNIT: []
PolicyName: Base-Protections-Int-Policy
RemediationEnabled: false
ResourceType: ResourceTypeList
ResourceTypeList:
- AWS::ElasticLoadBalancingV2::LoadBalancer
- AWS::ApiGateway::Stage
SecurityServicePolicyData: >-
{"type": "WAFV2", "ManagedServiceData": "{\"type\": \"WAFV2\", \"preProcessRuleGroups\":
[{\"ruleGroupArn\": null, \"overrideAction\": {\"type\": \"COUNT\"}, \"managedRuleGroupIdentifier\":
{\"version\": null, \"vendorName\": \"AWS\", \"managedRuleGroupName\": \"AWSManagedRulesCommonRuleSet\"},
\"ruleGroupType\": \"ManagedRuleGroup\"}, {\"ruleGroupArn\": null, \"overrideAction\":
{\"type\": \"COUNT\"}, \"managedRuleGroupIdentifier\": {\"version\": null,
\"vendorName\": \"AWS\", \"managedRuleGroupName\": \"AWSManagedRulesAmazonIpReputationList\"},
\"ruleGroupType\": \"ManagedRuleGroup\"}, {\"ruleGroupArn\": \"${BaseIntRuleGroup.Arn}\",
\"overrideAction\": {\"type\": \"NONE\"}, \"ruleGroupType\": \"RuleGroup\"}],
\"postProcessRuleGroups\": [], \"defaultAction\": {\"type\": \"ALLOW\"}}"}
Type: AWS::FMS::Policy
```

Furthermore, attempting to add a troposphere Sub() object around the _ManagedServiceData_ string results in an error that the Sub() object is not JSON Serializable.

I propose that an additional helper object be defined in FMS.py that allows further breakout of these items and moves the json_checker validation to the _ManagedServiceData_ definition under the new object.

I'm curious to know if anyone has this working as is.

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.