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

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