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.


Jika ingin mengikuti panduan langkah demi langkah untuk tugas ini langsung di Konsol Google Cloud, 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. 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. Instal Node.js dan NPM.

Menyiapkan aplikasi CLI Perlindungan Data Sensitif

Untuk menyiapkan aplikasi CLI Perlindungan Data Sensitif 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 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 pada 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 selanjutnya

  • Untuk mulai memeriksa teks dan gambar guna menemukan data sensitif, lihat Panduan cara.

  • Untuk lebih memahami inspeksi, penyamaran, infoTypes, dan kemungkinan, lihat Konsep.

  • Pelajari DLP API lebih lanjut.

  • Pelajari Klien Node.js Cloud DLP lebih lanjut.