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