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