OIDC 管理

平台支持 OIDC(OpenID Connect)协议,在添加 OIDC 配置后,平台管理员可以使用第三方账号登录。平台管理员还可以更新和删除已配置的 OIDC 服务。

OIDC 概述

OIDC(OpenID Connect)是基于 OAuth 2.0 协议的身份认证标准协议。它使用 OAuth 2.0 授权服务器为第三方客户端提供用户身份认证,并将相应的身份认证信息传递给客户端。

OIDC 允许各类客户端(包括服务端、移动端和 JavaScript 客户端)请求并接收已认证会话和最终用户信息。该规范套件具有可扩展性,参与方可以在有意义时使用身份数据加密、OpenID Provider 发现和会话管理等可选功能。更多信息请参考 OIDC 官方文档

添加 OIDC

通过添加 OIDC,您可以使用第三方平台账号登录平台。

注意:OIDC 用户成功登录平台后,平台将使用用户的 email 属性作为唯一标识符。支持 OIDC 的第三方平台用户必须具有 email 属性,否则将无法登录平台。

操作步骤

  1. 在左侧导航栏中,点击 Users > IDPs

  2. 点击 Add OIDC

  3. 配置 Basic Information 参数。

  4. 配置 OIDC Server Configuration 参数:

    • Identity Provider URL:发行者 URL,即 OIDC identity provider 的访问地址。

    • Client ID:OIDC 客户端的客户端标识符。

    • Client Secret:OIDC 客户端的密钥。

    • Redirect URI:登录第三方平台后的回调地址,即 dex issuer 的 URL + /callback

    • Logout URL:用户执行 Logout 操作后访问的地址。如果为空,则退出地址为平台的初始登录页面。

  5. IDP Service Configuration Validation 区域中,输入有效 OIDC 账号的 UsernamePassword 以验证配置。

    提示:如果用户名和密码不正确,添加时会报错,提示凭据无效,并且无法添加 OIDC。

  6. 点击 Create

通过 YAML 添加 OIDC

除了表单配置外,平台还支持通过 YAML 添加 OIDC,从而可以更灵活地配置认证参数、claim 映射、用户组同步以及其他高级功能。

示例:配置 OIDC 连接器

以下示例演示了如何配置一个 OIDC 连接器,以集成 OIDC 身份认证服务。此配置示例适用于以下场景:

  1. 需要将 OIDC 集成为身份认证服务器。

  2. 需要支持用户组信息同步。

  3. 需要自定义退出登录跳转地址。

  4. 需要配置特定的 OIDC scopes。

  5. 需要自定义 claim 映射。

apiVersion: dex.coreos.com/v1
kind: Connector
# Connector basic information
id: oidc               # Connector unique identifier
name: oidc             # Connector display name
type: oidc             # Connector type is OIDC
metadata:
  annotations:
    cpaas.io/description: "11"  # Connector description
  name: oidc
  namespace: cpaas-system
spec:
  config:
    # OIDC server configuration
    # Configure server connection information, including server address, client credentials, and callback address
    issuer: http://auth.com/auth/realms/master               # OIDC server address
    clientID: dex                                            # Client ID
    # Service account secret key, valid when creating Connector resources for the first time
    clientSecret: xxxxxxx
    redirectURI: https://example.com/dex/callback            # Callback address, must match the address registered by the OIDC client

    # Security configuration
    # Configure SSL verification and user information acquisition method
    insecureSkipVerify: true                                # Whether to skip SSL verification, it is recommended to set to false in a production environment
    getUserInfo: false                                      # Whether to obtain additional user information through the UserInfo endpoint

    # Logout configuration
    # Configure the redirect address after user logout
    logoutURL: https://test.com                            # Logout redirect address, can be customized to the page jumped after user logout

    # Scope configuration
    # Configure the required authorization scope, ensure that the OIDC server supports these scopes
    scopes:
      - openid                                             # Required, used for OIDC basic authentication
      - profile                                            # Optional, used to obtain user basic information
      - email                                              # Optional, used to obtain user email

    # Claim mapping configuration
    # Configure the mapping relationship between OIDC returned claims and platform user attributes
    overrideClaimMapping: false                          # Whether to enforce the claimMapping rules when standard claims are also returned
    claimMapping:
      email: email                                         # Email mapping, used for user unique identification
      groups: groups                                       # Group claim mapping. For non-standard claims, set it to the actual key, such as "cognito:groups"
      phone: ""                                            # Phone mapping, optional
      preferred_username: preferred_username               # Username mapping, used for display name

    # Custom claimextra configuration
    # External custom fields will be dynamically added to the user object spec.extra field
    claimExtra:
      - field: xxx            # Custom field name
        type: string          # Field type value is consistent with the definition of golang language type. For example: string, int, bool, map[string]string, []string, []int

    # User group configuration
    # Configure user group synchronization related parameters, ensure that the token contains group information
    groupsKey: groups                                      # Key name used to read group data. Keep it consistent with claimMapping.groups
    insecureEnableGroups: false                           # Whether to enable group synchronization (group claims may be stale until ID token refresh)

OIDC 组相关字段

当您需要从 OIDC provider 同步用户组时,请同时配置以下字段:

字段描述
overrideClaimMapping控制 claimMapping 中的映射是否覆盖默认的 claim 选择行为。当 provider 同时返回标准和非标准 claim,且您希望强制使用自定义映射时,将其设置为 true
claimMapping.groups将 provider 的某个 claim 映射为平台使用的标准 groups claim。如果 provider 返回的是非标准 key(例如 cognito:groups),请将此字段设置为该 key。
groupsKey指定用于读取组数据进行同步的 claim key。为避免不匹配,请使用与 claimMapping.groups 相同的值。
insecureEnableGroups为 OIDC 登录启用 group claim 处理。仅当您需要组同步且 provider 返回 group claims 时才应启用此项。

说明

  • 如果 provider 需要显式的 group scope,请在 scopes 中包含 groups
  • 除非将 overrideClaimMapping 设置为 true,否则 claimMapping 可能不会覆盖 provider 返回的标准 claim。
  • 组 claim 会在 ID token 刷新时同步更新。provider 侧的组成员关系变更可能不会立即生效。

相关操作

您可以在列表页右侧点击 ,或在详情页右上角点击 Actions,按需更新或删除 OIDC。

操作描述
Update OIDC更新已添加的 OIDC 配置。更新 OIDC 配置信息后,原有用户和认证方式将根据当前配置重新设置并同步。
Delete OIDC删除平台不再使用的 OIDC。删除 OIDC 后,所有通过此 OIDC 同步到平台的用户都将处于 Invalid 状态(用户与角色之间的绑定关系保持不变),且无法登录平台。重新集成后,用户可通过成功登录平台来激活。

提示:删除 IDP 后,如果需要删除通过 OIDC 同步到平台的用户和用户组,请勾选提示框下方的复选框 Clean IDP Users and User Groups