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

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