9ad913
From 0ed1632ac9f659734f9397c21d0b2de3c2c2d895 Mon Sep 17 00:00:00 2001
9ad913
From: Florence Blanc-Renaud <flo@redhat.com>
9ad913
Date: Tue, 15 Jan 2019 17:53:55 +0100
9ad913
Subject: [PATCH] replica installation: add master record only if in managed
9ad913
 zone
9ad913
9ad913
Scenario: install a replica with DNS, whose IP address is part of a
9ad913
forward zone.
9ad913
Currently, the replica installation fails because the installer is
9ad913
trying to add a A/AAAA record for the replica in the zone
9ad913
when setting up the bind instance, and addition of records in a
9ad913
forward zone is forbidden.
9ad913
9ad913
The bind installer should check if the IP address is in a master zone
9ad913
(i.e. a DNS zone managed by IdM, not a forward zone), and avoid
9ad913
creating the record if it's not the case.
9ad913
9ad913
During uninstallation, perform the same check before removing the
9ad913
DNS record (if in a forward zone, no need to call dnsrecord-del).
9ad913
Fixes: https://pagure.io/freeipa/issue/7369
9ad913
Reviewed-By: Francois Cami <fcami@redhat.com>
9ad913
Reviewed-By: Christian Heimes <cheimes@redhat.com>
9ad913
---
9ad913
 ipaserver/install/bindinstance.py | 13 ++++++++++---
9ad913
 1 file changed, 10 insertions(+), 3 deletions(-)
9ad913
9ad913
diff --git a/ipaserver/install/bindinstance.py b/ipaserver/install/bindinstance.py
9ad913
index 7c858aab4417ccf3a4999fcaaa1c7e0f93464e4d..3b03e536117677f0f073fc1f06a28ebab0cfe006 100644
9ad913
--- a/ipaserver/install/bindinstance.py
9ad913
+++ b/ipaserver/install/bindinstance.py
9ad913
@@ -844,10 +844,13 @@ class BindInstance(service.Service):
9ad913
 
9ad913
         # Add forward and reverse records to self
9ad913
         for addr in addrs:
9ad913
-            try:
9ad913
+            # Check first if the zone is a master zone
9ad913
+            # (if it is a forward zone, dns_zone_exists will return False)
9ad913
+            if dns_zone_exists(zone, api=self.api):
9ad913
                 add_fwd_rr(zone, host, addr, self.api)
9ad913
-            except errors.NotFound:
9ad913
-                pass
9ad913
+            else:
9ad913
+                logger.debug("Skip adding record %s to a zone %s "
9ad913
+                             "not managed by IPA", addr, zone)
9ad913
 
9ad913
             reverse_zone = find_reverse_zone(addr, self.api)
9ad913
             if reverse_zone:
9ad913
@@ -1063,6 +1066,10 @@ class BindInstance(service.Service):
9ad913
         self.fqdn = fqdn
9ad913
         self.domain = domain_name
9ad913
 
9ad913
+        if not dns_zone_exists(zone, api=self.api):
9ad913
+            # Zone may be a forward zone, skip update
9ad913
+            return
9ad913
+
9ad913
         areclist = get_fwd_rr(zone, host, api=self.api)
9ad913
         for rdata in areclist:
9ad913
             del_fwd_rr(zone, host, rdata, api=self.api)
9ad913
-- 
9ad913
2.20.1
9ad913