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

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