Blame SOURCES/0014-Filter-out-the-pki-healthcheck-sources-if-IPA-CA-is-.patch

151c79
From eb377fed539e44194fb1ad822c0d4c6e9ea38d03 Mon Sep 17 00:00:00 2001
151c79
From: Rob Crittenden <rcritten@redhat.com>
151c79
Date: Tue, 11 May 2021 13:26:00 -0400
151c79
Subject: [PATCH] Filter out the pki healthcheck sources if IPA CA is not
151c79
 installed
151c79
151c79
The pki checks spew the error "Invalid PKI instance: pki-tomcat" so
151c79
we need to suppress them in the IPA CA-less installation case.
151c79
151c79
So if the IPA CA is not configured then don't register the
151c79
pki sources.
151c79
151c79
A side-effect is that to user the sources will not be listed at
151c79
all in this case.
151c79
151c79
This should not affect pki-healthcheck and it will continue to
151c79
return errors in the unconfigured case.
151c79
151c79
https://github.com/freeipa/freeipa-healthcheck/issues/201
151c79
151c79
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
151c79
---
151c79
 src/ipahealthcheck/core/core.py  | 13 +++++++++++++
151c79
 src/ipahealthcheck/ipa/plugin.py |  4 ++++
151c79
 2 files changed, 17 insertions(+)
151c79
151c79
diff --git a/src/ipahealthcheck/core/core.py b/src/ipahealthcheck/core/core.py
151c79
index eaa2d9c..a6b4fe8 100644
151c79
--- a/src/ipahealthcheck/core/core.py
151c79
+++ b/src/ipahealthcheck/core/core.py
151c79
@@ -281,6 +281,13 @@ class RunChecks:
151c79
         if rval is not None:
151c79
             return rval
151c79
 
151c79
+        # If we have IPA configured without a CA then we want to skip
151c79
+        # the pkihealthcheck plugins otherwise they will generated a
151c79
+        # lot of false positives. The IPA plugins are loaded first so
151c79
+        # which should set ca_configured in its registry to True or
151c79
+        # False. We will skip the pkihealthcheck plugins only if
151c79
+        # ca_configured is False which means that it was set by IPA.
151c79
+        ca_configured = False
151c79
         for name, registry in find_registries(self.entry_points).items():
151c79
             try:
151c79
                 registry.initialize(framework, config, options)
151c79
@@ -292,6 +299,12 @@ class RunChecks:
151c79
                 except Exception as e:
151c79
                     logger.error("Unable to initialize %s: %s" % (name, e))
151c79
                     continue
151c79
+            if hasattr(registry, 'ca_configured'):
151c79
+                ca_configured = registry.ca_configured
151c79
+        for name, registry in find_registries(self.entry_points).items():
151c79
+            if 'pkihealthcheck' in name and ca_configured is False:
151c79
+                logger.debug('IPA CA is not configured, skipping %s', name)
151c79
+                continue
151c79
             for plugin in find_plugins(name, registry):
151c79
                 plugins.append(plugin)
151c79
 
151c79
diff --git a/src/ipahealthcheck/ipa/plugin.py b/src/ipahealthcheck/ipa/plugin.py
151c79
index 67d93e5..debb1bb 100644
151c79
--- a/src/ipahealthcheck/ipa/plugin.py
151c79
+++ b/src/ipahealthcheck/ipa/plugin.py
151c79
@@ -35,6 +35,7 @@ class IPARegistry(Registry):
151c79
         super(IPARegistry, self).__init__()
151c79
         self.trust_agent = False
151c79
         self.trust_controller = False
151c79
+        self.ca_configured = False
151c79
 
151c79
     def initialize(self, framework, config, options=None):
151c79
         super(IPARegistry, self).initialize(framework, config)
151c79
@@ -58,6 +59,9 @@ class IPARegistry(Registry):
151c79
                 logging.debug('Failed to connect to LDAP: %s', e)
151c79
             return
151c79
 
151c79
+        ca = cainstance.CAInstance(api.env.realm, host_name=api.env.host)
151c79
+        self.ca_configured = ca.is_configured()
151c79
+
151c79
         # This package is pulled in when the trust package is installed
151c79
         # and is required to lookup trust users. If this is not installed
151c79
         # then it can be inferred that trust is not enabled.
151c79
-- 
151c79
2.31.1
151c79