Cloud Data Loss Prevention (Cloud DLP) fait désormais partie de la protection des données sensibles. Le nom de l'API reste le même: API Cloud Data Loss Prevention (DLP). Pour en savoir plus sur les services qui constituent Sensitive Data Protection, consultez la section Présentation de Sensitive Data Protection.
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Inspecter un texte sensible à l'aide de l'API DLP
Découvrez comment analyser un exemple de chaîne à la recherche d'informations sensibles à l'aide de l'API Cloud Data Loss Prevention de Sensitive Data Protection et de JSON.
Pour obtenir des instructions détaillées sur cette tâche directement dans la console Google Cloud , cliquez sur Visite guidée :
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.
USER_IDENTIFIER: the identifier for your user
account—for example, myemail@example.com.
ROLE: the IAM role that you grant to your user account.
Détecter des informations sensibles dans une chaîne
Cette section vous explique comment configurer l'API DLP pour analyser un exemple de texte à l'aide de la méthode REST projects.content.inspect.
Dans cette section, vous devez enregistrer l'exemple de requête dans un fichier JSON. Si vous utilisez Cloud Shell, vous pouvez créer le fichier à l'aide de l'éditeur Cloud Shell. Pour lancer l'éditeur, cliquez sur
editOuvrir l'éditeur
launch dans la barre d'outils de la fenêtre Cloud Shell.
Avant d'utiliser les données de requête, effectuez les remplacements suivants :
PROJECT_ID : ID de votre projet Google Cloud . Les ID de projet sont des chaînes alphanumériques, telles que my-project.
Méthode HTTP et URL :
POST https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect
Pour éviter que les ressources utilisées dans cette démonstration soient facturées sur votre compte Google Cloud , supprimez le projet Google Cloud qui les contient.
Supprimer le projet
Si vous avez créé un projet pour ce guide de démarrage rapide, le moyen le plus simple d'éviter des frais supplémentaires est de le supprimer.
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
Révoquer vos identifiants
Optional: Revoke credentials from the gcloud CLI.
gcloudauthrevoke
Étapes suivantes
Pour découvrir comment inspecter du texte et des images afin d'identifier les données sensibles, consultez les guides pratiques.
Pour mieux comprendre l'inspection, le masquage, les infoTypes et la probabilité de correspondance, consultez Concepts.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Inspect sensitive text by using the DLP API\n===========================================\n\nLearn how to scan a sample string for sensitive information by using the\nCloud Data Loss Prevention API of Sensitive Data Protection and JSON.\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nGoogle Cloud console, click **Guide me**:\n\n[Guide me](https://console.cloud.google.com/freetrial?redirectPath=/?walkthrough_id=dlp--inspect-sensitive-text-api)\n\n*** ** * ** ***\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n- [Create or select a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects).\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n - Create a Google Cloud project:\n\n ```\n gcloud projects create PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with a name for the Google Cloud project you are creating.\n - Select the Google Cloud project that you created:\n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project name.\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the DLP API:\n\n\n ```bash\n gcloud services enable dlp.googleapis.com\n ```\n-\n Grant roles to your user account. Run the following command once for each of the following\n IAM roles:\n `roles/dlp.user`\n\n ```bash\n gcloud projects add-iam-policy-binding PROJECT_ID --member=\"user:\u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e\" --role=ROLE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your project ID.\n - \u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e: the identifier for your user account---for example, `myemail@example.com`.\n - \u003cvar translate=\"no\"\u003eROLE\u003c/var\u003e: the IAM role that you grant to your user account.\n\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n- [Create or select a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects).\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n - Create a Google Cloud project:\n\n ```\n gcloud projects create PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with a name for the Google Cloud project you are creating.\n - Select the Google Cloud project that you created:\n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project name.\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the DLP API:\n\n\n ```bash\n gcloud services enable dlp.googleapis.com\n ```\n-\n Grant roles to your user account. Run the following command once for each of the following\n IAM roles:\n `roles/dlp.user`\n\n ```bash\n gcloud projects add-iam-policy-binding PROJECT_ID --member=\"user:\u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e\" --role=ROLE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your project ID.\n - \u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e: the identifier for your user account---for example, `myemail@example.com`.\n - \u003cvar translate=\"no\"\u003eROLE\u003c/var\u003e: the IAM role that you grant to your user account.\n\n\u003cbr /\u003e\n\nInspect a string for sensitive information\n------------------------------------------\n\nThis section shows you how to configure the DLP API to scan\nsample text using the [`projects.content.inspect`](/sensitive-data-protection/docs/reference/rest/v2/projects.content/inspect)\nREST method.\n\nThis section requires you to save the sample request in a JSON file. If you're\nusing Cloud Shell, you can use the Cloud Shell Editor to create the\nfile. To launch the editor, click edit **Open Editor** launch on the toolbar of the Cloud Shell window.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your Google Cloud project ID. Project IDs are alphanumeric strings, like `my-project`.\n\n\nHTTP method and URL:\n\n```\nPOST https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect\n```\n\n\nRequest JSON body:\n\n```\n{\n \"item\": {\n \"value\": \"My phone number is (800) 555-0123.\"\n },\n \"inspectConfig\": {\n \"infoTypes\": [\n {\n \"name\": \"PHONE_NUMBER\"\n },\n {\n \"name\": \"US_TOLLFREE_PHONE_NUMBER\"\n }\n ],\n \"minLikelihood\": \"POSSIBLE\",\n \"limits\": {\n \"maxFindingsPerItem\": 0\n },\n \"includeQuote\": true\n }\n}\n```\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `inspect-request.json`,\nand execute the following command:\n\n```\ncurl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: PROJECT_ID\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -d @inspect-request.json \\\n \"https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect\"\n```\n\n#### PowerShell (Windows)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `inspect-request.json`,\nand execute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\"; \"x-goog-user-project\" = \"PROJECT_ID\" }\n\nInvoke-WebRequest `\n -Method POST `\n -Headers $headers `\n -ContentType: \"application/json; charset=utf-8\" `\n -InFile inspect-request.json `\n -Uri \"https://dlp.googleapis.com/v2/projects/PROJECT_ID/content:inspect\" | Select-Object -Expand Content\n```\n\nYou should receive a JSON response similar to the following:\n\n```\n{\n \"result\": {\n \"findings\": [\n {\n \"quote\": \"(800) 555-0123\",\n \"infoType\": {\n \"name\": \"US_TOLLFREE_PHONE_NUMBER\"\n },\n \"likelihood\": \"LIKELY\",\n \"location\": {\n \"byteRange\": {\n \"start\": \"19\",\n \"end\": \"33\"\n },\n \"codepointRange\": {\n \"start\": \"19\",\n \"end\": \"33\"\n }\n },\n \"createTime\": \"2022-09-23T01:53:05.303Z\",\n \"findingId\": \"2022-09-23T01:53:05.306348Z5328915744504121862\"\n }\n ]\n }\n}\n```\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, delete the Google Cloud project with the\nresources.\n\n### Delete the project\n\nIf you created a new project for this quickstart, the easiest way to prevent\nadditional charges is to delete the project.\n\n| **Caution** : Deleting a project has the following effects:\n|\n| - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.\n| - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.\n|\n|\n| If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects\n| can help you avoid exceeding project quota limits.\n1. Delete a Google Cloud project: \n\n```\ngcloud projects delete PROJECT_ID\n```\n\n\u003cbr /\u003e\n\n### Revoke your credentials\n\n-\n Optional: Revoke credentials from the gcloud CLI.\n\n ```bash\n gcloud auth revoke\n ```\n\nWhat's next\n-----------\n\n- To get started with inspecting text and images for sensitive data, see\n [How-to guides](/sensitive-data-protection/docs/how-to).\n\n- To better understand inspection, redaction, infoTypes, and likelihood, see\n [Concepts](/sensitive-data-protection/docs/concepts).\n\n- Learn more about the [DLP API](/sensitive-data-protection/docs/reference/rest/v2)."]]