5.9.3.6. 创建服务主体

由于 OpenShift Container Platform 及其安装程序必须通过 Azure Resource Manager 创建 Microsoft Azure 资源,因此您必须创建一个能代表它的服务主体。

先决条件

  • 安装或更新 Azure CLI
  • 安装jq软件包。
  • 您的 Azure 帐户具有您所用订阅所需的角色。

流程

  1. 登录 Azure CLI:

    $ az login

    在 Web 控制台中,使用您的凭证登录 Azure。

  2. 如果您的 Azure 帐户使用订阅,请确保使用正确的订阅。

    1. 查看可用帐户列表并记录您要用于集群的订阅的 tenantId 值:

      $ az account list --refresh

      输出示例

      [
        {
          "cloudName": "AzureCloud",
          "id": "9bab1460-96d5-40b3-a78e-17b15e978a80",
          "isDefault": true,
          "name": "Subscription Name",
          "state": "Enabled",
          "tenantId": "6057c7e9-b3ae-489d-a54e-de3f6bf6a8ee",
          "user": {
            "name": "you@example.com",
            "type": "user"
          }
        }
      ]

    2. 查看您的活跃帐户详情,确认 tenantId 值与您要使用的订阅匹配:

      $ az account show

      输出示例

      {
        "environmentName": "AzureCloud",
        "id": "9bab1460-96d5-40b3-a78e-17b15e978a80",
        "isDefault": true,
        "name": "Subscription Name",
        "state": "Enabled",
        "tenantId": "6057c7e9-b3ae-489d-a54e-de3f6bf6a8ee", 1
        "user": {
          "name": "you@example.com",
          "type": "user"
        }
      }

      1
      确定 tenantId 参数的值是正确订阅的 UUID。
    3. 如果您使用的订阅不正确,请更改活跃的订阅:

      $ az account set -s <id> 1
      1
      替换您要用于 <id> 的订阅的 id 值。
    4. 如果您更改了活跃订阅,请重新显示您的帐户信息:

      $ az account show

      输出示例

      {
        "environmentName": "AzureCloud",
        "id": "33212d16-bdf6-45cb-b038-f6565b61edda",
        "isDefault": true,
        "name": "Subscription Name",
        "state": "Enabled",
        "tenantId": "8049c7e9-c3de-762d-a54e-dc3f6be6a7ee",
        "user": {
          "name": "you@example.com",
          "type": "user"
        }
      }

  3. 记录前面输出中 tenantIdid 参数的值。OpenShift Container Platform 安装过程中需要这些值。
  4. 为您的帐户创建服务主体:

    $ az ad sp create-for-rbac --role Contributor --name <service_principal> 1
    1
    <service_principal> 替换要您要分配给服务主体的名称。

    输出示例

    Changing "<service_principal>" to a valid URI of "http://<service_principal>", which is the required format used for service principal names
    Retrying role assignment creation: 1/36
    Retrying role assignment creation: 2/36
    Retrying role assignment creation: 3/36
    Retrying role assignment creation: 4/36
    {
      "appId": "8bd0d04d-0ac2-43a8-928d-705c598c6956",
      "displayName": "<service_principal>",
      "name": "http://<service_principal>",
      "password": "ac461d78-bf4b-4387-ad16-7e32e328aec6",
      "tenant": "6048c7e9-b2ad-488d-a54e-dc3f6be6a7ee"
    }

  5. 记录前面输出中 appIdpassword 参数的值。OpenShift Container Platform 安装过程中需要这些值。
  6. 为服务主体授予额外权限。

    • 您必须始终将 ContributorUser Access Administrator 角色添加到应用程序注册服务主体中,以便集群可以为组件分配凭证。
    • 要以 mint 模式操作 Cloud Credential Operator(CCO),应用程序注册服务主体还需要 Azure Active Directory Graph/Application.ReadWrite.OwnedBy API 权限。
    • 要以 passthrough 模式 操作 CCO,应用程序注册服务主体不需要额外的 API 权限。

    如需有关 CCO 模式的更多信息,请参阅 身份验证和授权 指南的"管理云供应商凭证"一节中的"关于 Cloud Credential Operator"。

    1. 要分配 User Access Administrator 角色,请运行以下命令:

      $ az role assignment create --role "User Access Administrator" \
          --assignee-object-id $(az ad sp list --filter "appId eq '<appId>'" \
             | jq '.[0].id' -r) 1
      1
      <appId> 替换为服务器主体的 appId 参数值。
    2. 要分配 Azure Active Directory Graph 权限,请运行以下命令:

      $ az ad app permission add --id <appId> \ 1
           --api 00000002-0000-0000-c000-000000000000 \
           --api-permissions 824c81eb-e3f8-4ee6-8f6d-de7f50d565b7=Role
      1
      <appId> 替换为服务器主体的 appId 参数值。

      输出示例

      Invoking "az ad app permission grant --id 46d33abc-b8a3-46d8-8c84-f0fd58177435 --api 00000002-0000-0000-c000-000000000000" is needed to make the change effective

      如需进一步了解可通过此命令授予的具体权限,请参阅 Windows Azure Active Directory 权限的 GUID 表

    3. 批准权限请求。如果您的帐户没有 Azure Active Directory 租户管理员角色,请按照您的组织的准则请租户管理员批准您的权限请求。

      $ az ad app permission grant --id <appId> \ 1
           --api 00000002-0000-0000-c000-000000000000
      1
      <appId> 替换为服务器主体的 appId 参数值。

其他资源