本文档介绍了如何在 Dataform 中执行以下操作:
准备工作
- 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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. - 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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. 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
Verify that billing is enabled for your Google Cloud project.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
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
Verify that billing is enabled for your Google Cloud project.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
向 Dataform 授予所需的访问权限
本部分介绍如何授予 Dataform 服务代理和自定义服务账号在 BigQuery 中运行工作流所需的 Identity and Access Management (IAM) 角色。
自定义服务账号和 Dataform 服务代理简介
您可以通过以下方式配置自定义服务账号,以代表您运行工作流:
创建 Dataform 代码库或工作流配置时,您可以选择您拥有 act-as 权限的任何服务账号。您必须为与 Dataform 资源关联的所有服务账号配置所需的 act-as 权限。
首次创建 Dataform 代码库时,Dataform 会自动生成服务代理。 Dataform 会使用服务代理代表您与 BigQuery 进行交互。
您的 Dataform 服务代理 ID 采用以下格式:
service-PROJECT_NUMBER@gcp-sa-dataform.iam.gserviceaccount.com
将 PROJECT_NUMBER 替换为您的Google Cloud 项目的数字 ID。您可以在Google Cloud 控制台信息中心找到 Google Cloud 项目 ID。如需了解详情,请参阅查找项目名称、编号和 ID。
Dataform 服务代理、自定义服务账号和 Google 账号所需的角色
Dataform 服务代理、自定义服务账号以及用于在 Dataform 中进行身份验证的 Google 账号的用户凭据(预览版)需要具有以下 BigQuery IAM 角色,才能在 BigQuery 中运行工作流:
- 对 Dataform 需要同时具有读取和写入权限的项目拥有 BigQuery Data Editor (
roles/bigquery.dataEditor) 角色。这些项目通常包括托管 Dataform 代码库的项目。 - Dataform 需要对项目具有只读权限,因此您需要为这些项目授予 BigQuery Data Viewer (
roles/bigquery.dataViewer) 角色。 - 托管 Dataform 代码库的项目中的 BigQuery Job User (
roles/bigquery.jobUser)。 - 如果您想查询 BigQuery 数据集,则需要拥有 BigQuery Data Owner (
roles/bigquery.dataOwner) 角色。 - 如果您想使用 BigQuery 政策标记,请参阅 BigQuery 列级访问权限控制角色。
此外,还需向工作流配置的有效服务账号授予 Dataform 服务代理的以下角色。这些角色是严格的“模拟为”模式正常运行所必需的。
- Service Account User
(
roles/iam.serviceAccountUser) - Service Account Token Creator
(
roles/iam.serviceAccountTokenCreator)
如需自动发布代码库和自动运行工作流,请向 Dataform 服务代理授予有效服务账号的 iam.serviceAccounts.actAs 权限。
安全注意事项
向 Dataform 服务代理、自定义服务账号或用户的 Google 账号授予 Dataform 所需的角色(预览版)时,需要考虑以下安全问题:
无论 VPC Service Controls 是否启用,任何被授予所需角色的自定义服务账号都可能会获得对该服务账号所属项目的 BigQuery 或 Secret Manager 的访问权限。当 Dataform 使用自定义服务账号执行工作流时,Dataform 请求会被视为源自包含您的代码库的项目的 VPC Service Controls 边界内。因此,如果 Dataform 和其他服务(例如 BigQuery 或 Secret Manager)的资源位于同一服务边界内,VPC Service Controls 不会阻止它们之间的通信。
如需详细了解如何管理这些安全边界,请参阅配置 VPC Service Controls。
拥有
dataform.repositories.createIAM 权限的任何用户都可以使用 Dataform 服务代理和授予该服务代理或服务账号的所有权限来运行代码。如需了解详情,请参阅 Dataform 权限的安全注意事项。
为了保持安全的权限模型,请定期审核 Dataform 服务代理角色绑定。如需详细了解监控说明,请参阅使用 Security Command Center 监控服务代理权限。
如需限制用户、服务代理或服务账号在 BigQuery 中可以读取或写入的数据,您可以向所选 BigQuery 数据集或表授予精细的 BigQuery IAM 权限。如需了解详情,请参阅控制对数据集的访问权限和控制对表和视图的访问权限。
为防止用户在使用其他用户的 Google 账号的用户凭据时执行操作,系统会强制执行以下限制:
- 如需使用附加到工作流配置的其他 Google 账号的用户凭据修改工作流配置,您需要将您自己的 Google 账号的用户凭据附加到工作流配置,或者更改工作流配置以使用自定义服务账号进行身份验证。
- 如果存在引用发布配置的工作流配置,且该配置附加了其他 Google 账号用户的凭据,则您无法修改发布配置的编译结果。
您无法将工作流配置设置为使用 Google 账号用户凭据进行身份验证,也无法引用具有时间表的发布配置。此限制会带来以下后果:
- 如果存在引用相应发布配置且设置为使用 Google 账号用户凭据进行身份验证的工作流配置,您就无法更新发布配置以使用时间表。
- 您无法创建使用 Google 账号用户凭据进行身份验证并指向具有时间表的发布配置的工作流配置。
- 您无法创建或更新工作流配置,以使用 Google 账号用户凭据并指向具有时间表的发布配置。