Inspecione texto sensível através da API DLP

Saiba como analisar uma string de exemplo para encontrar informações confidenciais através da API Cloud Data Loss Prevention da Sensitive Data Protection e do JSON.


Para seguir orientações passo a passo para esta tarefa diretamente na Google Cloud consola, clique em Orientar-me:

Visita guiada


Antes de começar

  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 estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

  4. Para inicializar a CLI gcloud, execute o seguinte comando:

    gcloud init
  5. 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 the resourcemanager.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.

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

  7. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    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 estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

  11. Para inicializar a CLI gcloud, execute o seguinte comando:

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

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

  14. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    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. Inspecione uma string para verificar a existência de informações confidenciais

    Esta secção mostra como configurar a API DLP para analisar texto de exemplo através do método REST projects.content.inspect.

    Esta secção requer que guarde o pedido de exemplo num ficheiro JSON. Se estiver a usar o Cloud Shell, pode usar o editor do Cloud Shell para criar o ficheiro. Para iniciar o editor, clique em Abrir editor na barra de ferramentas da janela do Cloud Shell.

    Antes de usar qualquer um dos dados do pedido, faça as seguintes substituições:

    • PROJECT_ID: o ID do seu Google Cloud projeto. Os IDs dos projetos são strings alfanuméricas, como my-project.

    Método HTTP e URL:

    POST https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect

    Corpo JSON do pedido:

    {
      "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
      }
    }
    

    Para enviar o seu pedido, expanda uma destas opções:

    Deve receber uma resposta JSON semelhante à seguinte:

    {
      "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"
          }
        ]
      }
    }

    Limpar

    Para evitar incorrer em custos na sua Google Cloud conta pelos recursos usados nesta página, elimine o Google Cloud projeto com os recursos.

    Elimine o projeto

    Se criou um novo projeto para este início rápido, a forma mais fácil de evitar custos adicionais é eliminar o projeto.

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    Revogue as suas credenciais

    Optional: Revoke credentials from the gcloud CLI.

    gcloud auth revoke

    O que se segue?

    • Para começar a inspecionar texto e imagens quanto a dados confidenciais, consulte os guias de instruções.

    • Para compreender melhor a inspeção, a ocultação, os infoTypes e a probabilidade, consulte os Conceitos.

    • Saiba mais acerca da API DLP.