搜索

7.8. 在 kube-system 项目中存储管理员级别的 secret 的替代方案

download PDF

默认情况下,管理员 secret 存储在 kube-system 项目中。如果您在 install-config.yaml 文件中将 credentialsMode 参数配置为 Manual,则必须使用以下替代方案之一:

7.8.1. 手动创建长期凭证

在无法访问云身份和访问管理(IAM)API 的环境中,或者管理员更不希望将管理员级别的凭证 secret 存储在集群 kube-system 命名空间中时,可以在安装前将 Cloud Credential Operator(CCO)放入手动模式。

流程

  1. 如果您没有将 install-config.yaml 配置文件中的 credentialsMode 参数设置为 Manual,请修改值,如下所示:

    配置文件片段示例

    apiVersion: v1
    baseDomain: example.com
    credentialsMode: Manual
    # ...

  2. 如果您之前还没有创建安装清单文件,请运行以下命令:

    $ openshift-install create manifests --dir <installation_directory>

    其中 <installation_directory> 是安装程序在其中创建文件的目录。

  3. 运行以下命令,使用安装文件中的发行镜像设置 $RELEASE_IMAGE 变量:

    $ RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')
  4. 运行以下命令,从 OpenShift Container Platform 发行镜像中提取 CredentialsRequest 自定义资源 (CR) 列表:

    $ oc adm release extract \
      --from=$RELEASE_IMAGE \
      --credentials-requests \
      --included \1
      --install-config=<path_to_directory_with_installation_configuration>/install-config.yaml \2
      --to=<path_to_directory_for_credentials_requests> 3
    1
    --included 参数仅包含特定集群配置所需的清单。
    2
    指定 install-config.yaml 文件的位置。
    3
    指定要存储 CredentialsRequest 对象的目录的路径。如果指定的目录不存在,这个命令会创建它。

    此命令为每个 CredentialsRequest 对象创建一个 YAML 文件。

    CredentialsRequest 对象示例

    apiVersion: cloudcredential.openshift.io/v1
    kind: CredentialsRequest
    metadata:
      name: <component_credentials_request>
      namespace: openshift-cloud-credential-operator
      ...
    spec:
      providerSpec:
        apiVersion: cloudcredential.openshift.io/v1
        kind: AzureProviderSpec
        roleBindings:
        - role: Contributor
      ...

  5. 在之前生成的 openshift-install 清单目录中为 secret 创建 YAML 文件。secret 必须使用在 spec.secretRef 中为每个 CredentialsRequest 定义的命名空间和 secret 名称存储。

    带有 secret 的 CredentialsRequest 对象示例

    apiVersion: cloudcredential.openshift.io/v1
    kind: CredentialsRequest
    metadata:
      name: <component_credentials_request>
      namespace: openshift-cloud-credential-operator
      ...
    spec:
      providerSpec:
        apiVersion: cloudcredential.openshift.io/v1
        kind: AzureProviderSpec
        roleBindings:
        - role: Contributor
          ...
      secretRef:
        name: <component_secret>
        namespace: <component_namespace>
      ...

    Secret 对象示例

    apiVersion: v1
    kind: Secret
    metadata:
      name: <component_secret>
      namespace: <component_namespace>
    data:
      azure_subscription_id: <base64_encoded_azure_subscription_id>
      azure_client_id: <base64_encoded_azure_client_id>
      azure_client_secret: <base64_encoded_azure_client_secret>
      azure_tenant_id: <base64_encoded_azure_tenant_id>
      azure_resource_prefix: <base64_encoded_azure_resource_prefix>
      azure_resourcegroup: <base64_encoded_azure_resourcegroup>
      azure_region: <base64_encoded_azure_region>

重要

在升级使用手动维护凭证的集群前,您必须确保 CCO 处于可升级状态。

7.8.2. 配置 Azure 集群以使用短期凭证

要安装使用 Microsoft Entra Workload ID 的集群,您必须配置 Cloud Credential Operator 工具,并为集群创建所需的 Azure 资源。

7.8.2.1. 配置 Cloud Credential Operator 工具

当 Cloud Credential Operator(CCO)以手动模式运行时,要从集群外部创建和管理云凭证,提取并准备 CCO 实用程序(ccoctl)二进制文件。

注意

ccoctl 工具是在 Linux 环境中运行的 Linux 二进制文件。

先决条件

  • 您可以访问具有集群管理员权限的 OpenShift Container Platform 帐户。
  • 已安装 OpenShift CLI(oc)。
  • 您已为 ccoctl 工具创建了全局 Microsoft Azure 帐户,用于以下权限:

    例 7.3. 所需的 Azure 权限

    • Microsoft.Resources/subscriptions/resourceGroups/read
    • Microsoft.Resources/subscriptions/resourceGroups/write
    • Microsoft.Resources/subscriptions/resourceGroups/delete
    • Microsoft.Authorization/roleAssignments/read
    • Microsoft.Authorization/roleAssignments/delete
    • Microsoft.Authorization/roleAssignments/write
    • Microsoft.Authorization/roleDefinitions/read
    • Microsoft.Authorization/roleDefinitions/write
    • Microsoft.Authorization/roleDefinitions/delete
    • Microsoft.Storage/storageAccounts/listkeys/action
    • Microsoft.Storage/storageAccounts/delete
    • Microsoft.Storage/storageAccounts/read
    • Microsoft.Storage/storageAccounts/write
    • Microsoft.Storage/storageAccounts/blobServices/containers/write
    • Microsoft.Storage/storageAccounts/blobServices/containers/delete
    • Microsoft.Storage/storageAccounts/blobServices/containers/read
    • Microsoft.ManagedIdentity/userAssignedIdentities/delete
    • Microsoft.ManagedIdentity/userAssignedIdentities/read
    • Microsoft.ManagedIdentity/userAssignedIdentities/write
    • Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/read
    • Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/write
    • Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/delete
    • Microsoft.Storage/register/action
    • Microsoft.ManagedIdentity/register/action

流程

  1. 运行以下命令,为 OpenShift Container Platform 发行镜像设置变量:

    $ RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')
  2. 运行以下命令,从 OpenShift Container Platform 发行镜像获取 CCO 容器镜像:

    $ CCO_IMAGE=$(oc adm release info --image-for='cloud-credential-operator' $RELEASE_IMAGE -a ~/.pull-secret)
    注意

    确保 $RELEASE_IMAGE 的架构与将使用 ccoctl 工具的环境架构相匹配。

  3. 运行以下命令,将 CCO 容器镜像中的 ccoctl 二进制文件提取到 OpenShift Container Platform 发行镜像中:

    $ oc image extract $CCO_IMAGE --file="/usr/bin/ccoctl" -a ~/.pull-secret
  4. 运行以下命令更改权限以使 ccoctl 可执行:

    $ chmod 775 ccoctl

验证

  • 要验证 ccoctl 是否准备就绪,可以尝试显示帮助文件。运行命令时使用相对文件名,例如:

    $ ./ccoctl.rhel9

    输出示例

    OpenShift credentials provisioning tool
    
    Usage:
      ccoctl [command]
    
    Available Commands:
      alibabacloud Manage credentials objects for alibaba cloud
      aws          Manage credentials objects for AWS cloud
      azure        Manage credentials objects for Azure
      gcp          Manage credentials objects for Google cloud
      help         Help about any command
      ibmcloud     Manage credentials objects for IBM Cloud
      nutanix      Manage credentials objects for Nutanix
    
    Flags:
      -h, --help   help for ccoctl
    
    Use "ccoctl [command] --help" for more information about a command.

7.8.2.2. 使用 Cloud Credential Operator 实用程序创建 Azure 资源

您可以使用 ccoctl azure create-all 命令自动创建 Azure 资源。

注意

默认情况下,ccoctl 在运行命令的目录中创建对象。要在其他目录中创建对象,请使用 --output-dir 标志。此流程使用 <path_to_ccoctl_output_dir> 来引用这个目录。

先决条件

您必须:

  • 提取并准备好 ccoctl 二进制文件。
  • 使用 Azure CLI 访问 Microsoft Azure 帐户。

流程

  1. 运行以下命令,使用安装文件中的发行镜像设置 $RELEASE_IMAGE 变量:

    $ RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')
  2. 运行以下命令,从 OpenShift Container Platform 发行镜像中提取 CredentialsRequest 对象列表:

    $ oc adm release extract \
      --from=$RELEASE_IMAGE \
      --credentials-requests \
      --included \1
      --install-config=<path_to_directory_with_installation_configuration>/install-config.yaml \2
      --to=<path_to_directory_for_credentials_requests> 3
    1
    --included 参数仅包含特定集群配置所需的清单。
    2
    指定 install-config.yaml 文件的位置。
    3
    指定要存储 CredentialsRequest 对象的目录的路径。如果指定的目录不存在,这个命令会创建它。
    注意

    此命令可能需要一些时间才能运行。

  3. 要启用 ccoctl 工具自动检测 Azure 凭证,请运行以下命令登录到 Azure CLI:

    $ az login
  4. 运行以下命令,使用 ccoctl 工具处理所有 CredentialsRequest 对象:

    $ ccoctl azure create-all \
      --name=<azure_infra_name> \1
      --output-dir=<ccoctl_output_dir> \2
      --region=<azure_region> \3
      --subscription-id=<azure_subscription_id> \4
      --credentials-requests-dir=<path_to_credentials_requests_directory> \5
      --dnszone-resource-group-name=<azure_dns_zone_resource_group_name> \6
      --tenant-id=<azure_tenant_id> 7
    1
    为用于跟踪的所有创建 Azure 资源指定用户定义的名称。
    2
    可选:指定您希望 ccoctl 实用程序在其中创建对象的目录。默认情况下,实用程序在运行命令的目录中创建对象。
    3
    指定在其中创建云资源的 Azure 区域。
    4
    指定要使用的 Azure 订阅 ID。
    5
    指定包含组件 CredentialsRequest 对象文件的目录。
    6
    指定包含集群基域 Azure DNS 区的资源组名称。
    7
    指定要使用的 Azure 租户 ID。
    注意

    如果您的集群使用 TechPreviewNoUpgrade 功能集启用的技术预览功能,则必须包含 --enable-tech-preview 参数。

    要查看其他可选参数以及如何使用它们的说明,请运行 azure create-all --help 命令。

验证

  • 要验证 OpenShift Container Platform secret 是否已创建,列出 <path_to_ccoctl_output_dir>/manifests 目录中的文件:

    $ ls <path_to_ccoctl_output_dir>/manifests

    输出示例

    azure-ad-pod-identity-webhook-config.yaml
    cluster-authentication-02-config.yaml
    openshift-cloud-controller-manager-azure-cloud-credentials-credentials.yaml
    openshift-cloud-network-config-controller-cloud-credentials-credentials.yaml
    openshift-cluster-api-capz-manager-bootstrap-credentials-credentials.yaml
    openshift-cluster-csi-drivers-azure-disk-credentials-credentials.yaml
    openshift-cluster-csi-drivers-azure-file-credentials-credentials.yaml
    openshift-image-registry-installer-cloud-credentials-credentials.yaml
    openshift-ingress-operator-cloud-credentials-credentials.yaml
    openshift-machine-api-azure-cloud-credentials-credentials.yaml

    您可以验证 Microsoft Entra ID 服务账户通过查询 Azure 而创建。如需更多信息,请参阅 Azure 文档中有关列出 Entra ID 服务帐户的内容。

7.8.2.3. 整合 Cloud Credential Operator 实用程序清单

要为单个组件在集群外实现短期安全凭证,您必须将创建 Cloud Credential Operator 实用程序 (ccoctl) 的清单文件移到安装程序的正确目录中。

先决条件

  • 您已使用托管集群的云平台配置了帐户。
  • 您已配置了 Cloud Credential Operator 实用程序 (ccoctl)。
  • 已使用 ccoctl 工具创建了集群所需的云供应商资源。

流程

  1. 如果您没有将 install-config.yaml 配置文件中的 credentialsMode 参数设置为 Manual,请修改值,如下所示:

    配置文件片段示例

    apiVersion: v1
    baseDomain: example.com
    credentialsMode: Manual
    # ...

  2. 如果您使用 ccoctl 实用程序创建新的 Azure 资源组,而不是使用现有资源组,请修改 install-config.yaml 中的 resourceGroupName 参数,如下所示:

    配置文件片段示例

    apiVersion: v1
    baseDomain: example.com
    # ...
    platform:
      azure:
        resourceGroupName: <azure_infra_name> 1
    # ...

    1
    这个值必须与 ccoctl azure create-all 命令的 --name 参数指定的 Azure 资源用户定义的名称匹配。
  3. 如果您之前还没有创建安装清单文件,请运行以下命令:

    $ openshift-install create manifests --dir <installation_directory>

    其中 <installation_directory> 是安装程序在其中创建文件的目录。

  4. 运行以下命令,将 ccoctl 工具生成的清单复制到安装程序创建的 manifests 目录中:

    $ cp /<path_to_ccoctl_output_dir>/manifests/* ./manifests/
  5. 将包含私钥的 tls 目录复制到安装目录中:

    $ cp -a /<path_to_ccoctl_output_dir>/tls .
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.