Google Cloud Data Loss Prevention 擴充功能

您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件
info

版本:2.0.2

使用這項擴充功能,即可遮蓋內容和圖片中的私密資料。例如,您可能會遮蓋信用卡號碼、姓名和身分證字號。

必要條件

這項內容提供設定及使用這項擴充功能的參考資料。使用 ExtensionCallout 政策從 API Proxy 使用擴充功能之前,請務必完成下列步驟:

  1. 為專案啟用 Google Cloud DLP API

  2. 授予權限,決定擴充功能可存取的內容。

  3. 使用 Google Cloud 控制台產生服務帳戶的金鑰

  4. 使用產生的金鑰 JSON 檔案內容,透過設定參考資料新增及設定擴充功能。

關於 Cloud Data Loss Prevention (DLP)

Cloud Data Loss Prevention (DLP) API 可檢查文字、圖片和其他資料,找出及管理機密資料。

詳情請參閱 DLP 總覽。如要參閱這個擴充功能公開的 API,請參閱 Cloud Data Loss Prevention (DLP) API

範例

下列範例說明如何使用 ExtensionCallout 政策,設定支援 Cloud DLP 擴充功能動作。

為方便試用這個範例程式碼,這些範例會使用 AssignMessage 政策設定流程變數值,並擷取擴充功能回應值,以便在追蹤工具中顯示。

使用星號遮蔽

這個範例使用 deidentifyWithMask 動作,以政策中指定的字元 (在此為 * 字元) 遮蓋指定類型的文字。

下列 AssignMessage 政策會設定 request.content 變數,僅供說明用途。通常你會從用戶端的要求中擷取要求內容。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Set-Variable">
    <DisplayName>Set Variable</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <AssignVariable>
        <Name>request.content</Name>
        <Value>Visit my site at https://example.com. Or contact me at gladys@example.com.</Value>
    </AssignVariable>
</AssignMessage>

下列擴充功能註解政策會擷取 request.content 變數值,並傳遞至 Cloud DLP 擴充功能 (在此稱為 example-dlp)。該擴充功能已設定為根據 URLEMAIL_ADDRESS infoTypes 遮蓋值。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="true" enabled="true" name="Data-Loss-Extension-Callout">
    <DisplayName>Data Loss Prevention Extension Callout</DisplayName>
    <Connector>example-dlp</Connector>
    <Action>deidentifyWithMask</Action>
    <Input><![CDATA[{
        "text" : "{request.content}",
        "mask" : "*"
    }]]></Input>
    <Output>masked.output</Output>
</ConnectorCallout>

下列 AssignMessage 政策會擷取擴充功能的輸出內容,以便在追蹤工具中顯示。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Get-DLP-Output">
    <DisplayName>Get DLP Output</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <Set>
        <Payload contentType="application/json">{masked.output}</Payload>
    </Set>
</AssignMessage>

以下是這段程式碼的輸出範例。

{"text":"Visit my site at ******************* Or contact me at *****************."}

使用名稱遮蔽

這個範例會使用 deidentifyWithType 動作,以資訊類型名稱遮蓋指定類型的文字。舉例來說,這項功能會將電子郵件地址 gladys@example.com 替換為 EMAIL_ADDRESS

下列 AssignMessage 政策會設定 request.content 變數,僅供說明用途。通常你會從用戶端的要求中擷取要求內容。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Set-Variable">
    <DisplayName>Set Variable</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <AssignVariable>
        <Name>request.content</Name>
        <Value>Visit my site at https://example.com. Or contact me at gladys@example.com.</Value>
    </AssignVariable>
</AssignMessage>

下列 ExtensionCallout 政策會擷取 request.content 變數值,並傳遞至 Cloud DLP 擴充功能 (在此稱為 example-dlp)。該擴充功能已設定為根據 URLEMAIL_ADDRESS infoTypes 遮蓋值。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="true" enabled="true" name="Data-Loss-Extension-Callout">
    <DisplayName>Data Loss Prevention Extension Callout</DisplayName>
    <Connector>example-dlp</Connector>
    <Action>deidentifyWithType</Action>
    <Input><![CDATA[{
        "text" : "{request.content}"
    }]]></Input>
    <Output>masked.output</Output>
</ConnectorCallout>

下列 AssignMessage 政策會擷取擴充功能的輸出內容,以便在追蹤工具中顯示。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Get-DLP-Output">
    <DisplayName>Get DLP Output</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <Set>
        <Payload contentType="application/json">{masked.output}</Payload>
    </Set>
</AssignMessage>

以下是這段程式碼的輸出範例。

{"text":"Visit my site at [URL] Or contact me at [EMAIL_ADDRESS]."}

動作

deidentifyWithMask

text 中的機密資料去識別化,並以 mask 字元遮蓋資料。這項動作會遮蓋 擴充功能設定infoTypes 屬性指定的 text 部分。

遮蓋機密資料會將字元替換為符號,例如星號 (*) 或井字號 (#)。您可以在擴充功能設定中設定機密資料類型。

語法

<Action>deidentifyWithMask</Action>
<Input><![CDATA[{
  "text" : "text-to-deidentify",
  "mask" : "masking-character"
}]]></Input>

範例

在下列範例中,要遮蓋的輸入內容是儲存在 input.email.address 流程變數中的電子郵件地址。如要支援這個特定範例,必須先將擴充功能設定為支援 EMAIL_ADDRESS infoType。如需 infoType 清單,請參閱 InfoType 偵測工具參考資料

<Action>deidentifyWithMask</Action>
<Input><![CDATA[{
    "text" : "{input.email.address}",
    "mask" : "*"
}]]></Input>
<Output>masked.output</Output>

這個範例的輸出內容如下:

{"text":"*****************"}

要求參數

參數 說明 類型 預設 必填
文字 要去除識別資訊的文字。 字串 無。 是。
掩蓋 用來遮蓋機密資料的字元。 字串 無。 是。

回應

輸入文字,其中指定 infoType 的值已替換為指定字元。例如:

{"text":"*********"}

deidentifyWithTemplate

使用範本將文字內容中的機密資料去識別化,並設定要將哪些文字去識別化,以及如何處理。

範本很適合用於將檢查內容和去識別化方式等設定與 API 呼叫的實作分離,範本不僅可以讓您重複使用設定,也能保持使用者和資料集之間的一致性。

在範本中,您會指定代表要進行去識別化內容的 infoTypes。如需 infoType 清單,請參閱 InfoType 偵測工具參考資料。去識別化會遮蓋範本中 infoTypes 屬性指定的文字部分。

語法

<Action>deidentifyWithTemplate</Action>
<Input><![CDATA[{
  "text" : "text-to-deidentify"
  "templateName" : "path-to-template"
}]]></Input>

範例

在下列範例中,要取消識別的輸入內容是 request.content 流程變數攜帶的要求主體。

<Action>deidentifyWithTemplate</Action>
<Input><![CDATA[{
    "text" : "{request.content}"
    "templateName" : "projects/[PROJECT_ID]/deidentifyTemplates/1231258663242"
}]]></Input>

這個範例的輸出內容會是去識別化的要求內容。

要求參數

參數 說明 類型 預設 必填
文字 要進行去識別化的文字。這是去識別化程序運作的對象。 物件 無。 是。
範本名稱 要使用的範本。這是範本的路徑,格式如下:projects or organizations/PROJECT_ID/deidentifyTemplates/TEMPLATE_ID。使用 Google API 建立範本時,請將回應的 name 屬性值做為 templateName 字串 無。 是。

回應

輸入文字,其中指定 infoType 的值已替換為 infoType 名稱。

deidentifyWithType

將文字內容中的機密資料去識別化,並將每個相符的值替換為 infoType 的名稱。如需 infoType 清單,請參閱 InfoType 偵測工具參考資料。這項動作會遮蓋 擴充功能設定infoTypes 屬性指定的 text 部分。

在下列範例中,服務會辨識電話號碼,然後替換為 infoType 名稱本身。

  • 輸入文字:

    John Smith, 123 Main St, Seattle, WA 98122, 206-555-0123.

  • 結果文字:

    John Smith, 123 Main St, Seattle, WA 98122, PHONE_NUMBER.

語法

<Action>deidentifyWithType</Action>
<Input><![CDATA[{
  "text" : "text-to-deidentify"
}]]></Input>

範例

在下列範例中,要遮蓋的輸入內容是儲存在 input.email.address 流程變數中的電子郵件地址。如要支援這個特定範例,必須先將擴充功能設定為支援 EMAIL_ADDRESS infoType。如需 infoType 清單,請參閱 InfoType 偵測工具參考資料

<Action>deidentifyWithType</Action>
<Input><![CDATA[{
    "text" : "{input.email.address}"
}]]></Input>

這個範例的輸出內容如下:

{"text":"EMAIL_ADDRESS"}

要求參數

參數 說明 類型 預設 必填
文字 要進行去識別化的文字。 字串 無。 是。

回應

輸入文字,其中指定 infoType 的值已替換為 infoType 名稱。例如:

{"text":"EMAIL_ADDRESS"}

redactImage

遮蓋屬於任一 infoType 類別的文字。系統會偵測到經過修訂的內容,並以不透明的矩形遮蓋。這項動作會遮蓋 擴充功能設定infoTypes 屬性指定的 image_data 部分。

如需 infoType 清單,請參閱 InfoType 偵測工具參考資料

要求參數

<Action>redactImage</Action>
<Input><![CDATA[{
  "image_data" : "base64-encoded-image-to-analyze",
  "image_type" : "type-of-image"
}]]></Input>
參數 說明 類型 預設 必填
image_data 以 Base64 編碼的圖片資料。 字串 無。 是。
image_type 圖片類型的常數。可用的值包括 IMAGE_JPEG、IMAGE_BMP、IMAGE_PNG、IMAGE_SVG。 字串 無。 是。

回應

文字經過遮蓋的圖片。

設定參考資料

設定及部署這個擴充功能,以便在 API Proxy 中使用時,請參考下列資訊。如要瞭解如何使用 Apigee 控制台設定擴充功能,請參閱「新增及設定擴充功能」。

常見的擴充功能屬性

每個擴充功能都有下列屬性。

屬性 說明 預設 必要
name 您要為這項擴充功能設定的名稱。 相容
packageName Apigee Edge 指定的擴充功能套件名稱。 相容
version 擴充功能的擴充功能套件版本號碼。 相容
configuration 您要新增的擴充功能專屬的設定值。請參閱「這個擴充功能套件的屬性」一文 相容

這個擴充套件的屬性

指定下列設定屬性的值,這些屬性專屬於這個擴充功能。

屬性 說明 預設 必填
projectId 已啟用 Cloud Data Loss Prevention API 的 Google Cloud 專案 ID。 無。 是。
infoTypes 機密資料的資訊類型。如果省略,服務會偵測所有內建型別。如需 Google Cloud DLP 服務支援的 infoType 清單,請參閱 InfoType 偵測工具參考資料 無。 不會。
憑證 在 Apigee Edge 控制台中輸入時,這是服務帳戶金鑰檔案的內容。透過 Management API 傳送時,這是從服務帳戶金鑰檔案產生的 base64 編碼值。 無。 是。