Skip to content

Commit 360e519

Browse files
author
Nisha K
committed
Allow explicitly turning off src-tls-verify
In situations where TLS is not enabled for a registry, users may now turn off the option to check TLS certificates and use HTTP rather than HTTPS to pull images using skopeo. It is advised to not use this flag for untrusted registries and only use it for registries hosted locally to testing or debugging. This option is also added for the `debug` sub-command. Fixes tern-tools#1121 and tern-tools#1087 Signed-off-by: Nisha K <[email protected]>
1 parent 1d9f547 commit 360e519

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

tern/__main__.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
#
4-
# Copyright (c) 2017-2021 VMware, Inc. All Rights Reserved.
4+
# Copyright (c) 2017-2022 VMware, Inc. All Rights Reserved.
55
# SPDX-License-Identifier: BSD-2-Clause
66

77
"""
@@ -181,6 +181,12 @@ def main():
181181
parser_report.add_argument('-i', '--image',
182182
help="A container image referred either by "
183183
" repo:tag or repo@digest-type:digest")
184+
parser_report.add_argument('--no-tls', default=False,
185+
action='store_true',
186+
help="When fetching an image, DO NOT use HTTPS "
187+
" and DO NOT verify TLS certificates of the "
188+
"registry.\nThis is useful when using a local "
189+
"registry instance for debugging purposes.")
184190
parser_report.add_argument('-w', '--raw-image', metavar='FILE',
185191
help="Raw container image that exists locally "
186192
"in the form of a tar archive. Only the output"
@@ -269,6 +275,12 @@ def main():
269275
" The option can be used to pull docker"
270276
" images by digest as well -"
271277
" <repo>@<digest-type>:<digest>")
278+
parser_report.add_argument('--no-tls', default=False,
279+
action='store_true',
280+
help="When fetching an image, DO NOT use HTTPS "
281+
" and DO NOT verify TLS certificates of the "
282+
"registry.\nThis is useful when using a local "
283+
"registry instance for debugging purposes.")
272284
parser_debug.add_argument('-w', '--raw-image', metavar='FILE',
273285
help="Raw container image that exists locally "
274286
"in the form of a tar archive.")

tern/analyze/default/container/run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (c) 2019-2021 VMware, Inc. All Rights Reserved.
3+
# Copyright (c) 2019-2022 VMware, Inc. All Rights Reserved.
44
# SPDX-License-Identifier: BSD-2-Clause
55

66
"""
@@ -29,7 +29,7 @@ def extract_image(args):
2929
Return an image name and tag and an image digest if it exists"""
3030
if args.image:
3131
# download the image
32-
result = skopeo.pull_image(args.image)
32+
result = skopeo.pull_image(args.image, args.no_tls)
3333
if result:
3434
return 'oci', args.image
3535
logger.critical("Cannot download Container image: \"%s\"", args.image)

tern/analyze/default/debug/run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (c) 2017-2021 VMware, Inc. All Rights Reserved.
3+
# Copyright (c) 2017-2022 VMware, Inc. All Rights Reserved.
44
# SPDX-License-Identifier: BSD-2-Clause
55

66
"""
@@ -189,7 +189,7 @@ def recover(driver):
189189
def execute_debug(args):
190190
"""Debug container images"""
191191
if args.image:
192-
image_type, image_string = run.extract_image(args)
192+
image_type, image_string = run.extract_image(args, args.no_tls)
193193
full_image, success = check_image_obj(image_string, image_type)
194194
if success:
195195
if args.keys:

tern/load/skopeo.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (c) 2021 VMware, Inc. All Rights Reserved.
3+
# Copyright (c) 2021-2022 VMware, Inc. All Rights Reserved.
44
# SPDX-License-Identifier: BSD-2-Clause
55

66
"""
@@ -27,16 +27,20 @@ def check_skopeo_setup():
2727
sys.exit(1)
2828

2929

30-
def pull_image(image_tag_string):
30+
def pull_image(image_tag_string, no_tls=False):
3131
"""Use skopeo to pull a remote image into the working directory"""
3232
# Check if skopeo is set up
3333
check_skopeo_setup()
3434
# we will assume the docker transport for now
3535
remote = f'docker://{image_tag_string}'
3636
local = f'dir:{rootfs.get_working_dir()}'
3737
logger.debug("Attempting to pull image \"%s\"", image_tag_string)
38-
result, error = rootfs.shell_command(
39-
False, ['skopeo', 'copy', remote, local])
38+
if no_tls:
39+
result, error = rootfs.shell_command(
40+
False, ['skopeo', 'copy', '--src-tls-verify=false', remote, local])
41+
else:
42+
result, error = rootfs.shell_command(
43+
False, ['skopeo', 'copy', remote, local])
4044
if error:
4145
logger.error("Error when downloading image: \"%s\"", error)
4246
return None

0 commit comments

Comments
 (0)