3f51ca
From a3bcb05ce1c554aa98af9343bec7335521db3a3e Mon Sep 17 00:00:00 2001
3f51ca
From: Alexander Bokovoy <abokovoy@redhat.com>
3f51ca
Date: Mon, 16 Oct 2017 13:32:38 +0300
3f51ca
Subject: [PATCH] ds: ignore time skew during initial replication step
3f51ca
3f51ca
Initial replica creation can go with ignoring time skew checks.
3f51ca
We should, however, force time skew checks during normal operation.
3f51ca
3f51ca
Fixes https://pagure.io/freeipa/issue/7211
3f51ca
3f51ca
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
3f51ca
---
3f51ca
 install/share/Makefile.am                    |  1 +
3f51ca
 install/share/replica-prevent-time-skew.ldif |  4 ++++
3f51ca
 ipaserver/install/dsinstance.py              | 24 ++++++++++++++++++++++++
3f51ca
 3 files changed, 29 insertions(+)
3f51ca
 create mode 100644 install/share/replica-prevent-time-skew.ldif
3f51ca
3f51ca
diff --git a/install/share/Makefile.am b/install/share/Makefile.am
3f51ca
index 85a061c6976dcc55b0ba2250423a344e14f2ce97..46b3d77663113f770765c8bd1d8a916791d628f4 100644
3f51ca
--- a/install/share/Makefile.am
3f51ca
+++ b/install/share/Makefile.am
3f51ca
@@ -38,6 +38,7 @@ dist_app_DATA =				\
3f51ca
 	default-trust-view.ldif		\
3f51ca
 	delegation.ldif			\
3f51ca
 	replica-acis.ldif		\
3f51ca
+	replica-prevent-time-skew.ldif  \
3f51ca
 	ds-nfiles.ldif			\
3f51ca
 	dns.ldif			\
3f51ca
 	dnssec.ldif			\
3f51ca
diff --git a/install/share/replica-prevent-time-skew.ldif b/install/share/replica-prevent-time-skew.ldif
3f51ca
new file mode 100644
3f51ca
index 0000000000000000000000000000000000000000..5d301feddb56347f3b35be89edaae1a7d91e07de
3f51ca
--- /dev/null
3f51ca
+++ b/install/share/replica-prevent-time-skew.ldif
3f51ca
@@ -0,0 +1,4 @@
3f51ca
+dn: cn=config
3f51ca
+changetype: modify
3f51ca
+replace: nsslapd-ignore-time-skew
3f51ca
+nsslapd-ignore-time-skew: $SKEWVALUE
3f51ca
diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py
3f51ca
index c9db8ac28c3ca10539b745ca09f4d8aaece02e0c..7a88612997a3fa96cf394852401fb01e5e4501d5 100644
3f51ca
--- a/ipaserver/install/dsinstance.py
3f51ca
+++ b/ipaserver/install/dsinstance.py
3f51ca
@@ -392,7 +392,21 @@ class DsInstance(service.Service):
3f51ca
         self.step("restarting directory server", self.__restart_instance)
3f51ca
 
3f51ca
         self.step("creating DS keytab", self.request_service_keytab)
3f51ca
+
3f51ca
+        # 389-ds allows to ignore time skew during replication. It is disabled
3f51ca
+        # by default to avoid issues with non-contiguous CSN values which
3f51ca
+        # derived from a time stamp when the change occurs. However, there are
3f51ca
+        # cases when we are interested only in the changes coming from the
3f51ca
+        # other side and should therefore allow ignoring the time skew.
3f51ca
+        #
3f51ca
+        # This helps with initial replication or force-sync because
3f51ca
+        # the receiving side has no valuable changes itself yet.
3f51ca
+        self.step("ignore time skew for initial replication",
3f51ca
+                  self.__replica_ignore_initial_time_skew)
3f51ca
+
3f51ca
         self.step("setting up initial replication", self.__setup_replica)
3f51ca
+        self.step("prevent time skew after initial replication",
3f51ca
+                  self.replica_manage_time_skew)
3f51ca
         self.step("adding sasl mappings to the directory", self.__configure_sasl_mappings)
3f51ca
         self.step("updating schema", self.__update_schema)
3f51ca
         # See LDIFs for automember configuration during replica install
3f51ca
@@ -929,6 +943,16 @@ class DsInstance(service.Service):
3f51ca
     def __add_replication_acis(self):
3f51ca
         self._ldap_mod("replica-acis.ldif", self.sub_dict)
3f51ca
 
3f51ca
+    def __replica_ignore_initial_time_skew(self):
3f51ca
+        self.replica_manage_time_skew(prevent=False)
3f51ca
+
3f51ca
+    def replica_manage_time_skew(self, prevent=True):
3f51ca
+        if prevent:
3f51ca
+            self.sub_dict['SKEWVALUE'] = 'off'
3f51ca
+        else:
3f51ca
+            self.sub_dict['SKEWVALUE'] = 'on'
3f51ca
+        self._ldap_mod("replica-prevent-time-skew.ldif", self.sub_dict)
3f51ca
+
3f51ca
     def __setup_s4u2proxy(self):
3f51ca
         self._ldap_mod("replica-s4u2proxy.ldif", self.sub_dict)
3f51ca
 
3f51ca
-- 
3f51ca
2.9.5
3f51ca