בדיקת טקסט לאיתור מידע אישי רגיש

השירות Sensitive Data Protection יכול לזהות ולסווג מידע אישי רגיש בתוכן טקסט. בהינתן קלט טקסט, DLP API מחזיר פרטים על כל infoTypes שנמצאו בטקסט, ערך הסבירות ומידע על ההיסט.

שיטות מומלצות

זיהוי ותעדוף של סריקות

חשוב לזהות את המשאבים ולציין לאילו מהם יש עדיפות גבוהה יותר לסריקה. כשמתחילים להשתמש ב-Data Classification, יכול להיות שיש לכם כמות גדולה של נתונים שצריך לסווג, ואי אפשר לסרוק את כולם בבת אחת. מומלץ לבחור בהתחלה נתונים שמציבים את הסיכון הגבוה ביותר – לדוגמה, נתונים שניגשים אליהם לעיתים קרובות, נתונים שנגישים לכולם או נתונים לא ידועים.

הפחתת זמן האחזור

הזמן האחזור מושפע מכמה גורמים: כמות הנתונים שצריך לסרוק, מאגר האחסון שנסרק וסוגי ה-infoType ומספרם שמופעלים.

כדי לצמצם את זמן האחזור של העבודות, אפשר לנסות את הפעולות הבאות:

  • מפעילים דגימה.
  • מומלץ להימנע מהפעלת סוגי מידע שלא נחוצים. למרות שהם שימושיים בתרחישים מסוימים, חלק מה-infoTypes – כולל PERSON_NAME,‏ FEMALE_NAME,‏ MALE_NAME,‏ FIRST_NAME,‏ LAST_NAME,‏ DATE_OF_BIRTH,‏ LOCATION,‏ STREET_ADDRESS ו-ORGANIZATION_NAME – עלולים לגרום להרצת בקשות לאט יותר מאשר בקשות שלא כוללות אותם.
  • תמיד צריך לציין במפורש את סוגי המידע. אל תשתמשו ברשימה ריקה של infoTypes.
  • כדי לצמצם את מספר ההלוך ושוב ברשת, מומלץ לארגן את הנתונים לבדיקה בטבלה עם שורות ועמודות, אם אפשר.

הגבלת היקף הסריקות הראשונות

כדי לקבל את התוצאות הטובות ביותר, כדאי להגביל את היקף הסריקות הראשונות במקום לסרוק את כל הנתונים. מתחילים עם כמה בקשות. התובנות שתקבלו יהיו משמעותיות יותר אם תגדירו במדויק אילו אמצעי זיהוי להפעיל ואילו כללי החרגה עשויים להידרש כדי לצמצם את מספר התוצאות החיוביות השגויות. כדאי להימנע מהפעלת כל סוגי המידע אם לא צריך את כולם, כי טעויות בזיהוי או ממצאים לא שמישים עלולים להקשות על הערכת הסיכון. סוגי מידע מסוימים, כמו DATE, TIME, DOMAIN_NAME ו-URL, מזהים מגוון רחב של ממצאים, ולכן לא תמיד כדאי להפעיל אותם.

סריקות מקומיות, היברידיות ומרובות עננים

אם הנתונים שרוצים לסרוק נמצאים בשרת מקומי או מחוץ ל- Google Cloud, אפשר להשתמש בשיטות ה-API‏ content.inspect ו-content.deidentify כדי לסרוק את התוכן, לסווג את הממצאים ולבצע פסאודונימיזציה של התוכן בלי לשמור אותו מחוץ לאחסון המקומי.

בדיקת מחרוזת טקסט

בהמשך מופיעות דוגמאות ל-JSON ולקוד בכמה שפות שמדגימות איך להשתמש ב-DLP API כדי לבדוק מחרוזות טקסט לחיפוש מידע אישי רגיש.

C#

מידע על התקנת ספריית הלקוח של Sensitive Data Protection והשימוש בה מופיע במאמר ספריות הלקוח של Sensitive Data Protection.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


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 InspectString
{
    public static InspectContentResponse Inspect(
        string projectId,
        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, "global").ToString(),
            Item = new ContentItem
            {
                Value = dataValue
            },
            InspectConfig = inspectConfig
        };

        var dlp = DlpServiceClient.Create();
        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.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	dlp "cloud.google.com/go/dlp/apiv2"
	"cloud.google.com/go/dlp/apiv2/dlppb"
)

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

	// Initialize client.
	client, err := dlp.NewClient(ctx)
	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/global", projectID),
		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.

כדי לבצע אימות ב-Sensitive Data Protection, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


import com.google.cloud.dlp.v2.DlpServiceClient;
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 InspectString {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String