Inspecciona texto sensible con la API de DLP
Aprende a analizar una cadena de muestra en busca de información sensible con la API de Cloud Data Loss Prevention de Protección de datos sensibles y JSON.
Para seguir la guía paso a paso sobre esta tarea directamente en la consola Google Cloud , haz clic en Guiarme:
Antes de comenzar
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Install the Google Cloud CLI.
-
Si usas un proveedor de identidad externo (IdP), primero debes acceder a gcloud CLI con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the DLP API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.gcloud services enable dlp.googleapis.com
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/dlp.user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user account—for example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
-
Install the Google Cloud CLI.
-
Si usas un proveedor de identidad externo (IdP), primero debes acceder a gcloud CLI con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the DLP API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.gcloud services enable dlp.googleapis.com
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/dlp.user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user account—for example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
-
PROJECT_ID
: El ID de tu proyecto de Google Cloud . Los IDs de proyecto son cadenas alfanuméricas, comomy-project
. Para comenzar a inspeccionar imágenes y texto en busca de datos sensibles, consulta las guías prácticas.
Para comprender mejor la inspección, el ocultamiento, los Infotipos y la probabilidad, consulta Conceptos.
Obtén más información sobre la API de DLP.
Inspecciona una string en busca de información sensible
En esta sección, se muestra cómo configurar la API de DLP para analizar texto de muestra con el método de REST projects.content.inspect
.
En esta sección, debes guardar la solicitud de ejemplo en un archivo JSON. Si usas Cloud Shell, puedes usar el editor de Cloud Shell para crear el archivo. Para iniciar el editor, haz clic en
Abrir editor en la barra de herramientas de la ventana de Cloud Shell.Antes de usar cualquiera de los datos de solicitud a continuación, realiza los siguientes reemplazos:
Método HTTP y URL:
POST https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect
Cuerpo JSON de la solicitud:
{ "item": { "value": "My phone number is (800) 555-0123." }, "inspectConfig": { "infoTypes": [ { "name": "PHONE_NUMBER" }, { "name": "US_TOLLFREE_PHONE_NUMBER" } ], "minLikelihood": "POSSIBLE", "limits": { "maxFindingsPerItem": 0 }, "includeQuote": true } }
Para enviar tu solicitud, expande una de estas opciones:
Deberías recibir una respuesta JSON similar a la que se muestra a continuación:
{ "result": { "findings": [ { "quote": "(800) 555-0123", "infoType": { "name": "US_TOLLFREE_PHONE_NUMBER" }, "likelihood": "LIKELY", "location": { "byteRange": { "start": "19", "end": "33" }, "codepointRange": { "start": "19", "end": "33" } }, "createTime": "2022-09-23T01:53:05.303Z", "findingId": "2022-09-23T01:53:05.306348Z5328915744504121862" } ] } }
Limpia
Para evitar que se apliquen cargos a tu cuenta de Google Cloud por los recursos que se usaron en esta página, borra el proyecto de Google Cloud que tiene los recursos.
Borra el proyecto
Si creaste un proyecto nuevo para esta guía de inicio rápido, la forma más sencilla de evitar cargos adicionales es borrar el proyecto.
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
Revoca tus credenciales
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke