遮盖列数据
本文档介绍如何实现数据遮盖,以便有选择地遮盖敏感数据。通过实现数据遮盖,您可以为不同的用户组提供不同级别的可见性。如需了解一般信息,请参阅数据遮盖简介。
您可以通过向列添加数据政策来实现数据遮盖。要向列添加数据遮盖政策,您必须完成以下步骤:
- 创建至少包含一个政策标记的分类。
- 可选:向您创建的一个或多个政策标记上的一个或多个主账号授予 Data Catalog Fine-Grained Reader 角色。
- 为政策标记创建最多三个数据政策,以将遮盖规则和(表示用户或组的)主账号映射到该标记。
- 为列设置政策标记。这会将与政策标记关联的数据政策映射到选定的列。
- 将有权访问遮盖数据的用户分配给 BigQuery Masked Reader 角色。 最佳实践是在数据政策级层分配 BigQuery Masked Reader 角色。如果在项目级层或更高级层分配该角色,则用户将获得项目下所有数据政策的权限,这可能会导致权限多余而造成的问题。
您可以使用 Google Cloud 控制台或 BigQuery Data Policy API 来处理数据政策。
完成这些步骤后,根据列运行查询的用户会收到未遮盖的数据、遮盖的数据或访问遭拒错误,具体取决于他们所属的群组以及授予的角色。如需了解详情,请参阅 Masked Reader 和 Fine-Grained Reader 角色如何交互。
或者,您也可以直接对列应用数据政策(预览版)。如需了解详情,请参阅直接对列使用数据政策遮盖数据。
使用政策标记遮盖数据
使用政策标记有选择性地遮盖敏感数据。
准备工作
- 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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Data Catalog and BigQuery Data Policy APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. 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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Data Catalog and BigQuery Data Policy APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. - 新项目中会自动启用 BigQuery;但对于已存在的项目,您可能需要手动激活 BigQuery。
Enable the BigQuery API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. - 如果您要创建引用自定义遮盖例程的数据政策,请创建关联的遮盖 UDF,以便可在以下步骤中使用。
- 在Google Cloud 控制台中打开政策标记分类页面。
- 点击创建分类。
在新建分类页面上,执行以下操作:
- 对于分类名称,输入您要创建的分类的名称。
- 对于说明,输入一项说明。
- 视需要更改项目下列出的项目。
- 视需要更改位置下列出的位置。
- 在政策标记下,输入政策标记名称和说明。
- 如需为政策标记添加子政策标记,请点击添加子标记。
- 如需添加另一个与政策标记级别相同的新政策标记,请点击 + 添加政策标记。
- 根据需要继续为您的分类添加政策标记和子政策标记。
- 为层次结构创建了政策标记后,点击创建。
- 调用
taxonomies.create以创建分类。 - 调用
taxonomies.policytag.create以创建政策标记。 - 在Google Cloud 控制台中打开政策标记分类页面。
- 点击要打开的分类的名称。
- 选择一个政策标记。
- 点击管理数据政策。
- 在数据政策名称部分,输入数据政策的名称。数据政策名称在数据政策所在的项目中必须是唯一的。
- 在遮盖规则部分,选择一个预定义的遮盖规则或自定义遮盖例程。如果您要选择自定义屏蔽例程,请确保您在项目级别拥有
bigquery.routines.get和bigquery.routines.list权限。 - 在主账号部分,输入要授予其对该列的遮盖访问权限的一个或多个用户或群组的名称。请注意,您在此处输入的所有用户和群组均会被授予 BigQuery Masked Reader 角色。
- 点击提交。
调用
create方法。传入满足以下要求的DataPolicy资源:dataPolicyType字段设置为DATA_MASKING_POLICY。dataMaskingPolicy字段标识要使用的遮盖数据规则或例程。dataPolicyId字段提供数据政策的名称,该名称在数据政策所在的项目中是唯一的。
调用
setIamPolicy方法并传入Policy。Policy必须标识被授予遮盖数据访问权限的主账号,并为role字段指定roles/bigquerydatapolicy.maskedReader。
创建分类
您必须为需要创建分类的用户或服务账号授予 Data Catalog Policy Tag Admin 角色。
控制台
API
如需使用现有分类,请调用 taxonomies.import,而无需执行以下过程中的前两个步骤。
使用政策标记
如需详细了解如何使用政策标记(例如如何查看或更新政策标记),请参阅使用政策标记。如需了解最佳实践,请参阅在 BigQuery 中使用政策标记的最佳实践。
创建数据政策
创建数据政策的用户或服务账号必须具有 bigquery.dataPolicies.create、bigquery.dataPolicies.setIamPolicy 和 datacatalog.taxonomies.get 权限。
BigQuery Data Policy Admin、BigQuery Admin 和 BigQuery Data Owner 角色具有 bigquery.dataPolicies.create 和 bigquery.dataPolicies.setIamPolicy 权限。Data Catalog Admin 和 Data Catalog Viewer 角色具有 datacatalog.taxonomies.get 权限。
对于自定义遮盖,请向用户授予 BigQuery Admin 或 BigQuery Data Owner 角色,以确保其具有例程和数据政策所需的权限。
您最多可以为一个政策标记创建 9 个数据政策。其中一个政策预留用于列级访问权限控制设置。
控制台
API
Node.js
试用此示例之前,请按照