Ispeziona il testo sensibile utilizzando l'API DLP
Scopri come analizzare una stringa di esempio per individuare informazioni sensibili utilizzando l'API Cloud Data Loss Prevention di Sensitive Data Protection e JSON.
Per seguire le indicazioni dettagliate per questa attività direttamente nella Google Cloud console, fai clic su Procedura guidata:
Prima di iniziare
- 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.
-
Se utilizzi un provider di identità (IdP) esterno, devi prima accedere a gcloud CLI con la tua identità federata.
-
Per inizializzare gcloud CLI, esegui questo comando:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the DLP API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.gcloud services enable dlp.googleapis.com
-
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.
-
Install the Google Cloud CLI.
-
Se utilizzi un provider di identità (IdP) esterno, devi prima accedere a gcloud CLI con la tua identità federata.
-
Per inizializzare gcloud CLI, esegui questo comando:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the DLP API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.gcloud services enable dlp.googleapis.com
-
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.
-
PROJECT_ID
: il tuo ID progetto Google Cloud . Gli ID progetto sono stringhe alfanumeriche, comemy-project
. Per iniziare a ispezionare testo e immagini per l'individuazione di dati sensibili, consulta le guide pratiche.
Per comprendere meglio ispezione, oscuramento, infoType e probabilità, consulta la sezione Concetti.
Scopri di più sull'API DLP.
Ispeziona una stringa per individuare informazioni sensibili
Questa sezione mostra come configurare l'API DLP per analizzare
il testo di esempio utilizzando il metodo REST projects.content.inspect
.
Questa sezione richiede di salvare la richiesta di esempio in un file JSON. Se utilizzi Cloud Shell, puoi utilizzare l'editor di Cloud Shell per creare il file. Per avviare l'editor, fai clic su
Apri editor sulla barra degli strumenti della finestra di Cloud Shell.Prima di utilizzare i dati della richiesta, apporta le seguenti sostituzioni:
Metodo HTTP e URL:
POST https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect
Corpo JSON della richiesta:
{ "item": { "value": "My phone number is (800) 555-0123." }, "inspectConfig": { "infoTypes": [ { "name": "PHONE_NUMBER" }, { "name": "US_TOLLFREE_PHONE_NUMBER" } ], "minLikelihood": "POSSIBLE", "limits": { "maxFindingsPerItem": 0 }, "includeQuote": true } }
Per inviare la richiesta, espandi una di queste opzioni:
Dovresti ricevere una risposta JSON simile alla seguente:
{ "result": { "findings": [ { "quote": "(800) 555-0123", "infoType": { "name": "US_TOLLFREE_PHONE_NUMBER" }, "likelihood": "LIKELY", "location": { "byteRange": { "start": "19", "end": "33" }, "codepointRange": { "start": "19", "end": "33" } }, "createTime": "2022-09-23T01:53:05.303Z", "findingId": "2022-09-23T01:53:05.306348Z5328915744504121862" } ] } }
Esegui la pulizia
Per evitare che al tuo account Google Cloud vengano addebitati costi relativi alle risorse utilizzate in questa pagina, elimina il progetto Google Cloud con le risorse.
Elimina il progetto
Se hai creato un nuovo progetto per questa guida rapida, il modo più semplice per evitare addebiti aggiuntivi è eliminare il progetto.
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
Revocare le credenziali
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke