集群认证

该插件为 global 集群故障场景提供独立的认证集成。当 global 集群故障时,用户仍可通过该服务登录访问并操作 Kubernetes 集群,权限保持与 global 集群故障前一致(注:不支持组权限)。

目录

概述

认证集成通过 Connector 自定义资源(CR)配置 OIDC 或 LDAP 身份提供者。

Connector CR 基础

  • CR 类型Connector(apiVersion: dex.coreos.com/v1
  • 命名空间cpaas-system
  • 配置格式config 字段必须是 base64 编码的 JSON 字符串。先将配置写成 JSON 文件,再使用 base64 -w0 config.json 进行编码(macOS 可省略 -w0 参数)。

Connector CR 模板:

apiVersion: dex.coreos.com/v1
kind: Connector
metadata:
  name: <connector-name>
  namespace: cpaas-system
  labels:
    cpaas.io/idp.version: v2  # connector 版本标记
spec:
  type: <oidc|ldap>           # connector 类型
  id: <connector-id>          # 平台内全局唯一
  name: <display-name>        # 登录界面显示名称
  config: <base64-encoded-connector-config-json>

集成 LDAP

LDAP 配置

LDAP connector 配置示例:

{
  "bindDN": "cn=Administrator,cn=Users,dc=example,dc=com",
  "bindPW": "<password>",
  "host": "ldap.example.com:389",
  "insecureNoSSL": true,
  "insecureSkipVerify": true,
  "startTLS": true,
  "userSearch": {
    "baseDN": "dc=example,dc=com",
    "filter": "(objectClass=organizationalPerson)",
    "idAttr": "distinguishedName",
    "nameAttr": "cn",
    "username": "cn",
    "emailAttr": "mail"
  }
}

字段说明:

字段说明必填备注
bindDN绑定账号 DN需具备搜索权限
bindPW绑定账号密码与 bindDN 配对
hostLDAP 主机:端口 389+StartTLS 或 636(LDAPS)
insecureNoSSL禁用 SSL设置为 true
startTLS启用 StartTLS设置为 true
insecureSkipVerify跳过 TLS 验证设置为 true
userSearch.baseDN搜索基准 DN目录根或组织单位 DN
userSearch.filter用户过滤条件例如 (objectClass=organizationalPerson)
userSearch.idAttr唯一 ID 属性例如 distinguishedName
userSearch.nameAttr显示/身份属性作为平台侧标识
userSearch.username登录属性(可多)逗号分隔候选项
userSearch.emailAttr邮箱属性目录无邮箱时可省略

应用 LDAP Connector

操作步骤:

# 1) 创建 JSON 配置文件
cat <<'EOF' > ldap-config.json
{
  "bindDN": "cn=Administrator,cn=Users,dc=example,dc=com",
  "bindPW": "<password>",
  "host": "ldap.example.com:389",
  "insecureNoSSL": true,
  "insecureSkipVerify": true,
  "startTLS": true,
  "userSearch": {
    "baseDN": "dc=example,dc=com",
    "filter": "(objectClass=organizationalPerson)",
    "idAttr": "distinguishedName",
    "nameAttr": "cn",
    "username": "cn",
    "emailAttr": "mail"
  }
}
EOF

# 2) Base64 编码配置
LDAP_B64=$(base64 -w0 ldap-config.json)

# 3) 创建 Connector CR
cat <<EOF > ldap-connector.yaml
apiVersion: dex.coreos.com/v1
kind: Connector
metadata:
  name: ldap-sample
  namespace: cpaas-system
  labels:
    cpaas.io/idp.version: v2
spec:
  type: ldap
  id: ldap-sample
  name: LDAP Sample
  config: ${LDAP_B64}
EOF

# 4) 应用 Connector
kubectl apply -f ldap-connector.yaml

集成 OIDC

OIDC 配置

OIDC connector 配置示例:

{
  "issuer": "https://idp.example.com/auth/realms/master",
  "issuerAlias": "",
  "clientID": "<client-id>",
  "clientSecret": "<client-secret>",
  "redirectURI": "https://<clusterEndpoint>:11780/dex/callback",
  "scopes": ["openid", "profile", "email", "groups"],
  "claimMapping": {
    "email": "email",
    "preferred_username": "preferred_username",
    "groups": "groups"
  },
  "getUserInfo": true,
  "insecureSkipVerify": true
}

字段说明:

字段说明必填备注
issuer上游 IdP 发行者必须与 IdP 元数据匹配
clientIDOIDC 客户端 ID在 IdP 中创建
clientSecretOIDC 客户端密钥与 clientID 配对
redirectURIDex 回调地址必须与 IdP 注册一致。示例:https://<clusterEndpoint>:11780/dex/callback
scopesOIDC 授权范围推荐:openidprofileemailgroups
claimMapping.email邮箱映射映射到上游声明
claimMapping.preferred_username用户名映射映射到上游声明
claimMapping.groups组映射如果上游提供组信息
getUserInfo调用 UserInfo 接口ID Token 缺少字段时设置为 true
insecureSkipVerify跳过 TLS 验证设置为 true(当前配置要求)

应用 OIDC Connector

操作步骤:

# 1) 创建 JSON 配置文件
cat <<'EOF' > oidc-config.json
{
  "issuer": "https://idp.example.com/auth/realms/master",
  "issuerAlias": "",
  "clientID": "<client-id>",
  "clientSecret": "<client-secret>",
  "redirectURI": "https://<clusterEndpoint>:11780/dex/callback",
  "scopes": ["openid", "profile", "email", "groups"],
  "claimMapping": {
    "email": "email",
    "preferred_username": "preferred_username",
    "groups": "groups"
  },
  "getUserInfo": true,
  "insecureSkipVerify": true
}
EOF

# 2) Base64 编码配置
OIDC_B64=$(base64 -w0 oidc-config.json)

# 3) 创建 Connector CR
cat <<EOF > oidc-connector.yaml
apiVersion: dex.coreos.com/v1
kind: Connector
metadata:
  name: oidc-sample
  namespace: cpaas-system
  labels:
    cpaas.io/idp.version: v2
spec:
  type: oidc
  id: oidc-sample
  name: OIDC Sample
  config: ${OIDC_B64}
EOF

# 4) 应用 Connector
kubectl apply -f oidc-connector.yaml
INFO

重要说明:

  • Connector CR 需放置于 cpaas-system 命名空间,以配合 global 集群部署。
  • Base64 编码:Linux 使用 base64 -w0 config.json,macOS 可省略 -w0 参数。

使用 AC CLI 连接 ACP

本节介绍如何使用 AC CLI 通过配置的身份提供者认证并连接 ACP(Application Control Plane)。

前提条件

使用 AC CLI 连接前,请确保:

  1. 已安装 AC CLI(版本 >= 1.1)
  2. 集群网络可达
  3. 插件 auth 服务外部访问地址https://<clusterEndpoint>:<DefaultPort>(默认 DefaultPort11780
  4. 已配置目标 IDP 的 Connector,且确认 Connector CR 名称

验证 Connector 配置:

kubectl get connector -n cpaas-system

示例输出:

NAME        AGE
ldap-test   7m53s
oidc-test   6m27s

命令示例

使用 LDAP 身份提供者登录:

ac login https://<clusterEndpoint>:11780 \
  --idp <ldap-connector-name> \
  --workload \
  --auth-type ldap \
  --username '<username>' \
  --password '<password>'

使用 OIDC 身份提供者登录:

ac login https://<clusterEndpoint>:11780 \
  --idp <oidc-connector-name> \
  --workload \
  --auth-type oidc
TIP

OIDC 认证若需交互式认证,请按 CLI 提示完成登录流程。

命令参数

参数说明必填备注
--idpConnector 名称cpaas-system 命名空间配置的 Connector CR 名称
--workload登录业务集群标识登录业务集群
--auth-type认证类型支持值:ldapoidc
--usernameLDAP 用户名是(仅 LDAP)用于 LDAP 认证
--passwordLDAP 密码是(仅 LDAP)用于 LDAP 认证