Inspecter du texte sensible à l'aide de Node.js

Découvrez comment analyser un exemple de chaîne à la recherche d'informations sensibles à l'aide de l'API Cloud Data Loss Prevention de Sensitive Data Protection, de Google Cloud CLI et de Node.js.


Pour obtenir des instructions détaillées sur cette tâche directement dans la console Google Cloud , cliquez sur Visite guidée :

Visite guidée


Avant de commencer

  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. Si vous utilisez un fournisseur d'identité (IdP) externe, vous devez d'abord vous connecter à la gcloud CLI avec votre identité fédérée.

  4. Pour initialiser la gcloud CLI, exécutez la commande suivante :

    gcloud init
  5. 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.

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the DLP API:

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

    gcloud auth application-default login

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

  9. 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.
  10. Install the Google Cloud CLI.

  11. Si vous utilisez un fournisseur d'identité (IdP) externe, vous devez d'abord vous connecter à la gcloud CLI avec votre identité fédérée.

  12. Pour initialiser la gcloud CLI, exécutez la commande suivante :

    gcloud init
  13. 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.

  14. Verify that billing is enabled for your Google Cloud project.

  15. Enable the DLP API:

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

    gcloud auth application-default login

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

  17. 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.
  18. Installez Node.js et npm.
  19. Configurer une application CLI de Sensitive Data Protection

    Pour configurer une application CLI Sensitive Data Protection à l'aide de Node.js, procédez comme suit :

    1. Clonez la bibliothèque cliente DLP Node.js :

       git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
      
    2. Accédez au répertoire dlp :

       cd nodejs-docs-samples/dlp
      
    3. Installez les dépendances de l'application :

       npm install
      

    Détecter des informations sensibles dans une chaîne

    Pour analyser un exemple de texte à l'aide de l'API DLP et du script Node.js inspectString, exécutez la commande suivante :

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

    Le résultat ressemble à ce qui suit :

      Findings:
          Info type: EMAIL_ADDRESS
          Likelihood: LIKELY
    

    Effectuer un nettoyage

    Pour éviter que les ressources utilisées dans cette démonstration soient facturées sur votre compte Google Cloud , supprimez le projet Google Cloud qui les contient.

    Supprimer le projet

    Si vous avez créé un projet pour ce guide de démarrage rapide, le moyen le plus simple d'éviter des frais supplémentaires est de le supprimer.

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    Révoquer vos identifiants

    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

    Étapes suivantes

    • Pour découvrir comment inspecter du texte et des images afin d'identifier les données sensibles, consultez les guides pratiques.

    • Pour mieux comprendre l'inspection, le masquage, les infoTypes et la probabilité de correspondance, consultez Concepts.

    • En savoir plus sur l'API DLP

    • En savoir plus sur le client Node.js Cloud DLP