操作场景
Keycloak 是一个开源的身份和访问管理解决方案,它主要用于现代应用程序和服务的身份验证、授权和数据保护,可以帮助用户轻松地实现单点登录(SSO)。腾讯云支持基于 SAML 2.0(安全断言标记语言 2.0)的联合身份验证,SAML 2.0 是许多身份验证提供商(Identity Provider, IdP)使用的一种开放标准。您可以通过基于 SAML 2.0 联合身份验证将 IdP 与腾讯云进行集成,从而实现 Keycloak 账户自动登录(单一登录)腾讯云控制台管理腾讯云的资源,不必为企业或组织中的每一个成员都创建一个 CAM 子用户。
操作步骤
配置腾讯云访问管理(CAM)信息
1. 单击打开后保存身份提供商 IDP 元数据文档,可复制打开的文档信息保存为 XML 文件。
![](https://qcloudimg.tencent-cloud.cn/image/document/4187d308fe47114b6e979f96787c66c5.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/4187d308fe47114b6e979f96787c66c5.png)
2. 在腾讯云 访问管理控制台 > 角色SSO 新建身份提供商。选择身份提供商类型为 SAML 并上传身份提供商元数据文档,单击下一步,审阅信息无误后保存。
![](https://qcloudimg.tencent-cloud.cn/image/document/8d4b66a0cb1ca56f41c63de7ee2abd18.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/8d4b66a0cb1ca56f41c63de7ee2abd18.png)
3. 在 访问管理控制台 > 角色 页面,单击新建角色,选择角色载体为身份提供商。
![](https://qcloudimg.tencent-cloud.cn/image/document/f9f75e974799dcef7600cf4aa6ec64e7.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/f9f75e974799dcef7600cf4aa6ec64e7.png)
4. 身份提供商类型为 SAML,选择已创建的身份提供商,并允许该角色访问控制台。配置角色策略时可根据需求选择关联对应权限的策略,无其他要求可单击下一步直至审阅角色信息无误后完成角色创建。若配置角色策略时无匹配的策略,可 通过策略生成器创建自定义策略 再进行关联。
![](https://qcloudimg.tencent-cloud.cn/image/document/4a74bff556c20ff45b513488bbf07f14.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/4a74bff556c20ff45b513488bbf07f14.png)
5. 创建成功后,可在 角色 页面,单击创建好的角色名称,
查看角色信息。
![](https://qcloudimg.tencent-cloud.cn/image/document/dab32613170e2277b531d7676a87024d.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/dab32613170e2277b531d7676a87024d.png)
配置 Keycloak 客户端信息
1. 添加客户端,选择客户端协议为 saml。
![](https://qcloudimg.tencent-cloud.cn/image/document/0d0eb537bb66b0d3c18729683b074d32.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/0d0eb537bb66b0d3c18729683b074d32.png)
2. 按照如下信息进行填写客户端信息。
2.1 符号断言选择开启
2.2 名称 ID 格式:transient。
2.3 有效的重定向 URL:https://cloud.tencent.com/login/saml。
2.4 根 URL:先填写 IDP 发起的 SSO URL 名称,从提示中复制根 URL。
2.5 IDP 发起的 SSO URL名称:tencentcloud。
2.6 断言使用者服务 POST 绑定 URL:https://cloud.tencent.com/login/saml。
![](https://qcloudimg.tencent-cloud.cn/image/document/bd186d8b4ad2a70eedba614561bda501.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/bd186d8b4ad2a70eedba614561bda501.png)
配置 Keycloak 角色信息
1. 在 Keycloak 已创建的客户端中添加角色,角色名称使用腾讯云中创建的 角色 RoleArn 和角色载体,用英文逗号隔开。
![](https://qcloudimg.tencent-cloud.cn/image/document/2cae5673b9f70142550e5c360ba6ac09.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/2cae5673b9f70142550e5c360ba6ac09.png)
配置 Keycloak 客户端断言属性
1. 在 Keycloak 中打开已创建的客户端进行创建断言属性。断言属性包括 RoleSessionName 和 Role。
![](https://qcloudimg.tencent-cloud.cn/image/document/201ed41af5d2aa68ced8bacd420e989c.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/201ed41af5d2aa68ced8bacd420e989c.png)
1.1 创建 RoleSessionName 断言属性,参考以下内容:
名称:RoleSessionName。
映射器类型:User Property。
属性:username。
Friendly Name:RoleSessionName。
SAML Attribute Name:https://cloud.tencent.com/SAML/Attributes/RoleSessionName。
SAML Attribute NameFormat:Basic。
![](https://qcloudimg.tencent-cloud.cn/image/document/489d1e7ad7304202a9f6327e51200e68.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/489d1e7ad7304202a9f6327e51200e68.png)
1.2 创建 Role 断言属性,参考以下内容:
名称:Role。
映射器类型:Role list。
Role attribute name:https://cloud.tencent.com/SAML/Attributes/Role。
Friendly Name:Role。
SAML Attribute NameFormat:Basic。
![](https://qcloudimg.tencent-cloud.cn/image/document/d288d3f7ded6a3cf97b4da29ce6e5dcf.png)
2. 关闭全范围映射。
![](https://qcloudimg.tencent-cloud.cn/image/document/21dd29c26b38a74d6b2083eff673cea2.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/21dd29c26b38a74d6b2083eff673cea2.png)
3. 删除 Assigned Default Client Scopes 中的 role_list。
![](https://qcloudimg.tencent-cloud.cn/image/document/48b749faab4a48bdf96caa50cedc7c4d.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/48b749faab4a48bdf96caa50cedc7c4d.png)
配置 Keycloak 用户信息
1. 添加用户 user。
![](https://qcloudimg.tencent-cloud.cn/image/document/5bab1edd7780f2600ce066467c8f1f56.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/5bab1edd7780f2600ce066467c8f1f56.png)
2. 编辑用户 user 的角色映射信息,选择客户端已创建的角色并添加。
![](https://qcloudimg.tencent-cloud.cn/image/document/3eac9890ebef7dd34c8fbfcdc0a6148b.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/3eac9890ebef7dd34c8fbfcdc0a6148b.png)
3. 编辑用户 user 的密码信息。
![](https://qcloudimg.tencent-cloud.cn/image/document/b32a5e1a36f9c178deea2c6721b3f6c6.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/b32a5e1a36f9c178deea2c6721b3f6c6.png)
验证角色 SSO 登录到腾讯云
1. 单击客户端根 url。
![](https://qcloudimg.tencent-cloud.cn/image/document/82cd9916907937a364e8a49341ac0b8e.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/82cd9916907937a364e8a49341ac0b8e.png)
2. 输入 Keycloak 中创建的用户名称和密码。
![](https://qcloudimg.tencent-cloud.cn/image/document/a5d4d27a93180d8d0dbe069ed9c932bb.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/a5d4d27a93180d8d0dbe069ed9c932bb.png)
3. 登录成功。
![](https://qcloudimg.tencent-cloud.cn/image/document/6cab9ff4dd6e2953852f3e2bdac8d161.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/6cab9ff4dd6e2953852f3e2bdac8d161.png)