Node.js를 사용하여 민감한 텍스트 검사

민감한 정보 보호의 Cloud Data Loss Prevention API, Google Cloud CLI, Node.js를 사용하여 샘플 문자열에서 민감한 정보를 스캔하는 방법을 알아봅니다.


Google Cloud 콘솔에서 이 태스크에 대한 단계별 안내를 직접 수행하려면 둘러보기를 클릭합니다.

둘러보기


시작하기 전에

  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. Node.js 및 NPM 설치.

Sensitive Data Protection CLI 앱 설정

Node.js를 사용하여 Sensitive Data Protection CLI 앱을 설정하려면 다음을 수행합니다.

  1. Node.js DLP 클라이언트 라이브러리를 클론합니다.

     git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
    
  2. dlp 디렉터리로 이동합니다.

     cd nodejs-docs-samples/dlp
    
  3. 앱 종속 항목을 설치합니다.

     npm install
    

문자열에서 민감한 정보 검사

DLP API 및 inspectString Node.js 스크립트를 사용하여 샘플 텍스트를 스캔하려면 다음 명령어를 실행합니다.

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

출력은 다음과 비슷합니다.

  Findings:
      Info type: EMAIL_ADDRESS
      Likelihood: LIKELY

삭제

이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 리소스가 포함된 Google Cloud 프로젝트를 삭제하면 됩니다.

프로젝트 삭제

이 빠른 시작을 위해 새 프로젝트를 만든 경우 추가 요금 청구를 방지하는 가장 쉬운 방법은 프로젝트를 삭제하는 것입니다.

    Delete a Google Cloud project:

    gcloud projects delete PROJECT_ID

사용자 인증 정보 취소

  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

다음 단계