Use the Conformity Knowledge Base AI to help improve your Cloud Posture

Amazon SageMaker Notebook Instance In VPC

Trend Micro Cloud One™ – Conformity is a continuous assurance tool that provides peace of mind for your cloud infrastructure, delivering over 750 automated best practice checks.

Risk Level: Medium (should be achieved)
Rule ID: SageMaker-001

Ensure that your Amazon SageMaker notebook instances are running inside a Virtual Private Cloud (VPC) in order to be able to access VPC-only resources such as Amazon EFS file systems or resources which can't be accessed outside a VPC network. A SageMaker notebook instance is a Machine Learning (ML) compute instance running on Jupyter Notebook software.

This rule can help you with the following compliance standards:

  • PCI
  • APRA
  • MAS

For further details on compliance standards supported by Conformity, see here.

This rule can help you work with the AWS Well-Architected Framework.

This rule resolution is part of the Conformity Security & Compliance tool for AWS.

Security

Deploying and running your Amazon SageMaker notebook instances within a VPC network enables the SageMaker instances to access all AWS resources available within that VPC using private IP addresses.


Audit

To determine if your Amazon SageMaker notebook instances are running inside a VPC network, perform the following actions:

Using AWS Console

01 Sign in to the AWS Management Console.

02 Navigate to Amazon SageMaker console at https://console.aws.amazon.com/sagemaker/.

03 In the main navigation panel, select Notebook, then choose Notebook instances.

04 Click on the name (link) of the notebook instance that you want to examine.

05 In the Network section, check for any VPC network configuration details such as VPC subnet IDs and security group IDs. If the VPC configuration information is not available in the Network section, instead the following status is displayed: "No custom VPC settings applied.", the selected Amazon SageMaker notebook instance is not running within a VPC network.

06 Repeat step no. 4 and 5 for each Amazon SageMaker notebook instance provisioned in the current AWS region.

07 Change the AWS cloud region from the navigation bar to repeat the Audit process for other regions.

Using AWS CLI

01 Runlist-notebook-instances command (OSX/Linux/UNIX) to list the name of each SageMaker notebook instance provisioned in the selected AWS region:

aws sagemaker list-notebook-instances
  --region us-east-1
  --query 'NotebookInstances[*].NotebookInstanceName'

02 The command output should return the requested notebook instance names:

[
	"cc-ml-application-instance",
	"cc-sagemaker-notebook-instance"
]

03 Rundescribe-notebook-instance command (OSX/Linux/UNIX) using the name of the Amazon SageMaker notebook instance that you want to examine as the identifier parameter and custom query filters to describe the ID of the VPC subnet where the selected instance was deployed:

aws sagemaker describe-notebook-instance
  --region us-east-1
  --notebook-instance-name cc-ml-application-instance
  --query 'SubnetId'

04 The command output should return the requested subnet ID or null if the instance was not created within a VPC subnet:

null

If the describe-notebook-instance command output returns null, as shown in the example above, the selected Amazon SageMaker notebook instance is not running inside a Virtual Private Cloud (VPC) network.

05 Repeat step no. 3 and 4 for each SageMaker notebook instance available in the selected AWS region.

06 Change the AWS region by updating the --region command parameter value and repeat steps no. 1 – 5 to perform the Audit process for other regions.

Remediation / Resolution

To ensure that your Amazon SageMaker notebook instances are running within a VPC, you need to re-create these instances with the necessary network configuration. To deploy your SageMaker notebook instances within a Virtual Private Cloud (VPC), perform the following actions:

Using AWS CloudFormation

01 CloudFormation template (JSON):

{
	"AWSTemplateFormatVersion": "2010-09-09",
	"Resources": {
		"VpcNetwork": {
			"Type": "AWS::EC2::VPC",
			"Properties": {
				"CidrBlock": "10.0.0.0/16",
				"EnableDnsHostnames": true,
				"EnableDnsSupport": true,
				"InstanceTenancy": "default"
			}
		},
		"SageMakerInstanceExecutionRole": {
			"Type": "AWS::IAM::Role",
			"Properties": {
				"AssumeRolePolicyDocument": {
					"Version": "2012-10-17",
					"Statement": [
						{
							"Effect": "Allow",
							"Principal": {
								"Service": [
									"sagemaker.amazonaws.com"
								]
							},
							"Action": [
								"sts:AssumeRole"
							]
						}
					]
				},
				"Path": "/",
				"ManagedPolicyArns": [
					"arn:aws:iam::aws:policy/AmazonSageMakerReadOnly"
				]
			}
		},
		"SageMakerNotebookSubnet": {
			"Type": "AWS::EC2::Subnet",
			"Properties": {
				"VpcId": {
					"Ref": "VpcNetwork"
				}
			}
		},
		"SageMakerNotebookInstance": {
			"Type": "AWS::SageMaker::NotebookInstance",
			"Properties": {
				"InstanceType": "ml.t2.large",
				"RoleArn": {
					"Fn::GetAtt": [
						"SageMakerInstanceExecutionRole",
						"Arn"
					]
				},
				"SecurityGroupIds": [
					"sg-0abcd1234abcd1234",
					"sg-01234abcd1234abcd"
				],
				"SubnetId": {
					"Ref": "SageMakerNotebookSubnet"
				}
			}
		}
	}
}

02 CloudFormation template (YAML):

AWSTemplateFormatVersion: '2010-09-09'
	Resources:
	VpcNetwork:
		Type: AWS::EC2::VPC
		Properties:
		CidrBlock: 10.0.0.0/16
		EnableDnsHostnames: true
		EnableDnsSupport: true
		InstanceTenancy: default
	SageMakerInstanceExecutionRole:
		Type: AWS::IAM::Role
		Properties:
		AssumeRolePolicyDocument:
			Version: '2012-10-17'
			Statement:
			- Effect: Allow
				Principal:
				Service:
					- sagemaker.amazonaws.com
				Action:
				- sts:AssumeRole
		Path: /
		ManagedPolicyArns:
			- arn:aws:iam::aws:policy/AmazonSageMakerReadOnly
	SageMakerNotebookSubnet:
		Type: AWS::EC2::Subnet
		Properties:
		VpcId: !Ref 'VpcNetwork'
	SageMakerNotebookInstance:
		Type: AWS::SageMaker::NotebookInstance
		Properties:
		InstanceType: ml.t2.large
		RoleArn: !GetAtt 'SageMakerInstanceExecutionRole.Arn'
		SecurityGroupIds:
			- sg-0abcd1234abcd1234
			- sg-01234abcd1234abcd
		SubnetId: !Ref 'SageMakerNotebookSubnet'

Using Terraform (AWS Provider)

01 Terraform configuration file (.tf):

terraform {
	required_providers {
		aws = {
			source  = "hashicorp/aws"
			version = "~> 4.0"
		}
	}

	required_version = ">= 0.14.9"
}

provider "aws" {
	profile = "default"
	region  = "us-east-1"
}

resource "aws_vpc" "vpc-network" {
	cidr_block = "10.0.0.0/16"
	enable_dns_hostnames = true
	enable_dns_support = true
	instance_tenancy = "default"  
}

resource "aws_iam_role" "iam-role" {
	name = "sagemaker-instance-execution-role"
	path = "/"
	managed_policy_arns = [ "arn:aws:iam::aws:policy/AmazonSageMakerReadOnly" ]
	assume_role_policy = <<EOF
	{
		"Version": "2012-10-17",
		"Statement": [
			{
				"Action": "sts:AssumeRole",
				"Principal": {
					"Service": "sagemaker.amazonaws.com"
				},
				"Effect": "Allow"
			}
		]
	}
	EOF
}

resource "aws_subnet" "sagemaker-notebook-subnet" {
	vpc_id     = aws_vpc.vpc-network.id
	cidr_block = "10.0.1.0/24"
}

resource "aws_sagemaker_notebook_instance" "sagemaker-notebook-instance" {
	name            = "cc-prod-notebook-instance"
	instance_type   = "ml.t2.medium"
	role_arn        = aws_iam_role.iam-role.arn
	subnet_id       = aws_subnet.sagemaker-notebook-subnet.id
	security_groups = [ "sg-0abcd1234abcd1234", "sg-01234abcd1234abcd" ]
}

Using AWS Console

01 Sign in to the AWS Management Console.

02 Navigate to Amazon SageMaker console at https://console.aws.amazon.com/sagemaker/.

03 In the main navigation panel, select Notebook, then choose Notebook instances.

04 Click on the name of the notebook instance that you want to reconfigure and copy the instance configuration details such as instance type, volume size, instance permissions, etc.

05 Go back to the Notebook instances listing page, and choose Create notebook instance to initiate the launch process.

06 On Create notebook instance setup page, perform the following operations:

  1. For Notebook instance name, provide a unique name for the new Amazon SageMaker notebook instance.
  2. From the Notebook instance type dropdown list, select the same instance type as the source notebook instance, copied at step no. 4.
  3. (Optional) Choose the type of the Amazon Elastic Inference (EI) that you want to use for your instance, from the Elastic Inference dropdown list.
  4. Select the same platform as the source notebook instance from Platform identifier dropdown list.
  5. Select Additional configuration, and perform the following:
    • From Lifecycle configuration – optional dropdown list, select the available lifecycle configuration (if applicable) to customize your notebook environment with default scripts and plugins.
    • For Volume size in GB – optional, enter the volume size of the notebook instance in GB, copied at step no. 4.
  6. Choose the same IAM role as the one created for the source notebook instance from the IAM roledropdown list.
  7. For Root access – optional, choose whether or not to give users root access to your new netbook instance.
  8. Select the name (alias) of the KMS key that you want to use for storage volume encryption from the Encryption key – optional dropdown list.
  9. Select the ID of the Virtual Private Cloud (VPC) where you want to deploy your new notebook instance from the VPC – optional dropdown list. This will enable the instance to access VPC-only resources such as Amazon EFS file systems.
  10. Choose the ID of the VPC subnet that you want to use for your instance from the Subnet dropdown list.
  11. For Security group(s), select one or more security groups based on your access policy requirements.
  12. For Direct internet access, select Enable — Access the internet directly through Amazon SageMaker so that Amazon SageMaker can provide direct Internet access to your new notebook instance.
  13. Configure any necessary Git repositories in the Git repositories – optional section.
  14. In the Tags – optional section, create any required tags, according to the source instance tagging scheme.
  15. Choose Create notebook instance to launch and deploy your new Amazon SageMaker notebook instance to the selected Virtual Private Cloud (VPC).

07 Once your SageMaker notebook instance is created, copy the data from the source instance to the new (destination) instance.

08 (Optional) You can remove the source SageMaker notebook instance from your AWS cloud account to avoid further charges. To delete the unneeded SageMaker instance, perform the following:

  1. Select the SageMaker notebook instance that you want to remove.
  2. Choose Actions and select the Delete option.
  3. Inside the Delete <notebook-instance-name> confirmation box, choose Delete to remove the instance from your AWS account.

09 Repeat steps no. 4 – 8 for each non-VPC SageMaker notebook instance provisioned within the current AWS region.

10 Change the AWS cloud region from the navigation bar and repeat the Remediation process for other regions.

Using AWS CLI

01 Run describe-notebook-instance command (OSX/Linux/UNIX) using the name of the SageMaker notebook instance that you want to re-create as the identifier parameter, to describe the configuration information available for the selected notebook instance, information required later when the new instance will be created:

aws sagemaker describe-notebook-instance
  --region us-east-1
  --notebook-instance-name cc-ml-application-instance

02 The command output should return the requested configuration details:

{
	"NotebookInstanceStatus": "InService",
	"Url": "cc-ml-application-instance.notebook.us-east-1.sagemaker.aws",
	"RoleArn": "arn:aws:iam::123456789012:role/service-role/AmazonSageMaker-ExecutionPolicy-20180921T204001",
	"NotebookInstanceName": "cc-ml-application-instance",
	"CreationTime": 1537512545.117,
	"NotebookInstanceArn": "arn:aws:sagemaker:us-east-1:123456789012:notebook-instance/cc-ml-application-instance",
	"LastModifiedTime": 1537514345.153,
	"InstanceType": "ml.t2.large"
}

03 Run create-notebook-instance command (OSX/Linux/UNIX) using the configuration information returned at the previous step to relaunch the source (non-VPC) SageMaker notebook instance into a VPC network. To launch the instance within a VPC network, provide the ID of the VPC subnet that you want to use for your instance and the ID(s) of the security group(s) required for access control. Once the command request is sent, Amazon SageMaker creates a network interface in the specified VPC, which is inferred from the subnet that you provided in the input:

aws sagemaker create-notebook-instance
  --region us-east-1
  --notebook-instance-name cc-ml-vpc-application-instance
  --instance-type ml.t2.large
  --role-arn arn:aws:iam::123456789012:role/service-role/AmazonSageMaker-ExecutionRole-20180921T204001
  --kms-key-id arn:aws:kms:us-east-1:123456789012:key/aaaabbbb-cccc-dddd-eeee-aaaabbbbcccc
  --subnet-id subnet-1234abcd
  --security-group-ids sg-aabbccdd012345678

04 The command output should return the ARN of the new Amazon SageMaker notebook instance:

{
	"NotebookInstanceArn": "arn:aws:sagemaker:us-east-1:123456789012:notebook-instance/cc-ml-vpc-application-instance"
}

05 Copy the data from the source notebook instance to the new (destination) instance.

06 (Optional) You can remove the source SageMaker notebook instance from your AWS account in order to avoid further charges. To delete the unneeded SageMaker instance, run delete-notebook-instance command (OSX/Linux/UNIX), using the name of the notebook instance that you want to delete as the identifier parameter (the command does not produce an output):

aws sagemaker delete-notebook-instance
  --region us-east-1
  --notebook-instance-name cc-ml-application-instance

07 Repeat steps no. 1 – 6 for each non-VPC SageMaker notebook instance available in the selected AWS region.

08 Change the AWS cloud region by updating the --region command parameter value and repeat the Remediation process for other regions.

References

Publication date Oct 15, 2018

Unlock the Remediation Steps


Free 30-day Trial

Automatically audit your configurations with Conformity
and gain access to our cloud security platform.

Confirmity Cloud Platform

No thanks, back to article

You are auditing:

Amazon SageMaker Notebook Instance In VPC

Risk Level: Medium