Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you restart it, you'll have to start from the beginning.
- On the top left of your screen, click Start lab to begin
Enable the APIs
/ 25
Inspect strings and files
/ 25
De-identification
/ 25
Redact strings and images
/ 25
The Cloud Data Loss Prevention (DLP) API is part of Sensitive Data Protection, which is a fully managed service designed to help discover, classify, and protect sensitive information.
You can use the DLP API to classify data in a variety of ways, including data type, sensitivity level, and catagories.
The DLP API protects sensitive data in a variety of ways, including:
*
.In this lab, you learn the basic capabilities of the DLP API and try out various ways to use the API to protect data.
In this lab, you use the DLP API to do the following:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Set the region for your project:
samples
directory and install the required Node.js
packages:gcloud
command:Here are the APIs needed to enable your project:
gcloud
command:Click Check my progress to verify the objective.
The samples directory of the project downloaded in the preceding step contains several javascript files that make use of the different functionality of the DLP API. The file inspectString.js
inspects a provided string for sensitive info types.
The output tells you the findings for each matched info type, which includes:
InfoType: the information type detected for that part of the string. Find a full list of possible info types here. By default, inspectString.js
inspects only for info types CREDIT_CARD_NUMBER
, PHONE_NUMBER
, PERSON_NAME
AND EMAIL_ADDRESS
Likelihood: the results are categorized based on how likely they each represent a match. Likelihood can range from VERY_UNLIKELY
to VERY_LIKELY
.
Check the output using below command:
The findings for the request above are:
accounts.txt
file:The file includes the following text:
inspectFile.js
file to inspect the provided file for sensitive info types:Check the output using below command:
The results:
Below is the asynchronous function that uses the API to inspect the string input:
The arguments provided for the parameters above are used to construct a request object. That request is then provided to the inspectContent
function to get a response that results in the output:
Run the following commands to upload the responses on Cloud Storage for activity tracking validation:
Click Check my progress to verify the objective.
Beyond inspecting and detecting sensitive data, you can also use Sensitive Data Protection to perform de-identification using the DLP API. De-identification is the process of removing identifying information from data. The API detects sensitive data as defined by info types, then uses a de-identification transformation to mask, delete, or otherwise obscure the data.
deidentifyWithMask.js
to try de-identification with a mask:Check the output using below command:
With a mask, the API replaces the characters of the matching info type with a different character, * by default. Example output:
Notice that the email address in the string is obfuscated while the arbitrary order number is intact. (Custom info types are possible but out of scope of this lab).
Look at the function that uses the DLP API to de-identify with a mask. Once again, these arguments are used to construct a request object. This time it's provided to the deidentifyContent
function:
Run the following commands to upload the responses on Cloud Storage for activity tracking validation:
Click Check my progress to verify the objective.
Another method of obfuscating sensitive information is redaction. Redaction replaces a match with the info type it's identified to match with.
redactText.js
to redact text from a sample input:Check the output using below command:
The output replaces the sample credit card number with the info type CREDIT_CARD_NUMBER
:
This is useful if you'd like to hide sensitive information but still identify the type of information that's being removed. The DLP API can similarly redact information from images that contain text. Take a look at a sample image (located in the samples/resources
directory):
As specified, a new image named redacted-phone.png
is generated with the requested information blacked out. To verify, open the samples/redacted-phone.png
file using Cloud Shell Code Editor:
As specified, a new image named redacted-email.png
is generated with the requested information blacked out. To verify, open the samples/redacted-email.png
file in the Cloud Shell Code Editor:
Here is the function that is used to redact from a string:
And here is the request provided to the deidentifyContent
function:
Similarly, here is the function for redacting an image:
And here is the request provided to the redactImage
function:
Run the following commands to upload the responses on Cloud Storage for activity tracking validation:
Click Check my progress to verify the objective.
The Cloud Data Loss Prevention (DLP) API is a powerful tool that provides access to a powerful sensitive data inspection, classification, and de-identification platform. You used the DLP API to inspect strings and files for multiple info types, and then redact data from a string and an image.
Be sure to check out the following documentation for more practice with the DLP API:
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated January 23, 2025
Lab Last Tested January 23, 2025
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one