Google Cloud Data Loss Prevention 擴充功能

您正在查看 Apigee Edge 說明文件。
前往 Apigee X 說明文件
info

版本:2.0.0

使用這個擴充功能,即可在內容和圖片中模糊處理機密資料。例如,您可以遮蓋信用卡號碼、姓名和身分證字號。

必要條件

本內容提供設定和使用此擴充功能的參考資訊。使用 ExtensionCallout 政策從 API proxy 使用擴充功能前,您必須:

  1. 為專案啟用 Google Cloud DLP API

  2. 授予權限:指定擴充功能的存取層級。

  3. 使用 GCP 主控台為服務帳戶產生金鑰

  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>

下列 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>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 代理程式中使用,請使用下列說明。如要瞭解如何使用 Apigee 控制台設定擴充功能,請參閱「新增及設定擴充功能」。

常見的擴充功能屬性

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

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

這個擴充功能套件的屬性

請為下列專屬於此擴充功能的設定屬性指定值。

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