Inspecciona texto sensible con Node.js

Aprende a analizar una cadena de muestra en busca de información sensible con la API de Cloud Data Loss Prevention de Sensitive Data Protection, Google Cloud CLI y Node.js.


Para seguir la guía paso a paso en esta tarea directamente 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: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: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 Sensitive Data Protection

Para configurar una app de la CLI de Sensitive Data Protection 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 string en busca de información sensible

Para analizar un 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 a este:

  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

Cómo 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?