# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # elasticache_redis_cluster_auto_backup_check # # Description: # This control checks whether an Amazon ElastiCache Redis cluster has automatic backups enabled. # # Reports on: # AWS::ElastiCache::CacheCluster # # 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 ElastiCache cache cluster resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ElastiCache CacheCluster resource # And: 'Engine' has not been provided or has been provided and is not set to 'redis' # Then: SKIP # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ElastiCache cache cluster resource # And: 'Engine' has been provided and set to 'redis' # And: 'SnapshotRetentionLimit' has not been provided # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ElastiCache cache cluster resource # And: 'Engine' has been provided and set to 'redis' # And: 'SnapshotRetentionLimit' has been provided and set to a non-integer value or an integer value of 0 # Then: FAIL # Scenario: 5 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ElastiCache cache cluster resource # And: 'Engine' has been provided and set to 'redis' # And: 'SnapshotRetentionLimit' has been provided and set to an integer value greater than 0 # Then: PASS # # Constants # let ELASTICACHE_CACHE_CLUSTER_TYPE = "AWS::ElastiCache::CacheCluster" let REDIS_ENGINE_TYPE = "redis" let INPUT_DOCUMENT = this # # Assignments # let elasticache_clusters = Resources.*[ Type == %ELASTICACHE_CACHE_CLUSTER_TYPE ] # # Primary Rules # rule elasticache_redis_cluster_auto_backup_check when is_cfn_template(%INPUT_DOCUMENT) %elasticache_clusters not empty { check(%elasticache_clusters.Properties) << [CT.ELASTICACHE.PR.1]: Require an Amazon ElastiCache for Redis cluster to have automatic backups activated [FIX]: Set the value of the 'SnapshotRetentionLimit' parameter to an integer value greater than 0. >> } rule elasticache_redis_cluster_auto_backup_check when is_cfn_hook(%INPUT_DOCUMENT, %ELASTICACHE_CACHE_CLUSTER_TYPE) { check(%INPUT_DOCUMENT.%ELASTICACHE_CACHE_CLUSTER_TYPE.resourceProperties) << [CT.ELASTICACHE.PR.1]: Require an Amazon ElastiCache for Redis cluster to have automatic backups activated [FIX]: Set the value of the 'SnapshotRetentionLimit' parameter to an integer value greater than 0. >> } # # Parameterized Rules # rule check(elasticache_cache_cluster) { %elasticache_cache_cluster [ # Scenario 2 Engine exists Engine == %REDIS_ENGINE_TYPE ] { # Scenarios 3, 4 and 5 SnapshotRetentionLimit exists SnapshotRetentionLimit > 0 } } # # 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 }