使用 IAM 控制对 Dataform 的访问权限

本文档介绍了 Dataform 的访问权限控制选项,并介绍了如何查看和授予 Dataform 角色。 Dataform 使用 Identity and Access Management (IAM) 进行访问权限控制。如需详细了解 IAM 中的角色和权限,请参阅了解角色和权限

预定义的 Dataform 角色

下表列出了可让您访问 Dataform 资源的预定义角色:

Role Permissions

(roles/dataform.admin)

Full access to all Dataform resources.

dataform.*

  • dataform.compilationResults.create
  • dataform.compilationResults.get
  • dataform.compilationResults.list
  • dataform.compilationResults.query
  • dataform.config.get
  • dataform.config.update
  • dataform.locations.get
  • dataform.locations.list
  • dataform.releaseConfigs.create
  • dataform.releaseConfigs.delete
  • dataform.releaseConfigs.get
  • dataform.releaseConfigs.list
  • dataform.releaseConfigs.update
  • dataform.repositories.commit
  • dataform.repositories.computeAccessTokenStatus
  • dataform.repositories.create
  • dataform.repositories.delete
  • dataform.repositories.fetchHistory
  • dataform.repositories.fetchRemoteBranches
  • dataform.repositories.get
  • dataform.repositories.getIamPolicy
  • dataform.repositories.list
  • dataform.repositories.queryDirectoryContents
  • dataform.repositories.readFile
  • dataform.repositories.setIamPolicy
  • dataform.repositories.update
  • dataform.workflowConfigs.create
  • dataform.workflowConfigs.delete
  • dataform.workflowConfigs.get
  • dataform.workflowConfigs.list
  • dataform.workflowConfigs.update
  • dataform.workflowInvocations.cancel
  • dataform.workflowInvocations.create
  • dataform.workflowInvocations.delete
  • dataform.workflowInvocations.get
  • dataform.workflowInvocations.list
  • dataform.workflowInvocations.query
  • dataform.workspaces.commit
  • dataform.workspaces.create
  • dataform.workspaces.delete
  • dataform.workspaces.fetchFileDiff
  • dataform.workspaces.fetchFileGitStatuses
  • dataform.workspaces.fetchGitAheadBehind
  • dataform.workspaces.get
  • dataform.workspaces.getIamPolicy
  • dataform.workspaces.installNpmPackages
  • dataform.workspaces.list
  • dataform.workspaces.makeDirectory
  • dataform.workspaces.moveDirectory
  • dataform.workspaces.moveFile
  • dataform.workspaces.pull
  • dataform.workspaces.push
  • dataform.workspaces.queryDirectoryContents
  • dataform.workspaces.readFile
  • dataform.workspaces.removeDirectory
  • dataform.workspaces.removeFile
  • dataform.workspaces.reset
  • dataform.workspaces.searchFiles
  • dataform.workspaces.setIamPolicy
  • dataform.workspaces.writeFile

resourcemanager.projects.get

resourcemanager.projects.list

(roles/dataform.codeCreator)

Access only to private and shared code resources. The permissions in the Code Creator let you create and list code in Dataform, and access only the code that you created and code that was explicitly shared with you.

dataform.locations.*

  • dataform.locations.get
  • dataform.locations.list

dataform.repositories.create

dataform.repositories.list

resourcemanager.projects.get

resourcemanager.projects.list

(roles/dataform.codeEditor)

Edit access code resources.

dataform.locations.*

  • dataform.locations.get
  • dataform.locations.list

dataform.repositories.commit

dataform.repositories.computeAccessTokenStatus

dataform.repositories.create

dataform.repositories.fetchHistory

dataform.repositories.fetchRemoteBranches

dataform.repositories.get

dataform.repositories.getIamPolicy

dataform.repositories.list

dataform.repositories.queryDirectoryContents

dataform.repositories.readFile

dataform.workspaces.commit

dataform.workspaces.create

dataform.workspaces.delete

dataform.workspaces.fetchFileDiff

dataform.workspaces.fetchFileGitStatuses

dataform.workspaces.fetchGitAheadBehind

dataform.workspaces.get

dataform.workspaces.getIamPolicy

dataform.workspaces.installNpmPackages

dataform.workspaces.list

dataform.workspaces.makeDirectory

dataform.workspaces.moveDirectory

dataform.workspaces.moveFile

dataform.workspaces.pull

dataform.workspaces.push

dataform.workspaces.queryDirectoryContents

dataform.workspaces.readFile

dataform.workspaces.removeDirectory

dataform.workspaces.removeFile

dataform.workspaces.reset

dataform.workspaces.searchFiles

dataform.workspaces.writeFile

resourcemanager.projects.get

resourcemanager.projects.list

(roles/dataform.codeOwner)

Full access to code resources.

dataform.locations.*

  • dataform.locations.get
  • dataform.locations.list

dataform.repositories.*

  • dataform.repositories.commit
  • dataform.repositories.computeAccessTokenStatus
  • dataform.repositories.create
  • dataform.repositories.delete
  • dataform.repositories.fetchHistory
  • dataform.repositories.fetchRemoteBranches
  • dataform.repositories.get
  • dataform.repositories.getIamPolicy
  • dataform.repositories.list
  • dataform.repositories.queryDirectoryContents
  • dataform.repositories.readFile
  • dataform.repositories.setIamPolicy
  • dataform.repositories.update

dataform.workspaces.*

  • dataform.workspaces.commit
  • dataform.workspaces.create
  • dataform.workspaces.delete
  • dataform.workspaces.fetchFileDiff
  • dataform.workspaces.fetchFileGitStatuses
  • dataform.workspaces.fetchGitAheadBehind
  • dataform.workspaces.get
  • dataform.workspaces.getIamPolicy
  • dataform.workspaces.installNpmPackages
  • dataform.workspaces.list
  • dataform.workspaces.makeDirectory
  • dataform.workspaces.moveDirectory
  • dataform.workspaces.moveFile
  • dataform.workspaces.pull
  • dataform.workspaces.push
  • dataform.workspaces.queryDirectoryContents
  • dataform.workspaces.readFile
  • dataform.workspaces.removeDirectory
  • dataform.workspaces.removeFile
  • dataform.workspaces.reset
  • dataform.workspaces.searchFiles
  • dataform.workspaces.setIamPolicy
  • dataform.workspaces.writeFile

resourcemanager.projects.get

resourcemanager.projects.list

(roles/dataform.codeViewer)

Read-only access to all code resources.

dataform.locations.*

  • dataform.locations.get
  • dataform.locations.list

dataform.repositories.computeAccessTokenStatus

dataform.repositories.fetchHistory

dataform.repositories.fetchRemoteBranches

dataform.repositories.get

dataform.repositories.getIamPolicy

dataform.repositories.list

dataform.repositories.queryDirectoryContents

dataform.repositories.readFile

dataform.workspaces.fetchFileDiff

dataform.workspaces.fetchFileGitStatuses

dataform.workspaces.fetchGitAheadBehind

dataform.workspaces.get

dataform.workspaces.getIamPolicy

dataform.workspaces.list

dataform.workspaces.queryDirectoryContents

dataform.workspaces.readFile

dataform.workspaces.searchFiles

resourcemanager.projects.get

resourcemanager.projects.list

(roles/dataform.editor)

Edit access to Workspaces and Read-only access to Repositories.

dataform.compilationResults.*

  • dataform.compilationResults.create
  • dataform.compilationResults.get
  • dataform.compilationResults.list
  • dataform.compilationResults.query

dataform.config.get

dataform.locations.*

  • dataform.locations.get
  • dataform.locations.list

dataform.releaseConfigs.get

dataform.releaseConfigs.list

dataform.repositories.computeAccessTokenStatus

dataform.repositories.fetchHistory

dataform.repositories.fetchRemoteBranches

dataform.repositories.get

dataform.repositories.getIamPolicy

dataform.repositories.list

dataform.repositories.queryDirectoryContents

dataform.repositories.readFile

dataform.workflowConfigs.get

dataform.workflowConfigs.list

dataform.workflowInvocations.*

  • dataform.workflowInvocations.cancel
  • dataform.workflowInvocations.create
  • dataform.workflowInvocations.delete
  • dataform.workflowInvocations.get
  • dataform.workflowInvocations.list
  • dataform.workflowInvocations.query

dataform.workspaces.commit

dataform.workspaces.create

dataform.workspaces.delete

dataform.workspaces.fetchFileDiff

dataform.workspaces.fetchFileGitStatuses

dataform.workspaces.fetchGitAheadBehind

dataform.workspaces.get

dataform.workspaces.getIamPolicy

dataform.workspaces.installNpmPackages

dataform.workspaces.list

dataform.workspaces.makeDirectory

dataform.workspaces.moveDirectory

dataform.workspaces.moveFile

dataform.workspaces.pull

dataform.workspaces.push

dataform.workspaces.queryDirectoryContents

dataform.workspaces.readFile

dataform.workspaces.removeDirectory

dataform.workspaces.removeFile

dataform.workspaces.reset

dataform.workspaces.searchFiles

dataform.workspaces.writeFile

resourcemanager.projects.get

resourcemanager.projects.list

(roles/dataform.viewer)

Read-only access to all Dataform resources.

dataform.compilationResults.get

dataform.compilationResults.list

dataform.compilationResults.query

dataform.config.get

dataform.locations.*

  • dataform.locations.get
  • dataform.locations.list

dataform.releaseConfigs.get

dataform.releaseConfigs.list

dataform.repositories.computeAccessTokenStatus

dataform.repositories.fetchHistory

dataform.repositories.fetchRemoteBranches

dataform.repositories.get

dataform.repositories.getIamPolicy

dataform.repositories.list

dataform.repositories.queryDirectoryContents

dataform.repositories.readFile

dataform.workflowConfigs.get

dataform.workflowConfigs.list

dataform.workflowInvocations.get

dataform.workflowInvocations.list

dataform.workflowInvocations.query

dataform.workspaces.fetchFileDiff

dataform.workspaces.fetchFileGitStatuses

dataform.workspaces.fetchGitAheadBehind

dataform.workspaces.get

dataform.workspaces.getIamPolicy

dataform.workspaces.list

dataform.workspaces.queryDirectoryContents

dataform.workspaces.readFile

dataform.workspaces.searchFiles

resourcemanager.projects.get

resourcemanager.projects.list

自定义 Dataform 角色

自定义角色可以包含您指定的任何权限。您可以创建包含执行特定管理操作(如创建开发工作区或在开发工作区中创建文件和目录)的权限的自定义角色。如需创建自定义角色,请参阅创建和管理自定义角色

Dataform 权限的安全注意事项

任何拥有 dataform.repositories.create 权限的用户都可以使用默认的 Dataform 服务帐号以及授予该服务账号的所有权限在 BigQuery 中执行代码。这包括 Dataform SQL 工作流的执行。

以下 IAM 角色拥有 dataform.repositories.create 权限:

如需限制用户或服务帐号可在 BigQuery 中读取或写入的数据,您可以授予对所选 BigQuery 数据集或表的精细 BigQuery IAM 权限。如需了解详情,请参阅控制对数据集的访问权限控制对表和视图的访问权限

如需详细了解默认 Dataform 服务帐号及其所需的角色和权限,请参阅向 Dataform 授予所需的访问权限

准备工作

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the BigQuery and Dataform APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the BigQuery and Dataform APIs.

    Enable the APIs

查看 Dataform 角色

在 Google Cloud 控制台中,执行以下步骤:

  1. 转到 IAM 和管理 > 角色页面。

    打开“角色”

  2. 过滤条件字段中,选择使用范围,输入 Dataform,然后按 Enter 键。

  3. 点击列出的某个角色,即可在右侧窗格中查看该角色的权限。

    例如,Dataform Admin 角色拥有对所有 Dataform 资源的完整访问权限。

如需详细了解如何在项目上授予角色,请参阅授予角色。通过这种方式,您可以授予预定义角色或自定义角色。

控制对单个代码库的访问权限

如需使用精细权限控制对 Dataform 的访问权限,您可以使用 Dataform API repositories.setIamPolicy 请求在各个代码库上设置 Dataform IAM 角色。

如需在单个 Dataform 代码库上设置 Dataform IAM 角色,请按以下步骤操作:

  1. 在终端中,传递带有访问权限政策的 Dataform API repositories.setIamPolicy 请求。

  2. 在该政策中,按以下格式将用户、群组、网域或服务帐号绑定到所选角色:

    {
    "policy":
       {
          "bindings": [
          {
             "role": "roles/ROLE",
             "members": [
                "TYPE:IDENTIFIER",
             ]
          },
          ],
       }
    }
    

    替换以下内容:

    • ROLE:您要针对代码库授予的 Dataform IAM 角色
    • TYPEusergroupdomainserviceAccount
    • IDENTIFIER:您要将角色授予的用户、群组、网域或服务帐号
  3. 在 IAM 页面中,确保所有用户都可以通过具有 dataform.repositories.list 权限的 Dataform 角色查看 Dataform 代码库的完整列表。

  4. 在 IAM 中,确保只有需要对所有 Dataform 代码库的完整访问权限的用户才会获得对所有代码库的 Dataform Admin 角色。

以下命令会将 repositories.setIamPolicy Dataform API 请求(用于向单个用户授予 sales 代码库的 Dataform Editor 角色)传递:

curl -H "Content-Type: application/json" -X POST -d '{ "policy": { "bindings": [{ "role": "roles/dataform.editor", "members": ["user:sasha@examplepetstore.com"]}] }}' "https://dataform.googleapis.com/v1beta1/projects/examplepetstore/locations/us-central1/repositories/sales:setIamPolicy"

授予对代码库的公开访问权限

您可以通过向 allAuthenticatedUsers 主帐号授予对 Dataform 代码库的 IAM 角色来授予对 Dataform 代码库的公开访问权限。

allAuthenticatedUsers 主帐号分配 IAM 角色后,服务帐号和互联网上所有已使用 Google 帐号进行身份验证的用户将被授予该角色。这包括未关联到 Google Workspace 帐号或 Cloud Identity 网域的帐号,例如个人 Gmail 帐号。不包括未经身份验证的用户,例如匿名访问者。如需了解详情,请参阅所有经过身份验证的用户

例如,当您在 sales 代码库上向 allAuthenticatedUsers 授予 Dataform Viewer 角色时,所有使用 Google 帐号进行身份验证的互联网服务帐号和用户对所有 sales 代码资源的只读权限。

如需授予对 Dataform 代码库的公开访问权限,请按以下步骤操作:

  1. 在终端中,传递带有访问权限政策的 Dataform API repositories.setIamPolicy 请求。

  2. 在该政策中,按以下格式将 allAuthenticatedUsers 主帐号绑定到所选角色:

    {
    "policy":
       {
          "bindings": [
          {
             "role": "roles/ROLE",
             "members": [
                "allAuthenticatedUsers",
             ]
          },
          ],
       }
    }
    

    替换以下内容:

    • ROLE:您要授予所有经过身份验证的用户的 Dataform IAM 角色。

以下命令会将在 sales 代码库上授予 Dataform Viewer 角色的 repositories.setIamPolicy Dataform API 请求传递给 allAuthenticatedUsers

curl -H "Content-Type: application/json" -X POST -d '{ "policy": { "bindings": [{ "role": "roles/dataform.viewer", "members": ["allAuthenticatedUsers"]}] }}' "https://dataform.googleapis.com/v1beta1/projects/examplepetstore/locations/us-central1/repositories/sales:setIamPolicy"

阻止公开访问代码库

如需确保未向公众授予对任何 Dataform 代码库的访问权限,您可以在项目中限制 allAuthenticatedUsers 主帐号。

如需限制项目中的 allAuthenticatedUsers,您可以设置 iam.allowedPolicyMemberDomains 政策,并从 allowed_values 列表中移除 allAuthenticatedUsers

iam.allowedPolicyMemberDomains 政策中限制 allAuthenticatedUsers 后,allAuthenticatedUsers 主帐号不能用于项目的任何 IAM 政策,这会导致无法授予对所有资源(包括 Dataform 代码库)的公开访问权限。

如需详细了解 iam.allowedPolicyMemberDomains 政策及设置说明,请参阅按网域限制身份

Dataform 中的员工身份联合

借助员工身份联合,您可以使用外部身份提供方 (IdP) 通过 IAM 对用户使用 Google Cloud 服务进行身份验证和授权。

Dataform 支持员工身份联合,并且没有任何已知的限制。

后续步骤