Blame SOURCES/pki-core-fix-ipa-replica-install-timing-issue.patch

120910
From 609b98cccc77fa8b8e8d307c2f84651429068ec6 Mon Sep 17 00:00:00 2001
120910
From: Fraser Tweedale <ftweedal@redhat.com>
120910
Date: Mon, 9 Oct 2017 16:26:21 +1100
120910
Subject: [PATCH 1/5] CMSServlet.renderFinalError: log exception
120910
120910
renderFinalError is a "last resort" error handler that writes an
120910
error message back to the client.  If the exception was not already
120910
logged, the call stack will be discarded after renderFinalError is
120910
finished with the exception.
120910
120910
Log the exception so that the call stack information is not lost.
120910
120910
Part of: https://pagure.io/dogtagpki/issue/2557
120910
120910
Change-Id: I2fd608adf205e3f72b67d822b1966fdb1b8bc60f
120910
(cherry picked from commit 386357c347f8433e14ccd8637576f4c4a4e42492)
120910
(cherry picked from commit 3af42c306446ddc931fc0d44505cd237aa2267d7)
120910
---
120910
 base/server/cms/src/com/netscape/cms/servlet/base/CMSServlet.java | 2 ++
120910
 1 file changed, 2 insertions(+)
120910
120910
diff --git a/base/server/cms/src/com/netscape/cms/servlet/base/CMSServlet.java b/base/server/cms/src/com/netscape/cms/servlet/base/CMSServlet.java
120910
index 65dc06a..fe18ee1 100644
120910
--- a/base/server/cms/src/com/netscape/cms/servlet/base/CMSServlet.java
120910
+++ b/base/server/cms/src/com/netscape/cms/servlet/base/CMSServlet.java
120910
@@ -763,6 +763,8 @@ public abstract class CMSServlet extends HttpServlet {
120910
 
120910
     public void renderFinalError(CMSRequest cmsReq, Exception ex)
120910
             throws IOException {
120910
+        CMS.debug("Caught exception in renderFinalError:");
120910
+        CMS.debug(ex);
120910
         // this template is the last resort for all other unexpected
120910
         // errors in other templates so we can only output text.
120910
         HttpServletResponse httpResp = cmsReq.getHttpResp();
120910
-- 
120910
1.8.3.1
120910
120910
120910
From c160d49e0b61d650a14eae9be38e5f381aeb0b24 Mon Sep 17 00:00:00 2001
120910
From: Fraser Tweedale <ftweedal@redhat.com>
120910
Date: Mon, 9 Oct 2017 16:45:51 +1100
120910
Subject: [PATCH 2/5] TokenAuthenticate: avoid NPE on null session table
120910
120910
If the security domain session table is null for some reason, detect
120910
this condition, log it, and return cleanly instead of throwing a
120910
NullPointerException.
120910
120910
Part of: https://pagure.io/dogtagpki/issue/2557
120910
120910
Change-Id: Ie487492ed6eec913f0271221fd12842fe7128ceb
120910
(cherry picked from commit bc329a0162ae9af382c81e75742b282ea8c5df0d)
120910
(cherry picked from commit 76d85a648bc6be0f690d36341e6a11d64a3ff6b6)
120910
---
120910
 .../cms/src/com/netscape/cms/servlet/csadmin/TokenAuthenticate.java | 6 +++++-
120910
 1 file changed, 5 insertions(+), 1 deletion(-)
120910
120910
diff --git a/base/server/cms/src/com/netscape/cms/servlet/csadmin/TokenAuthenticate.java b/base/server/cms/src/com/netscape/cms/servlet/csadmin/TokenAuthenticate.java
120910
index 27f4782..1d98693 100644
120910
--- a/base/server/cms/src/com/netscape/cms/servlet/csadmin/TokenAuthenticate.java
120910
+++ b/base/server/cms/src/com/netscape/cms/servlet/csadmin/TokenAuthenticate.java
120910
@@ -81,7 +81,11 @@ public class TokenAuthenticate extends CMSServlet {
120910
         String uid = "";
120910
         String gid = "";
120910
         CMS.debug("TokenAuthentication: checking session in the session table");
120910
-        if (table.sessionExists(sessionId)) {
120910
+        if (table == null) {
120910
+            CMS.debug("TokenAuthentication: session table is null");
120910
+            outputError(httpResp, "Error: session table is null");
120910
+            return;
120910
+        } else if (table.sessionExists(sessionId)) {
120910
             CMS.debug("TokenAuthentication: found session");
120910
             if (checkIP) {
120910
                 String hostname = table.getIP(sessionId);
120910
-- 
120910
1.8.3.1
120910
120910
120910
From 275d3b1ad88721e1a5a5bfd8b5013a14d3db2263 Mon Sep 17 00:00:00 2001
120910
From: Fraser Tweedale <ftweedal@redhat.com>
120910
Date: Tue, 10 Oct 2017 00:21:57 +1100
120910
Subject: [PATCH 3/5] TokenAuthentication: log error message on error
120910
120910
If a TokenAuthenticate response indicates failure (state != 0), log
120910
the error string in addition to the status code.
120910
120910
Part of: https://pagure.io/dogtagpki/issue/2557
120910
120910
Change-Id: I22ba44be109a06f33ae6015e62393a2ef575b6b2
120910
(cherry picked from commit 9eb354883c9d965bb271223bf870839bb756db26)
120910
(cherry picked from commit c9908785df9f22b1ca4f507c9f51bf904193a143)
120910
---
120910
 .../cms/src/com/netscape/cms/authentication/TokenAuthentication.java     | 1 +
120910
 1 file changed, 1 insertion(+)
120910
120910
diff --git a/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java b/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
120910
index ebda0b6..2aa32d4 100644
120910
--- a/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
120910
+++ b/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
120910
@@ -183,6 +183,7 @@ public class TokenAuthentication implements IAuthManager,
120910
                 CMS.debug("TokenAuthentication: status=" + status);
120910
                 if (!status.equals("0")) {
120910
                     String error = parser.getValue("Error");
120910
+                    CMS.debug("TokenAuthentication: error: " + error);
120910
                     throw new EBaseException(error);
120910
                 }
120910
 
120910
-- 
120910
1.8.3.1
120910
120910
120910
From 2a8f26e1169f8840a59f1707964d98b47619ca1c Mon Sep 17 00:00:00 2001
120910
From: Fraser Tweedale <ftweedal@redhat.com>
120910
Date: Wed, 11 Oct 2017 15:41:15 +1100
120910
Subject: [PATCH 4/5] Sleep after security domain login during configuration
120910
120910
Clone installation can fail due to security domain token
120910
authentication failure that arises because:
120910
120910
1. The security domain session gets created on the replica's CA
120910
   instance.
120910
120910
2. The "updateNumberRange" is performed against the subsystem being
120910
   cloned, and results in a token authentication request to the CA
120910
   subsystem on the same host.
120910
120910
3. LDAP replication lag means that the master does not yet see
120910
   the security domain session that was created on the replica.
120910
120910
To avoid this problem, introduce a small delay after logging into
120910
the security domain, to allow for replication to occur.  The delay
120910
is configurable and defaults to 5 seconds.
120910
120910
Fixes: https://pagure.io/dogtagpki/issue/2557
120910
Change-Id: Ib11c077518c40b3b16699c9170b61085f55a1913
120910
(cherry picked from commit fa2d731b6ce51c5db9fb0b004d586b8f3e1decd3)
120910
(cherry picked from commit 5fae20defb5e938a621fc40f92954eb7daba1c7b)
120910
---
120910
 .../netscape/certsrv/system/ConfigurationRequest.java   | 14 ++++++++++++++
120910
 .../org/dogtagpki/server/rest/SystemConfigService.java  | 17 ++++++++++++++++-
120910
 2 files changed, 30 insertions(+), 1 deletion(-)
120910
120910
diff --git a/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java b/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java
120910
index 26f45f0..03dbfa6 100644
120910
--- a/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java
120910
+++ b/base/common/src/com/netscape/certsrv/system/ConfigurationRequest.java
120910
@@ -244,6 +244,11 @@ public class ConfigurationRequest {
120910
     @XmlElement
120910
     protected String signingCertSerialNumber;
120910
 
120910
+    /** Seconds to sleep after logging into the Security Domain,
120910
+     * so that replication of the session data may complete. */
120910
+    @XmlElement
120910
+    protected Long securityDomainPostLoginSleepSeconds;
120910
+
120910
     public ConfigurationRequest() {
120910
         // required for JAXB
120910
     }
120910
@@ -974,6 +979,14 @@ public class ConfigurationRequest {
120910
         this.signingCertSerialNumber = signingCertSerialNumber;
120910
     }
120910
 
120910
+    public Long getSecurityDomainPostLoginSleepSeconds() {
120910
+        return securityDomainPostLoginSleepSeconds;
120910
+    }
120910
+
120910
+    public void setSecurityDomainPostLoginSleepSeconds(Long d) {
120910
+        securityDomainPostLoginSleepSeconds = d;
120910
+    }
120910
+
120910
     @Override
120910
     public String toString() {
120910
         return "ConfigurationRequest [pin=XXXX" +
120910
@@ -983,6 +996,7 @@ public class ConfigurationRequest {
120910
                ", securityDomainName=" + securityDomainName +
120910
                ", securityDomainUser=" + securityDomainUser +
120910
                ", securityDomainPassword=XXXX" +
120910
+               ", securityDomainPostLoginSleepSeconds=" + securityDomainPostLoginSleepSeconds +
120910
                ", isClone=" + isClone +
120910
                ", cloneUri=" + cloneUri +
120910
                ", subsystemName=" + subsystemName +
120910
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
120910
index afbb24a..9ffb6e3 100644
120910
--- a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
120910
+++ b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
120910
@@ -950,7 +950,22 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
120910
 
120910
         getInstallToken(data, host, port);
120910
 
120910
-        return getDomainXML(host, port);
120910
+        String domainXML = getDomainXML(host, port);
120910
+
120910
+        /* Sleep for a bit to allow security domain session to replicate
120910
+         * to other clones.  In the future we can use signed tokens
120910
+         * (ticket https://pagure.io/dogtagpki/issue/2831) but we need to
120910
+         * be mindful of working with older versions, too.
120910
+         *
120910
+         * The default sleep time is 5s.
120910
+         */
120910
+        Long d = data.getSecurityDomainPostLoginSleepSeconds();
120910
+        if (null == d || d <= 0)
120910
+            d = new Long(5);
120910
+        CMS.debug("Logged into security domain; sleeping for " + d + "s");
120910
+        Thread.sleep(d * 1000);
120910
+
120910
+        return domainXML;
120910
     }
120910
 
120910
     private String getDomainXML(String host, int port) {
120910
-- 
120910
1.8.3.1
120910
120910
120910
From 2cf5ab35f9fda67405b209ae46891232c38eb4f0 Mon Sep 17 00:00:00 2001
120910
From: Fraser Tweedale <ftweedal@redhat.com>
120910
Date: Wed, 11 Oct 2017 18:12:04 +1100
120910
Subject: [PATCH 5/5] pkispawn: make security domain login sleep duration
120910
 configurable
120910
120910
Add the pki_security_domain_post_login_sleep_seconds pkispawn
120910
config, so that the administrator may set a duration other than the
120910
default.
120910
120910
Part of: https://pagure.io/dogtagpki/issue/2557
120910
120910
Change-Id: I74f16ea15621773e0742f709adc87df559cb530a
120910
(cherry picked from commit 8c0a7eee3bbfe01b2d965dbe09e95221c5031c8b)
120910
(cherry picked from commit 32ec33f8e49d1085ac1b28657a8321547a6bf910)
120910
---
120910
 base/server/man/man8/pkispawn.8                       | 7 +++++++
120910
 base/server/python/pki/server/deployment/pkihelper.py | 7 +++++++
120910
 2 files changed, 14 insertions(+)
120910
120910
diff --git a/base/server/man/man8/pkispawn.8 b/base/server/man/man8/pkispawn.8
120910
index 002520a..1d4ae24 100644
120910
--- a/base/server/man/man8/pkispawn.8
120910
+++ b/base/server/man/man8/pkispawn.8
120910
@@ -956,6 +956,7 @@ pki_security_domain_password=\fISecret123\fP
120910
 pki_security_domain_hostname=<master_ca_hostname>
120910
 pki_security_domain_https_port=<master_ca_https_port>
120910
 pki_security_domain_user=caadmin
120910
+pki_security_domain_post_login_sleep_seconds=\fI5\fP
120910
 
120910
 [Tomcat]
120910
 pki_clone=True
120910
@@ -997,6 +998,12 @@ and the \fBpki_backup_password\fP is set.  The PKCS#12 file is then found under
120910
 be generated at any time post-installation using \fBPKCS12Export\fP.
120910
 
120910
 .PP
120910
+The \fBpki_security_domain_post_login_sleep_seconds\fP config specifies sleep
120910
+duration after logging into a security domain, to allow the security domain
120910
+session data to be replicated to subsystems on other hosts.  It is optional and
120910
+defaults to 5 seconds.
120910
+
120910
+.PP
120910
 An example invocation showing the export of the system certificates and keys,
120910
 copying the keys to the replica subsystem, and setting the relevant SELinux and
120910
 file permissions is shown below.  \fBpwfile\fP is a text file containing the
120910
diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py
120910
index cf2a748..9bb0dfc 100644
120910
--- a/base/server/python/pki/server/deployment/pkihelper.py
120910
+++ b/base/server/python/pki/server/deployment/pkihelper.py
120910
@@ -4045,6 +4045,13 @@ class ConfigClient:
120910
         if self.subordinate:
120910
             self.set_subca_security_domain(data)
120910
 
120910
+        try:
120910
+            d = int(self.mdict['pki_security_domain_post_login_sleep_seconds'])
120910
+            if d > 0:
120910
+                data.securityDomainPostLoginSleepSeconds = d
120910
+        except (KeyError, ValueError):
120910
+            pass
120910
+
120910
         # database
120910
         if self.subsystem != "RA":
120910
             self.set_database_parameters(data)
120910
-- 
120910
1.8.3.1
120910