Inspecciona texto sensible con Node.js

Aprende a analizar una string de muestra en busca de información sensible con la API de Cloud Data Loss Prevention de Protección de datos sensibles, Google Cloud CLI y Node.js.


Para seguir la guía paso a paso sobre esta tarea de forma directa en la consola de Google Cloud, haz clic en Guiarme:

Guiarme


Antes de comenzar

  1. 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.
  2. Install the Google Cloud CLI.
  3. To initialize the gcloud CLI, run the following command:

    gcloud init
  4. Create or select a Google Cloud project.

    • 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.

  5. Make sure that billing is enabled for your Google Cloud project.

  6. Enable the DLP API:

    gcloud services enable dlp.googleapis.com
  7. Create local authentication credentials for your user account:

    gcloud auth application-default login
  8. 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_IDENTIFIER" --role=ROLE
    • Replace PROJECT_ID with your project ID.
    • Replace USER_IDENTIFIER with the identifier for your user account. For example, user:myemail@example.com.

    • Replace ROLE with each individual role.
  9. Install the Google Cloud CLI.
  10. To initialize the gcloud CLI, run the following command:

    gcloud init
  11. Create or select a Google Cloud project.

    • 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.

  12. Make sure that billing is enabled for your Google Cloud project.

  13. Enable the DLP API:

    gcloud services enable dlp.googleapis.com
  14. Create local authentication credentials for your user account:

    gcloud auth application-default login
  15. 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_IDENTIFIER" --role=ROLE
    • Replace PROJECT_ID with your project ID.
    • Replace USER_IDENTIFIER with the identifier for your user account. For example, user:myemail@example.com.

    • Replace ROLE with each individual role.
  16. Instala Node.js y NPM.

Configura una app de la CLI de protección de datos sensibles

Para configurar una app de la CLI de protección de datos sensibles con Node.js, haz lo siguiente:

  1. Clona la biblioteca cliente de DLP de Node.js:

     git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
    
  2. Navega al directorio dlp.

     cd nodejs-docs-samples/dlp
    
  3. Usa este comando para instalar las dependencias de la app:

     npm install
    

Inspecciona una cadena en busca de información sensible

Para analizar texto de muestra con la API de DLP y la secuencia de comandos inspectString de Node.js, ejecuta el siguiente comando:

  node inspectString.js PROJECT_ID "My email address is joe@example.com."

El resultado es similar al siguiente:

  Findings:
      Info type: EMAIL_ADDRESS
      Likelihood: LIKELY

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 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 fácil de evitar cargos adicionales es borrarlo.

    Delete a Google Cloud project:

    gcloud projects delete PROJECT_ID

Revocar tus credenciales

  1. Optional: Revoke the authentication credentials that you created, and delete the local credential file.

    gcloud auth application-default revoke
  2. Optional: Revoke credentials from the gcloud CLI.

    gcloud auth revoke

¿Qué sigue?