|
|
b1f2c6 |
From eea0fd27e7bed6a225bbd6702960bcf394f19536 Mon Sep 17 00:00:00 2001
|
|
|
b1f2c6 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
b1f2c6 |
Date: Wed, 24 Jan 2018 17:39:04 +0100
|
|
|
b1f2c6 |
Subject: [PATCH 1/2] Modified the code that temp images are not forgotten.
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
---
|
|
|
b1f2c6 |
utils/oscap_docker_python/oscap_docker_util.py | 20 ++++++++++++--------
|
|
|
b1f2c6 |
1 file changed, 12 insertions(+), 8 deletions(-)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
diff --git a/utils/oscap_docker_python/oscap_docker_util.py b/utils/oscap_docker_python/oscap_docker_util.py
|
|
|
b1f2c6 |
index b06b6001a..b9a08a99c 100644
|
|
|
b1f2c6 |
--- a/utils/oscap_docker_python/oscap_docker_util.py
|
|
|
b1f2c6 |
+++ b/utils/oscap_docker_python/oscap_docker_util.py
|
|
|
b1f2c6 |
@@ -155,7 +155,8 @@ def oscap_chroot(self, chroot_path, target, *oscap_args):
|
|
|
b1f2c6 |
sys.stderr.write(oscap_stderr.decode("utf-8") + "\n")
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
# Clean up
|
|
|
b1f2c6 |
- self._cleanup_by_path(chroot_path)
|
|
|
b1f2c6 |
+ DM = DockerMount("/tmp")
|
|
|
b1f2c6 |
+ self._cleanup_by_path(chroot_path, DM)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
sys.exit(1)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
@@ -186,18 +187,17 @@ def resolve_image(self, image):
|
|
|
b1f2c6 |
# TODO
|
|
|
b1f2c6 |
pass
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
- def _cleanup_by_path(self, path):
|
|
|
b1f2c6 |
+ def _cleanup_by_path(self, path, DM):
|
|
|
b1f2c6 |
'''
|
|
|
b1f2c6 |
Cleans up the mounted chroot by umounting it and
|
|
|
b1f2c6 |
removing the temporary directory
|
|
|
b1f2c6 |
'''
|
|
|
b1f2c6 |
# Sometimes when this def is called, path will have 'rootfs'
|
|
|
b1f2c6 |
# appended. If it does, strip it and proceed
|
|
|
b1f2c6 |
+ _no_rootfs = path
|
|
|
b1f2c6 |
+ if os.path.basename(path) == 'rootfs':
|
|
|
b1f2c6 |
+ _no_rootfs = os.path.dirname(path)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
- _no_rootfs = os.path.dirname(path) if os.path.basename(path) == \
|
|
|
b1f2c6 |
- 'rootfs' else path
|
|
|
b1f2c6 |
-
|
|
|
b1f2c6 |
- DM = DockerMount("/tmp")
|
|
|
b1f2c6 |
# umount chroot
|
|
|
b1f2c6 |
DM.unmount_path(_no_rootfs)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
@@ -206,6 +206,10 @@ def _cleanup_by_path(self, path):
|
|
|
b1f2c6 |
os.rmdir(_no_rootfs)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
+def mount_image_filesystem():
|
|
|
b1f2c6 |
+ _tmp_mnt_dir = DM.mount(image)
|
|
|
b1f2c6 |
+
|
|
|
b1f2c6 |
+
|
|
|
b1f2c6 |
class OscapScan(object):
|
|
|
b1f2c6 |
def __init__(self, tmp_dir=tempfile.gettempdir(), mnt_dir=None,
|
|
|
b1f2c6 |
hours_old=2):
|
|
|
b1f2c6 |
@@ -276,7 +280,7 @@ def scan_cve(self, image, scan_args):
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
finally:
|
|
|
b1f2c6 |
# Clean up
|
|
|
b1f2c6 |
- self.helper._cleanup_by_path(_tmp_mnt_dir)
|
|
|
b1f2c6 |
+ self.helper._cleanup_by_path(_tmp_mnt_dir, DM)
|
|
|
b1f2c6 |
self._remove_mnt_dir(mnt_dir)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
def scan(self, image, scan_args):
|
|
|
b1f2c6 |
@@ -301,5 +305,5 @@ def scan(self, image, scan_args):
|
|
|
b1f2c6 |
sys.stdout.write(self.helper._scan(chroot, image, scan_args))
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
# Clean up
|
|
|
b1f2c6 |
- self.helper._cleanup_by_path(_tmp_mnt_dir)
|
|
|
b1f2c6 |
+ self.helper._cleanup_by_path(_tmp_mnt_dir, DM)
|
|
|
b1f2c6 |
self._remove_mnt_dir(mnt_dir)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
From 432ee1841003b57408e7a1040c6f317cc56a9071 Mon Sep 17 00:00:00 2001
|
|
|
b1f2c6 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
b1f2c6 |
Date: Thu, 25 Jan 2018 14:03:48 +0100
|
|
|
b1f2c6 |
Subject: [PATCH 2/2] Refactored error handling during scan.
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
---
|
|
|
b1f2c6 |
utils/oscap_docker_python/oscap_docker_util.py | 24 +++++++++++-------------
|
|
|
b1f2c6 |
1 file changed, 11 insertions(+), 13 deletions(-)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
diff --git a/utils/oscap_docker_python/oscap_docker_util.py b/utils/oscap_docker_python/oscap_docker_util.py
|
|
|
b1f2c6 |
index b9a08a99c..ca48d5846 100644
|
|
|
b1f2c6 |
--- a/utils/oscap_docker_python/oscap_docker_util.py
|
|
|
b1f2c6 |
+++ b/utils/oscap_docker_python/oscap_docker_util.py
|
|
|
b1f2c6 |
@@ -154,10 +154,6 @@ def oscap_chroot(self, chroot_path, target, *oscap_args):
|
|
|
b1f2c6 |
sys.stderr.write("Command returned exit code {0}.\n".format(oscap_process.returncode))
|
|
|
b1f2c6 |
sys.stderr.write(oscap_stderr.decode("utf-8") + "\n")
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
- # Clean up
|
|
|
b1f2c6 |
- DM = DockerMount("/tmp")
|
|
|
b1f2c6 |
- self._cleanup_by_path(chroot_path, DM)
|
|
|
b1f2c6 |
-
|
|
|
b1f2c6 |
sys.exit(1)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
sys.stderr.write(oscap_stderr.decode("utf-8") + "\n")
|
|
|
b1f2c6 |
@@ -207,7 +203,7 @@ def _cleanup_by_path(self, path, DM):
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
def mount_image_filesystem():
|
|
|
b1f2c6 |
- _tmp_mnt_dir = DM.mount(image)
|
|
|
b1f2c6 |
+ _tmp_mnt_dir = DM.mount(image)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
class OscapScan(object):
|
|
|
b1f2c6 |
@@ -261,9 +257,9 @@ def scan_cve(self, image, scan_args):
|
|
|
b1f2c6 |
sys.stderr.write(str(e) + "\n")
|
|
|
b1f2c6 |
return None
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
- chroot = self._find_chroot_path(_tmp_mnt_dir)
|
|
|
b1f2c6 |
-
|
|
|
b1f2c6 |
try:
|
|
|
b1f2c6 |
+ chroot = self._find_chroot_path(_tmp_mnt_dir)
|
|
|
b1f2c6 |
+
|
|
|
b1f2c6 |
# Figure out which RHEL dist is in the chroot
|
|
|
b1f2c6 |
dist = self.helper._get_dist(chroot, image)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
@@ -299,11 +295,13 @@ def scan(self, image, scan_args):
|
|
|
b1f2c6 |
sys.stderr.write(str(e) + "\n")
|
|
|
b1f2c6 |
return None
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
- chroot = self._find_chroot_path(_tmp_mnt_dir)
|
|
|
b1f2c6 |
+ try:
|
|
|
b1f2c6 |
+ chroot = self._find_chroot_path(_tmp_mnt_dir)
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
- # Scan the chroot
|
|
|
b1f2c6 |
- sys.stdout.write(self.helper._scan(chroot, image, scan_args))
|
|
|
b1f2c6 |
+ # Scan the chroot
|
|
|
b1f2c6 |
+ sys.stdout.write(self.helper._scan(chroot, image, scan_args))
|
|
|
b1f2c6 |
|
|
|
b1f2c6 |
- # Clean up
|
|
|
b1f2c6 |
- self.helper._cleanup_by_path(_tmp_mnt_dir, DM)
|
|
|
b1f2c6 |
- self._remove_mnt_dir(mnt_dir)
|
|
|
b1f2c6 |
+ finally:
|
|
|
b1f2c6 |
+ # Clean up
|
|
|
b1f2c6 |
+ self.helper._cleanup_by_path(_tmp_mnt_dir, DM)
|
|
|
b1f2c6 |
+ self._remove_mnt_dir(mnt_dir)
|