Node.js를 사용하여 민감한 텍스트 검사
민감한 정보 보호의 Cloud Data Loss Prevention API, Google Cloud CLI, Node.js를 사용하여 샘플 문자열에서 민감한 정보를 스캔하는 방법을 알아봅니다.
Google Cloud 콘솔에서 이 태스크에 대한 단계별 안내를 직접 수행하려면 둘러보기를 클릭합니다.
시작하기 전에
- 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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the DLP API:
gcloud services enable dlp.googleapis.com
-
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.
-
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.
- Replace
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the DLP API:
gcloud services enable dlp.googleapis.com
-
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.
-
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.
- Replace
- Node.js 및 NPM 설치.
Sensitive Data Protection CLI 앱 설정
Node.js를 사용하여 Sensitive Data Protection CLI 앱을 설정하려면 다음을 수행합니다.
Node.js DLP 클라이언트 라이브러리를 클론합니다.
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
dlp
디렉터리로 이동합니다.cd nodejs-docs-samples/dlp
앱 종속 항목을 설치합니다.
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
사용자 인증 정보 취소
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
다음 단계
텍스트 및 이미지에서 민감한 데이터 검사를 시작하려면 안내 가이드를 참조하세요.
검사, 수정, infoType, 가능성에 대한 자세한 내용은 개념을 참조하세요.
DLP API 자세히 알아보기
Cloud DLP Node.js 클라이언트 자세히 알아보기