我正在开发使用数据泄漏预防(GCP)的PII de身份识别应用程序。我正在使用de标识模板来执行去标识规则。
问题:我不能弄清楚如何在识别模板中使用自定义信息类型。
以下是一个识别模板示例:
{
"deidentifyTemplate":{
"displayName":"Email and id masker",
"description":"De-identifies emails and ids with a series of asterisks.",
"deidentifyConfig":{
"infoTypeTransformations":{
"transformations":[
{
"infoTypes":[
{
"name":"EMAIL_ADDRESS"
}
],
"primitiveTransformation":{
"characterMaskConfig":{
"maskingCharacter":"*"
}
}
}
]
}
}
}
}
在上面的示例中,它是一个构建信息类型(电子邮件),文档中的自定义信息类型代码片段如下所示:
"inspect_config":{
"custom_info_types":[
{
"info_type":{
"name":"CUSTOM_ID"
},
"regex":{
"pattern":"[1-9]{2}-[1-9]{4}"
},
"likelihood":"POSSIBLE"
}
]
}
在识别模板的rest文档中没有有效的inspect_config
对象定义,它只在检查模板中有效。
是否可以在识别模板(infoTypeTransformations
)中使用自定义信息类型?
下面是rest文档的link。
发布于 2020-12-12 04:12:27
是的,可以使用自定义信息类型。需要做的是创建一个识别模板和一个检查模板。
然后,在调用API时,将这两个模板作为参数发送。对于使用dlp客户端库的python,下面是一些伪代码示例
from google.cloud import dlp_v2
dlp_client = dlp_v2.DlpServiceClient()
dlp_client.deidentify_content(
request={
inspect_template_name = "projects/<project>/locations/global/inspectTemplates/<templateId>,
deidentify_template_name = "projects/<project>/locations/global/deidentifyTemplates/<templateId>,
parent = <parent>,
item = <item>
}
)
发布于 2020-12-12 22:51:40
我们可以通过stored
info types在deidentification
模板中使用custom info types。
我们可以使用API调用来创建stored
信息类型,并且该stored
信息类型可以像内置信息类型一样被引用。
创建存储信息类型的
import google.cloud.dlp
import os
dlp = google.cloud.dlp_v2.DlpServiceClient()
default_project = os.environ['GOOGLE_PROJECT'] # project id
parent = f"projects/{default_project}"
# details of custom info types
custom_info_id = "<unique-id>" # example: IP_ADDRESS
custom_info_id_pattern = r"<regex pattern>"
info_config = {
"display_name": custom_info_id,
"description": custom_info_id,
"regex":
{
"pattern": custom_info_id_pattern
}
}
response = dlp.create_stored_info_type(request={
"parent": parent,
"config": info_config,
"stored_info_type_id": custom_info_id
})
如何引用存储的信息类型
stored_info_type_id
进行操作: {
"info_types":[
{
"name":"IP_ADDRESS" # this is defined stored_info_type_id
}
],
"primitive_transformation":{
"character_mask_config":{
"characters_to_ignore":[
{
"characters_to_skip":"."
}
],
"masking_character":"*"
}
}
},
https://stackoverflow.com/questions/65093584
复制相似问题