OIDC 身份验证
KubeSphere 支持通过 OpenID Connect (OIDC) 进行外部身份验证,以便使用 OIDC 的用户名和密码登录 KubeSphere Web 控制台。
平台管理员可以通过 secret(保密字典)配置 OIDC 身份验证。
操作步骤
-
以具有 platform-admin 角色的用户登录 KubeSphere Web 控制台。
-
点击集群管理,并进入 host 集群。
-
在左侧导航栏选择配置 > 保密字典。
-
在页面点击创建。
-
在创建保密字典对话框,点击右上角的编辑 YAML 开关,使用 yaml 创建保密字典。
-
按照以下示例及参数说明修改 yaml 文件,配置完成后,点击创建。
-
登出 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.yaml 下 provider 部分的配置,其他部分请与 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.yaml 下 provider 部分的参数说明。保密字典中其他部分的参数说明,请参阅配置外部身份验证。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
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 键名 |