使用 Google CLI 创建私钥

要在 UDP 控制台中创建‘VSB 到 GCP’计划,需要使用私钥。

在创建新密钥之前,必须安装并初始化 gcloud CLI。请按照下面链接中提到的步骤,以管理员权限安装和初始化 CLI 工具。

在同一环境中安装并初始化 gcloud 后,请按照以下步骤手动创建密钥或运行 Windows powershell 脚本 gcp_auth_key_create.ps1:

  1. 安装并初始化 gcloud 工具后,请执行以下操作:
    1. 通过使用命令“gcloud --version”来检查版本,测试并确认 gcloud 工具已成功安装。
    2. 在初始化过程中,使用对组织有完全控制权的管理员帐户在 gcloud 中进行身份验证,将其附加到特定项目。
    3. 使用“gcloud config set project PROJECT_ID”命令设置需要在其中创建 VSB 实例的项目,其中 PROJECT_ID 是组织中的一个有效项目。
  2. 通过为项目创建一个允许执行 VSB 相关任务的自定义角色,使用 gcloud 为用户配置对项目的访问权限。
  3. 要创建服务帐户,请替换以下值并运行下面给出的命令:
  4. gcloud iam service-accounts create SA_NAME --display-name="DISPLAY_NAME"

  5. 获取服务帐户电子邮件地址并运行此命令:
  6. gcloud iam service-accounts list --filter "displayName=DISPLAY_NAME"

  7. 替换以下内容:
  8. DISPLAY_NAME:在步骤 3 中提供的显示名称。
  9. 记录上述命令的输出内容中的服务帐户电子邮件地址,其格式如下并在其余步骤中表示为 SA_EMAIL:
  10. SA_NAME@PROJECT_ID.iam.gserviceaccount.com
  11. 要创建并下载 JSON 密钥文件,请替换以下值并运行下面给出的命令:
  12. gcloud iam service-accounts keys create KEY_FILE --iam-account=SA_EMAIL

  13. JSON 密钥文件包含您稍后需要在 UDP 控制台中使用的私人密钥。
  14. 要创建包含 VSB 任务所需的以下 69 种权限的自定义角色,请替换以下值并运行命令:
  15. gcloud iam roles create ROLE_NAME --project PROJECT_ID –permissions=
    compute.addresses.list,compute.addresses.use,compute.disks.create,compute.disks.createSnapshot,
    compute.disks.delete,compute.disks.get,compute.disks.use,compute.firewallPolicies.create,compute.firewallPolicies.delete,
    compute.firewallPolicies.get,compute.firewallPolicies.list,compute.firewallPolicies.update,compute.firewallPolicies.use,
    compute.firewalls.create,compute.firewalls.delete,compute.firewalls.get,compute.firewalls.list,compute.firewalls.update,
    compute.globalOperations.get,compute.images.useReadOnly,compute.instances.addAccessConfig,
    compute.instances.attachDisk,compute.instances.create,compute.instances.delete,compute.instances.deleteAccessConfig,
    compute.instances.detachDisk,compute.instances.list,compute.instances.setMetadata,compute.instances.setServiceAccount,
    compute.instances.start,compute.instances.stop,compute.instances.update,compute.instances.updateDisplayDevice,compute.machineTypes.list,compute.networks.access,
    compute.networks.create,compute.networks.delete,compute.networks.get,compute.networks.getEffectiveFirewalls,compute.networks.list,compute.networks.update,
    compute.networks.use,compute.networks.useExternalIp,compute.regionOperations.get,compute.snapshots.create,compute.snapshots.delete,compute.snapshots.get,
    compute.snapshots.useReadOnly,compute.subnetworks.create,compute.subnetworks.delete,compute.subnetworks.get,compute.subnetworks.list,compute.subnetworks.update,
    compute.subnetworks.use,compute.subnetworks.useExternalIp,compute.zoneOperations.get,compute.zones.list,iam.serviceAccounts.actAs,iam.serviceAccounts.get,iam.serviceAccounts.list,
    resourcemanager.projects.get,serviceusage.services.use,storage.buckets.create,storage.buckets.enableObjectRetention,storage.buckets.list,storage.objects.create,storage.objects.delete,
    storage.objects.get,storage.objects.list

  16. 此命令将在项目中创建一个名为 ROLE_NAME 的自定义角色,并赋予其创建和管理实例的权限。角色的全名将作为上述命令的输出信息列出,角色名称格式为 projects/PROJECT_ID/roles/ROLE_NAME
  17. 注意:角色是一组权限。不能直接向用户分配权限,而应该为用户授予角色。向用户授予一个角色时,将为他们授予该角色中包含的所有权限。

  18. 要将自定义角色 ROLE_NAME 绑定到服务帐户 SA_NAME,请替换以下值并运行下面给出的命令:
  19. gcloud projects add-iam-policy-binding PROJECT_ID --member serviceAccount:SA_EMAIL --role=ROLE_FULL_NAME

  20. 在 UDP 控制台中,使用在步骤 5 中下载的服务帐户 JSON 密钥文件创建‘VSB 到 GCP’计划。