Google Cloud Data Loss Prevention 運算子

Google Cloud DLP 提供工具來分類、遮罩、代碼化和轉換敏感元素,以協助您更好地管理您收集、儲存或用於業務或分析的資料。

先決條件任務

要使用這些運算子,您必須執行一些操作

資訊類型 (Info-Types)

Google Cloud DLP 使用資訊類型 (info-types) 來定義掃描的內容。

建立已儲存的資訊類型 (Stored Info-Type)

要建立自訂資訊類型,您可以使用 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",
)

檢索已儲存的資訊類型 (Stored Info-Type)

要檢索 DLP-API 支援的敏感資訊類型列表以供參考,您可以使用 CloudDLPListInfoTypesOperator

同樣地,要檢索自訂資訊類型列表,您可以使用 CloudDLPListStoredInfoTypesOperator

要檢索單一資訊類型,請使用 CloudDLPGetStoredInfoTypeOperator

更新已儲存的資訊類型 (Stored Info-Type)

要更新資訊類型,您可以使用 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",
)

刪除已儲存的資訊類型 (Stored 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",
)

範本 (Templates)

範本可用於建立和持久化組態資訊,以用於 Cloud Data Loss Prevention。Airflow 支援兩種 DLP 範本類型

  • 檢查範本 (Inspection Template)

  • 去識別化範本 (De-Identification Template)

在這裡,我們將使用識別範本作為範例

建立範本 (Creating Template)

要建立檢查範本,您可以使用 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,
)

檢索範本 (Retrieving Template)

如果您已經有現有的檢查範本,您可以使用 CloudDLPGetInspectTemplateOperator 來檢索它。現有檢查範本的列表可以使用 CloudDLPListInspectTemplatesOperator 檢索

使用範本 (Using Template)

要使用我們剛建立的檢查範本尋找潛在的敏感資訊,我們可以使用 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'] }}",
)

更新範本 (Updating Template)

要更新範本,您可以使用 CloudDLPUpdateInspectTemplateOperator

刪除範本 (Deleting Template)

要刪除範本,您可以使用 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,
)

去識別化範本 (De-Identification Template)

與檢查範本類似,去識別化範本也具有 CRUD 運算子

  • CloudDLPCreateDeidentifyTemplateOperator

  • CloudDLPDeleteDeidentifyTemplateOperator

  • CloudDLPUpdateDeidentifyTemplateOperator

  • CloudDLPGetDeidentifyTemplateOperator

  • CloudDLPListDeidentifyTemplatesOperator

任務與任務觸發器 (Jobs & Job Triggers)

Cloud Data Loss Protection 使用任務來執行動作,以掃描內容中的敏感資料或計算重新識別的風險。您可以使用任務觸發器排程這些任務。

建立任務 (Creating Job)

要建立任務,您可以使用 CloudDLPCreateDLPJobOperator

檢索任務 (Retrieving Job)

要檢索任務列表,您可以使用 CloudDLPListDLPJobsOperator。要檢索單一任務,請使用 CloudDLPGetDLPJobOperator

刪除任務 (Deleting Job)

要刪除任務,您可以使用 CloudDLPDeleteDLPJobOperator

取消任務 (Canceling a Job)

要啟動長時間運行的 DLP 任務的異步取消,您可以使用 CloudDLPCancelDLPJobOperator

建立任務觸發器 (Creating Job Trigger)

要建立任務觸發器,您可以使用 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",
)

檢索任務觸發器 (Retrieving Job Trigger)

要檢索任務觸發器列表,您可以使用 CloudDLPListJobTriggersOperator。要檢索單一任務觸發器,您可以使用 CloudDLPGetDLPJobTriggerOperator

更新任務觸發器 (Updating Job Trigger)

要更新任務觸發器,您可以使用 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",
)

刪除任務觸發器 (Deleting Job Trigger)

要刪除任務觸發器,您可以使用 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"
)

內容方法 (Content Method)

與儲存方法 (任務) 不同,內容方法是同步、無狀態的方法。

去識別化內容 (De-identify Content)

去識別化是從資料中移除識別資訊的過程。組態資訊定義您希望如何去識別化敏感資料。

此設定可以儲存並持久化在去識別化範本中,或在 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",
)

重新識別化內容 (Re-identify Content)

要重新識別化已去識別化的內容,您可以使用 CloudDLPReidentifyContentOperator

編輯圖片 (Redact Image)

要編輯內容圖片中潛在的敏感資訊,您可以使用 CloudDLPRedactImageOperator

參考 (Reference)

如需更多資訊,請查看

此條目是否有幫助?