Skip to content

Commit c97d088

Browse files
committed
feature: support inter container traffic encryption for processing jobs
1 parent 3bf569e commit c97d088

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/sagemaker/model_monitor/model_monitoring.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ def update_monitoring_schedule(
453453
network_config_dict = None
454454
if self.network_config is not None:
455455
network_config_dict = self.network_config._to_request_dict()
456+
if "EnableInterContainerTrafficEncryption" in network_config_dict:
457+
raise ValueError(
458+
"EnableInterContainerTrafficEncryption is not supported in Model Monitor"
459+
)
456460

457461
self.sagemaker_session.update_monitoring_schedule(
458462
monitoring_schedule_name=self.monitoring_schedule_name,

src/sagemaker/network.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,38 @@ class NetworkConfig(object):
2020
"""Accepts network configuration parameters and provides a method to turn these parameters
2121
into a dictionary."""
2222

23-
def __init__(self, enable_network_isolation=False, security_group_ids=None, subnets=None):
23+
def __init__(
24+
self,
25+
enable_network_isolation=False,
26+
security_group_ids=None,
27+
subnets=None,
28+
encrypt_inter_container_traffic=None,
29+
):
2430
"""Initialize a ``NetworkConfig`` instance. NetworkConfig accepts network configuration
2531
parameters and provides a method to turn these parameters into a dictionary.
2632
2733
Args:
2834
enable_network_isolation (bool): Boolean that determines whether to enable
2935
network isolation.
36+
encrypt_inter_container_traffic (bool): Boolean that determines whether to
37+
encrypt inter-container traffic.
3038
security_group_ids ([str]): A list of strings representing security group IDs.
3139
subnets ([str]): A list of strings representing subnets.
3240
"""
3341
self.enable_network_isolation = enable_network_isolation
42+
self.encrypt_inter_container_traffic = encrypt_inter_container_traffic
3443
self.security_group_ids = security_group_ids
3544
self.subnets = subnets
3645

3746
def _to_request_dict(self):
3847
"""Generates a request dictionary using the parameters provided to the class."""
3948
network_config_request = {"EnableNetworkIsolation": self.enable_network_isolation}
4049

50+
if self.encrypt_inter_container_traffic is not None:
51+
network_config_request[
52+
"EnableInterContainerTrafficEncryption"
53+
] = self.encrypt_inter_container_traffic
54+
4155
if self.security_group_ids is not None or self.subnets is not None:
4256
network_config_request["VpcConfig"] = {}
4357

tests/unit/test_processing.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def test_sklearn_with_all_parameters(exists_mock, isfile_mock, ecr_prefix, sagem
141141
subnets=["my_subnet_id"],
142142
security_group_ids=["my_security_group_id"],
143143
enable_network_isolation=True,
144+
encrypt_inter_container_traffic=True,
144145
),
145146
sagemaker_session=sagemaker_session,
146147
)
@@ -330,6 +331,7 @@ def test_script_processor_with_all_parameters(exists_mock, isfile_mock, sagemake
330331
subnets=["my_subnet_id"],
331332
security_group_ids=["my_security_group_id"],
332333
enable_network_isolation=True,
334+
encrypt_inter_container_traffic=True,
333335
),
334336
sagemaker_session=sagemaker_session,
335337
)
@@ -386,6 +388,26 @@ def test_processor_with_required_parameters(sagemaker_session):
386388
sagemaker_session.process.assert_called_with(**expected_args)
387389

388390

391+
def test_processor_with_missing_network_config_parameters(sagemaker_session):
392+
processor = Processor(
393+
role=ROLE,
394+
image_uri=CUSTOM_IMAGE_URI,
395+
instance_count=1,
396+
instance_type="ml.m4.xlarge",
397+
sagemaker_session=sagemaker_session,
398+
network_config=NetworkConfig(enable_network_isolation=True),
399+
)
400+
401+
processor.run()
402+
403+
expected_args = _get_expected_args(processor._current_job_name)
404+
del expected_args["app_specification"]["ContainerEntrypoint"]
405+
expected_args["inputs"] = []
406+
expected_args["network_config"] = {"EnableNetworkIsolation": True}
407+
408+
sagemaker_session.process.assert_called_with(**expected_args)
409+
410+
389411
def test_processor_with_all_parameters(sagemaker_session):
390412
processor = Processor(
391413
role=ROLE,
@@ -405,6 +427,7 @@ def test_processor_with_all_parameters(sagemaker_session):
405427
subnets=["my_subnet_id"],
406428
security_group_ids=["my_security_group_id"],
407429
enable_network_isolation=True,
430+
encrypt_inter_container_traffic=True,
408431
),
409432
)
410433

@@ -580,6 +603,7 @@ def _get_expected_args_all_parameters(job_name):
580603
"environment": {"my_env_variable": "my_env_variable_value"},
581604
"network_config": {
582605
"EnableNetworkIsolation": True,
606+
"EnableInterContainerTrafficEncryption": True,
583607
"VpcConfig": {
584608
"SecurityGroupIds": ["my_security_group_id"],
585609
"Subnets": ["my_subnet_id"],

tests/unit/test_session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def test_process(boto_session):
131131
},
132132
"environment": {"my_env_variable": 20},
133133
"network_config": {
134+
"EnableInterContainerTrafficEncryption": True,
134135
"EnableNetworkIsolation": True,
135136
"VpcConfig": {
136137
"SecurityGroupIds": ["my_security_group_id"],
@@ -219,6 +220,7 @@ def test_process(boto_session):
219220
},
220221
"Environment": {"my_env_variable": 20},
221222
"NetworkConfig": {
223+
"EnableInterContainerTrafficEncryption": True,
222224
"EnableNetworkIsolation": True,
223225
"VpcConfig": {
224226
"SecurityGroupIds": ["my_security_group_id"],

0 commit comments

Comments
 (0)