Blame SOURCES/oscap-anaconda-addon-2.0.1-various_bugfixes-PR_166.patch

34a780
From aeb0e2ed5a524c5d4e5b72b2b11ea74a5119d45a Mon Sep 17 00:00:00 2001
34a780
From: Matej Tyc <matyc@redhat.com>
34a780
Date: Mon, 2 Aug 2021 17:23:17 +0200
34a780
Subject: [PATCH 1/3] Improve logging
34a780
34a780
Make all log entries identifiable easily.
34a780
---
34a780
 org_fedora_oscap/common.py               |  4 ++--
34a780
 org_fedora_oscap/content_discovery.py    | 16 +++++++++++-----
34a780
 org_fedora_oscap/gui/spokes/oscap.py     | 19 ++++++++++++-------
34a780
 org_fedora_oscap/rule_handling.py        |  8 ++++----
34a780
 org_fedora_oscap/service/installation.py |  6 +++---
34a780
 org_fedora_oscap/service/kickstart.py    |  2 +-
34a780
 org_fedora_oscap/service/oscap.py        | 12 ++++++------
34a780
 7 files changed, 39 insertions(+), 28 deletions(-)
34a780
34a780
diff --git a/org_fedora_oscap/common.py b/org_fedora_oscap/common.py
34a780
index a307baa..c432168 100644
34a780
--- a/org_fedora_oscap/common.py
34a780
+++ b/org_fedora_oscap/common.py
34a780
@@ -564,7 +564,7 @@ def get_content_name(data):
34a780
 def get_raw_preinst_content_path(data):
34a780
     """Path to the raw (unextracted, ...) pre-installation content file"""
34a780
     if data.content_type == "scap-security-guide":
34a780
-        log.debug("Using scap-security-guide, no single content file")
34a780
+        log.debug("OSCAP addon: Using scap-security-guide, no single content file")
34a780
         return None
34a780
 
34a780
     content_name = get_content_name(data)
34a780
@@ -667,7 +667,7 @@ def set_packages_data(data: PackagesConfigurationData):
34a780
     payload_proxy = get_payload_proxy()
34a780
 
34a780
     if payload_proxy.Type != PAYLOAD_TYPE_DNF:
34a780
-        log.debug("The payload doesn't support packages.")
34a780
+        log.debug("OSCAP addon: The payload doesn't support packages.")
34a780
         return
34a780
 
34a780
     return payload_proxy.SetPackages(
34a780
diff --git a/org_fedora_oscap/content_discovery.py b/org_fedora_oscap/content_discovery.py
34a780
index 894f3e1..bc14ef1 100644
34a780
--- a/org_fedora_oscap/content_discovery.py
34a780
+++ b/org_fedora_oscap/content_discovery.py
34a780
@@ -98,7 +98,7 @@ def fetch_content(self, what_if_fail, ca_certs_path=""):
34a780
     def _fetch_files(self, scheme, path, destdir, ca_certs_path, what_if_fail):
34a780
         with self.activity_lock:
34a780
             if self.now_fetching_or_processing:
34a780
-                msg = "Strange, it seems that we are already fetching something."
34a780
+                msg = "OSCAP Addon: Strange, it seems that we are already fetching something."
34a780
                 log.warn(msg)
34a780
                 return
34a780
             self.now_fetching_or_processing = True
34a780
@@ -175,7 +175,7 @@ def finish_content_fetch(self, fetching_thread_name, fingerprint, report_callbac
34a780
 
34a780
     def _verify_fingerprint(self, dest_filename, fingerprint=""):
34a780
         if not fingerprint:
34a780
-            log.info("No fingerprint provided, skipping integrity check")
34a780
+            log.info("OSCAP Addon: No fingerprint provided, skipping integrity check")
34a780
             return
34a780
 
34a780
         hash_obj = utils.get_hashing_algorithm(fingerprint)
34a780
@@ -183,15 +183,19 @@ def _verify_fingerprint(self, dest_filename, fingerprint=""):
34a780
                                             hash_obj)
34a780
         if digest != fingerprint:
34a780
             log.error(
34a780
+                "OSCAP Addon: "
34a780
                 f"File {dest_filename} failed integrity check - assumed a "
34a780
                 f"{hash_obj.name} hash and '{fingerprint}', got '{digest}'"
34a780
             )
34a780
-            msg = _(f"Integrity check of the content failed - {hash_obj.name} hash didn't match")
34a780
+            msg = _(f"OSCAP Addon: Integrity check of the content failed - {hash_obj.name} hash didn't match")
34a780
             raise content_handling.ContentCheckError(msg)
34a780
         log.info(f"Integrity check passed using {hash_obj.name} hash")
34a780
 
34a780
     def _finish_actual_fetch(self, wait_for, fingerprint, report_callback, dest_filename):
34a780
-        threadMgr.wait(wait_for)
34a780
+        if wait_for:
34a780
+            log.info(f"OSCAP Addon: Waiting for thread {wait_for}")
34a780
+            threadMgr.wait(wait_for)
34a780
+            log.info(f"OSCAP Addon: Finished waiting for thread {wait_for}")
34a780
         actually_fetched_content = wait_for is not None
34a780
 
34a780
         if fingerprint and dest_filename:
34a780
@@ -201,6 +205,7 @@ def _finish_actual_fetch(self, wait_for, fingerprint, report_callback, dest_file
34a780
 
34a780
         structured_content = ObtainedContent(self.CONTENT_DOWNLOAD_LOCATION)
34a780
         content_type = self.get_content_type(str(dest_filename))
34a780
+        log.info(f"OSCAP Addon: started to look at the content")
34a780
         if content_type in ("archive", "rpm"):
34a780
             structured_content.add_content_archive(dest_filename)
34a780
 
34a780
@@ -211,6 +216,7 @@ def _finish_actual_fetch(self, wait_for, fingerprint, report_callback, dest_file
34a780
         if fingerprint and dest_filename:
34a780
             structured_content.record_verification(dest_filename)
34a780
 
34a780
+        log.info(f"OSCAP Addon: finished looking at the content")
34a780
         return structured_content
34a780
 
34a780
     def _gather_available_files(self, actually_fetched_content, dest_filename):
34a780
@@ -232,7 +238,7 @@ def _gather_available_files(self, actually_fetched_content, dest_filename):
34a780
                     )
34a780
                 except common.ExtractionError as err:
34a780
                     msg = f"Failed to extract the '{dest_filename}' archive: {str(err)}"
34a780
-                    log.error(msg)
34a780
+                    log.error("OSCAP Addon: " + msg)
34a780
                     raise err
34a780
 
34a780
             elif content_type == "file":
34a780
diff --git a/org_fedora_oscap/gui/spokes/oscap.py b/org_fedora_oscap/gui/spokes/oscap.py
34a780
index 76e508f..332e956 100644
34a780
--- a/org_fedora_oscap/gui/spokes/oscap.py
34a780
+++ b/org_fedora_oscap/gui/spokes/oscap.py
34a780
@@ -331,6 +331,7 @@ def initialize(self):
34a780
 
34a780
         # if no content was specified and SSG is available, use it
34a780
         if not self._policy_data.content_type and common.ssg_available():
34a780
+            log.info("OSCAP Addon: Defaulting to local content")
34a780
             self._policy_data.content_type = "scap-security-guide"
34a780
             self._policy_data.content_path = common.SSG_DIR + common.SSG_CONTENT
34a780
 
34a780
@@ -351,7 +352,7 @@ def initialize(self):
34a780
             self._fetch_data_and_initialize()
34a780
 
34a780
     def _handle_error(self, exception):
34a780
-        log.error(str(exception))
34a780
+        log.error("OSCAP Addon: " + str(exception))
34a780
         if isinstance(exception, KickstartValueError):
34a780
             self._invalid_url()
34a780
         elif isinstance(exception, common.OSCAPaddonNetworkError):
34a780
@@ -365,7 +366,7 @@ def _handle_error(self, exception):
34a780
         elif isinstance(exception, content_handling.ContentCheckError):
34a780
             self._integrity_check_failed()
34a780
         else:
34a780
-            log.exception("Unknown exception occurred", exc_info=exception)
34a780
+            log.exception("OSCAP Addon: Unknown exception occurred", exc_info=exception)
34a780
             self._general_content_problem()
34a780
 
34a780
     def _render_selected(self, column, renderer, model, itr, user_data=None):
34a780
@@ -385,6 +386,7 @@ def _fetch_data_and_initialize(self):
34a780
 
34a780
         thread_name = None
34a780
         if self._policy_data.content_url and self._policy_data.content_type != "scap-security-guide":
34a780
+            log.info(f"OSCAP Addon: Actually fetching content from somewhere")
34a780
             thread_name = self.content_bringer.fetch_content(
34a780
                 self._handle_error, self._policy_data.certificates)
34a780
 
34a780
@@ -442,7 +444,7 @@ def update_progress_label(msg):
34a780
                 msg += f" with tailoring {preinst_tailoring_path}"
34a780
             else:
34a780
                 msg += " without considering tailoring"
34a780
-            log.info(msg)
34a780
+            log.info("OSCAP Addon: " + msg)
34a780
 
34a780
             self._content_handler = scap_content_handler.SCAPContentHandler(
34a780
                 preinst_content_path,
34a780
@@ -456,7 +458,7 @@ def update_progress_label(msg):
34a780
 
34a780
             return
34a780
 
34a780
-        log.info("OAA: Done with analysis")
34a780
+        log.info("OSCAP Addon: Done with analysis")
34a780
 
34a780
         self._ds_checklists = self._content_handler.get_data_streams_checklists()
34a780
         if self._using_ds:
34a780
@@ -592,7 +594,7 @@ def _update_profiles_store(self):
34a780
         try:
34a780
             profiles = self._content_handler.get_profiles()
34a780
         except scap_content_handler.SCAPContentHandlerError as e:
34a780
-            log.warning(str(e))
34a780
+            log.warning("OSCAP Addon: " + str(e))
34a780
             self._invalid_content()
34a780
 
34a780
         for profile in profiles:
34a780
@@ -736,7 +738,7 @@ def _select_profile(self, profile_id):
34a780
                 ds, xccdf, common.get_preinst_tailoring_path(self._policy_data))
34a780
         except common.OSCAPaddonError as exc:
34a780
             log.error(
34a780
-                "Failed to get rules for the profile '{}': {}"
34a780
+                "OSCAP Addon: Failed to get rules for the profile '{}': {}"
34a780
                 .format(profile_id, str(exc)))
34a780
             self._set_error(
34a780
                 "Failed to get rules for the profile '{}'"
34a780
@@ -908,6 +910,7 @@ def refresh(self):
34a780
     def _refresh_ui(self):
34a780
         """Refresh the UI elements."""
34a780
         if not self._content_defined:
34a780
+            log.info("OSCAP Addon: Content not defined")
34a780
             # hide the control buttons
34a780
             really_hide(self._control_buttons)
34a780
 
34a780
@@ -1156,7 +1159,9 @@ def on_fetch_button_clicked(self, *args):
34a780
         with self._fetch_flag_lock:
34a780
             if self._fetching:
34a780
                 # some other fetching/pre-processing running, give up
34a780
-                log.warn("Clicked the fetch button, although the GUI is in the fetching mode.")
34a780
+                log.warn(
34a780
+                    "OSCAP Addon: "
34a780
+                    "Clicked the fetch button, although the GUI is in the fetching mode.")
34a780
                 return
34a780
 
34a780
         # prevent user from changing the URL in the meantime
34a780
diff --git a/org_fedora_oscap/rule_handling.py b/org_fedora_oscap/rule_handling.py
34a780
index c478aa0..244aac8 100644
34a780
--- a/org_fedora_oscap/rule_handling.py
34a780
+++ b/org_fedora_oscap/rule_handling.py
34a780
@@ -261,7 +261,7 @@ def new_rule(self, rule):
34a780
         try:
34a780
             actions[first_word](rule)
34a780
         except (ModifiedOptionParserException, KeyError) as e:
34a780
-            log.warning("Unknown OSCAP Addon rule '{}': {}".format(rule, e))
34a780
+            log.warning("OSCAP Addon: Unknown OSCAP Addon rule '{}': {}".format(rule, e))
34a780
 
34a780
     def eval_rules(self, ksdata, storage, report_only=False):
34a780
         """:see: RuleHandler.eval_rules"""
34a780
@@ -565,7 +565,7 @@ def eval_rules(self, ksdata, storage, report_only=False):
34a780
             # root password set
34a780
             if users_proxy.IsRootPasswordCrypted:
34a780
                 msg = _("cannot check root password length (password is crypted)")
34a780
-                log.warning("cannot check root password length (password is crypted)")
34a780
+                log.warning("OSCAP Addon: cannot check root password length (password is crypted)")
34a780
                 return [RuleMessage(self.__class__,
34a780
                                     common.MESSAGE_TYPE_WARNING, msg)]
34a780
             elif len(users_proxy.RootPassword) < self._minlen:
34a780
@@ -880,7 +880,7 @@ def eval_rules(self, ksdata, storage, report_only=False):
34a780
 
34a780
                 kdump_proxy.KdumpEnabled = self._kdump_enabled
34a780
             else:
34a780
-                log.warning("com_redhat_kdump is not installed. "
34a780
+                log.warning("OSCAP Addon: com_redhat_kdump is not installed. "
34a780
                             "Skipping kdump configuration")
34a780
 
34a780
         return messages
34a780
@@ -894,7 +894,7 @@ def revert_changes(self, ksdata, storage):
34a780
             if self._kdump_enabled is not None:
34a780
                 kdump_proxy.KdumpEnabled = self._kdump_default_enabled
34a780
         else:
34a780
-            log.warning("com_redhat_kdump is not installed. "
34a780
+            log.warning("OSCAP Addon: com_redhat_kdump is not installed. "
34a780
                         "Skipping reverting kdump configuration")
34a780
 
34a780
         self._kdump_enabled = None
34a780
diff --git a/org_fedora_oscap/service/installation.py b/org_fedora_oscap/service/installation.py
34a780
index e3a1d0f..2da8559 100644
34a780
--- a/org_fedora_oscap/service/installation.py
34a780
+++ b/org_fedora_oscap/service/installation.py
34a780
@@ -28,14 +28,14 @@
34a780
 from org_fedora_oscap.content_handling import ContentCheckError
34a780
 from org_fedora_oscap import content_discovery
34a780
 
34a780
-log = logging.getLogger(__name__)
34a780
+log = logging.getLogger("anaconda")
34a780
 
34a780
 
34a780
 REQUIRED_PACKAGES = ("openscap", "openscap-scanner",)
34a780
 
34a780
 
34a780
 def _handle_error(exception):
34a780
-    log.error("Failed to fetch and initialize SCAP content!")
34a780
+    log.error("OSCAP Addon: Failed to fetch and initialize SCAP content!")
34a780
 
34a780
     if isinstance(exception, ContentCheckError):
34a780
         msg = _("The integrity check of the security content failed.")
34a780
@@ -87,7 +87,7 @@ def run(self):
34a780
 
34a780
         content = self.content_bringer.finish_content_fetch(
34a780
             fetching_thread_name, self._policy_data.fingerprint,
34a780
-            lambda msg: log.info(msg), content_dest, _handle_error)
34a780
+            lambda msg: log.info("OSCAP Addon: " + msg), content_dest, _handle_error)
34a780
 
34a780
         if not content:
34a780
             # this shouldn't happen because error handling is supposed to
34a780
diff --git a/org_fedora_oscap/service/kickstart.py b/org_fedora_oscap/service/kickstart.py
34a780
index 341c6c5..d6f22ac 100644
34a780
--- a/org_fedora_oscap/service/kickstart.py
34a780
+++ b/org_fedora_oscap/service/kickstart.py
34a780
@@ -25,7 +25,7 @@
34a780
 from org_fedora_oscap import common, utils
34a780
 from org_fedora_oscap.structures import PolicyData
34a780
 
34a780
-log = logging.getLogger(__name__)
34a780
+log = logging.getLogger("anaconda")
34a780
 
34a780
 __all__ = ["OSCAPKickstartSpecification"]
34a780
 
34a780
diff --git a/org_fedora_oscap/service/oscap.py b/org_fedora_oscap/service/oscap.py
34a780
index d491060..4237a47 100755
34a780
--- a/org_fedora_oscap/service/oscap.py
34a780
+++ b/org_fedora_oscap/service/oscap.py
34a780
@@ -34,7 +34,7 @@
34a780
 from org_fedora_oscap.service.oscap_interface import OSCAPInterface
34a780
 from org_fedora_oscap.structures import PolicyData
34a780
 
34a780
-log = logging.getLogger(__name__)
34a780
+log = logging.getLogger("anaconda")
34a780
 
34a780
 __all__ = ["OSCAPService"]
34a780
 
34a780
@@ -71,7 +71,7 @@ def policy_enabled(self, value):
34a780
         """
34a780
         self._policy_enabled = value
34a780
         self.policy_enabled_changed.emit()
34a780
-        log.debug("Policy enabled is set to '%s'.", value)
34a780
+        log.debug("OSCAP Addon: Policy enabled is set to '%s'.", value)
34a780
 
34a780
     @property
34a780
     def policy_data(self):
34a780
@@ -89,7 +89,7 @@ def policy_data(self, value):
34a780
         """
34a780
         self._policy_data = value
34a780
         self.policy_data_changed.emit()
34a780
-        log.debug("Policy data is set to '%s'.", value)
34a780
+        log.debug("OSCAP Addon: Policy data is set to '%s'.", value)
34a780
 
34a780
     @property
34a780
     def installation_enabled(self):
34a780
@@ -150,7 +150,7 @@ def collect_requirements(self):
34a780
         :return: a list of requirements
34a780
         """
34a780
         if not self.installation_enabled:
34a780
-            log.debug("The installation is disabled. Skip the requirements.")
34a780
+            log.debug("OSCAP Addon: The installation is disabled. Skip the requirements.")
34a780
             return []
34a780
 
34a780
         requirements = [
34a780
@@ -180,7 +180,7 @@ def configure_with_tasks(self):
34a780
         :return: a list of tasks
34a780
         """
34a780
         if not self.installation_enabled:
34a780
-            log.debug("The installation is disabled. Skip the configuration.")
34a780
+            log.debug("OSCAP Addon: The installation is disabled. Skip the configuration.")
34a780
             return []
34a780
 
34a780
         tasks = [
34a780
@@ -205,7 +205,7 @@ def install_with_tasks(self):
34a780
         :return: a list of tasks
34a780
         """
34a780
         if not self.installation_enabled:
34a780
-            log.debug("The installation is disabled. Skip the installation.")
34a780
+            log.debug("OSCAP Addon: The installation is disabled. Skip the installation.")
34a780
             return []
34a780
 
34a780
         tasks = [
34a780
34a780
From b081e32012b93177167d3f7d0cc2024deb50e965 Mon Sep 17 00:00:00 2001
34a780
From: Matej Tyc <matyc@redhat.com>
34a780
Date: Mon, 2 Aug 2021 17:24:15 +0200
34a780
Subject: [PATCH 2/3] Save addon data when using local content
34a780
34a780
Addon loads its data from the shared storage upon refresh,
34a780
which caused it to overwrite clicking on the "use SSG content" button.
34a780
34a780
Now the data is saved after clicking that button, and convenience
34a780
load/save methods were introduced.
34a780
---
34a780
 org_fedora_oscap/gui/spokes/oscap.py | 27 +++++++++++++++------------
34a780
 1 file changed, 15 insertions(+), 12 deletions(-)
34a780
34a780
diff --git a/org_fedora_oscap/gui/spokes/oscap.py b/org_fedora_oscap/gui/spokes/oscap.py
34a780
index 332e956..4425757 100644
34a780
--- a/org_fedora_oscap/gui/spokes/oscap.py
34a780
+++ b/org_fedora_oscap/gui/spokes/oscap.py
34a780
@@ -232,11 +232,8 @@ def __init__(self, data, storage, payload):
34a780
         # the proxy to OSCAP DBus module
34a780
         self._oscap_module = OSCAP.get_proxy()
34a780
 
34a780
-        # the security policy data
34a780
-        self._policy_enabled = self._oscap_module.PolicyEnabled
34a780
-        self._policy_data = PolicyData.from_structure(
34a780
-            self._oscap_module.PolicyData
34a780
-        )
34a780
+        self._policy_data = PolicyData()
34a780
+        self._load_policy_data()
34a780
 
34a780
         # used for changing profiles
34a780
         self._rule_data = None
34a780
@@ -334,6 +331,7 @@ def initialize(self):
34a780
             log.info("OSCAP Addon: Defaulting to local content")
34a780
             self._policy_data.content_type = "scap-security-guide"
34a780
             self._policy_data.content_path = common.SSG_DIR + common.SSG_CONTENT
34a780
+            self._save_policy_data()
34a780
 
34a780
         if not self._content_defined:
34a780
             # nothing more to be done now, the spoke is ready
34a780
@@ -351,6 +349,16 @@ def initialize(self):
34a780
             # else fetch data
34a780
             self._fetch_data_and_initialize()
34a780
 
34a780
+    def _save_policy_data(self):
34a780
+        self._oscap_module.PolicyData = PolicyData.to_structure(self._policy_data)
34a780
+        self._oscap_module.PolicyEnabled = self._policy_enabled
34a780
+
34a780
+    def _load_policy_data(self):
34a780
+        self._policy_data.update_from(PolicyData.from_structure(
34a780
+            self._oscap_module.PolicyData
34a780
+        ))
34a780
+        self._policy_enabled = self._oscap_module.PolicyEnabled
34a780
+
34a780
     def _handle_error(self, exception):
34a780
         log.error("OSCAP Addon: " + str(exception))
34a780
         if isinstance(exception, KickstartValueError):
34a780
@@ -897,13 +905,7 @@ def refresh(self):
34a780
         :see: pyanaconda.ui.common.UIObject.refresh
34a780
 
34a780
         """
34a780
-        # update the security policy data
34a780
-        self._policy_enabled = self._oscap_module.PolicyEnabled
34a780
-        fresh_data = PolicyData.from_structure(
34a780
-            self._oscap_module.PolicyData
34a780
-        )
34a780
-
34a780
-        self._policy_data.update_from(fresh_data)
34a780
+        self._load_policy_data()
34a780
         # update the UI elements
34a780
         self._refresh_ui()
34a780
 
34a780
@@ -1202,4 +1204,5 @@ def on_change_content_clicked(self, *args):
34a780
 
34a780
     def on_use_ssg_clicked(self, *args):
34a780
         self.content_bringer.use_system_content()
34a780
+        self._save_policy_data()
34a780
         self._fetch_data_and_initialize()
34a780
34a780
From fee170f54aeb9f649ab891781532012a7b069f8f Mon Sep 17 00:00:00 2001
34a780
From: Matej Tyc <matyc@redhat.com>
34a780
Date: Tue, 3 Aug 2021 11:01:59 +0200
34a780
Subject: [PATCH 3/3] Refactor content identification
34a780
34a780
Don't use the multiprocessing pool - it sometimes creates probems during
34a780
its initialization:
34a780
https://bugzilla.redhat.com/show_bug.cgi?id=1989434
34a780
---
34a780
 org_fedora_oscap/content_handling.py | 9 +++++----
34a780
 1 file changed, 5 insertions(+), 4 deletions(-)
34a780
34a780
diff --git a/org_fedora_oscap/content_handling.py b/org_fedora_oscap/content_handling.py
34a780
index f2af22f..65d5a28 100644
34a780
--- a/org_fedora_oscap/content_handling.py
34a780
+++ b/org_fedora_oscap/content_handling.py
34a780
@@ -111,9 +111,8 @@ def parse_HTML_from_content(content):
34a780
 
34a780
 
34a780
 def identify_files(fpaths):
34a780
-    with multiprocessing.Pool(os.cpu_count()) as p:
34a780
-        labels = p.map(get_doc_type, fpaths)
34a780
-    return {path: label for (path, label) in zip(fpaths, labels)}
34a780
+    result = {path: get_doc_type(path) for path in fpaths}
34a780
+    return result
34a780
 
34a780
 
34a780
 def get_doc_type(file_path):
34a780
@@ -131,7 +130,9 @@ def get_doc_type(file_path):
34a780
     except UnicodeDecodeError:
34a780
         # 'oscap info' supplied weird output, which happens when it tries
34a780
         # to explain why it can't examine e.g. a JPG.
34a780
-        return None
34a780
+        pass
34a780
+    except Exception as e:
34a780
+        log.warning(f"OSCAP addon: Unexpected error when looking at {file_path}: {str(e)}")
34a780
     log.info("OSCAP addon: Identified {file_path} as {content_type}"
34a780
              .format(file_path=file_path, content_type=content_type))
34a780
     return content_type