建立及管理內容政策

本文說明如何建立、取得、列出、更新及刪除內容政策。如要進一步瞭解內容政策,請參閱「內容政策總覽」。

必要的角色

如要取得建立及管理內容政策所需的權限,請要求管理員授予您專案的「DLP 管理員 」(roles/dlp.admin) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

這個預先定義的角色具備建立及管理內容政策所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

如要建立及管理內容政策,必須具備下列權限:

  • dlp.contentPolicies.create
  • dlp.contentPolicies.update
  • dlp.contentPolicies.list
  • dlp.contentPolicies.get
  • dlp.contentPolicies.delete

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

如果您打算對 Gemini Enterprise 連接器和應用程式或 Gemini Notebook Enterprise 筆記本套用內容政策,也必須將 DLP 使用者 (roles/dlp.user) 角色授予 Gemini Enterprise 服務帳戶。詳情請參閱「保護來源中的機密資料」。

事前準備

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Cloud Data Loss Prevention API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  6. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Cloud Data Loss Prevention API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  10. 選用:如要將內容政策動作記錄到 BigQuery 資料表,請建立資料表。如要瞭解匯出記錄的結構定義,請參閱 ContentPolicyActionLog

建立內容政策

控制台

  1. 前往 Google Cloud 控制台的「Sensitive Data Protection」(敏感資料保護) 頁面。

    前往內容政策

  2. 選取專案。

  3. 點選「建立」

  4. 在「基本資訊」中,執行下列操作:

    1. 輸入內容政策名稱。
    2. 選用。輸入專屬內容政策 ID。如果您未輸入內容政策 ID,Sensitive Data Protection 會自動設定。
    3. 選取要儲存內容政策的區域或多區域。
    4. 按一下「繼續」
  5. 在「檢查設定」中,執行下列操作:

    1. 選取要偵測的內建自訂 infoType。詳情請參閱透過Google Cloud 控制台管理 infoType

      如要使用現有的檢查範本設定偵測功能,請按一下「從範本匯入」,然後輸入範本的完整資源名稱。

    2. 選用。新增檢查規則集。

      按一下即可顯示操作說明

      檢查規則集可讓您使用內容規則,自訂內建和自訂的 infoType 偵測工具。檢查規則類型包括:

      • 排除規則:可協助排除誤判或不需要的發現項目。
      • 啟動字詞規則:可協助偵測更多的發現項目。
      • 調整規則:根據發現項目出現的前後文,調整發現項目的可能性。

      如要新增規則集,請先在「InfoTypes」InfoTypes部分指定一或多個內建或自訂 infoType 偵測工具。選取規則集修改的所有 infoType 偵測工具 (target infoType),或用於評估的偵測工具 (context infoType)。然後執行下列步驟:

      1. 按一下「新增規則集」
      2. 在「選擇目標 infoType」欄位中,選取規則集在符合規則時要修改的 infoType。
      3. 按一下「新增規則」,開啟含有選項的選單,包括「啟動字詞規則」、「排除規則」和「調整規則」

      如要建立啟動字詞規則,請選取「啟動字詞規則」。然後執行下列步驟:

      1. 在「Hotword」(熱字) 欄位中,輸入 Sensitive Data Protection 要搜尋的規則運算式。
      2. 在「啟動字詞鄰近程度」選單中,選取輸入的啟動字詞是在所選 infoType 之前或之後。
      3. 在「啟動字詞與 infoType 的距離」中,輸入啟動字詞和所選 infoType 之間的約略字元數。
      4. 在「信賴水準調整」中,選取要為相符項目指派固定可能性等級,還是要將預設可能性等級調高或調低特定幅度。

      如要建立排除規則,請選取「排除規則」和要建立的排除規則類型,例如「規則運算式」。然後執行下列步驟:

      1. 根據您選取的排除規則類型,輸入規則運算式、詞組、啟動字詞或結構定義 infoType,系統必須找到這些項目才能套用規則。
      2. 視您選取的排除規則類型而定,設定相符類型或圖片包含類型:
        • 如果您選取以文字為準的排除規則,請選取下列其中一種比對類型:
          • 完全比對:發現項目必須與您提供的文字或脈絡資訊 infoType 完全相符。
          • 部分相符:發現項目的子字串必須與您提供的文字或脈絡資訊 infoType 相符。
          • 反向比對:發現項目不得與您提供的文字或脈絡資訊 infoType 相符。
        • 如果您選取以圖片為準的排除規則,請選取目標和內容 infoType 之間的必要空間關係。舉例來說,如果您選取「Encloses」(封閉),則情境發現項目必須封閉目標發現項目,規則才會套用。

      如要建立調整規則,請選取「調整規則」和調整規則類型,例如「依圖片結果調整」。然後執行下列步驟:

      1. 在「Context infoTypes」欄位中,選取可為目標發現項目提供脈絡的 infoType 偵測工具。Sensitive Data Protection 會使用背景資訊類型,評估是否需要調整目標資訊類型。
      2. 在「最低可能性」欄位中,選取內容 infoType 的最低可能性等級,只要達到這個等級,就會觸發調整規則。如果偵測到的任何內容發現項目的可能性值低於這個值,Sensitive Data Protection 就不會調整目標發現項目的可能性。
      3. 如果是圖片結果,請在「圖片包含類型」欄位中,選取目標和內容資訊類型之間所需的空間關係。舉例來說,如果您選取「Encloses」(封閉),則情境發現項目必須封閉目標發現項目,規則才會套用。
      4. 在「可能性」欄位中,選取要指派給目標發現項目的新可能性等級。

      您可以新增更多規則集,進一步縮小掃描結果範圍。

    3. 選用。設定要偵測的發現項目可信度門檻。詳情請參閱「比對可能性」。

    4. 按一下「繼續」

  6. 在「政策規則」中新增政策規則,指定 Sensitive Data Protection 在偵測到您在檢查設定中指定的 infoType 時,應傳回的判定結果 (「允許」或「封鎖」)。您可以新增單一政策規則,針對任何 infoType 傳回相同判定結果,也可以新增多項政策規則,針對不同 infoType 傳回不同判定結果。您必須為新增的每項政策規則設定條件。

    如要新增政策規則,請按照下列步驟操作:

    1. 按一下「新增政策規則」
    2. 選取要指派給 infoType 發現項目的判決:選取「允許」或「封鎖」
    3. 按一下「新增條件」。如要為不同 infoType 設定不同判決,請將「條件類型」設為「任何 infoType」或「特定 infoType」
    4. 如果您選取「特定 infoType」,請輸入必須偵測到的 infoType,Sensitive Data Protection 功能才會傳回您選取的判定結果。
    5. 視需要新增更多政策規則和對應條件。
    6. 按一下「繼續」
  7. 選用。在「預設動作」中,指定要在下列情況套用的判決:

    • 要指派給不支援檔案的判決。詳情請參閱「支援的檔案類型和掃描模式」。
    • 要指派給過大而無法掃描的支援檔案的判決。
    • 無法掃描的檔案 (例如損毀或加密的檔案) 適用的判定。
    • 如果掃描內容不符合任何規則,要指派的判決。

    針對上述每項條件,預設的判定結果為 ALLOW

    按一下「繼續」

  8. 選用。在「記錄設定」中啟用記錄功能,記錄內容政策對掃描資料發布的判定結果。請執行下列步驟:

    1. 選取「將政策執行記錄寫入 BigQuery」
    2. 輸入現有 BigQuery 資料表的詳細資料,Sensitive Data Protection 必須將結果記錄在該資料表中。
  9. 按一下「Create」(建立)

REST

如要建立內容政策,請對 projects.locations.contentPolicies.create 方法發出 POST 要求。要求主體會定義 content_policy 物件,其中包含檢查設定和規則,可根據發現項目判斷結果。

content_policy 物件具有下列屬性:

{
  "contentPolicy": {
    "displayName": "DISPLAY_NAME",
    "inspectConfig": {
      "infoTypes": [
        {
          "name": "INFOTYPE_DETECTOR"
        }
      ],
      "ruleSet": "LIST_OF_RULES"
    },
    "rules": [
      {
        "conditions": [
          {
            "infoTypeCondition": {
              "anyInfoType": {}
            }
          }
        ],
        "action": {
          "returnVerdict": "INFOTYPE_CONDITION_VERDICT"
        }
      }
    ],
    "unsupportedFileType": {
      "returnVerdict": "UNSUPPORTED_FILE_TYPE_VERDICT"
    },
    "inputTooLarge": {
      "returnVerdict": "INPUT_TOO_LARGE_VERDICT"
    },
    "failedToScanSupportedFileType": {
      "returnVerdict": "FAILED_TO_SCAN_VERDICT"
    },
    "defaultAction": {
      "returnVerdict": "DEFAULT_ACTION_VERDICT"
    },
    "loggingConfigs": [
      {
        "logToBigQuery": {
          "projectId": "LOG_PROJECT_ID",
          "datasetId": "LOG_DATASET_ID",
          "tableId": "LOG_TABLE_ID"
        }
      }
    ]
  },
  "contentPolicyId": "CONTENT_POLICY_ID"
}

更改下列內容:

  • DISPLAY_NAME:選用。使用者可解讀的內容政策名稱。
  • INFOTYPE_DETECTOR內建自訂 infoType。
  • LIST_OF_RULES:選用。檢查規則清單,如「修改 infoType 偵測工具以修正掃描結果」一文所述。為求簡潔,這段程式碼已截斷。如要查看內容政策中的規則集定義範例,請參閱擴充範例
  • INFOTYPE_CONDITION_VERDICT:要指派給 infoType 發現項目的判定結果:ALLOWBLOCK
  • UNSUPPORTED_FILE_TYPE_VERDICT:選用。要指派給不支援檔案的判決:ALLOWBLOCK。詳情請參閱「支援的檔案類型和掃描模式」。
  • INPUT_TOO_LARGE_VERDICT:選用。要指派給過大而無法掃描的支援檔案的判決:ALLOWBLOCK
  • FAILED_TO_SCAN_VERDICT:選用。要指派給無法掃描的檔案 (例如損毀或加密的檔案) 的判定結果:ALLOWBLOCK
  • DEFAULT_ACTION_VERDICT:選用。如果沒有任何規則符合掃描內容,則要指派的判決:ALLOWBLOCK
  • LOG_PROJECT_ID:包含要寫入的 BigQuery 資料表的專案 ID。
  • LOG_DATASET_ID:包含要寫入的 BigQuery 資料表的資料集 ID。
  • LOG_TABLE_ID:要寫入的 BigQuery 資料表 ID。
  • CONTENT_POLICY_ID:內容政策的專屬 ID。

如需回應範例,請參閱「Expanded example」。

取得內容政策的詳細資料

控制台

  1. 前往 Google Cloud 控制台的「Sensitive Data Protection」(敏感資料保護) 頁面。

    前往內容政策

  2. 選取專案。

  3. 按一下要查看的內容政策資源名稱。

  4. 在「詳細資料」分頁中,查看內容政策的詳細資料。

REST

如要取得內容政策,請向 projects.locations.contentPolicies.get 方法傳送 GET 要求。

使用任何要求資料之前,請先修改下列項目的值:

  • REGION:儲存內容政策的區域,例如 us-west2。如需完整地區清單,請參閱「Sensitive Data Protection 地區」。
  • PROJECT_ID:包含內容政策的專案 ID。
  • CONTENT_POLICY_ID:要取得詳細資料的內容政策 ID。

HTTP 方法和網址:

GET https://dlp.REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/contentPolicies/CONTENT_POLICY_ID

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/example-project/locations/us-west1/contentPolicies/block-credit-cards-policy",
  "rules": [
    {
      "conditions": [
        {
          "infoTypeCondition": {
            "anyInfoType": {}
          }
        }
      ],
      "action": {
        "returnVerdict": "BLOCK"
      }
    }
  ],
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "CREDIT_CARD_NUMBER"
      }
    ],
    "minLikelihood": "LIKELY",
    "limits": {}
  }
}

列出專案中的所有內容政策

控制台

  1. 前往 Google Cloud 控制台的「Sensitive Data Protection」(敏感資料保護) 頁面。

    前往內容政策

  2. 選取所需專案。專案中的內容政策清單隨即顯示。

REST

如要列出專案中的內容政策,請對 projects.locations.contentPolicies.list 方法傳送 LIST 要求。

使用任何要求資料之前,請先修改下列項目的值:

  • REGION:要列出內容政策的儲存區域,例如 us-west2。如需完整地區清單,請參閱「Sensitive Data Protection 地區」。
  • PROJECT_ID:包含要列出內容政策的專案 ID。

HTTP 方法和網址:

GET https://dlp.REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/contentPolicies

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "contentPolicies": [
      {
  "name": "projects/example-project/locations/us-west1/contentPolicies/block-credit-cards-policy",
  "rules": [
    {
      "conditions": [
        {
          "infoTypeCondition": {
            "anyInfoType": {}
          }
        }
      ],
      "action": {
        "returnVerdict": "BLOCK"
      }
    }
  ],
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "CREDIT_CARD_NUMBER"
      }
    ],
    "minLikelihood": "LIKELY",
    "limits": {}
  }
},
    {
      "name": "projects/example-project/locations/us-west1/contentPolicies/block-pii",
      ...
    }
  ]
}

更新內容政策

控制台

  1. 前往 Google Cloud 控制台的「Sensitive Data Protection」(敏感資料保護) 頁面。

    前往內容政策

  2. 選取專案。

  3. 按一下要編輯的內容政策資源名稱。

  4. 按一下 [編輯]

  5. 編輯內容政策的詳細資料。

REST

如要更新內容政策,請使用 projects.locations.contentPolicies.patch 方法傳送 PATCH 要求。要求主體會定義更新的 content_policy 物件。

使用任何要求資料之前,請先修改下列項目的值:

  • REGION:提供 Sensitive Data Protection 區域端點的區域,例如 us-west2。如需完整地區清單,請參閱「Sensitive Data Protection 地區」。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 為英數字串,例如 example-project
  • CONTENT_POLICY_ID:要更新的內容政策 ID。

HTTP 方法和網址:

PATCH https://dlp.REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/contentPolicies/CONTENT_POLICY_ID

JSON 要求主體:

{
  "contentPolicy": {
    "displayName": "displayName",
    "inspectConfig": {
      "infoTypes": [
        {
          "name": "CREDIT_CARD_NUMBER"
        }
      ],
      "minLikelihood": "LIKELY"
    },
    "rules": [
      {
        "conditions": [
          {
            "infoTypeCondition": {
              "anyInfoType": {}
            }
          }
        ],
        "action": {
          "returnVerdict": "BLOCK"
        }
      }
    ]
  }
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/example-project/locations/us-west1/contentPolicies/block-credit-cards-policy",
  "rules": [
    {
      "conditions": [
        {
          "infoTypeCondition": {
            "anyInfoType": {}
          }
        }
      ],
      "action": {
        "returnVerdict": "BLOCK"
      }
    }
  ],
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "CREDIT_CARD_NUMBER"
      }
    ],
    "minLikelihood": "LIKELY",
    "limits": {}
  }
}

刪除內容政策

控制台

  1. 前往 Google Cloud 控制台的「Sensitive Data Protection」(敏感資料保護) 頁面。

    前往內容政策

  2. 選取專案。

  3. 選取要刪除的內容政策。

  4. 按一下「刪除」

REST

如要刪除內容政策,請使用 projects.locations.contentPolicies.delete 方法傳送 DELETE 要求。

使用任何要求資料之前,請先修改下列項目的值:

  • REGION:儲存內容政策的區域,例如 us-west2。如需完整地區清單,請參閱「Sensitive Data Protection 地區」。
  • PROJECT_ID:包含內容政策的專案 ID。
  • CONTENT_POLICY_ID:要刪除的內容政策 ID。

HTTP 方法和網址:

DELETE https://dlp.REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/contentPolicies/CONTENT_POLICY_ID

請展開以下其中一個選項,以傳送要求:

您應該會收到執行成功的狀態碼 (2xx) 和空白回應。

REST 範例

下列 REST 範例說明如何使用 REST API 建立內容政策。

簡單範例

以下範例會建立政策,找出可能性為 POSSIBLE 以上的 CREDIT_CARD_NUMBER 發現項目。如果系統找到信用卡號碼,機密資料保護功能會傳回 BLOCK 判定結果。

使用任何要求資料之前,請先修改下列項目的值:

  • REGION:提供 Sensitive Data Protection 區域端點的區域,例如 us-west2。如需完整地區清單,請參閱「Sensitive Data Protection 地區」。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 為英數字串,例如 example-project

HTTP 方法和網址:

POST https://dlp.REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/contentPolicies

JSON 要求主體:

{
  "contentPolicy": {
    "displayName": "displayName",
    "inspectConfig": {
      "infoTypes": [
        {
          "name": "CREDIT_CARD_NUMBER"
        }
      ],
      "minLikelihood": "POSSIBLE"
    },
    "rules": [
      {
        "conditions": [
          {
            "infoTypeCondition": {
              "anyInfoType": {}
            }
          }
        ],
        "action": {
          "returnVerdict": "BLOCK"
        }
      }
    ]
  },
  "contentPolicyId": "block-credit-cards-policy"
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/example-project/locations/us-west1/contentPolicies/block-credit-cards-policy",
  "rules": [
    {
      "conditions": [
        {
          "infoTypeCondition": {
            "anyInfoType": {}
          }
        }
      ],
      "action": {
        "returnVerdict": "BLOCK"
      }
    }
  ],
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "CREDIT_CARD_NUMBER"
      }
    ],
    "minLikelihood": "POSSIBLE",
    "limits": {}
  }
}

Expanded example

以下範例會建立政策,找出可能性為 POSSIBLE 以上的 CREDIT_CARD_NUMBER 發現項目。這項規則包含啟動字詞規則,如果發現項目附近偵測到「VERY_LIKELY」一詞,就會將發現項目的可能性值提高至 credit card

  • 如果 Sensitive Data Protection 偵測到可能的信用卡號碼,就會傳回 BLOCK 判決。
  • 如果掃描的檔案不支援、過大、已損毀、經過加密或無法掃描,Sensitive Data Protection 會傳回 BLOCK 判定結果。
  • 如果掃描內容不符合任何規則,Sensitive Data Protection 會傳回 ALLOW 判定結果。

使用任何要求資料之前,請先修改下列項目的值:

  • REGION:提供 Sensitive Data Protection 區域端點的區域,例如 us-west2。如需完整地區清單,請參閱「Sensitive Data Protection 地區」。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 為英數字串,例如 example-project

HTTP 方法和網址:

POST https://dlp.REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/contentPolicies

JSON 要求主體:

{
  "contentPolicy": {
    "displayName": "displayName",
    "inspectConfig": {
      "infoTypes": [
        {
          "name": "CREDIT_CARD_NUMBER"
        }
      ],
      "ruleSet": [
        {
          "infoTypes": [
            {
              "name": "CREDIT_CARD_NUMBER"
            }
          ],
          "rules": [
            {
              "hotwordRule": {
                "hotwordRegex": {
                  "pattern": "credit\\scard"
                },
                "proximity": {
                  "windowBefore": 10,
                  "windowAfter": 10
                },
                "likelihoodAdjustment": {
                  "fixedLikelihood": "VERY_LIKELY"
                }
              }
            }
          ]
        }
      ]
    },
    "rules": [
      {
        "conditions": [
          {
            "infoTypeCondition": {
              "anyInfoType": {}
            }
          }
        ],
        "action": {
          "returnVerdict": "BLOCK"
        }
      }
    ],
    "unsupportedFileType": {
      "returnVerdict": "BLOCK"
    },
    "inputTooLarge": {
      "returnVerdict": "BLOCK"
    },
    "failedToScanSupportedFileType": {
      "returnVerdict": "BLOCK"
    },
    "defaultAction": {
      "returnVerdict": "ALLOW"
    }
  },
  "contentPolicyId": "block-credit-cards-policy"
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/example-project/locations/us-west2/contentPolicies/block-credit-cards-policy",
  "rules": [
    {
      "conditions": [
        {
          "infoTypeCondition": {
            "anyInfoType": {}
          }
        }
      ],
      "action": {
        "returnVerdict": "BLOCK"
      }
    }
  ],
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "CREDIT_CARD_NUMBER"
      }
    ],
    "limits": {},
    "ruleSet": [
      {
        "infoTypes": [
          {
            "name": "CREDIT_CARD_NUMBER"
          }
        ],
        "rules": [
          {
            "hotwordRule": {
              "hotwordRegex": {
                "pattern": "credit\\scard"
              },
              "proximity": {
                "windowBefore": 10,
                "windowAfter": 10
              },
              "likelihoodAdjustment": {
                "fixedLikelihood": "VERY_LIKELY"
              }
            }
          }
        ]
      }
    ]
  },
  "unsupportedFileType": {
    "returnVerdict": "BLOCK"
  },
  "inputTooLarge": {
    "returnVerdict": "BLOCK"
  },
  "failedToScanSupportedFileType": {
    "returnVerdict": "BLOCK"
  },
  "defaultAction": {
    "returnVerdict": "ALLOW"
  }
}

掃描中繼資料標籤的範例

以下範例會指示 Sensitive Data Protection 掃描信用卡號碼和含有 MSIP_Label_12345-12345-1234-12345_Enabled 鍵的中繼資料標籤。如果發現任何敏感資料,Sensitive Data Protection 會傳回 BLOCK 判定結果。

如要進一步瞭解中繼資料標籤掃描,請參閱「建立自訂中繼資料標籤偵測工具」一文。

使用任何要求資料之前,請先修改下列項目的值:

  • REGION:提供 Sensitive Data Protection 區域端點的區域,例如 us-west2。如需完整地區清單,請參閱「Sensitive Data Protection 地區」。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 為英數字串,例如 example-project

HTTP 方法和網址:

POST https://dlp.REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/contentPolicies

JSON 要求主體:

{
  "contentPolicy": {
    "displayName": "displayName",
    "inspectConfig": {
      "infoTypes": [
        {
          "name": "CREDIT_CARD_NUMBER"
        }
      ],
      "customInfoTypes": [
        {
          "infoType": {
            "name": "CUSTOM_MSIP1"
          },
          "likelihood": "VERY_LIKELY",
          "fileLabelInfoType": {
            "sensitivityLabel": {
              "guid": "12345678-1234-1234-1234-123456789012"
            }
          }
        }
      ],
      "minLikelihood": "POSSIBLE"
    },
    "rules": [
      {
        "conditions": [
          {
            "infoTypeCondition": {
              "anyInfoType": {}
            }
          }
        ],
        "action": {
          "returnVerdict": "BLOCK"
        }
      }
    ]
  },
  "contentPolicyId": "block-credit-cards-policy-metadata-scanning"
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/example-project/locations/us-west1/contentPolicies/block-credit-cards-policy-metadata-scanning",
  "rules": [
    {
      "conditions": [
        {
          "infoTypeCondition": {
            "anyInfoType": {}
          }
        }
      ],
      "action": {
        "returnVerdict": "BLOCK"
      }
    }
  ],
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "CREDIT_CARD_NUMBER"
      }
    ],
    "minLikelihood": "POSSIBLE",
    "limits": {},
    "customInfoTypes": [
      {
        "infoType": {
          "name": "CUSTOM_MSIP1"
        },
        "likelihood": "VERY_LIKELY",
        "fileLabelInfoType": {
          "sensitivityLabel": {
            "guid": "12345678-1234-1234-1234-123456789012"
          }
        }
      }
    ]
  }
}

後續步驟