Skip to content

Commit

Permalink
Allow explicitly turning off src-tls-verify
Browse files Browse the repository at this point in the history
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 <nishak@vmware.com>
  • Loading branch information
Nisha K committed Feb 19, 2022
1 parent 1d9f547 commit d049409
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
14 changes: 13 additions & 1 deletion tern/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017-2021 VMware, Inc. All Rights Reserved.
# Copyright (c) 2017-2022 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: BSD-2-Clause

"""
Expand Down Expand Up @@ -181,6 +181,12 @@ def main():
parser_report.add_argument('-i', '--image',
help="A container image referred either by "
" repo:tag or repo@digest-type:digest")
parser_report.add_argument('--no-tls', default=False,
action='store_true',
help="When fetching an image, DO NOT use HTTPS "
" and DO NOT verify TLS certificates of the "
"registry.\nThis is useful when using a local "
"registry instance for debugging purposes.")
parser_report.add_argument('-w', '--raw-image', metavar='FILE',
help="Raw container image that exists locally "
"in the form of a tar archive. Only the output"
Expand Down Expand Up @@ -269,6 +275,12 @@ def main():
" The option can be used to pull docker"
" images by digest as well -"
" <repo>@<digest-type>:<digest>")
parser_debug.add_argument('--no-tls', default=False,
action='store_true',
help="When fetching an image, DO NOT use HTTPS "
" and DO NOT verify TLS certificates of the "
"registry.\nThis is useful when using a local "
"registry instance for debugging purposes.")
parser_debug.add_argument('-w', '--raw-image', metavar='FILE',
help="Raw container image that exists locally "
"in the form of a tar archive.")
Expand Down
4 changes: 2 additions & 2 deletions tern/analyze/default/container/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2019-2021 VMware, Inc. All Rights Reserved.
# Copyright (c) 2019-2022 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: BSD-2-Clause

"""
Expand Down Expand Up @@ -29,7 +29,7 @@ def extract_image(args):
Return an image name and tag and an image digest if it exists"""
if args.image:
# download the image
result = skopeo.pull_image(args.image)
result = skopeo.pull_image(args.image, args.no_tls)
if result:
return 'oci', args.image
logger.critical("Cannot download Container image: \"%s\"", args.image)
Expand Down
12 changes: 8 additions & 4 deletions tern/load/skopeo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021 VMware, Inc. All Rights Reserved.
# Copyright (c) 2021-2022 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: BSD-2-Clause

"""
Expand All @@ -27,16 +27,20 @@ def check_skopeo_setup():
sys.exit(1)


def pull_image(image_tag_string):
def pull_image(image_tag_string, no_tls=False):
"""Use skopeo to pull a remote image into the working directory"""
# Check if skopeo is set up
check_skopeo_setup()
# we will assume the docker transport for now
remote = f'docker://{image_tag_string}'
local = f'dir:{rootfs.get_working_dir()}'
logger.debug("Attempting to pull image \"%s\"", image_tag_string)
result, error = rootfs.shell_command(
False, ['skopeo', 'copy', remote, local])
if no_tls:
result, error = rootfs.shell_command(
False, ['skopeo', 'copy', '--src-tls-verify=false', remote, local])
else:
result, error = rootfs.shell_command(
False, ['skopeo', 'copy', remote, local])
if error:
logger.error("Error when downloading image: \"%s\"", error)
return None
Expand Down

0 comments on commit d049409

Please sign in to comment.