Vertraulichen Text mit Node.js prüfen

Hier erfahren Sie, wie Sie einen Beispielstring mithilfe der Cloud Data Loss Prevention API des Schutzes sensibler Daten, der Google Cloud CLI und Node.js auf vertrauliche Informationen scannen.


Eine detaillierte Anleitung dazu finden Sie direkt in der Google Cloud Console. Klicken Sie dazu einfach auf Anleitung:

Anleitung


Hinweise

  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. Wenn Sie einen externen Identitätsanbieter (IdP) verwenden, müssen Sie sich zuerst mit Ihrer föderierten Identität in der gcloud CLI anmelden.

  4. Führen Sie folgenden Befehl aus, um die gcloud CLI zu initialisieren:

    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. Wenn Sie einen externen Identitätsanbieter (IdP) verwenden, müssen Sie sich zuerst mit Ihrer föderierten Identität in der gcloud CLI anmelden.

  12. Führen Sie folgenden Befehl aus, um die gcloud CLI zu initialisieren:

    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. Installieren Sie Node.js und NPM.
  19. CLI-App zum Schutz sensibler Daten einrichten

    So richten Sie eine CLI-Anwendung zum Schutz sensibler Daten mit Node.js ein:

    1. Klonen Sie die Node.js-DLP-Clientbibliothek:

       git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
      
    2. Rufen Sie das Verzeichnis dlp auf.

       cd nodejs-docs-samples/dlp
      
    3. Installieren Sie die Anwendungsabhängigkeiten:

       npm install
      

    String auf vertrauliche Informationen prüfen

    Führen Sie den folgenden Befehl aus, um Beispieltext mit der DLP API und dem Node.js-Skript inspectString zu scannen:

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

    Die Ausgabe sieht etwa so aus:

      Findings:
          Info type: EMAIL_ADDRESS
          Likelihood: LIKELY
    

    Bereinigen

    Löschen Sie das Google Cloud -Projekt mit den Ressourcen, damit Ihrem Google Cloud -Konto die auf dieser Seite verwendeten Ressourcen nicht in Rechnung gestellt werden.

    Projekt löschen

    Wenn Sie für diese Kurzanleitung ein neues Projekt erstellt haben, können Sie zusätzliche Gebühren am einfachsten vermeiden, indem Sie das Projekt löschen.

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    Anmeldedaten widerrufen

    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

    Nächste Schritte