Blame SOURCES/0004-ipa-kdb-do-not-remove-keys-for-hardened-auth-enabled-users_rhbz#2033342.patch

a47729
From 6d70421f57d0eca066a922e09416ef7195ee96d4 Mon Sep 17 00:00:00 2001
a47729
From: Julien Rische <jrische@redhat.com>
a47729
Date: Tue, 1 Feb 2022 16:43:09 +0100
a47729
Subject: [PATCH] ipa-kdb: do not remove keys for hardened auth-enabled users
a47729
a47729
Since 5d51ae5, principal keys were dropped in case user auth indicator
a47729
was not including password. Thereafter, the key removal behavior was
a47729
removed by 15ff9c8 in the context of the kdcpolicy plugin introduction.
a47729
Support for hardened pre-auth methods (FAST and SPAKE) was added in
a47729
d057040, and the removal of principal keys was restored afterwards by
a47729
f0d12b7, but not taking the new hardened auth indicator into account.
a47729
a47729
Fixes: https://pagure.io/freeipa/issue/9065
a47729
Related to: https://pagure.io/freeipa/issue/8001
a47729
a47729
Signed-off-by: Julien Rische <jrische@redhat.com>
a47729
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
a47729
Reviewed-By: Francisco Trivino <ftrivino@redhat.com>
a47729
---
a47729
 daemons/ipa-kdb/ipa_kdb_principals.c | 23 ++++++++++++-----------
a47729
 1 file changed, 12 insertions(+), 11 deletions(-)
a47729
a47729
diff --git a/daemons/ipa-kdb/ipa_kdb_principals.c b/daemons/ipa-kdb/ipa_kdb_principals.c
a47729
index 15f3df4fe..0d0d3748c 100644
a47729
--- a/daemons/ipa-kdb/ipa_kdb_principals.c
a47729
+++ b/daemons/ipa-kdb/ipa_kdb_principals.c
a47729
@@ -788,17 +788,18 @@ static krb5_error_code ipadb_parse_ldap_entry(krb5_context kcontext,
a47729
                                       &res_key_data, &result, &mkvno);
a47729
     switch (ret) {
a47729
     case 0:
a47729
-        /* Only set a principal's key if password auth can be used. Otherwise
a47729
-         * the KDC would add pre-authentication methods to the NEEDED_PREAUTH
a47729
-         * reply for AS-REQs which indicate the password authentication is
a47729
-         * available. This might confuse applications like e.g. SSSD which try
a47729
-         * to determine suitable authentication methods and corresponding
a47729
-         * prompts with the help of MIT Kerberos' responder interface which
a47729
-         * acts on the returned pre-authentication methods. A typical example
a47729
-         * is enforced OTP authentication where of course keys are available
a47729
-         * for the first factor but password authentication should not be
a47729
-         * advertised by the KDC. */
a47729
-        if (!(ua & IPADB_USER_AUTH_PASSWORD) && (ua != IPADB_USER_AUTH_NONE)) {
a47729
+        /* Only set a principal's key if password or hardened auth can be used.
a47729
+         * Otherwise the KDC would add pre-authentication methods to the
a47729
+         * NEEDED_PREAUTH reply for AS-REQs which indicate the password
a47729
+         * authentication is available. This might confuse applications like
a47729
+         * e.g. SSSD which try to determine suitable authentication methods and
a47729
+         * corresponding prompts with the help of MIT Kerberos' responder
a47729
+         * interface which acts on the returned pre-authentication methods. A
a47729
+         * typical example is enforced OTP authentication where of course keys
a47729
+         * are available for the first factor but password authentication
a47729
+         * should not be advertised by the KDC. */
a47729
+        if (!(ua & (IPADB_USER_AUTH_PASSWORD | IPADB_USER_AUTH_HARDENED)) &&
a47729
+            (ua != IPADB_USER_AUTH_NONE)) {
a47729
             /* This is the same behavior as ENOENT below. */
a47729
             ipa_krb5_free_key_data(res_key_data, result);
a47729
             break;
a47729
-- 
a47729
2.34.1
a47729
a47729
From 294ae35a61e6ca8816b261c57508e4be21221864 Mon Sep 17 00:00:00 2001
a47729
From: Julien Rische <jrische@redhat.com>
a47729
Date: Tue, 1 Feb 2022 19:38:29 +0100
a47729
Subject: [PATCH] ipatests: add case for hardened-only ticket policy
a47729
a47729
Signed-off-by: Julien Rische <jrische@redhat.com>
a47729
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
a47729
Reviewed-By: Francisco Trivino <ftrivino@redhat.com>
a47729
---
a47729
 ipatests/test_integration/test_krbtpolicy.py | 30 ++++++++++++++++++--
a47729
 1 file changed, 28 insertions(+), 2 deletions(-)
a47729
a47729
diff --git a/ipatests/test_integration/test_krbtpolicy.py b/ipatests/test_integration/test_krbtpolicy.py
a47729
index 63e75ae67..9489fbc97 100644
a47729
--- a/ipatests/test_integration/test_krbtpolicy.py
a47729
+++ b/ipatests/test_integration/test_krbtpolicy.py
a47729
@@ -103,8 +103,8 @@ class TestPWPolicy(IntegrationTest):
a47729
         result = master.run_command('klist | grep krbtgt')
a47729
         assert maxlife_within_policy(result.stdout_text, MAXLIFE) is True
a47729
 
a47729
-    def test_krbtpolicy_hardended(self):
a47729
-        """Test a hardened kerberos ticket policy with 10 min tickets"""
a47729
+    def test_krbtpolicy_password_and_hardended(self):
a47729
+        """Test a pwd and hardened kerberos ticket policy with 10min tickets"""
a47729
         master = self.master
a47729
         master.run_command(['ipa', 'user-mod', USER1,
a47729
                             '--user-auth-type', 'password',
a47729
@@ -131,6 +131,32 @@ class TestPWPolicy(IntegrationTest):
a47729
         result = master.run_command('klist | grep krbtgt')
a47729
         assert maxlife_within_policy(result.stdout_text, MAXLIFE) is True
a47729
 
a47729
+    def test_krbtpolicy_hardended(self):
a47729
+        """Test a hardened kerberos ticket policy with 30min tickets"""
a47729
+        master = self.master
a47729
+        master.run_command(['ipa', 'user-mod', USER1,
a47729
+                            '--user-auth-type', 'hardened'])
a47729
+        master.run_command(['ipa', 'config-mod',
a47729
+                            '--user-auth-type', 'hardened'])
a47729
+        master.run_command(['ipa', 'krbtpolicy-mod', USER1,
a47729
+                            '--hardened-maxlife', '1800'])
a47729
+
a47729
+        tasks.kdestroy_all(master)
a47729
+
a47729
+        master.run_command(['kinit', USER1],
a47729
+                           stdin_text=PASSWORD + '\n')
a47729
+        result = master.run_command('klist | grep krbtgt')
a47729
+        assert maxlife_within_policy(result.stdout_text, 1800,
a47729
+                                     slush=1800) is True
a47729
+
a47729
+        tasks.kdestroy_all(master)
a47729
+
a47729
+        # Verify that the short policy only applies to USER1
a47729
+        master.run_command(['kinit', USER2],
a47729
+                           stdin_text=PASSWORD + '\n')
a47729
+        result = master.run_command('klist | grep krbtgt')
a47729
+        assert maxlife_within_policy(result.stdout_text, MAXLIFE) is True
a47729
+
a47729
     def test_krbtpolicy_password(self):
a47729
         """Test the kerberos ticket policy which issues 20 min tickets"""
a47729
         master = self.master
a47729
-- 
a47729
2.34.1
a47729