# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # opensearch_fine_grained_access_control_enabled_check # # Description: # This control checks whether Amazon OpenSearch Service domains have fine-grained access control enabled. # # Reports on: # AWS::OpenSearchService::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 OpenSearch Service domain resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an OpenSearch Service domain resource # And: 'AdvancedSecurityOptions' 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 OpenSearch Service domain resource # And: 'AdvancedSecurityOptions' has been provided # And: 'Enabled' in 'AdvancedSecurityOptions' has not been provided or # has been provided and set to a value other than bool(true) # And: 'InternalUserDatabaseEnabled' in 'AdvancedSecurityOptions' has not been provided or provided and set to a # non boolean value # And: 'MasterUserOptions' in 'AdvancedSecurityOptions' has not been provided or provided and set to a value # other than a struct # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an OpenSearch Service domain resource # And: 'AdvancedSecurityOptions' has been provided # And: 'Enabled' in 'AdvancedSecurityOptions' has been provided and set to bool(true) # And: 'InternalUserDatabaseEnabled' in 'AdvancedSecurityOptions' has not been provided or provided and set to a # non boolean value # And: 'MasterUserOptions' in 'AdvancedSecurityOptions' has not been provided or provided and set to a value # other than a struct # Then: FAIL # Scenario: 5 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an OpenSearch Service domain resource # And: 'AdvancedSecurityOptions' has been provided # And: 'Enabled' in 'AdvancedSecurityOptions' has been provided and set to bool(true) # And: 'InternalUserDatabaseEnabled' in 'AdvancedSecurityOptions' has been provided and set to a # boolean value # And: 'MasterUserOptions' in 'AdvancedSecurityOptions' has not been provided or provided and set to a value # other than a struct # Then: FAIL # Scenario: 6 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an OpenSearch Service domain resource # And: 'AdvancedSecurityOptions' has been provided # And: 'Enabled' in 'AdvancedSecurityOptions' has been provided and set to bool(true) # And: 'InternalUserDatabaseEnabled' in 'AdvancedSecurityOptions' has not been provided or provided and set to a # non boolean value # And: 'MasterUserOptions' in 'AdvancedSecurityOptions' has been provided and set to a struct # Then: FAIL # Scenario: 7 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an OpenSearch Service domain resource # And: 'AdvancedSecurityOptions' has been provided # And: 'Enabled' in 'AdvancedSecurityOptions' has been provided and set to bool(true) # And: 'InternalUserDatabaseEnabled' in 'AdvancedSecurityOptions' has been provided and set to a # boolean value # And: 'MasterUserOptions' in 'AdvancedSecurityOptions' has been provided and set to a struct # Then: PASS # # Constants # let OPENSEARCH_SERVICE_DOMAIN_TYPE = "AWS::OpenSearchService::Domain" let INPUT_DOCUMENT = this # # Assignments # let opensearch_service_domains = Resources.*[ Type == %OPENSEARCH_SERVICE_DOMAIN_TYPE ] # # Primary Rules # rule opensearch_fine_grained_access_control_enabled_check when is_cfn_template(%INPUT_DOCUMENT) %opensearch_service_domains not empty { check(%opensearch_service_domains.Properties) << [CT.OPENSEARCH.PR.15]: Require an Amazon OpenSearch Service domain to use fine-grained access control [FIX]: Within 'AdvancedSecurityOptions', set 'Enabled' to 'true', set 'InternalUserDatabaseEnabled' to 'true' or 'false', and set 'MasterUserOptions' with an options configuration for your master user. >> } rule opensearch_fine_grained_access_control_enabled_check when is_cfn_hook(%INPUT_DOCUMENT, %OPENSEARCH_SERVICE_DOMAIN_TYPE) { check(%INPUT_DOCUMENT.%OPENSEARCH_SERVICE_DOMAIN_TYPE.resourceProperties) << [CT.OPENSEARCH.PR.15]: Require an Amazon OpenSearch Service domain to use fine-grained access control [FIX]: Within 'AdvancedSecurityOptions', set 'Enabled' to 'true', set 'InternalUserDatabaseEnabled' to 'true' or 'false', and set 'MasterUserOptions' with an options configuration for your master user. >> } # # Parameterized Rules # rule check(opensearch_service_domain) { %opensearch_service_domain { # Scenario 2 AdvancedSecurityOptions exists AdvancedSecurityOptions is_struct AdvancedSecurityOptions { # Scenarios 3, 4, 5, 6 and 7 Enabled exists Enabled == true InternalUserDatabaseEnabled exists InternalUserDatabaseEnabled in [ true, false ] MasterUserOptions exists MasterUserOptions is_struct } } } # # 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 }