第 10 章 托管 control plane 的身份验证和授权


OpenShift Container Platform control plane 包含内置的 OAuth 服务器。您可以获取 OAuth 访问令牌来向 OpenShift Container Platform API 进行身份验证。创建托管集群后,您可以通过指定身份提供程序来配置 OAuth。

10.1. 使用 CLI 为托管集群配置 OAuth 服务器

您可以使用 CLI 为托管集群配置内部 OAuth 服务器。

您可以为以下支持的身份提供程序配置 OAuth:

  • oidc
  • htpasswd
  • keystone
  • ldap
  • basic-authentication
  • request-header
  • github
  • gitlab
  • google

在 OAuth 配置中添加任何身份提供程序会删除默认的 kubeadmin 用户提供程序。

注意

在配置身份提供程序时,您必须事先在托管集群中配置至少一个 NodePool 副本。DNS 解析的流量通过 worker 节点发送。您不需要提前为 htpasswdrequest-header 身份提供程序配置 NodePool 副本。

先决条件

  • 已创建托管集群。

流程

  1. 运行以下命令,在管理集群上编辑 HostedCluster 自定义资源(CR):

    $ oc edit hostedcluster <hosted_cluster_name> -n <hosted_cluster_namespace>
  2. 使用以下示例在 HostedCluster CR 中添加 OAuth 配置:

    apiVersion: hypershift.openshift.io/v1alpha1
    kind: HostedCluster
    metadata:
      name: <hosted_cluster_name>
      namespace: <hosted_cluster_namespace>
    spec:
      configuration:
        oauth:
          identityProviders:
          - openID:
              claims:
                email:
                  - <email_address>
                name:
                  - <display_name>
                preferredUsername:
                  - <preferred_username>
              clientID: <client_id>
              clientSecret:
                name: <client_id_secret_name>
              issuer: https://example.com/identity
            mappingMethod: lookup
            name: IAM
            type: OpenID
    • metadata.name 指定托管集群名称。
    • metadata.namespace 指定托管集群命名空间。
    • spec.configuration.oauth. identityProviders.openID 是一个供应商名称,作为身份声明值的前缀,以此组成身份名称。提供程序名称也用于构建重定向 URL。
    • spec.configuration.oauth. identityProviders.openID.claims.email 定义用作电子邮件地址的属性列表。
    • spec.configuration.oauth. identityProviders.openID.claims.name 定义用作显示名称的属性列表。
    • spec.configuration.oauth. identityProviders.openID.claims.preferredUsername 定义用作首选用户名的属性列表。
    • spec.configuration.oauth. identityProviders.openID.clientID 定义在 OpenID 供应商处注册的客户端 ID。您必须允许客户端重定向到 https://oauth-openshift.apps.<cluster_name>.<cluster_domain>/oauth2callback/<idp_provider_name> URL。
    • spec.configuration.oauth. identityProviders.openID.clientSecret.name 定义在 OpenID 供应商处注册的客户端 secret。
    • spec.configuration.oauth. identityProviders.openID.issuer 指定 OpenID spec 中描述的签发者标识符。您必须使用没有查询或片段组件的 https。有关签发者标识符的更多信息,请参阅"签发者标识符"。
    • spec.configuration.oauth. identityProviders.mappingMethod 定义了一个映射方法,用于控制如何在此供应商和 User 对象的身份之间建立映射。
  3. 保存文件以使改变生效。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部