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

參考資料

有關更多資訊,請參閱

此條目有幫助嗎?