Memeriksa teks sensitif menggunakan Node.js

Pelajari cara memindai string contoh untuk menemukan informasi sensitif menggunakan Cloud Data Loss Prevention API dari Sensitive Data Protection, Google Cloud CLI, dan Node.js.


Untuk mengikuti panduan langkah demi langkah tugas ini langsung di Google Cloud konsol, klik Pandu saya:

Pandu saya


Sebelum memulai

  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. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  4. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    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. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  12. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    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. Instal Node.js dan NPM.
  19. Menyiapkan aplikasi CLI Sensitive Data Protection

    Untuk menyiapkan aplikasi CLI Sensitive Data Protection menggunakan Node.js, lakukan hal berikut:

    1. Clone library klien DLP Node.js:

       git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
      
    2. Buka direktori dlp.

       cd nodejs-docs-samples/dlp
      
    3. Instal dependensi aplikasi:

       npm install
      

    Memeriksa string untuk menemukan informasi sensitif

    Untuk memindai contoh teks menggunakan DLP API dan skrip Node.js inspectString, jalankan perintah berikut:

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

    Outputnya mirip dengan hal berikut ini:

      Findings:
          Info type: EMAIL_ADDRESS
          Likelihood: LIKELY
    

    Pembersihan

    Agar tidak menimbulkan biaya pada akun Google Cloud Anda untuk resource yang digunakan di halaman ini, hapus project Google Cloud yang berisi resource tersebut.

    Menghapus project

    Jika Anda membuat project baru untuk panduan memulai ini, cara termudah untuk mencegah biaya tambahan adalah dengan menghapus project tersebut.

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    Mencabut kredensial Anda

    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

    Langkah berikutnya