Blame SOURCES/0006-ipa-kdb-PAC-consistency-checker-needs-to-handle-child-domains-as-well_rhbz#2166324.patch

5347ee
From 2a0868fccbc9f4dfc540a7d3bb5dfa22c0bdce4e Mon Sep 17 00:00:00 2001
5347ee
From: Alexander Bokovoy <abokovoy@redhat.com>
5347ee
Date: Mon, 30 Jan 2023 14:22:30 +0200
5347ee
Subject: [PATCH 1/2] ipa-kdb: PAC consistency checker needs to handle child
5347ee
 domains as well
5347ee
5347ee
When PAC check is performed, we might get a signing TGT instead of the
5347ee
client DB entry. This means it is a principal from a trusted domain but
5347ee
we don't know which one exactly because we only have a krbtgt for the
5347ee
forest root. This happens in MIT Kerberos 1.20 or later where KDB's
5347ee
issue_pac() callback never gets the original client principal directly.
5347ee
5347ee
Look into known child domains as well and make pass the check if both
5347ee
NetBIOS name and SID correspond to one of the trusted domains under this
5347ee
forest root. Move check for the SID before NetBIOS name check because we
5347ee
can use SID of the domain in PAC to find out the right child domain in
5347ee
our trusted domains' topology list.
5347ee
5347ee
Fixes: https://pagure.io/freeipa/issue/9316
5347ee
5347ee
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
5347ee
---
5347ee
 daemons/ipa-kdb/ipa_kdb_mspac.c | 51 +++++++++++++++++++++------------
5347ee
 1 file changed, 32 insertions(+), 19 deletions(-)
5347ee
5347ee
diff --git a/daemons/ipa-kdb/ipa_kdb_mspac.c b/daemons/ipa-kdb/ipa_kdb_mspac.c
5347ee
index a15050e2166..476d1cb558a 100644
5347ee
--- a/daemons/ipa-kdb/ipa_kdb_mspac.c
5347ee
+++ b/daemons/ipa-kdb/ipa_kdb_mspac.c
5347ee
@@ -1827,11 +1827,43 @@ krb5_error_code filter_logon_info(krb5_context context,
5347ee
     bool result;
5347ee
     char *domstr = NULL;
5347ee
 
5347ee
+    ipactx = ipadb_get_context(context);
5347ee
+    if (!ipactx || !ipactx->mspac) {
5347ee
+        return KRB5_KDB_DBNOTINITED;
5347ee
+    }
5347ee
+
5347ee
     domain = get_domain_from_realm_update(context, realm);
5347ee
     if (!domain) {
5347ee
         return EINVAL;
5347ee
     }
5347ee
 
5347ee
+    /* check exact sid */
5347ee
+    result = dom_sid_check(&domain->domsid, info->info->info3.base.domain_sid, true);
5347ee
+    if (!result) {
5347ee
+        struct ipadb_mspac *mspac_ctx = ipactx->mspac;
5347ee
+        result = FALSE;
5347ee
+        /* Didn't match but perhaps the original PAC was issued by a child domain's DC? */
5347ee
+        for (k = 0; k < mspac_ctx->num_trusts; k++) {
5347ee
+            result = dom_sid_check(&mspac_ctx->trusts[k].domsid,
5347ee
+                             info->info->info3.base.domain_sid, true);
5347ee
+            if (result) {
5347ee
+                domain = &mspac_ctx->trusts[k];
5347ee
+                break;
5347ee
+            }
5347ee
+        }
5347ee
+        if (!result) {
5347ee
+            domstr = dom_sid_string(NULL, info->info->info3.base.domain_sid);
5347ee
+            krb5_klog_syslog(LOG_ERR, "PAC Info mismatch: domain = %s, "
5347ee
+                                      "expected domain SID = %s, "
5347ee
+                                      "found domain SID = %s",
5347ee
+                                      domain->domain_name, domain->domain_sid,
5347ee
+                                      domstr ? domstr : "<failed to display>");
5347ee
+            talloc_free(domstr);
5347ee
+            return EINVAL;
5347ee
+        }
5347ee
+    }
5347ee
+
5347ee
+    /* At this point we may have changed the domain we look at, */
5347ee
     /* check netbios/flat name */
5347ee
     if (strcasecmp(info->info->info3.base.logon_domain.string,
5347ee
                    domain->flat_name) != 0) {
5347ee
@@ -1843,21 +1875,6 @@ krb5_error_code filter_logon_info(krb5_context context,
5347ee
         return EINVAL;
5347ee
     }
5347ee
 
5347ee
-    /* check exact sid */
5347ee
-    result = dom_sid_check(&domain->domsid, info->info->info3.base.domain_sid, true);
5347ee
-    if (!result) {
5347ee
-        domstr = dom_sid_string(NULL, info->info->info3.base.domain_sid);
5347ee
-        if (!domstr) {
5347ee
-            return EINVAL;
5347ee
-        }
5347ee
-        krb5_klog_syslog(LOG_ERR, "PAC Info mismatch: domain = %s, "
5347ee
-                                  "expected domain SID = %s, "
5347ee
-                                  "found domain SID = %s",
5347ee
-                                  domain->domain_name, domain->domain_sid, domstr);
5347ee
-        talloc_free(domstr);
5347ee
-        return EINVAL;
5347ee
-    }
5347ee
-
5347ee
     /* Check if this domain has been filtered out by the trust itself*/
5347ee
     if (domain->parent != NULL) {
5347ee
         for(k = 0; k < domain->parent->len_sid_blocklist_incoming; k++) {
5347ee
@@ -1944,10 +1961,6 @@ krb5_error_code filter_logon_info(krb5_context context,
5347ee
      * should include different possibilities into account
5347ee
      * */
5347ee
     if (info->info->info3.sidcount != 0) {
5347ee
-        ipactx = ipadb_get_context(context);
5347ee
-        if (!ipactx || !ipactx->mspac) {
5347ee
-            return KRB5_KDB_DBNOTINITED;
5347ee
-        }
5347ee
         count = info->info->info3.sidcount;
5347ee
         i = 0;
5347ee
         j = 0;
5347ee
5347ee
From 1a4f2597253c750696f6cd34613b375dc30fe456 Mon Sep 17 00:00:00 2001
5347ee
From: Anuja More <amore@redhat.com>
5347ee
Date: Mon, 30 Jan 2023 19:27:49 +0530
5347ee
Subject: [PATCH 2/2] Add test for SSH with GSSAPI auth.
5347ee
5347ee
Added test for aduser with GSSAPI authentication.
5347ee
5347ee
Related : https://pagure.io/freeipa/issue/9316
5347ee
5347ee
Signed-off-by: Anuja More <amore@redhat.com>
5347ee
---
5347ee
 ipatests/test_integration/test_trust.py | 46 +++++++++++++++++++++++++
5347ee
 1 file changed, 46 insertions(+)
5347ee
5347ee
diff --git a/ipatests/test_integration/test_trust.py b/ipatests/test_integration/test_trust.py
5347ee
index 21c814ff1a9..a1ed906c6ae 100644
5347ee
--- a/ipatests/test_integration/test_trust.py
5347ee
+++ b/ipatests/test_integration/test_trust.py
5347ee
@@ -527,6 +527,35 @@ def test_subordinate_suffix(self):
5347ee
                    .format(self.ad_domain, subordinate_suffix))
5347ee
             self.ad.run_command(['powershell', '-c', cmd])
5347ee
 
5347ee
+    def test_ssh_aduser(self):
5347ee
+        """Test ssh with GSSAPI is working with aduser
5347ee
+
5347ee
+        When kerberos ticket is obtained for child domain user
5347ee
+        and ssh with this ticket should be successful
5347ee
+        with no password prompt.
5347ee
+
5347ee
+        Related : https://pagure.io/freeipa/issue/9316
5347ee
+        """
5347ee
+        testuser = 'testuser@{0}'.format(self.ad_domain)
5347ee
+        testusersub = 'subdomaintestuser@{0}'.format(self.ad_subdomain)
5347ee
+
5347ee
+        def sshuser(host, user):
5347ee
+            tasks.kdestroy_all(host)
5347ee
+            try:
5347ee
+                tasks.kinit_as_user(host, user,
5347ee
+                                    host.config.ad_admin_password
5347ee
+                                    )
5347ee
+                ssh_cmd = "ssh -q -K -l {user} {host} hostname"
5347ee
+                valid_ssh = host.run_command(
5347ee
+                    ssh_cmd.format(user=user, host=host.hostname)
5347ee
+                )
5347ee
+                assert host.hostname in valid_ssh.stdout_text
5347ee
+            finally:
5347ee
+                tasks.kdestroy_all(host)
5347ee
+
5347ee
+        sshuser(self.master, testuser)
5347ee
+        sshuser(self.master, testusersub)
5347ee
+
5347ee
     def test_remove_nonposix_trust(self):
5347ee
         self.remove_trust(self.ad)
5347ee
         tasks.unconfigure_dns_for_trust(self.master, self.ad)
5347ee
@@ -784,6 +813,23 @@ def test_user_gid_uid_resolution_in_external_treedomain_trust(self):
5347ee
         assert re.search(
5347ee
             testuser_regex, result.stdout_text), result.stdout_text
5347ee
 
5347ee
+    def test_ssh_adtreeuser(self):
5347ee
+        testuser = 'treetestuser@{0}'.format(self.ad_treedomain)
5347ee
+        self.master.run_command(["id", testuser])
5347ee
+        tasks.clear_sssd_cache(self.master)
5347ee
+        tasks.kdestroy_all(self.master)
5347ee
+        try:
5347ee
+            tasks.kinit_as_user(self.master, testuser,
5347ee
+                                password="Secret123456"
5347ee
+                                )
5347ee
+            ssh_cmd = "ssh -q -K -l {user} {host} hostname"
5347ee
+            valid_ssh = self.master.run_command(
5347ee
+                ssh_cmd.format(user=testuser, host=self.master.hostname)
5347ee
+            )
5347ee
+            assert self.master.hostname in valid_ssh.stdout_text
5347ee
+        finally:
5347ee
+            tasks.kdestroy_all(self.master)
5347ee
+
5347ee
     def test_remove_external_treedomain_trust(self):
5347ee
         self.remove_trust(self.tree_ad)
5347ee
         tasks.unconfigure_dns_for_trust(self.master, self.ad, self.tree_ad)