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

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