Google Cloud Data Loss Prevention 擴充功能

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

版本:1.5.1

你可以使用這項擴充功能來遮蓋內容和圖片中的機密資料。舉例來說,您可以遮蓋信用卡號碼、姓名和身分證字號。

必要條件

本文提供設定和使用這個擴充功能的參考資料。透過 Extension callout 政策透過 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

範例

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

為讓您輕鬆嘗試這個程式碼範例,這些範例使用 AssignMessage 政策來設定流程變數值,以及擷取要在 Trace 工具中顯示的擴充功能回應值。

有星星的遮罩

這個範例使用 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 政策會擷取擴充功能的輸出內容並在 Trace 工具中顯示。

<?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 動作遮蓋指定類型的文字,並使用 infoType 名稱本身。例如將電子郵件地址 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>

下列擴充功能呼叫政策會擷取 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 政策會擷取擴充功能的輸出內容並在 Trace 工具中顯示。

<?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":"*****************"}

要求參數

參數 說明 類型 預設 需要
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>

本例的輸出結果是去識別化要求內容。

要求參數

參數 說明 類型 預設 需要
text 要去識別化的文字。這就是去識別化程序的運作方式。 物件 無。 可以。
templateName 要使用的範本。這會是一個範本路徑,格式如下: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"}

要求參數

參數 說明 類型 預設 需要
text 要去識別化的文字。 字串 無。 可以。

回應

輸入文字中的指定 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 的 GCP 專案 ID。 無。 可以。
infoTypes 機密資料的資訊類型。如果省略,服務會偵測所有內建類型。如需 Google Cloud DLP 服務支援的 infoType 清單,請參閱 InfoType 偵測工具參考資料 無。 不會。
憑證 在 Apigee Edge 控制台中輸入時,這是服務帳戶金鑰檔案的內容。透過 Management API 傳送時,是由服務帳戶金鑰檔案產生的 Base64 編碼值。 無。 可以。