Google Cloud 数据丢失防护 Operator

Google Cloud DLP 提供分类、屏蔽、标记化和转换敏感元素的工具,帮助您更好地管理出于业务或分析目的而收集、存储或使用的数据。

先决任务

要使用这些 Operator,您必须执行以下几项操作:

信息类型

Google Cloud DLP 使用信息类型来定义扫描内容。

创建存储的信息类型

要创建自定义信息类型,您可以使用 CloudDLPCreateStoredInfoTypeOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_info_types.py

create_info_type = CloudDLPCreateStoredInfoTypeOperator(
    project_id=PROJECT_ID,
    config=CUSTOM_INFO_TYPES,
    stored_info_type_id=CUSTOM_INFO_TYPE_ID,
    task_id="create_info_type",
)

检索存储的信息类型

要检索 DLP-API 支持的敏感信息类型列表以供参考,您可以使用 CloudDLPListInfoTypesOperator

类似地,要检索自定义信息类型列表,您可以使用 CloudDLPListStoredInfoTypesOperator

要检索单个信息类型,请使用 CloudDLPGetStoredInfoTypeOperator

更新存储的信息类型

要更新信息类型,您可以使用 CloudDLPUpdateStoredInfoTypeOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_info_types.py

update_info_type = CloudDLPUpdateStoredInfoTypeOperator(
    project_id=PROJECT_ID,
    stored_info_type_id=CUSTOM_INFO_TYPE_ID,
    config=UPDATE_CUSTOM_INFO_TYPE,
    task_id="update_info_type",
)

删除存储的信息类型

要删除信息类型,您可以使用 CloudDLPDeleteStoredInfoTypeOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_info_types.py

delete_info_type = CloudDLPDeleteStoredInfoTypeOperator(
    project_id=PROJECT_ID,
    stored_info_type_id=CUSTOM_INFO_TYPE_ID,
    task_id="delete_info_type",
)

模板

模板可用于创建和持久化配置信息,以便与 Cloud Data Loss Prevention 配合使用。Airflow 支持两种类型的 DLP 模板:

  • 检查模板

  • 去标识化模板

此处我们将使用识别模板作为示例

创建模板

要创建检查模板,您可以使用 CloudDLPCreateInspectTemplateOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_inspect_template.py

create_template = CloudDLPCreateInspectTemplateOperator(
    task_id="create_template",
    project_id=PROJECT_ID,
    inspect_template=INSPECT_TEMPLATE,
    template_id=TEMPLATE_ID,
    do_xcom_push=True,
)

检索模板

如果您已有检查模板,可以使用 CloudDLPGetInspectTemplateOperator 检索它。现有检查模板的列表可以通过 CloudDLPListInspectTemplatesOperator 检索。

使用模板

要使用我们刚刚创建的检查模板查找潜在敏感信息,我们可以使用 CloudDLPInspectContentOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_inspect_template.py

inspect_content = CloudDLPInspectContentOperator(
    task_id="inspect_content",
    project_id=PROJECT_ID,
    item=ITEM,
    inspect_template_name="{{ task_instance.xcom_pull('create_template', key='return_value')['name'] }}",
)

更新模板

要更新模板,您可以使用 CloudDLPUpdateInspectTemplateOperator

删除模板

要删除模板,您可以使用 CloudDLPDeleteInspectTemplateOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_inspect_template.py

delete_template = CloudDLPDeleteInspectTemplateOperator(
    task_id="delete_template",
    template_id=TEMPLATE_ID,
    project_id=PROJECT_ID,
)

去标识化模板

与检查模板一样,去标识化模板也具有 CRUD Operator

  • CloudDLPCreateDeidentifyTemplateOperator

  • CloudDLPDeleteDeidentifyTemplateOperator

  • CloudDLPUpdateDeidentifyTemplateOperator

  • CloudDLPGetDeidentifyTemplateOperator

  • CloudDLPListDeidentifyTemplatesOperator

作业与作业触发器

Cloud Data Loss Prevention 使用作业来运行扫描内容以查找敏感数据或计算重新标识化风险的操作。您可以使用作业触发器来安排这些作业。

创建作业

要创建作业,您可以使用 CloudDLPCreateDLPJobOperator

检索作业

要检索作业列表,您可以使用 CloudDLPListDLPJobsOperator。要检索单个作业,请使用 CloudDLPGetDLPJobOperator

删除作业

要删除作业,您可以使用 CloudDLPDeleteDLPJobOperator

取消作业

要开始异步取消长时间运行的 DLP 作业,您可以使用 CloudDLPCancelDLPJobOperator

创建作业触发器

要创建作业触发器,您可以使用 CloudDLPCreateJobTriggerOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_job_trigger.py

create_trigger = CloudDLPCreateJobTriggerOperator(
    project_id=PROJECT_ID,
    job_trigger=JOB_TRIGGER,
    trigger_id=TRIGGER_ID,
    task_id="create_trigger",
)

检索作业触发器

要检索作业触发器列表,您可以使用 CloudDLPListJobTriggersOperator。要检索单个作业触发器,您可以使用 CloudDLPGetDLPJobTriggerOperator

更新作业触发器

要更新作业触发器,您可以使用 CloudDLPUpdateJobTriggerOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_job_trigger.py

update_trigger = CloudDLPUpdateJobTriggerOperator(
    project_id=PROJECT_ID,
    job_trigger_id=TRIGGER_ID,
    job_trigger=JOB_TRIGGER,
    task_id="update_info_type",
)

删除作业触发器

要删除作业触发器,您可以使用 CloudDLPDeleteJobTriggerOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_job_trigger.py

delete_trigger = CloudDLPDeleteJobTriggerOperator(
    project_id=PROJECT_ID, job_trigger_id=TRIGGER_ID, task_id="delete_info_type"
)

内容方法

与存储方法(作业)不同,内容方法是同步的无状态方法。

对内容进行去标识化

去标识化是删除数据中标识信息的过程。配置信息定义了您希望如何对敏感数据进行去标识化处理。

此配置可以保存并持久化在去标识化模板中,也可以在 DeidentifyConfig 对象中定义

tests/system/google/cloud/data_loss_prevention/example_dlp_deidentify_content.py

DEIDENTIFY_CONFIG = {
    "info_type_transformations": {
        "transformations": [
            {
                "primitive_transformation": {
                    "replace_config": {"new_value": {"string_value": "[deidentified_number]"}}
                }
            }
        ]
    }
}

要对内容项目中的潜在敏感信息进行去标识化处理,您可以使用 CloudDLPDeidentifyContentOperator

tests/system/google/cloud/data_loss_prevention/example_dlp_deidentify_content.py

deidentify_content = CloudDLPDeidentifyContentOperator(
    project_id=PROJECT_ID,
    item=ITEM,
    deidentify_config=DEIDENTIFY_CONFIG,
    inspect_config=INSPECT_CONFIG,
    task_id="deidentify_content",
)

对内容进行重新标识化

要重新标识化已进行去标识化处理的内容,您可以使用 CloudDLPReidentifyContentOperator

图像脱敏

要对图像内容中的潜在敏感信息进行脱敏处理,您可以使用 CloudDLPRedactImageOperator

参考资料

有关更多信息,请参阅

此条目有帮助吗?