DLP API を使用して機密テキストを検査する

機密データの保護と JSON の Cloud Data Loss Prevention API を使用して、サンプル文字列をスキャンして機密情報を検出する方法について説明します。


このタスクを 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. 外部 ID プロバイダ(IdP)を使用している場合は、まずフェデレーション ID を使用して gcloud CLI にログインする必要があります。

  4. gcloud CLI を初期化するには、次のコマンドを実行します。

    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. 外部 ID プロバイダ(IdP)を使用している場合は、まずフェデレーション ID を使用して gcloud CLI にログインする必要があります。

  11. gcloud CLI を初期化するには、次のコマンドを実行します。

    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. 文字列に含まれる機密情報を検査する

    このセクションでは、projects.content.inspect REST メソッドを使用してサンプル テキストをスキャンするように DLP API を構成する方法について説明します。

    このセクションでは、サンプル リクエストを JSON ファイルに保存する必要があります。Cloud Shell を使用している場合は、Cloud Shell エディタを使用してファイルを作成できます。エディタを起動するには、Cloud Shell ウィンドウのツールバーにある [エディタを開く] をクリックします。

    リクエストのデータを使用する前に、次のように置き換えます。

    • PROJECT_ID: 実際の Google Cloud プロジェクト ID。プロジェクト ID は英数字からなる文字列です(例: my-project)。

    HTTP メソッドと URL:

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

    リクエストの本文(JSON):

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

    リクエストを送信するには、次のいずれかのオプションを展開します。

    次のような JSON レスポンスが返されます。

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

    クリーンアップ

    このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、リソースを含む Google Cloud プロジェクトを削除します。

    プロジェクトの削除

    このクイックスタート向けに新しいプロジェクトを作成した場合、追加料金の発生を防ぐ最も簡単な方法としては、プロジェクトを削除します。

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    認証情報を取り消す

    Optional: Revoke credentials from the gcloud CLI.

    gcloud auth revoke

    次のステップ

    • テキストと画像の機密データの検査を開始するにあたって、入門ガイドを確認します。

    • 検査、秘匿化、infoType、可能性について、コンセプトを参照して理解を深めます。

    • DLP API について詳細を確認します。