c4c001
From 109cd579e3b089b7fad4c92bf25594eba1af8a21 Mon Sep 17 00:00:00 2001
c4c001
From: Alexander Bokovoy <abokovoy@redhat.com>
c4c001
Date: Tue, 23 Aug 2022 16:58:07 +0300
c4c001
Subject: [PATCH] fix canonicalization issue in Web UI
c4c001
c4c001
When Kerberos principal alias is used to login to a Web UI, we end up
c4c001
with a request that is authenticated by a ticket issued in the alias
c4c001
name but metadata processed for the canonical user name. This confuses
c4c001
RPC layer of Web UI code and causes infinite loop to reload the page.
c4c001
c4c001
Fix it by doing two things:
c4c001
c4c001
 - force use of canonicalization of an enterprise principal on server
c4c001
   side, not just specifying that the principal is an enterprise one;
c4c001
c4c001
 - recognize that a principal in the whoami()-returned object can have
c4c001
   aliases and the principal returned by the server in the JSON response
c4c001
   may be one of those aliases.
c4c001
c4c001
Fixes: https://pagure.io/freeipa/issue/9226
c4c001
c4c001
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
c4c001
Reviewed-By: Armando Neto <abiagion@redhat.com>
c4c001
---
c4c001
 install/ui/src/freeipa/ipa.js | 8 +++++++-
c4c001
 ipaserver/rpcserver.py        | 1 +
c4c001
 2 files changed, 8 insertions(+), 1 deletion(-)
c4c001
c4c001
diff --git a/install/ui/src/freeipa/ipa.js b/install/ui/src/freeipa/ipa.js
c4c001
index 758db1b00..a08d632e9 100644
c4c001
--- a/install/ui/src/freeipa/ipa.js
c4c001
+++ b/install/ui/src/freeipa/ipa.js
c4c001
@@ -271,7 +271,13 @@ var IPA = function () {
c4c001
                             var cn = that.whoami.data.krbcanonicalname;
c4c001
                             if (cn) that.principal = cn[0];
c4c001
                             if (!that.principal) {
c4c001
-                                that.principal = that.whoami.data.krbprincipalname[0];
c4c001
+                                var principal = data.principal;
c4c001
+                                var idx = that.whoami.data.krbprincipalname.indexOf(principal);
c4c001
+                                if (idx > -1) {
c4c001
+                                    that.principal = principal;
c4c001
+                                } else {
c4c001
+                                    that.principal = that.whoami.data.krbprincipalname[0];
c4c001
+                                }
c4c001
                             }
c4c001
                         } else if (entity === 'idoverrideuser') {
c4c001
                             that.principal = that.whoami.data.ipaoriginaluid[0];
c4c001
diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py
c4c001
index 1f85e9898..4e8a08b66 100644
c4c001
--- a/ipaserver/rpcserver.py
c4c001
+++ b/ipaserver/rpcserver.py
c4c001
@@ -1109,6 +1109,7 @@ class login_password(Backend, KerberosSession):
c4c001
                 ccache_name,
c4c001
                 armor_ccache_name=armor_path,
c4c001
                 enterprise=True,
c4c001
+                canonicalize=True,
c4c001
                 lifetime=self.api.env.kinit_lifetime)
c4c001
 
c4c001
             if armor_path:
c4c001
-- 
c4c001
2.37.3
c4c001