Blame SOURCES/0005-Fall-back-to-krbprincipalname-when-validating-host-a_rhbz#1979625.patch

b39a24
From 8ad535b618d60fa016061212ff85d0ad28ccae59 Mon Sep 17 00:00:00 2001
b39a24
From: Rob Crittenden <rcritten@redhat.com>
b39a24
Date: Mon, 12 Jul 2021 11:02:10 -0400
b39a24
Subject: [PATCH] Fall back to krbprincipalname when validating host auth
b39a24
 indicators
b39a24
b39a24
When adding a new host the principal cannot be determined because it
b39a24
relies on either:
b39a24
b39a24
a) an entry to already exist
b39a24
b) krbprincipalname be a component of the dn
b39a24
b39a24
As a result the full dn is being passed into ipapython.Kerberos
b39a24
which can't parse it.
b39a24
b39a24
Look into the entry in validate_validate_auth_indicator() for
b39a24
krbprincipalname in this case.
b39a24
b39a24
https://pagure.io/freeipa/issue/8206
b39a24
b39a24
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
b39a24
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
b39a24
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
b39a24
---
b39a24
 ipaserver/plugins/service.py             |  5 +++++
b39a24
 ipatests/test_xmlrpc/test_host_plugin.py | 11 +++++++++++
b39a24
 2 files changed, 16 insertions(+)
b39a24
b39a24
diff --git a/ipaserver/plugins/service.py b/ipaserver/plugins/service.py
b39a24
index cfbbff3c6..498f5e444 100644
b39a24
--- a/ipaserver/plugins/service.py
b39a24
+++ b/ipaserver/plugins/service.py
b39a24
@@ -209,6 +209,11 @@ def validate_auth_indicator(entry):
b39a24
     # and shouldn't be allowed to have auth indicators.
b39a24
     # https://pagure.io/freeipa/issue/8206
b39a24
     pkey = api.Object['service'].get_primary_key_from_dn(entry.dn)
b39a24
+    if pkey == str(entry.dn):
b39a24
+        # krbcanonicalname may not be set yet if this is a host entry,
b39a24
+        # try krbprincipalname
b39a24
+        if 'krbprincipalname' in entry:
b39a24
+            pkey = entry['krbprincipalname']
b39a24
     principal = kerberos.Principal(pkey)
b39a24
     server = api.Command.server_find(principal.hostname)['result']
b39a24
     if server:
b39a24
diff --git a/ipatests/test_xmlrpc/test_host_plugin.py b/ipatests/test_xmlrpc/test_host_plugin.py
b39a24
index 9cfde3565..ff50e796c 100644
b39a24
--- a/ipatests/test_xmlrpc/test_host_plugin.py
b39a24
+++ b/ipatests/test_xmlrpc/test_host_plugin.py
b39a24
@@ -615,6 +615,17 @@ class TestProtectedMaster(XMLRPC_test):
b39a24
         )):
b39a24
             command()
b39a24
 
b39a24
+    def test_add_non_master_with_auth_ind(self, host5):
b39a24
+        host5.ensure_missing()
b39a24
+        command = host5.make_command(
b39a24
+            'host_add', host5.fqdn, krbprincipalauthind=['radius'],
b39a24
+            force=True
b39a24
+        )
b39a24
+        result = command()
b39a24
+        # The fact that the command succeeds exercises the change but
b39a24
+        # let's check the indicator as well.
b39a24
+        assert result['result']['krbprincipalauthind'] == ('radius',)
b39a24
+
b39a24
 
b39a24
 @pytest.mark.tier1
b39a24
 class TestValidation(XMLRPC_test):
b39a24
-- 
b39a24
2.31.1
b39a24