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

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