KubeSphere 支持通过 OpenID Connect (OIDC) 进行外部身份验证,以便使用 OIDC 的用户名和密码登录 KubeSphere Web 控制台。

平台管理员可以通过 secret(保密字典)配置 OIDC 身份验证。

操作步骤

  1. 以具有 platform-admin 角色的用户登录 KubeSphere Web 控制台。

  2. 点击集群管理,并进入 host 集群。

  3. 在左侧导航栏选择配置 > 保密字典

  4. 在页面点击创建

  5. 创建保密字典对话框,点击右上角的编辑 YAML 开关,使用 yaml 创建保密字典。

  6. 按照以下示例及参数说明修改 yaml 文件,配置完成后,点击创建

  7. 登出 KubeSphere Web 控制台,在登录页面,点击通过 oidc 登录,输入 OpenID Connect 用户名和密码进行登录。

说明

多集群环境中,只需要在主集群中进行配置。

OIDC 基本配置

apiVersion: v1
kind: Secret
metadata:
  namespace: kubesphere-system  # 请勿修改
  name: identity-provider-oidc  # 确保该 Secret 名称在 Kubernetes 集群中唯一
  labels:
    config.kubesphere.io/type: identityprovider # 请勿修改
    config.kubesphere.io/identityprovider: oidc # 与 configuration.yaml 中的 name 字段保持一致
type: config.kubesphere.io/identityprovider # 请勿修改

stringData:
  configuration.yaml: |
    name: oidc
    type: OIDCIdentityProvider
    mappingMethod: auto
    hidden: false
    disabled: false
    provider:
        # 使用自动发现
        issuer: https://accounts.google.com
        clientID: "your-client-id"
        clientSecret: "your-client-secret"
        redirectURL: "https://your-app.com/oauth/callback"

OIDC 完整配置

以下仅展示 stringData:configuration.yamlprovider 部分的配置,其他部分请与 OIDC 基本配置的相应部分保持相同。

    provider:
        # 基本配置
        issuer: https://accounts.google.com
        clientID: "your-client-id"
        clientSecret: "your-client-secret"
        redirectURL: "https://your-app.com/oauth/callback"

        # 可选配置
        scopes:
            - "openid"
            - "email"
            - "profile"
        getUserInfo: true
        insecureSkipVerify: false

        # 自定义 claims 配置
        emailKey: "email"
        preferredUsernameKey: "preferred_username"
        displayNameKey: "name"

        # 手动端点配置(当不使用 issuer 时,endpoint 相关配置为必填项)
        endpoint:
            authURL: "https://accounts.google.com/o/oauth2/v2/auth"
            tokenURL: "https://oauth2.googleapis.com/token"
            userInfoURL: "https://openidconnect.googleapis.com/v1/userinfo"
            jwksURL: "https://www.googleapis.com/oauth2/v3/certs"
            endSessionURL: "https://accounts.google.com/logout"

OIDC 参数说明

此为 stringData:configuration.yamlprovider 部分的参数说明。保密字典中其他部分的参数说明,请参阅配置外部身份验证

参数 类型 必填 默认值 说明

issuer

string

-

OpenID Provider 的发行者 URL,用于动态发现配置

clientID

string

-

OAuth2 客户端 ID

clientSecret

string

-

OAuth2 客户端密钥

redirectURL

string

-

OAuth2 回调地址

scopes

[]string

["openid"]

请求的权限范围。默认包含 "openid"

getUserInfo

bool

false

是否使用 userinfo 端点获取额外用户信息

insecureSkipVerify

bool

false

是否跳过 TLS 证书验证

endpoint.authURL

string

-

OAuth2 授权端点 URL

endpoint.tokenURL

string

-

OAuth2 令牌端点 URL

endpoint.userInfoURL

string

-

OpenID UserInfo 端点 URL

endpoint.jwksURL

string

-

JSON Web Key Set URL

endpoint.endSessionURL

string

-

登出端点 URL

emailKey

string

"email"

邮箱信息的自定义 claim 键名

preferredUsernameKey

string

"preferred_username"

用户名信息的自定义 claim 键名

displayNameKey

string

-

显示名称的自定义 claim 键名