# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # sagemaker_notebook_instance_root_access_check # # Description: # This control checks whether Amazon SageMaker notebook instances allow root access. # # Reports on: # AWS::SageMaker::NotebookInstance # # 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 SageMaker notebook instance resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a SageMaker notebook instance resource # And: 'RootAccess' 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 a SageMaker notebook instance resource # And: 'RootAccess' has been provided and is set to a value other than 'Disabled' # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a SageMaker notebook instance resource # And: 'RootAccess' has been provided and is set to 'Disabled' # Then: PASS # # Constants # let SAGEMAKER_NOTEBOOK_INSTANCE_TYPE = "AWS::SageMaker::NotebookInstance" let INPUT_DOCUMENT = this # # Assignments # let sagemaker_notebook_instances = Resources.*[ Type == %SAGEMAKER_NOTEBOOK_INSTANCE_TYPE ] # # Primary Rules # rule sagemaker_notebook_instance_root_access_check when is_cfn_template(%INPUT_DOCUMENT) %sagemaker_notebook_instances not empty { check(%sagemaker_notebook_instances.Properties) << [CT.SAGEMAKER.PR.3]: Require Amazon SageMaker notebook instances to have root access disallowed [FIX]: Set 'RootAccess' to 'Disabled'. >> } rule sagemaker_notebook_instance_root_access_check when is_cfn_hook(%INPUT_DOCUMENT, %SAGEMAKER_NOTEBOOK_INSTANCE_TYPE) { check(%INPUT_DOCUMENT.%SAGEMAKER_NOTEBOOK_INSTANCE_TYPE.resourceProperties) << [CT.SAGEMAKER.PR.3]: Require Amazon SageMaker notebook instances to have root access disallowed [FIX]: Set 'RootAccess' to 'Disabled'. >> } rule check(sagemaker_notebook_instance) { %sagemaker_notebook_instance { # Scenarios 2, 3 and 4 RootAccess exists RootAccess == "Disabled" } } # # 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 }