# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # elasticsearch_node_to_node_encryption_check # # Description: # This control checks whether Elasticsearch domains have node-to-node encryption enabled. # # Reports on: # AWS::Elasticsearch::Domain # # Evaluates: # AWS CloudFormation, AWS CloudFormation hook # # Rule Parameters: # None # # Scenarios: # Scenario: 1 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document does not contain any Elasticsearch domain resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an Elasticsearch domain resource # And: 'NodeToNodeEncryptionOptions' has not been provided # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an Elasticsearch domain resource # And: 'NodeToNodeEncryptionOptions' has been provided # And: 'Enabled' in 'NodeToNodeEncryptionOptions' has not been provided or has been provided # and set to a value other than bool(true) # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an Elasticsearch domain resource # And: 'NodeToNodeEncryptionOptions' has been provided # And: 'Enabled' in 'NodeToNodeEncryptionOptions' has been provided and set to a # value of bool(true) # Then: PASS # # Constants # let ELASTICSEARCH_DOMAIN_TYPE = "AWS::Elasticsearch::Domain" let INPUT_DOCUMENT = this # # Assignments # let elasticsearch_domains = Resources.*[ Type == %ELASTICSEARCH_DOMAIN_TYPE ] # # Primary Rules # rule elasticsearch_node_to_node_encryption_check when is_cfn_template(%INPUT_DOCUMENT) %elasticsearch_domains not empty { check(%elasticsearch_domains.Properties) << [CT.OPENSEARCH.PR.3]: Require an Elasticsearch domain to encrypt data sent between nodes [FIX]: Within 'NodeToNodeEncryptionOptions', set 'Enabled' to 'true'. >> } rule elasticsearch_node_to_node_encryption_check when is_cfn_hook(%INPUT_DOCUMENT, %ELASTICSEARCH_DOMAIN_TYPE) { check(%INPUT_DOCUMENT.%ELASTICSEARCH_DOMAIN_TYPE.resourceProperties) << [CT.OPENSEARCH.PR.3]: Require an Elasticsearch domain to encrypt data sent between nodes [FIX]: Within 'NodeToNodeEncryptionOptions', set 'Enabled' to 'true'. >> } # # Parameterized Rules # rule check(elasticsearch_domain) { %elasticsearch_domain { # Scenario 2 NodeToNodeEncryptionOptions exists NodeToNodeEncryptionOptions is_struct NodeToNodeEncryptionOptions { # Scenarios 3 and 4 Enabled exists Enabled == true } } } # # Utility Rules # rule is_cfn_template(doc) { %doc { AWSTemplateFormatVersion exists or Resources exists } } rule is_cfn_hook(doc, RESOURCE_TYPE) { %doc.%RESOURCE_TYPE.resourceProperties exists }