b39a24
From 4fdab0c94c4e17e42e5f38a0e671bea39bcc9b74 Mon Sep 17 00:00:00 2001
b39a24
From: Anuja More <amore@redhat.com>
b39a24
Date: Mon, 9 Aug 2021 20:57:22 +0530
b39a24
Subject: [PATCH] ipatests: Test unsecure nsupdate.
b39a24
b39a24
The test configures an external bind server on the ipa-server
b39a24
(not the IPA-embedded DNS server) that allows unauthenticated nsupdates.
b39a24
b39a24
When the IPA client is registered using ipa-client-install,
b39a24
DNS records are added for the client in the bind server using nsupdate.
b39a24
The first try is using GSS-TIG but fails as expected, and the client
b39a24
installer then tries with unauthenticated nsupdate.
b39a24
b39a24
Related : https://pagure.io/freeipa/issue/8402
b39a24
b39a24
Signed-off-by: Anuja More <amore@redhat.com>
b39a24
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
b39a24
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
b39a24
---
b39a24
 .../test_installation_client.py               | 118 ++++++++++++++++++
b39a24
 1 file changed, 118 insertions(+)
b39a24
b39a24
diff --git a/ipatests/test_integration/test_installation_client.py b/ipatests/test_integration/test_installation_client.py
b39a24
index fa59a5255..014b0f6ab 100644
b39a24
--- a/ipatests/test_integration/test_installation_client.py
b39a24
+++ b/ipatests/test_integration/test_installation_client.py
b39a24
@@ -8,10 +8,15 @@ Module provides tests for various options of ipa-client-install.
b39a24
 
b39a24
 from __future__ import absolute_import
b39a24
 
b39a24
+import pytest
b39a24
+import re
b39a24
 import shlex
b39a24
+import textwrap
b39a24
 
b39a24
+from ipaplatform.paths import paths
b39a24
 from ipatests.test_integration.base import IntegrationTest
b39a24
 from ipatests.pytest_ipa.integration import tasks
b39a24
+from ipatests.pytest_ipa.integration.firewall import Firewall
b39a24
 
b39a24
 
b39a24
 class TestInstallClient(IntegrationTest):
b39a24
@@ -70,3 +75,116 @@ class TestInstallClient(IntegrationTest):
b39a24
                              extra_args=['--ssh-trust-dns'])
b39a24
         result = self.clients[0].run_command(['cat', '/etc/ssh/ssh_config'])
b39a24
         assert 'HostKeyAlgorithms' not in result.stdout_text
b39a24
+
b39a24
+
b39a24
+class TestClientInstallBind(IntegrationTest):
b39a24
+    """
b39a24
+    The test configures an external bind server on the ipa-server
b39a24
+    (not the IPA-embedded DNS server) that allows unauthenticated nsupdates.
b39a24
+    When the IPA client is registered using ipa-client-install,
b39a24
+    DNS records are added for the client in the bind server using nsupdate.
b39a24
+    The first try is using GSS-TIG but fails as expected, and the client
b39a24
+    installer then tries with unauthenticated nsupdate.
b39a24
+    """
b39a24
+
b39a24
+    num_clients = 1
b39a24
+
b39a24
+    @classmethod
b39a24
+    def install(cls, mh):
b39a24
+        cls.client = cls.clients[0]
b39a24
+
b39a24
+    @pytest.fixture
b39a24
+    def setup_bindserver(self):
b39a24
+        bindserver = self.master
b39a24
+        named_conf_backup = tasks.FileBackup(self.master, paths.NAMED_CONF)
b39a24
+        # create a zone in the BIND server that is identical to the IPA
b39a24
+        add_zone = textwrap.dedent("""
b39a24
+        zone "{domain}" IN {{ type master;
b39a24
+        file "{domain}.db"; allow-query {{ any; }};
b39a24
+        allow-update {{ any; }}; }};
b39a24
+        """).format(domain=bindserver.domain.name)
b39a24
+
b39a24
+        namedcfg = bindserver.get_file_contents(
b39a24
+            paths.NAMED_CONF, encoding='utf-8')
b39a24
+        namedcfg += '\n' + add_zone
b39a24
+        bindserver.put_file_contents(paths.NAMED_CONF, namedcfg)
b39a24
+
b39a24
+        def update_contents(path, pattern, replace):
b39a24
+            contents = bindserver.get_file_contents(path, encoding='utf-8')
b39a24
+            namedcfg_query = re.sub(pattern, replace, contents)
b39a24
+            bindserver.put_file_contents(path, namedcfg_query)
b39a24
+
b39a24
+        update_contents(paths.NAMED_CONF, 'localhost;', 'any;')
b39a24
+        update_contents(paths.NAMED_CONF, "listen-on port 53 { 127.0.0.1; };",
b39a24
+                        "#listen-on port 53 { 127.0.0.1; };")
b39a24
+        update_contents(paths.NAMED_CONF, "listen-on-v6 port 53 { ::1; };",
b39a24
+                        "#listen-on-v6 port 53 { ::1; };")
b39a24
+
b39a24
+        add_records = textwrap.dedent("""
b39a24
+        @   IN  SOA     {fqdn}. root.{domain}. (
b39a24
+        1001    ;Serial
b39a24
+        3H      ;Refresh
b39a24
+        15M     ;Retry
b39a24
+        1W      ;Expire
b39a24
+        1D      ;Minimum 1D
b39a24
+        )
b39a24
+        @      IN  NS      {fqdn}.
b39a24
+        ns1 IN  A       {bindserverip}
b39a24
+        _kerberos.{domain}. IN TXT {zoneupper}
b39a24
+        {fqdn}.    IN  A       {bindserverip}
b39a24
+        ipa-ca.{domain}.        IN  A       {bindserverip}
b39a24
+        _kerberos-master._tcp.{domain}. IN SRV 0 100 88 {fqdn}.
b39a24
+        _kerberos-master._udp.{domain}. IN SRV 0 100 88 {fqdn}.
b39a24
+        _kerberos._tcp.{domain}. 	IN SRV 0 100 88 {fqdn}.
b39a24
+        _kerberos._udp.{domain}. 	IN SRV 0 100 88 {fqdn}.
b39a24
+        _kpasswd._tcp.{domain}. 	IN SRV 0 100 464 {fqdn}.
b39a24
+        _kpasswd._udp.{domain}. 	IN SRV 0 100 464 {fqdn}.
b39a24
+        _ldap._tcp.{domain}. 		IN SRV 0 100 389 {fqdn}.
b39a24
+        """).format(
b39a24
+            fqdn=bindserver.hostname,
b39a24
+            domain=bindserver.domain.name,
b39a24
+            bindserverip=bindserver.ip,
b39a24
+            zoneupper=bindserver.domain.name.upper()
b39a24
+        )
b39a24
+        bindserverdb = "/var/named/{0}.db".format(bindserver.domain.name)
b39a24
+        bindserver.put_file_contents(bindserverdb, add_records)
b39a24
+        bindserver.run_command(['systemctl', 'start', 'named'])
b39a24
+        Firewall(bindserver).enable_services(["dns"])
b39a24
+        yield
b39a24
+        named_conf_backup.restore()
b39a24
+        bindserver.run_command(['rm', '-rf', bindserverdb])
b39a24
+
b39a24
+    def test_client_nsupdate(self, setup_bindserver):
b39a24
+        """Test secure nsupdate failed, then try unsecure nsupdate..
b39a24
+
b39a24
+        Test to verify when bind is configured with dynamic update policy,
b39a24
+        and during client-install 'nsupdate -g' fails then it should run with
b39a24
+        second call using unauthenticated nsupdate.
b39a24
+
b39a24
+        Related : https://pagure.io/freeipa/issue/8402
b39a24
+        """
b39a24
+        # with pre-configured bind server, install ipa-server without dns.
b39a24
+        tasks.install_master(self.master, setup_dns=False)
b39a24
+        self.client.resolver.backup()
b39a24
+        self.client.resolver.setup_resolver(
b39a24
+            self.master.ip, self.master.domain.name)
b39a24
+        try:
b39a24
+            self.client.run_command(['ipa-client-install', '-U',
b39a24
+                                     '--domain', self.client.domain.name,
b39a24
+                                     '--realm', self.client.domain.realm,
b39a24
+                                     '-p', self.client.config.admin_name,
b39a24
+                                     '-w', self.client.config.admin_password,
b39a24
+                                     '--server', self.master.hostname])
b39a24
+            # call unauthenticated nsupdate if GSS-TSIG nsupdate failed.
b39a24
+            str1 = "nsupdate (GSS-TSIG) failed"
b39a24
+            str2 = "'/usr/bin/nsupdate', '/etc/ipa/.dns_update.txt'"
b39a24
+            client_log = self.client.get_file_contents(
b39a24
+                paths.IPACLIENT_INSTALL_LOG, encoding='utf-8'
b39a24
+            )
b39a24
+            assert str1 in client_log and str2 in client_log
b39a24
+            dig_after = self.client.run_command(
b39a24
+                ['dig', '@{0}'.format(self.master.ip), self.client.hostname,
b39a24
+                 '-t', 'SSHFP'])
b39a24
+            assert "ANSWER: 0" not in dig_after.stdout_text.strip()
b39a24
+        finally:
b39a24
+            self.client.resolver.restore()
b39a24
-- 
b39a24
2.31.1
b39a24