{"id":891,"date":"2022-12-23T10:22:56","date_gmt":"2022-12-23T09:22:56","guid":{"rendered":"https:\/\/www.ume.li\/blog\/?p=891"},"modified":"2022-12-23T10:22:56","modified_gmt":"2022-12-23T09:22:56","slug":"keycloak-and-kerberos","status":"publish","type":"post","link":"https:\/\/www.ume.li\/blog\/2022\/12\/23\/keycloak-and-kerberos\/","title":{"rendered":"Keycloak and Kerberos"},"content":{"rendered":"<p>Goal:<br \/>\nLogin to your Windows Client and do not have to login to Connections<\/p>\n<p>My setup for this:<br \/>\n&#8211; Windows 2019 Server &#8211; AD for the domain &#8216;belsoft-lab.ch&#8217; &#8211; fresh install<br \/>\n&#8211; Windows 10 Client &#8211; Testing &#8211; already domain joined to &#8216;belsoft-lab.ch&#8217;<br \/>\n&#8211; Rocky Linux 8 &#8211; Keycloak 20.0.2 &#8211; already up and connected to AD through LDAP &#8211; url: login.belsoft-lab.ch \/ hostname login1.belsoft-lab.ch<br \/>\n&#8211; HCL Connections 8 already configured for OIDC against Keycloak (<a title=\"Configure OIDC\" href=\"https:\/\/opensource.hcltechsw.com\/connections-doc\/admin\/secure\/c_azure_oidc_container.html\" target=\"_blank\" rel=\"noopener\">configure OIDC in HCL Connections<\/a><\/p>\n<p>Motivation:<br \/>\nSure you can configure SPNEGO directly in WebSphere. But you might want to support OTP\/WebAuthn for external users which are not in your AD?<\/p>\n<p>Based on <a title=\"Keycloak Documentation\" href=\"https:\/\/www.keycloak.org\/docs\/latest\/server_admin\/index.html#_kerberos\" target=\"_blank\" rel=\"noopener\">keycloak documentation<\/a><\/p>\n<p><strong>Prepare the Keytab file<\/strong><br \/>\nCreate a user for the service account. For this example I use kk@belsoft-lab.ch. And add all the possible URL&#8217;s<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nktpass -out c:\\temp\\keycloak.keytab -princ HTTP\/login.belsoft-lab.ch@BELSOFT-LAB.CH -mapUser kk@belsoft-lab.ch  -kvno 0 -ptype KRB5_NT_PRINCIPAL -crypto AES256-SHA1 -pass *****\r\nsetspn -S HTTP\/login1.belsoft-lab.ch@BELSOFT-LAB.CH belsoft-lab\\kk\r\nsetspn -S HTTP\/login1.belsoft-lab.ch belsoft-lab\\kk\r\nsetspn -S HTTP\/login.belsoft-lab.ch belsoft-lab\\kk\r\nsetspn -l kk\r\n<\/pre>\n<p>The &#8216;setspn -l kk&#8217; displays the successfull registration and I&#8217;ve got the keycloak.keytab file in c:\\temp which I then have to copy to my keycloak server(s).<br \/>\n<a href=\"https:\/\/www.ume.li\/blog\/2022\/12\/23\/keycloak-and-kerberos\/selection_588\/\" rel=\"attachment wp-att-895\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-895\" src=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_588-300x46.png\" alt=\"\" width=\"300\" height=\"46\" srcset=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_588-300x46.png 300w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_588.png 717w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Prepare Keycloak<\/strong><\/p>\n<p>As I&#8217;ve already configured ldap against my AD server, I just need to activate Kerberos in the user federation.<br \/>\n<a href=\"https:\/\/www.ume.li\/blog\/2022\/12\/23\/keycloak-and-kerberos\/selection_589\/\" rel=\"attachment wp-att-896\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-896\" src=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_589-300x177.png\" alt=\"\" width=\"300\" height=\"177\" srcset=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_589-300x177.png 300w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_589-768x452.png 768w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_589-850x500.png 850w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_589.png 985w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Verify that the default authentication flow has set Kerberos to Alternative<br \/>\n<a href=\"https:\/\/www.ume.li\/blog\/2022\/12\/23\/keycloak-and-kerberos\/selection_590\/\" rel=\"attachment wp-att-897\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-897\" src=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_590-300x155.png\" alt=\"\" width=\"300\" height=\"155\" srcset=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_590-300x155.png 300w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_590-1024x530.png 1024w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_590-768x397.png 768w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_590.png 1210w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndnf install freeipa-client\r\n<\/pre>\n<p>Update the \/etc\/krb5.conf file on the keycloak server with my domain<br \/>\n<a href=\"https:\/\/www.ume.li\/blog\/2022\/12\/23\/keycloak-and-kerberos\/selection_591\/\" rel=\"attachment wp-att-898\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-898\" src=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_591-300x123.png\" alt=\"\" width=\"300\" height=\"123\" srcset=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_591-300x123.png 300w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_591.png 318w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Testing<\/strong><\/p>\n<p>And of course it did not work. I just got the default login window when I tried to go to keycloak&#8217;s account page.<\/p>\n<p><strong>Troubleshooting<\/strong><\/p>\n<p>Turning on the debug parameters in keycloak. For this I added this environment variable<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nJAVA_OPTS_APPEND=&quot;-Dsun.security.krb5.debug=true -Dsun.security.spnego.debug=true&quot;\r\n<\/pre>\n<p>and added these to my keycloak.conf file<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nlog=file\r\nlog-file=\/opt\/keycloak\/log\/keycloak.log\r\nlog-level=info,org.keycloak.federation.kerberos:trace\r\n<\/pre>\n<p>the log file then showed this message:<br \/>\n<a href=\"https:\/\/www.ume.li\/blog\/2022\/12\/23\/keycloak-and-kerberos\/selection_592\/\" rel=\"attachment wp-att-900\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-900\" src=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_592-300x61.png\" alt=\"\" width=\"300\" height=\"61\" srcset=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_592-300x61.png 300w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_592-768x157.png 768w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_592.png 1020w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><em>java.security.PrivilegedActionException: GSSException: Failure unspecified at GSS-API level (Mechanism level: Encryption type RC4 with HMAC is not supported\/enabled<\/em><br \/>\nwhich led me to this <a href=\"https:\/\/bugs.openjdk.org\/browse\/JDK-8262273\" target=\"_blank\" rel=\"noopener\">RC4 deprecated<\/a>. Further research led to numerous posts which proposed obscure tipps.<\/p>\n<p><strong>Solution<\/strong><\/p>\n<p>In the test users account I had to tick &#8216;this account supports Kerberos AES 256 bit&#8217;<\/p>\n<p><a href=\"https:\/\/www.ume.li\/blog\/2022\/12\/23\/keycloak-and-kerberos\/selection_593\/\" rel=\"attachment wp-att-901\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-901\" src=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_593-300x156.png\" alt=\"\" width=\"300\" height=\"156\" srcset=\"https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_593-300x156.png 300w, https:\/\/www.ume.li\/blog\/wp-content\/uploads\/2022\/12\/Selection_593.png 395w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Relogin to my test client. Finally managed to access the account console without entering username or password.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: Login to your Windows Client and do not have to login to Connections My setup for this: &#8211; Windows<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[85,84,83,82,86],"class_list":["post-891","post","type-post","status-publish","format-standard","hentry","category-connections","category-uncategorized","tag-active-directory","tag-ad","tag-kerberos","tag-keycloak","tag-windows"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts\/891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/comments?post=891"}],"version-history":[{"count":7,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts\/891\/revisions"}],"predecessor-version":[{"id":904,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/posts\/891\/revisions\/904"}],"wp:attachment":[{"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/media?parent=891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/categories?post=891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ume.li\/blog\/wp-json\/wp\/v2\/tags?post=891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}