This patch enables currently developed SOA serial autoincrement feature in
bind-dyndb-ldap. The patch may be updated if any assumptions about this feature
are changed (or somebody finds a bug).

---

SOA serial autoincrement is a requirement for major DNS features,
e.g. zone transfers or DNSSEC. Enable it by default in named.conf
both for new and upgraded installations. Name of the bind-dyndb-ldap
option is "serial_autoincrement".

>From now on, idnsSOAserial attribute also has to be put to
replication agreement exclude list as serial will be incremented
on each DNS server separately and won't be shared. Exclude list
has to be updated both for new replication agreements and the
current ones.

https://fedorahosted.org/freeipa/ticket/2554
>From 52f37bef0bc4c31919397026785818519f053a3e Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Thu, 28 Jun 2012 16:46:48 +0200
Subject: [PATCH] Enable SOA serial autoincrement

SOA serial autoincrement is a requirement for major DNS features,
e.g. zone transfers or DNSSEC. Enable it by default in named.conf
both for new and upgraded installations. Name of the bind-dyndb-ldap
option is "serial_autoincrement".

>From now on, idnsSOAserial attribute also has to be put to
replication agreement exclude list as serial will be incremented
on each DNS server separately and won't be shared. Exclude list
has to be updated both for new replication agreements and the
current ones.

https://fedorahosted.org/freeipa/ticket/2554
---
 install/share/bind.named.conf.template            |    1 +
 install/tools/ipa-dns-install                     |   10 +++-
 install/tools/ipa-server-install                  |   12 ++++-
 install/tools/ipa-upgradeconfig                   |   57 +++++++++++++++++++--
 install/tools/man/ipa-dns-install.1               |    5 +-
 install/tools/man/ipa-server-install.1            |    5 +-
 ipalib/plugins/dns.py                             |   11 +++-
 ipaserver/install/bindinstance.py                 |   11 ++--
 ipaserver/install/plugins/fix_replica_memberof.py |   47 ++++++++++-------
 ipaserver/install/replication.py                  |    2 +-
 10 files changed, 129 insertions(+), 32 deletions(-)

diff --git a/install/share/bind.named.conf.template b/install/share/bind.named.conf.template
index f133b089a9eb428e9ad76b66a3ff162b45e5a779..9fdd91319947f6cfd3034f8d2a4fe8bb60d1af77 100644
--- a/install/share/bind.named.conf.template
+++ b/install/share/bind.named.conf.template
@@ -46,4 +46,5 @@ dynamic-db "ipa" {
 	arg "sasl_user DNS/$FQDN";
 	arg "zone_refresh $ZONE_REFRESH";
 	arg "psearch $PERSISTENT_SEARCH";
+	arg "serial_autoincrement $SERIAL_AUTOINCREMENT";
 };
diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install
index 6e9b9989792aba6f7607348da4693cf605dc0b76..47bffdf8354fa509d64af0ba0e15d5880010e425 100755
--- a/install/tools/ipa-dns-install
+++ b/install/tools/ipa-dns-install
@@ -62,6 +62,9 @@ def parse_options():
                       default=0, type="int",
                       help="When set to non-zero the name server will use DNS zone "
                            "detection based on polling instead of a persistent search")
+    parser.add_option("--no-serial-autoincrement", dest="serial_autoincrement",
+                      default=True, action="store_false",
+                      help="Do not enable SOA serial autoincrement")
     parser.add_option("-U", "--unattended", dest="unattended", action="store_true",
                       default=False, help="unattended installation never prompts the user")
 
@@ -85,6 +88,10 @@ def parse_options():
     if options.zone_notif:
         print >>sys.stderr, "WARNING: --zone-notif option is deprecated and has no effect"
 
+    if options.serial_autoincrement and not options.persistent_search:
+        parser.error('persistent search feature is required for '
+                     'DNS SOA serial autoincrement')
+
     return safe_options, options
 
 def main():
@@ -224,7 +231,8 @@ def main():
     bind.setup(api.env.host, ip_address, api.env.realm, api.env.domain,
                dns_forwarders, conf_ntp, reverse_zone, zonemgr=options.zonemgr,
                zone_refresh=options.zone_refresh,
-               persistent_search=options.persistent_search)
+               persistent_search=options.persistent_search,
+               serial_autoincrement=options.serial_autoincrement)
     bind.create_instance()
 
     # Restart http instance to make sure that python-dns has the right resolver
diff --git a/install/tools/ipa-server-install b/install/tools/ipa-server-install
index 6dc02f684e0b6fc21f150eadef1c286f2a326233..2c409eacba18f809d8254876ecebafc27fe931b4 100755
--- a/install/tools/ipa-server-install
+++ b/install/tools/ipa-server-install
@@ -210,7 +210,10 @@ def parse_options():
                       default=False,
                       help="Do not use DNS for hostname lookup during installation")
     dns_group.add_option("--no-dns-sshfp", dest="create_sshfp", default=True, action="store_false",
-                      help="do not automatically create DNS SSHFP records")
+                      help="Do not automatically create DNS SSHFP records")
+    dns_group.add_option("--no-serial-autoincrement", dest="serial_autoincrement",
+                      default=True, action="store_false",
+                      help="Do not enable SOA serial autoincrement")
     parser.add_option_group(dns_group)
 
     uninstall_group = OptionGroup(parser, "uninstall options")
@@ -304,6 +307,10 @@ def parse_options():
     elif options.zone_refresh > 0:
         options.persistent_search = False   # mutually exclusive features
 
+    if options.serial_autoincrement and not options.persistent_search:
+        parser.error('persistent search feature is required for '
+                     'DNS SOA serial autoincrement')
+
     if options.zone_notif:
         print >>sys.stderr, "WARNING: --zone-notif option is deprecated and has no effect"
 
@@ -1036,7 +1043,8 @@ def main():
     bind.setup(host_name, ip_address, realm_name, domain_name, dns_forwarders,
                options.conf_ntp, reverse_zone, zonemgr=options.zonemgr,
                zone_refresh=options.zone_refresh,
-               persistent_search=options.persistent_search)
+               persistent_search=options.persistent_search,
+               serial_autoincrement=options.serial_autoincrement,)
     if options.setup_dns:
         api.Backend.ldap2.connect(bind_dn="cn=Directory Manager", bind_pw=dm_password)
 
diff --git a/install/tools/ipa-upgradeconfig b/install/tools/ipa-upgradeconfig
index bc8e6a249d96c9998e91c6037321aaa9c53ff00c..b665a6a3b2834906a2b3374676c17702285d325d 100644
--- a/install/tools/ipa-upgradeconfig
+++ b/install/tools/ipa-upgradeconfig
@@ -282,7 +282,7 @@ def upgrade_httpd_selinux(fstore):
     http = httpinstance.HTTPInstance(fstore)
     http.configure_selinux_for_httpd()
 
-def enable_psearch_for_named():
+def named_enable_psearch():
     """
     From IPA 3.0, persistent search is a preferred mechanism for new DNS zone
     detection and is also needed for other features (DNSSEC, SOA serial
@@ -353,6 +353,55 @@ def enable_psearch_for_named():
         root_logger.debug('No changes made')
     return changed
 
+def named_enable_serial_autoincrement():
+    """
+    Serial autoincrement is a requirement for zone transfers or DNSSEC. It
+    should be enabled both for new installs and upgraded servers.
+
+    When some change in named.conf is done, this functions returns True
+    """
+    changed = False
+
+    root_logger.info('[Enabling serial autoincrement in DNS]')
+
+    if not bindinstance.named_conf_exists():
+        # DNS service may not be configured
+        root_logger.debug('DNS not configured')
+        return changed
+
+    try:
+        psearch = bindinstance.named_conf_get_directive('psearch').lower()
+        serial_autoincrement = bindinstance.named_conf_get_directive(
+                                    'serial_autoincrement').lower()
+    except IOError, e:
+        root_logger.debug('Cannot retrieve psearch option from %s: %s',
+                bindinstance.NAMED_CONF, e)
+        return changed
+
+    # enable SOA serial autoincrement
+    if not sysupgrade.get_upgrade_state('named.conf', 'autoincrement_enabled'):
+        if psearch != "yes":    # psearch is required
+            root_logger.debug('Persistent search is disabled, '
+                    'serial autoincrement cannot be enabled')
+        else:
+            if serial_autoincrement != 'yes':
+                try:
+                    bindinstance.named_conf_set_directive('serial_autoincrement', 'yes')
+                except IOError, e:
+                    root_logger.error('Cannot enable serial_autoincrement in %s: %s',
+                            bindinstance.NAMED_CONF, e)
+                    return changed
+                else:
+                    root_logger.debug('Serial autoincrement enabled')
+                    changed = True
+            else:
+                root_logger.debug('Serial autoincrement is alredy enabled')
+        sysupgrade.set_upgrade_state('named.conf', 'autoincrement_enabled', True)
+    else:
+        root_logger.debug('Skip serial autoincrement check')
+
+    return changed
+
 def main():
     """
     Get some basics about the system. If getting those basics fail then
@@ -414,9 +463,11 @@ def main():
 
     cleanup_kdc(fstore)
     upgrade_ipa_profile(krbctx.default_realm)
-    changed = enable_psearch_for_named()
-    if changed:
+    changed_psearch = named_enable_psearch()
+    changed_autoincrement = named_enable_serial_autoincrement()
+    if changed_psearch or changed_autoincrement:
         # configuration has changed, restart the name server
+        root_logger.info('Changes to named.conf have been made, restart named')
         bindinstance.BindInstance(fstore).restart()
 
 if __name__ == '__main__':
diff --git a/install/tools/man/ipa-dns-install.1 b/install/tools/man/ipa-dns-install.1
index 9fe89ed1ea267cde7216e9e28e95cfea2349172b..b0bdca94f4aea4a17fecc3362a92a9885bbafed0 100644
--- a/install/tools/man/ipa-dns-install.1
+++ b/install/tools/man/ipa-dns-install.1
@@ -16,7 +16,7 @@
 .\"
 .\" Author: Rob Crittenden <rcrit...@redhat.com>
 .\"
-.TH "ipa-dns-install" "1" "Sep 9, 2010" "FreeIPA" "FreeIPA Manual Pages"
+.TH "ipa-dns-install" "1" "Jun 28, 2012" "FreeIPA" "FreeIPA Manual Pages"
 .SH "NAME"
 ipa\-dns\-install \- Add DNS as a service to an IPA server
 .SH "SYNOPSIS"
@@ -55,6 +55,9 @@ Do not enable persistent search mechanism for updating the list of DNS zones in
 \fB\-\-zone\-refresh=\fIZONE_REFRESH\fR
 When set to non-zero value, persistent search zone update mechanism will be disabled and the name server will use a polling mechanism to load new DNS zones every \fIZONE_REFRESH\fR seconds.
 .TP
+\fB\-\-no\-serial\-autoincrement\fR
+Do not enable SOA serial autoincrement feature. SOA serial will have to be updated automatically or other DNS features like zone transfer od DNSSEC will not function properly. This feature requires persistent search zone update mechanism.
+.TP
 \fB\-U\fR, \fB\-\-unattended\fR
 An unattended installation that will never prompt for user input
 .SH "EXIT STATUS"
diff --git a/install/tools/man/ipa-server-install.1 b/install/tools/man/ipa-server-install.1
index 77d40685059fe74bed8d0693c38d2904909c01f3..61b7c669ca26d5fecbdbd9e30fccad4c1d4d9701 100644
--- a/install/tools/man/ipa-server-install.1
+++ b/install/tools/man/ipa-server-install.1
@@ -16,7 +16,7 @@
 .\"
 .\" Author: Rob Crittenden <rcrit...@redhat.com>
 .\"
-.TH "ipa-server-install" "1" "Sep 5 2011" "FreeIPA" "FreeIPA Manual Pages"
+.TH "ipa-server-install" "1" "Jun 28 2012" "FreeIPA" "FreeIPA Manual Pages"
 .SH "NAME"
 ipa\-server\-install \- Configure an IPA server
 .SH "SYNOPSIS"
@@ -156,6 +156,9 @@ Do not use DNS for hostname lookup during installation
 .TP
 \fB\-\-no\-dns\-sshfp\fR
 Do not automatically create DNS SSHFP records.
+.TP
+\fB\-\-no\-serial\-autoincrement\fR
+Do not enable SOA serial autoincrement feature. SOA serial will have to be updated automatically or other DNS features like zone transfer od DNSSEC will not function properly. This feature requires persistent search zone update mechanism.
 
 .SS "UNINSTALL OPTIONS"
 .TP
diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
index c2bf13a2ff5e1c05cb21d07ce9d63e9881ef0da2..857814917f9ce75886aee571885a3dd718427ef3 100644
--- a/ipalib/plugins/dns.py
+++ b/ipalib/plugins/dns.py
@@ -244,8 +244,15 @@ def _rname_validator(ugettext, zonemgr):
     return None
 
 def _create_zone_serial():
-    """ Generate serial number for zones. The format follows RFC 1912 """
-    return int('%s01' % time.strftime('%Y%m%d'))
+    """
+    Generate serial number for zones. bind-dyndb-ldap expects unix time in
+    to be used for SOA serial.
+
+    SOA serial in a date format would also work, but it may be set to far
+    future when many DNS updates are done per day (more than 100). Unix
+    timestamp is more resilient to this issue.
+    """
+    return int(time.time())
 
 def _reverse_zone_name(netstr):
     net = netaddr.IPNetwork(netstr)
diff --git a/ipaserver/install/bindinstance.py b/ipaserver/install/bindinstance.py
index 3ff593298979534cad79fa35f2626991db82cec7..9faf17698d3cb806ed601f728c3870bfe28c9424 100644
--- a/ipaserver/install/bindinstance.py
+++ b/ipaserver/install/bindinstance.py
@@ -467,7 +467,7 @@ class BindInstance(service.Service):
 
     def setup(self, fqdn, ip_address, realm_name, domain_name, forwarders, ntp,
               reverse_zone, named_user="named", zonemgr=None,
-              zone_refresh=0, persistent_search=True):
+              zone_refresh=0, persistent_search=True, serial_autoincrement=True):
         self.named_user = named_user
         self.fqdn = fqdn
         self.ip_address = ip_address
@@ -480,6 +480,7 @@ class BindInstance(service.Service):
         self.reverse_zone = reverse_zone
         self.zone_refresh = zone_refresh
         self.persistent_search = persistent_search
+        self.serial_autoincrement = True
 
         if not zonemgr:
             self.zonemgr = 'hostmaster.%s' % self.domain
@@ -576,7 +577,10 @@ class BindInstance(service.Service):
             optional_ntp += "_ntp._udp\t\tIN SRV 0 100 123\t%s""" % self.host_in_rr
         else:
             optional_ntp = ""
-        persistent_search = "yes" if self.persistent_search else "no"
+
+        boolean_var = {}
+        for var in ('persistent_search', 'serial_autoincrement'):
+            boolean_var[var] = "yes" if getattr(self, var, False) else "no"
 
         self.sub_dict = dict(FQDN=self.fqdn,
                              IP=self.ip_address,
@@ -589,7 +593,8 @@ class BindInstance(service.Service):
                              OPTIONAL_NTP=optional_ntp,
                              ZONEMGR=self.zonemgr,
                              ZONE_REFRESH=self.zone_refresh,
-                             PERSISTENT_SEARCH=persistent_search)
+                             PERSISTENT_SEARCH=boolean_var['persistent_search'],
+                             SERIAL_AUTOINCREMENT=boolean_var['serial_autoincrement'],)
 
     def __setup_dns_container(self):
         self._ldap_mod("dns.ldif", self.sub_dict)
diff --git a/ipaserver/install/plugins/fix_replica_memberof.py b/ipaserver/install/plugins/fix_replica_memberof.py
index 04152d36021f7d962b335a7553861a13ba03a769..b72b8fe3b92ef8e8bf3172cf3f509675a1c428a0 100644
--- a/ipaserver/install/plugins/fix_replica_memberof.py
+++ b/ipaserver/install/plugins/fix_replica_memberof.py
@@ -25,10 +25,11 @@ from ipaserver import ipaldap
 from ipaserver.install import replication
 from ipalib import api
 
-class update_replica_memberof(PreUpdate):
+class update_replica_exclude_attribute_list(PreUpdate):
     """
-    Run through all replication agreements and ensure that memberOf is
-    included in the EXCLUDE list so we don't cause replication storms.
+    Run through all replication agreements and ensure that EXCLUDE list
+    has all the required attributes so that we don't cause replication
+    storms.
     """
     order=MIDDLE
 
@@ -37,16 +38,22 @@ class update_replica_memberof(PreUpdate):
                          'krblastsuccessfulauth',
                          'krblastfailedauth',
                          'krbloginfailedcount')
-        excludes = ('memberof', ) + totalexcludes
+        # Excluded attributes:
+        #  - memberOf: this attribute is generated by memberof plugin on each
+        #       replica
+        #  - idnsSOAserial: the value is auto incremented by bind-dyndb-ldap
+        #       plugin on each DNS server separately
+        excludes = ('memberof', 'idnssoaserial') + totalexcludes
 
         # We need an IPAdmin connection to the backend
+        self.log.debug("Start replication agreement exclude list update task")
         conn = ipaldap.IPAdmin(api.env.host, ldapi=True, realm=api.env.realm)
         conn.do_external_bind(pwd.getpwuid(os.geteuid()).pw_name)
 
         repl = replication.ReplicationManager(api.env.realm, api.env.host,
                                               None, conn=conn)
         entries = repl.find_replication_agreements()
-        self.log.debug("Found %d agreement(s)" % len(entries))
+        self.log.debug("Found %d agreement(s)", len(entries))
         for replica in entries:
             self.log.debug(replica.description)
             attrlist = replica.getValue('nsDS5ReplicatedAttributeList')
@@ -62,21 +69,25 @@ class update_replica_memberof(PreUpdate):
                     repl.conn.updateEntry(replica.dn, current, replica.toDict())
                     self.log.debug("Updated")
                 except Exception, e:
-                    self.log.error("Error caught updating replica: %s" % str(e))
-            elif 'memberof' not in attrlist.lower():
-                self.log.debug("Attribute list needs updating")
-                current = replica.toDict()
-                replica.setValue('nsDS5ReplicatedAttributeList',
-                    replica.nsDS5ReplicatedAttributeList + ' memberof')
-                try:
-                    repl.conn.updateEntry(replica.dn, current, replica.toDict())
-                    self.log.debug("Updated")
-                except Exception, e:
-                    self.log.error("Error caught updating replica: %s" % str(e))
+                    self.log.error("Error caught updating replica: %s", str(e))
             else:
-                self.log.debug("No update necessary")
+                attrlist_normalized = attrlist.lower()
+                missing = [attr for attr in excludes if attr not in attrlist_normalized]
+
+                if missing:
+                    self.log.debug("Attribute list needs updating")
+                    current = replica.toDict()
+                    replica.setValue('nsDS5ReplicatedAttributeList',
+                        replica.nsDS5ReplicatedAttributeList + ' %s' % ' '.join(missing))
+                    try:
+                        repl.conn.updateEntry(replica.dn, current, replica.toDict())
+                        self.log.debug("Updated")
+                    except Exception, e:
+                        self.log.error("Error caught updating replica: %s", str(e))
+                else:
+                    self.log.debug("No update necessary")
         self.log.debug("Done updating agreements")
 
         return (False, False, []) # No restart, no apply now, no updates
 
-api.register(update_replica_memberof)
+api.register(update_replica_exclude_attribute_list)
diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py
index 03758dfcbe302e1d437293f544677fca93e3b21f..b1941a122782f1773056663584e61fa2c2eb350e 100644
--- a/ipaserver/install/replication.py
+++ b/ipaserver/install/replication.py
@@ -476,7 +476,7 @@ class ReplicationManager(object):
                          'krbloginfailedcount')
 
         # List of attributes that need to be excluded from normal replication.
-        excludes = ('memberof', ) + totalexcludes
+        excludes = ('memberof', 'idnssoaserial') + totalexcludes
 
         entry = ipaldap.Entry(dn)
         entry.setValues('objectclass', "nsds5replicationagreement")
-- 
1.7.10.2

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to