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:

Procedura guidata


Prima di iniziare

  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. Se utilizzi un provider di identitร  (IdP) esterno, devi prima accedere alla gcloud CLI con la tua identitร  federata.

  4. Per inizializzare gcloud CLI, esegui questo comando:

    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. 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.
  9. Install the Google Cloud CLI.

  10. Se utilizzi un provider di identitร  (IdP) esterno, devi prima accedere alla gcloud CLI con la tua identitร  federata.

  11. Per inizializzare gcloud CLI, esegui questo comando:

    gcloud init
  12. 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.

  13. Verify that billing is enabled for your Google Cloud project.

  14. Enable the DLP API:

    gcloud services enable dlp.googleapis.com
  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 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.
  16. 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:

    • PROJECT_ID: il tuo ID progetto Google Cloud . Gli ID progetto sono stringhe alfanumeriche, come my-project.

    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

  17. Optional: Revoke credentials from the gcloud CLI.

    gcloud auth revoke
  18. Passaggi successivi

    • 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.