示例 SSO 实现
此示例通过使用 SUSE Manager 公开三个端点并使用 Keycloak 21.0.1 或更高版本作为身份服务提供者 (IdP) 来实现 SSO。
首先安装 Keycloak IdP,然后设置 SUSE Manager 服务器。之后可以将端点添加为 Keycloak 客户端并创建用户。
|
This example is provided for illustrative purposes only. SUSE does not recommend or support third-party identity service providers, and is not affiliated with Keycloak. For Keycloak support, see www.keycloak.org. |
You can install Keycloak directly on your machine, or run it in a container. In this example, we run Keycloak in a Podman container. For more information about installing Keycloak, see the Keycloak documentation at https://www.keycloak.org/guides#getting-started.
根据 Keycloak 文档所述在 Podman 容器中安装 Keycloak。
使用
-td参数运行容器,以确保进程保持运行:podman run -td --name keycloak -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:21.0.1以
admin用户身份登录到 Keycloak Web UI,然后使用以下细节创建身份验证领域:
在
名称字段中输入领域的名称。 例如SUMA。在
端点字段中,单击SAML 2.0 身份提供者元数据链接。 如此您将转到一个页面,其中会显示要复制到 SUSE Manager 配置文件中的端点和证书。
安装 Keycloak 并创建领域后,便可以准备 SUSE Manager 服务器。
在 SUSE Manager Server 上打开
/etc/rhn/rhn.conf配置文件,然后编辑这些参数。 将<FQDN_SUMA>替换为您的 SUSE Manager 安装的完全限定域名:java.sso.onelogin.saml2.sp.entityid = https://<FQDN_SUMA>/rhn/manager/sso/metadata java.sso.onelogin.saml2.sp.assertion_consumer_service.url = https://<FQDN_SUMA>/rhn/manager/sso/acs java.sso.onelogin.saml2.sp.single_logout_service.url = https://<FQDN_SUMA>/rhn/manager/sso/sls在配置文件中,将
<FQDN_IDP>替换为您的 Keycloak 服务器的完全限定域名。 将<REALM>替换为您的身份验证领域,例如SUMA:java.sso.onelogin.saml2.idp.entityid = http://<FQDN_IDP>:8080/realms/<REALM> java.sso.onelogin.saml2.idp.single_sign_on_service.url = http://<FQDN_IDP>:8080/realms/<REALM>/protocol/saml java.sso.onelogin.saml2.idp.single_logout_service.url = http://<FQDN_IDP>:8080/realms/<REALM>/protocol/saml在 IdP 元数据中,找到公共 x509 证书。 It uses this format: http://<FQDN_IDP>:8080/realms/<REALM>/protocol/saml/descriptor. In the configuration file, specify the public x509 certificate of the IdP:
java.sso.onelogin.saml2.idp.x509cert = -----BEGIN CERTIFICATE----- <CERTIFICATE> -----END CERTIFICATE-----
下面是启用 SSO 后 SUSE Manager 上的 rhn.conf 的示例:
java.sso = true # This is the configuration file for Single Sign-On (SSO) via SAMLv2 protocol # To enable SSO, set java.sso = true in /etc/rhn/rhn.conf # # Mandatory changes: search this file for: # - YOUR-PRODUCT # - YOUR-IDP-ENTITY # # See product documentation and the comments inline in this file for more # information about every parameter. # # # # # If 'strict' is True, then the Java Toolkit will reject unsigned # or unencrypted messages if it expects them signed or encrypted # Also will reject the messages if not strictly follow the SAML # # WARNING: In production, this parameter setting parameter MUST be set as "true". # Otherwise your environment is not secure and will be exposed to attacks. # Enable debug mode (to print errors) # Identifier of the SP entity (must be a URI) java.sso.onelogin.saml2.sp.entityid = https://sumaserver.example.org/rhn/manager/sso/metadata # Specifies info about where and how the <AuthnResponse> message MUST be # returned to the requester, in this case our SP. # URL Location where the <Response> from the IdP will be returned java.sso.onelogin.saml2.sp.assertion_consumer_service.url = https://sumaserver.example.org/rhn/manager/sso/acs # Specifies info about where and how the <Logout Response> message MUST be # returned to the requester, in this case our SP. java.sso.onelogin.saml2.sp.single_logout_service.url = https://sumaserver.example.org/rhn/manager/sso/sls # Identifier of the IdP entity (must be a URI) java.sso.onelogin.saml2.idp.entityid = http://idp.example.org:8080/realms/SUMA # SSO endpoint info of the IdP. (Authentication Request protocol) # URL Target of the IdP where the SP will send the Authentication Request Message java.sso.onelogin.saml2.idp.single_sign_on_service.url = http://idp.example.org:8080/realms/SUMA/protocol/saml # SLO endpoint info of the IdP. # URL Location of the IdP where the SP will send the SLO Request java.sso.onelogin.saml2.idp.single_logout_service.url = http://idp.example.org:8080/realms/SUMA/protocol/saml # Public x509 certificate of the IdP java.sso.onelogin.saml2.idp.x509cert = -----BEGIN CERTIFICATE----- MIIClzCCAX8CBgGC+tPbVjANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDDARTVU1BMB4XDTIyMDkwMTIwNTEwNFoXDTMyMDkwMTIwNTI0NFowDzENMAsG A1UEAwwEU1VNQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMNSWJAalB5mShTkMBO5mrsOosyheEL8/A37WvuqDPwwEfm4x0cG7gmMHvONxYXZk+LRyzoQl2sBrNFrbMuwu5dnah5ZSMxQyUu697S280m4vIiegGaFdbgH+g4FGBu eSis1ssMzTcES+NUuI7pLkMLNmSQtncESnoL9q2SyeQSwYtr5dz1ydl6IzjwtaWeyQ9EGJNtJtLk3U4+arLPCpHAwqFAnLO9NeYcRDNUKhNBs1v5mHP+L066PZu1/DkE0mSgy/+qXaS0CgZVKqz8qB+bvHVuAq9W60g1CjqZKbwvPu72p/7+d8z 9DxXPIZ1uxdqn19q/kLEP2TYLtgQobSHECAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAga+raLMJDo/P/yN1Z6SGGocK227WFqovBiE/mLYlp5Ff0+0jS1US1plSppJ94xOr8j0m7HW0Wu5xCz6oOhzXTEtnfIbeRyr1Rms3BWdxyXgQ9bWUeZMWZ HfDkTbhgRRmjDEwSSfEXRKQNvw41CpnlB36I0++ejgGnjDvH7BbkCaoW55JF5j6DT/WYR0n7MkEl2Ova9CH0e9X7Gny8iOAg26oziy06uy3P/lx9Z9RmHnvpvN/Q34SGEq9z/HlQVuP12UPj//iT21Jc17OOZFsZQXlGFTG6bXKmO42W8FdUDJU ONoXZgjMb3eC7U691YyeowoqTY7mJKxNPprYY/lL0w== -----END CERTIFICATE----- # Organization java.sso.onelogin.saml2.organization.name = SUSE Manager admin java.sso.onelogin.saml2.organization.displayname = SUSE Manager admin java.sso.onelogin.saml2.organization.url = https://sumaserver.example.org java.sso.onelogin.saml2.organization.lang = # Contacts java.sso.onelogin.saml2.contacts.technical.given_name = SUSE Manager admin java.sso.onelogin.saml2.contacts.technical.email_address = suma@example.org java.sso.onelogin.saml2.contacts.support.given_name = SUSE Manager admin java.sso.onelogin.saml2.contacts.support.email_address = suma@example.org
您可以将 SUSE Manager 端点添加到 Keycloak 中。Keycloak 将端点称为客户端。
在 Keycloak Web UI 中,使用以下细节创建新客户端:
在
客户端类型字段中选择SAML。在
客户端 ID字段中,输入服务器配置文件中以java.sso.onelogin.saml2.idp.entityid形式指定的端点。 For example, https://<FQDN_SUMA>/rhn/manager/sso/metadata.在
设置选项卡中,使用以下细节对客户端进行精细调整:
将
对声明签名开关切换为开。在
签名算法字段中选择RSA_SHA1。在
SAML 签名密钥名称字段中,选择密钥 ID。在
密钥选项卡中:
将
需要客户端签名切换为关。在
高级选项卡上的精细 SAML 端点配置部分,使用以下细节添加两个端点:
在
声明使用者服务字段中,输入服务器配置文件中以java.sso.onelogin.saml2.sp.assertion_consumer_service.url形式指定的端点。 For example, https://<FQDN_SUMA>/rhn/manager/sso/acs.在
注销服务字段中,输入服务器配置文件中以java.sso.onelogin.saml2.sp.single_logout_service.url形式指定的端点。 For example, https://<FQDN_SUMA>/rhn/manager/sso/sls.
将端点添加为客户端后,可以配置客户端范围,并在 Keycloak 和 SUSE Manager 之间映射用户。
在 Keycloak Web UI 中,导航到选项卡,然后将
role_list指定为默认客户端范围。导航到选项卡,然后使用默认值添加用户属性
UID的映射程序。 SUSE Manager 需要此 SAML 属性。导航到,然后单击
role_list映射程序。将单角色属性设置为开。导航到部分并创建一个管理用户。 此用户不需要与 SUSE Manager 管理用户匹配。
导航到选项卡,使用与 SUSE Manager 管理用户的用户名匹配的值添加名为
UID的属性。导航到选项卡,设置 SUSE Manager 管理用户所用的同一口令。
保存更改。
完成配置后,可以测试安装是否按预期工作。重启动 SUSE Manager 服务器以应用您的更改,然后导航到 SUSE Manager Web UI。如果您的安装正常工作,则您会重定向到 Keycloak SSO 页面,可在其中成功完成身份验证。