创建具有用户凭据访问权限的实例
本页面介绍了如何创建通过用户凭据访问 Google Cloud 服务和 API 的 Vertex AI Workbench 实例。
您的用户凭据是与您的 Google 账号相关联的凭据。用户凭据决定了您的 Google 账号可以访问哪些 Google Cloud 服务和 API。
默认情况下,当您在 Vertex AI Workbench 实例中运行代码时,您的实例可以使用与实例服务账号关联的凭据访问 Google Cloud 服务和 API。这意味着,您的实例具有与服务账号相同的 Google Cloud 访问权限。
本页面介绍了如何创建和配置实例,使其具有与您的用户凭据相同的 Google Cloud 访问权限。
概览
Vertex AI Workbench 使用由 Google 管理的全局 OAuth 客户端来管理用户凭证访问权限,该权限的范围限定为用户项目中的 Google Cloud 资源。用户必须针对每个 Vertex AI Workbench 实例向 OAuth 客户端授予管理其凭证的同意声明。您只需在 Google Cloud 控制台中点击打开 JupyterLab 按钮,系统便会打开一个对话框,您只需通过该对话框为每个实例完成一次此操作。
用于创建 Vertex AI Workbench 实例的服务账号是以下服务代理:
service-PROJECT_NUMBER@gcp-sa-notebooks-vm.
。
此服务代理可为导出日志等基础服务提供有限的权限。如果启用了最终用户凭证,用户将无法指定其他服务账号。
启用了最终用户凭证的实例在虚拟机资源上附加了 notebooks-managed-euc: true
Compute Engine 标签和 euc-enabled: true
元数据键,以表示功能已启用。
限制
在规划项目时,请考虑以下限制:
Vertex AI Workbench 使用 Google 管理的全局 OAuth 客户端来管理用户凭证访问权限。组织无法实施精细的控制措施、访问 OAuth 客户端,也无法使用日志记录来检查 OAuth 客户端的使用情况。
为了保护使用托管式用户凭证的 Vertex AI Workbench 实例的安全性,用户不能执行以下操作:
- 使用 SSH 访问实例。
- 运行启动后脚本。
- 访问详细的虚拟机页面。
- 使用非 Google 创建的图片。
不支持使用第三方凭证,因为 OAuth 客户端仅支持 Google 管理的 OAuth 凭证。
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Notebooks API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Notebooks API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. 在 Google Cloud 控制台中,前往实例页面。
点击
新建。在新建实例对话框中,点击高级选项。
在创建实例对话框的详细信息部分中,为新实例提供以下信息:
- 名称:为新实例提供名称。 名称必须以字母开头,后面最多可跟 62 个小写字母、数字或连字符 (-),但不能以连字符结尾。
- 区域和可用区:为新实例选择区域和可用区。为获得最佳网络性能,请选择与您的地理位置最近的区域。 查看可用的 Vertex AI Workbench 位置。
在 IAM 和安全性部分中,选择单个用户。
在用户邮箱字段中,输入要授予访问权限的用户账号。如果指定用户不是实例的创建者,您必须向指定用户授予实例的服务账号的 Service Account User 角色 (
roles/iam.serviceAccountUser
)。选择启用托管式最终用户凭证。
完成实例创建对话框的其余部分,然后点击创建。
Vertex AI Workbench 会创建实例并自动启动该实例。当实例可供使用时,Vertex AI Workbench 会在 Google Cloud 控制台中激活打开 JupyterLab 链接。
用户必须针对每个 Vertex AI Workbench 实例向 OAuth 客户端授予管理其凭证的同意声明。此操作只需为每个实例执行一次。如需授予同意声明,请点击打开 JupyterLab,然后完成显示的对话框。
如果您尝试在未授予同意声明的情况下访问实例,JupyterLab 会显示一条消息,提示您通过从Google Cloud 控制台打开 JupyterLab 来进行身份验证。
如需验证您的最终用户凭证是否可在 JupyterLab 中使用,请在 JupyterLab 中打开终端,然后输入以下命令:
gcloud auth list
在 Google Cloud 控制台中,前往实例页面。
在实例名称旁边,点击打开 JupyterLab。
在 JupyterLab 中,选择文件 > 新建 > 终端。
在终端窗口中,运行以下命令:
gcloud auth login
输入
Y
。按照说明复制验证码,然后将其输入到终端中。
使用联合 JupyterLab 代理打开 JupyterLab。
在 JupyterLab 中,选择文件 > 新建 > 终端。
使用无头登录创建员工身份联合凭据文件。
在终端窗口中,运行以下命令:
gcloud auth login --cred-file="CREDENTIAL_FILE"
将 CREDENTIAL_FILE 替换为您创建的凭据文件的路径和名称。
按照说明通过第三方身份验证门户进行身份验证。
使用以下命令确认是否可以通过实例访问您的凭据:
gcloud auth list
所需的角色
如需获得创建 Vertex AI Workbench 实例所需的权限,请让您的管理员为您授予项目的 Notebooks Runner (roles/notebooks.runner
) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
创建单个用户实例
如需使用 Google Cloud 控制台创建 Vertex AI Workbench 实例,请执行以下操作:
使用您的用户凭据对实例进行身份验证
Vertex AI Workbench 可以使用应用默认凭证 (ADC),通过您的用户凭证向 Google Cloud 服务和 API 进行身份验证。本部分介绍在存在任何限制导致您无法启用受管理的凭证时,如何向 ADC 提供您的用户凭证。
身份验证步骤取决于您是使用 Google 账号还是第三方凭据。
Google 账号
在您能够访问实例上的 JupyterLab 后,请执行以下操作:
第三方凭据
如果您使用第三方凭据创建了实例,那么在 JupyterLab 代理可用后,请执行以下操作: