Skip to content

fix: fix ECR URI validation #719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/sagemaker/fw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def framework_name_from_image(image_name):
str: The image tag
str: If the image is script mode
"""
sagemaker_pattern = re.compile(r'^(\d+)(\.)dkr(\.)ecr(\.)(.+)(\.)amazonaws.com(/)(.*:.*)$')
sagemaker_pattern = re.compile(r'^(\d+)(\.)dkr(\.)ecr(\.)(.+)(\.)(amazonaws.com|c2s.ic.gov)(/)(.*:.*)$')
sagemaker_match = sagemaker_pattern.match(image_name)
if sagemaker_match is None:
return None, None, None, None
Expand All @@ -235,8 +235,8 @@ def framework_name_from_image(image_name):
legacy_name_pattern = re.compile(
r'^sagemaker-(tensorflow|mxnet)-(py2|py3)-(cpu|gpu):(.*)$')

name_match = name_pattern.match(sagemaker_match.group(8))
legacy_match = legacy_name_pattern.match(sagemaker_match.group(8))
name_match = name_pattern.match(sagemaker_match.group(9))
legacy_match = legacy_name_pattern.match(sagemaker_match.group(9))

if name_match is not None:
fw, scriptmode, ver, device, py = name_match.group(1), name_match.group(2), name_match.group(3),\
Expand Down
2 changes: 1 addition & 1 deletion src/sagemaker/local/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def _write_json_file(filename, content):

def _ecr_login_if_needed(boto_session, image):
# Only ECR images need login
if not ('dkr.ecr' in image and 'amazonaws.com' in image):
if not ('dkr.ecr' in image and ('amazonaws.com' in image or 'c2s.ic.gov' in image)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would a regex be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use regex.

return False

# do we have the image?
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_fw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ def test_framework_name_from_image_mxnet():
assert ('mxnet', 'py3', '1.1-gpu-py3', None) == fw_utils.framework_name_from_image(image_name)


def test_framework_name_from_image_mxnet_in_gov():
image_name = '123.dkr.ecr.region-name.c2s.ic.gov/sagemaker-mxnet:1.1-gpu-py3'
assert ('mxnet', 'py3', '1.1-gpu-py3', None) == fw_utils.framework_name_from_image(image_name)


def test_framework_name_from_image_tf():
image_name = '123.dkr.ecr.us-west-2.amazonaws.com/sagemaker-tensorflow:1.6-cpu-py2'
assert ('tensorflow', 'py2', '1.6-cpu-py2', None) == fw_utils.framework_name_from_image(image_name)
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,13 @@ def test_ecr_login_non_ecr():


@patch('sagemaker.local.image._check_output', return_value='123451324')
def test_ecr_login_image_exists(_check_output):
@pytest.mark.parametrize('image', [
'520713654638.dkr.ecr.us-east-1.amazonaws.com/image-i-have:1.0',
'520713654638.dkr.ecr.us-east-1.c2s.ic.gov.com/image-i-have:1.0'
])
def test_ecr_login_image_exists(_check_output, image):
session_mock = Mock()

image = '520713654638.dkr.ecr.us-east-1.amazonaws.com/image-i-have:1.0'
result = sagemaker.local.image._ecr_login_if_needed(session_mock, image)

session_mock.assert_not_called()
Expand Down