泛化和分桶

泛化是一种获取可区分值并将其抽象为较普通、较不易区分的值的过程。泛化的目的是保留数据效用,同时降低数据的可标识性。

存在许多级别的泛化,具体取决于数据类型。您可以使用敏感数据保护的风险分析方法中包含的技术,在数据集或实际人口中进行测量,了解需要什么级别的泛化。

Sensitive Data Protection 支持的一种常见泛化技术是分桶。通过分桶,您可以将记录分组到较小的存储分区中,以尽量降低攻击者将敏感信息与标识性信息相关联的风险。这样做可以保留含义和效用,但也会模糊参与者太少的个体值。

分桶场景 1

请考虑此数值分桶场景:数据库存储用户满意度分数,范围从 0 到 100。该数据库如下所示:

user_id 得分
1 100
2 100
3 92
...

扫描数据后,您会发现某些值很少被用户使用。 事实上,有一些分数只映射到一个用户。例如,大多数用户选择 0、25、50、75 或 100。但是,有五个用户选择了 95,只有一个用户选择了 92。您可以将这些值泛化到多个组中,并消除任何参与者太少的组,而不是保留原始数据。以这种方式泛化数据有助于防止重标识,具体取决于数据的使用方式。

您可以选择移除这些离群数据行,也可以尝试使用分桶保留其效用。在此示例中,我们根据以下项对所有值进行分桶:

  • 0-25:“低”
  • 26-75:“中”
  • 76-100:“高”

Sensitive Data Protection 中的分桶是可用于去标识化的多种初始转换之一。以下 JSON 配置说明了如何在 DLP API 中实现此分桶场景。此 JSON 可以包含在对 content.deidentify 方法的请求中:

C#

如需了解如何安装和使用 Sensitive Data Protection 客户端库,请参阅 Sensitive Data Protection 客户端库

如需向 Sensitive Data Protection 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为本地开发环境设置身份验证


using System;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dlp.V2;

public class DeidentifyTableWithPrimitiveBucketing
{
    public static Table DeidentifyData(
        string projectId,
        Table tableToInspect = null)
    {
        // Instantiate dlp client.
        var dlp = DlpServiceClient.Create();

        // Construct the table if null.
        if (tableToInspect == null)
        {
            var row1 = new Value[]
            {
                new Value { IntegerValue = 1 },
                new Value { IntegerValue = 95 }
            };
            var row2 = new Value[]
            {
                new Value { IntegerValue = 2 },
                new Value { IntegerValue = 61 }
            };
            var row3 = new Value[]
            {
                new Value { IntegerValue = 3 },
                new Value { IntegerValue = 22 }
            };

            tableToInspect = new Table
            {
                Headers =
                {
                    new FieldId { Name = "user_id" },
                    new FieldId { Name = "score" }
                },
                Rows =
                {
                    new Table.Types.Row { Values = { row1 } },
                    new Table.Types.Row { Values = { row2 } },
                    new Table.Types.Row { Values = { row3 } }
                }
            };
        }

        // Specify the table and construct the content item.
        var contentItem = new ContentItem { Table = tableToInspect };

        // Specify how the content should be de-identified.
        var bucketingConfig = new BucketingConfig
        {
            Buckets =
            {
                new BucketingConfig.Types.Bucket
                {
                    Min = new Value { IntegerValue = 0 },
                    Max = new Value { IntegerValue = 25 },
                    ReplacementValue = new Value { StringValue = "Low" }
                },
                new BucketingConfig.Types.Bucket
                {
                    Min = new Value { IntegerValue = 25 },
                    Max = new Value { IntegerValue = 75 },
                    ReplacementValue = new Value { StringValue = "Medium" }
                },
                new BucketingConfig.Types.Bucket
                {
                    Min = new Value { IntegerValue = 75 },
                    Max = new Value { IntegerValue = 100 },
                    ReplacementValue = new Value { StringValue = "High" }
                }
            }
        };

        // Specify the fields to be encrypted.
        var fields = new FieldId[] { new FieldId { Name = "score" } };


        // Associate the de-identification with the specified field.
        var fieldTransformation = new FieldTransformation
        {
            PrimitiveTransformation = new PrimitiveTransformation
            {
                BucketingConfig = bucketingConfig
            },
            Fields = { fields }
        };

        // Construct the de-identify config.
        var deidentifyConfig = new DeidentifyConfig
        {
            RecordTransformations = new RecordTransformations
            {
                FieldTransformations = { fieldTransformation }
            }
        };

        // Construct the request.
        var request = new DeidentifyContentRequest
        {
            ParentAsLocationName = new LocationName(projectId, "global"),
            DeidentifyConfig = deidentifyConfig,
            Item = contentItem,
        };

        // Call the API.
        DeidentifyContentResponse response = dlp.DeidentifyContent(request);

        // Inspect the response.
        Console.WriteLine(response.Item.Table);