指定處理位置

您可以指定執行機密資料防護作業的地區,控管可能含有機密資訊的資料處理位置。本文說明 Sensitive Data Protection 處理位置的概念,並示範如何指定區域。

如要查看支援的單一地區與多地區清單,請參閱「敏感資料保護位置」一文。

關於區域和多區域

「地區」是特定的地理位置,例如美國西部或東北亞。「多區域位置」 (或簡稱「多區域」) 是指包含兩個以上地理區域的大型地理區域,例如歐盟。

位置注意事項

適合的位置可讓您在延遲時間、可用性和頻寬費用之間取得平衡。

  • 使用單一區域可讓延遲時間和網路頻寬達到最佳化。

  • 如果您要處理來自 Google 網路外部且分布在較大地理區域的資料,或者需要跨區域備援帶來更高的可用性,請使用多地區。

  • 通常,您應該在方便的位置或包含大多數資料使用者的位置處理資料。

  • 如果貴機構必須將傳輸中資料保留在指定位置,請只使用支援區域端點 (REP) 的區域或多區域。在這種情況下,您需要使用 Cloud Data Loss Prevention API,因為機密資料保護服務的區域端點無法搭配Google Cloud 控制台使用。

指定區域

指定處理區域的方式取決於您傳送要求的端點類型,也就是全域端點區域端點。選擇端點類型時,請考量是否必須將傳輸中資料保留在特定區域。詳情請參閱「Sensitive Data Protection 的全域和區域端點」。

在對全球端點的要求中指定區域

控制台

設定 Sensitive Data Protection 作業時,請選擇區域。

舉例來說,建立工作觸發條件時,請從「資源位置」選單中選擇位置,如下所示:

如果不在意處理作業地點,請使用「全球」區域,Google 會選擇處理作業地點。預設區域為「全球」

REST

在要求端點網址中插入區域資訊。如果不在意處理作業地點,請使用 global 地區,Google 會選擇處理作業地點。請注意,要求指定 global 地區建立的任何資源,都會儲存在 global 地區。

以下是向全域端點發出的部分要求範例。

使用全域區域

以下兩個要求的效用相同。不納入區域與指定 locations/global/ 的效果相同。

POST https://www.googleapis.com/dlp/v2/projects/PROJECT_ID/locations/global/content:inspect
POST https://www.googleapis.com/dlp/v2/projects/PROJECT_ID/content:inspect

使用特定區域

如要指定處理作業的區域,請在資源網址中插入 locations/,然後插入區域名稱

POST https://www.googleapis.com/dlp/v2/projects/PROJECT_ID/locations/us-west2/content:inspect

在對區域端點提出的要求中指定區域

控制台

對於 Sensitive Data Protection,區域端點無法與 Google Cloud 控制台搭配使用。

C#

如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章

如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


using System;
using System.Collections.Generic;
using System.Linq;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dlp.V2;
using static Google.Cloud.Dlp.V2.InspectConfig.Types;

public class InspectStringRep
{
    public static InspectContentResponse Inspect(
        string projectId,
        string repLocation,
        string dataValue,
        string minLikelihood,
        int maxFindings,
        bool includeQuote,
        IEnumerable<InfoType> infoTypes,
        IEnumerable<CustomInfoType> customInfoTypes)
    {
        var inspectConfig = new InspectConfig
        {
            MinLikelihood = (Likelihood)Enum.Parse(typeof(Likelihood), minLikelihood, true),
            Limits = new FindingLimits
            {
                MaxFindingsPerRequest = maxFindings
            },
            IncludeQuote = includeQuote,
            InfoTypes = { infoTypes },
            CustomInfoTypes = { customInfoTypes }
        };
        var request = new InspectContentRequest
        {
            Parent = new LocationName(projectId, repLocation).ToString(),
            Item = new ContentItem
            {
                Value = dataValue
            },
            InspectConfig = inspectConfig
        };

        var dlp = new DlpServiceClientBuilder
        {
            Endpoint = $"dlp.{repLocation}.rep.googleapis.com"
        }.Build();

        var response = dlp.InspectContent(request);

        PrintResponse(includeQuote, response);

        return response;
    }

    private static void PrintResponse(bool includeQuote, InspectContentResponse response)
    {
        var findings = response.Result.Findings;
        if (findings.Any())
        {
            Console.WriteLine("Findings:");
            foreach (var finding in findings)
            {
                if (includeQuote)
                {
                    Console.WriteLine($"  Quote: {finding.Quote}");
                }
                Console.WriteLine($"  InfoType: {finding.InfoType}");
                Console.WriteLine($"  Likelihood: {finding.Likelihood}");
            }
        }
        else
        {
            Console.WriteLine("No findings.");
        }
    }
}

Go

如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章

如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

import (
	"context"
	"fmt"
	"io"

	dlp "cloud.google.com/go/dlp/apiv2"
	"cloud.google.com/go/dlp/apiv2/dlppb"
	"google.golang.org/api/option"
)

// inspectString inspects the a given string, and prints results.
func inspectStringRep(w io.Writer, projectID, repLocation, textToInspect string) error {
	// projectID := "my-project-id"
	// textToInspect := "My name is Gary and my email is gary@example.com"
	ctx := context.Background()

	// Assemble the regional endpoint url using provided rep location
	repEndpoint := fmt.Sprintf("dlp.%s.rep.googleapis.com:443", repLocation)

	// Initialize client.
	client, err := dlp.NewClient(ctx, option.WithEndpoint(repEndpoint))
	if err != nil {
		return err
	}
	defer client.Close() // Closing the client safely cleans up background resources.

	// Create and send the request.
	req := &dlppb.InspectContentRequest{
		Parent: fmt.Sprintf("projects/%s/locations/%s", projectID, repLocation),
		Item: &dlppb.ContentItem{
			DataItem: &dlppb.ContentItem_Value{
				Value: textToInspect,
			},
		},
		InspectConfig: &dlppb.InspectConfig{
			InfoTypes: []*dlppb.InfoType{
				{Name: "PHONE_NUMBER"},
				{Name: "EMAIL_ADDRESS"},
				{Name: "CREDIT_CARD_NUMBER"},
			},
			IncludeQuote: true,
		},
	}
	resp, err := client.InspectContent(ctx, req)
	if err != nil {
		return err
	}

	// Process the results.
	result := resp.Result
	fmt.Fprintf(w, "Findings: %d\n", len(result.Findings))
	for _, f := range result.Findings {
		fmt.Fprintf(w, "\tQuote: %s\n", f.Quote)
		fmt.Fprintf(w, "\tInfo type: %s\n", f.InfoType.Name)
		fmt.Fprintf(w, "\tLikelihood: %s\n", f.Likelihood)
	}
	return nil
}

Java

如要瞭解如何安裝及使用 Sensitive Data Protection 的用戶端程式庫,請參閱這篇文章

如要驗證 Sensitive Data Protection,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.dlp.v2.DlpServiceClient;
import com.google.cloud.dlp.v2.DlpServiceSettings;
import com.google.privacy.dlp.v2.ByteContentItem;
import com.google.privacy.dlp.v2.ByteContentItem.BytesType;
import com.google.privacy.dlp.v2.ContentItem;
import com.google.privacy.dlp.v2.Finding;
import com.google.privacy.dlp.v2.InfoType;
import com.google.privacy.dlp.v2.InspectConfig;
import com.google.privacy.dlp.v2.InspectContentRequest;
import com.google.privacy.dlp.v2.InspectContentResponse;
import com.google.privacy.dlp.v2.LocationName;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class InspectStringRep {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String repLocation = "regional-endpoint-location-to-use";
    String textToInspect = "My name is Gary and my email is gary@example.com";
    inspectString(projectId, repLocation, textToInspect);
  }

  // Inspects the provided text.
  public static void inspectString(String projectId, String repLocation, String textToInspect)
      throws IOException {
    // Assemble the regional endpoint url using provided rep location
    String repEndpoint = String.format("dlp.%s.rep.googleapis.com:443", repLocation);
    DlpServiceSettings settings = DlpServiceSettings.newBuilder()
        .setEndpoint(repEndpoint)
        .build();
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DlpServiceClient dlp = DlpServiceClient.create(settings)) {
      // Specify the type and content to be inspected.
      ByteContentItem byteItem =
          ByteContentItem.newBuilder()
              .setType(BytesType.TEXT_UTF8)
              .setData(ByteString.copyFromUtf8(textToInspect))
              .build();
      ContentItem item = ContentItem.newBuilder().setByteItem(byteItem).build();

      // Specify the type of info the inspection will look for.
      List<InfoType> infoTypes = new ArrayList<>();
      // See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
      for (String typeName : new String[] {"PHONE_NUMBER", "EMAIL_ADDRESS", "CREDIT_CARD_NUMBER"}) {
        infoTypes.add(InfoType.newBuilder().setName(typeName).build());
      }

      // Construct the configuration for the Inspect request.
      InspectConfig config =
          InspectConfig.newBuilder().addAllInfoTypes(infoTypes).setIncludeQuote(true).build();

      // Construct the Inspect request to be sent by the client.
      InspectContentRequest request =
          InspectContentRequest.newBuilder()
              .setParent(LocationName.of(projectId, repLocation).toString())
              .setItem(item)
              .setInspectConfig(config)
              .build();

      // Use the client to send the API request.
      InspectContentResponse response = dlp.inspectContent(request);

      // Parse the response and process results
      System.out.println("Findings: " + response.getResult().getFindingsCount());
      for (Finding f : response.getResult().getFindingsList()) {
        System.out.println("\tQuote: " + f.getQuote());
        System.out.println("\tInfo type: " + f.getInfoType().getName());
        System.out.println("\tLikelihood: " + f.getLikelihood());
      }
    }
  }
}

REST

下列範例會將 content.inspect 要求傳送至區域端點。 與這項要求相關聯的任何資料,在傳輸、使用中和靜態期間,都會保留在指定區域。

使用任何要求資料之前,請先替換以下項目:

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

HTTP 方法和網址:

POST https://dlp.REP_REGION.rep.googleapis.com/v2/projects/PROJECT_ID/locations/REP_REGION/content:inspect

JSON 要求主體:

{
  "inspectConfig": {
    "infoTypes": [
      {
        "name": "CREDIT_CARD_NUMBER"
      }
    ]
  },
  "item": {
    "value": "hi, my ccn is 4111111111111111"
  }
}

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

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

{
  "result": {
    "findings": [
      {
        "infoType": {
          "name": "CREDIT_CARD_NUMBER",
          "sensitivityScore": {
            "score": "SENSITIVITY_HIGH"
          }
        },
        "likelihood": "LIKELY",
        "location": {
          "byteRange": {
            "start": "14",
            "end": "30"
          },
          "codepointRange": {
            "start": "14",
            "end": "30"
          }
        },
        "createTime": "2024-08-09T19:54:13.348Z",
        "findingId": "2024-08-09T19:54:13.352163Z4747901452516738787"
      }
    ]
  }
}

主機代管注意事項

掃描 Cloud Storage 或 BigQuery 等儲存空間存放區時,您應在 Sensitive Data Protection 要求中指定與要掃描的存放區相同的位置。舉例來說,如果 BigQuery 資料集位於歐盟多地區位置,請在設定 Sensitive Data Protection 工作時,指定歐盟多地區 (europe)。

如果未將 Sensitive Data Protection 要求與掃描的儲存空間存放區共置,系統可能會在資料位置和要求中指定的位置之間,分割處理要求。

後續步驟