Example: Masking EMR data
If project users have query permissions on sensitive data in an E-MapReduce (EMR) project but you do not want them to view the complete sensitive data, you can apply dynamic data masking to query results. This topic describes how to enable the dynamic data masking feature for EMR and provides a reference example.
Limits
-
EMR clusters support only the sensitive data identification and data masking features of Data Security Guard. Other Data Security Guard features are not supported.
-
Sensitive data identification and data masking are supported only for specific EMR cluster types and table types. For more information, see Hive table types that support data preview in Data Map.
-
Metadata on the Data Security Guard side is updated on a T+1 basis. To use EMR data masking, create the data to be masked at least one day in advance.
-
Only exclusive resource groups for scheduling are supported. For more information, see Billing of exclusive resource groups for scheduling.
Preparations
Prerequisites
By default, Data Security Guard uses the cluster account mapped to the Alibaba Cloud account to sample data. If your cluster has LDAP or Kerberos authentication enabled and uses Ranger or DLF-Auth for table permission management, configure account mapping for the Alibaba Cloud account and make sure the mapped cluster account has permission to access the tables in the EMR cluster. For more information, see Data Studio (legacy): Register an EMR cluster.
Data preparation
Create an EMR table
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
-
On the Data Development page, click Create and choose to create a Hive node.
-
Edit the node code to create the
onefall_test_dsgtable.CREATE TABLE IF NOT EXISTS onefall_test_dsg ( username STRING ,gender STRING ,phone STRING ,email STRING ,card_no STRING ,address STRING ,zip_code STRING ) ROW FORMAT DELIMITED FIELDS TERMINATED BY',' ; -
Import test data into the
onefall_test_dsgtable.-
Download the test data file data.csv.
-
Import the test data.
-
Upload data.csv to a node in the EMR cluster and load the test data by using SQL.
LOAD DATA LOCAL INPATH '/…/data.csv' OVERWRITE INTO TABLE onefall_test_dsg; -
Upload data.csv to Object Storage Service (OSS) and load the test data by using SQL.
LOAD DATA INPATH 'oss://bucket-name.Endpoint/…/data.csv' OVERWRITE INTO TABLE onefall_test_dsg ;
-
-
Data Security Guard metadata update
Metadata on the Data Security Guard side is updated on a T+1 basis. After you create and publish the onefall_test_dsg table, wait until the next day before you configure data masking.
Configure data masking
Step 1: Create data identification rules
DataWorks uses identification rules to identify fields in EMR tables. Before you configure masking rules, you must configure the corresponding identification rules. For more information, see Configure data detection rules and tasks.
Go to the data identification rules page
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. On the page that appears, click Go to Security Center.
-
In the left-side navigation pane, click and then click Try Now to access Data Security Guard.
Note-
If your Alibaba Cloud account is already authorized, you are directed to the Data Security Guard homepage.
-
If your Alibaba Cloud account is not authorized, you are redirected to the Data Security Guard authorization page. To use Data Security Guard features for the first time, go to , select Data Security Guard in the pop-up dialog, and then complete the authorization.
-
-
In the left-side navigation pane, choose to go to the Data Identification Rules page.
Configure identification rules
This example uses the table created in the data preparation section to create identification rules. The goal is to identify the gender, phone, and email fields in the onefall_test_dsg table and apply masking to these three fields.
-
Select the data category for the sensitive fields.
In the Built-in Classification Template section on the left, select the data category for the sensitive field types. For more information, see Configure data detection rules and tasks.
-
Create sensitive field types and configure identification rules.
In the upper-right corner, click Sensitive Field Type to open the identification rule configuration page. For detailed configuration instructions, see Configure data detection rules and tasks.
NoteFor easier understanding, set the sensitive field type names to the field names of the
onefall_test_dsgtable:gender,phone, andemail. -
After you finish configuring the Data Identification Rules, click Batch Publish in the upper-right corner and select the rules you created to publish them in a batch. After configuration, the sensitive field type list displays gender (level 4), phone (level 2), and email (level 2). The identification rule definition method is Custom, accuracy is 100%, and the status is Published.
Step 2: Create data masking rules
DataWorks masks fields in EMR tables by using data masking rules. Before you configure masking rules, see Create a data masking rule.
Go to the data masking rules page
-
Log on to the DataWorks console and go to the Data Security Guard page. For more information, see Data Security Guard Overview.
-
Click Try Now to go to the Home Page of Data Security Guard.
-
In the left-side navigation pane, choose . On the Data Masking Management page, you can create masking scenario types and configure masking rules.
Create masking scenarios
-
DataWorks provides built-in level-1 masking scenarios such as Data Development/Data Map Display Masking, Data Analysis Display Masking, MaxCompute Engine-level Masking, Hologres Engine-level Masking for dynamic masking, and Data Integration Static Masking. These level-1 scenarios are fixed and cannot be created, edited, or deleted. You can create custom level-2 scenarios under them based on your business needs. For more information, see Create a data masking scenario.
-
This example uses Data Development/Data Map Display Masking and Data Analysis Display Masking.
-
Level-2 scenario name under Data Development/Data Map Display Masking:
Development display. -
Level-2 scenario name under Data Analysis Display Masking:
SQL analysis.
-
Create masking rules
After you create the masking scenarios, click Masking Rule in the upper-right corner to create three masking rules named gender, phone, and email. For more information, see Create a data masking rule.
-
Select the masking scenario.
On the Data Masking Management page, set Masking Scenario to , and click +Masking Rule on the right.
-
Create data masking rules.
-
On the Create Masking Rule page, configure Sensitive Field Type, Masking Rule Name, Masking Scenario, Masking Method, and other settings. For more information, see Entry point for data masking rule configuration.
-
The following table lists the configurations of the three masking rules in this example.
Configuration item
Configuration content
gender
email
phone
Sensitive field type
gender
email
phone
Masking rule name
gender
email
phone
Masking scenario
Development display,SQL analysisDevelopment display,SQL analysisDevelopment display,SQL analysisMasking method
Character replacement
Replacement position
Replace all
Replacement method
Random replacement
HASH encryption
Data watermarking
Off
Encryption algorithm
MDS
Salt value
5
Masking out
Redaction mode
NoteMultiple masking methods are available. This example uses String Replacement, HASH Encryption, and Masking Out as examples. For more information, see Configure masking methods.
-
Step 3: Run the sensitive data identification task
In the production environment, after Data Security Guard obtains EMR metadata each day, it calls DataWorks metadata OpenAPI to retrieve sample data from tables and identifies sensitive fields based on the identification rules. This example is a test case, so you can manually run the identification task to identify sensitive fields.
-
In the left-side navigation pane, choose to go to the Sensitive Data Identification page.
-
In the upper-left corner of the Sensitive Data Identification page, click Run Task to open the Enable Sensitive Data Identification Task panel and configure the following settings:
-
Task type: Manual task.
-
Account Used for Identification: The current account is used to sample and scan data. Different account permissions result in different data sampling scopes. In this example, select the Alibaba Cloud account.
-
Content Identification: You can choose table content identification or metadata identification. In this example, select content identification.
-
Sampling quantity: Specify the sampling quantity. Keep the default value of 100.
-
Scanning Range: Set to Custom Scope and use the workspace/database range to define the scope. In the Workspace/Database Range section, use the cascading selector to select the data source type (such as ODPS, EMR, or HOLO), workspace, and database. In this example, select the target database under the EMR type.
-
The table name in this example is
onefall_test_dsg.
-
-
After you define the scope, click Enable in the lower-right corner of the panel to start the identification task.
NoteTo view the execution details of the identification task, go to the Sensitive Data Identification page and click Task Execution Records.
Verify masking results by querying
View the masking result in EMR table preview
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. On the page that appears, click Go to Data Map.
-
Click the
icon on the left to switch to the search page. Click the dropdown at the top of the page, switch to the E-MapReduce data source, and search for the table name onefall_test_dsg. -
Click the table name in the search results. After the table details panel opens, click Data Preview to preview the table data. After searching for the
onefall_test_dsgtable, you can view the masking results. The masking methods for each field are as follows: username is replaced with random English word concatenation; gender is replaced with a random string; phone is masked with the middle four digits replaced by asterisks (for example, 159****4449); email is hashed (for example, 09154c5cf73f176c1ff964dd351585df); card_no and address fields are completely masked and not visible; zip_code retains the original value.
The fields in the table are masked in Preview based on the configured identification rules and masking rules.
View the masking result in the Data Development page
Querying masked data in the DataWorks development page is controlled by a project-level toggle in Data Development. Perform the following steps to enable it.
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
-
Click the
icon on the left to go to the development workspace settings page. -
On the development workspace settings page, click Security Settings and Others, and turn on the toggle.
Test the query result masking
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
-
Click the
icon on the left to go to the Ad Hoc Query page. Then click
and choose to create an ad hoc query node. -
In the node, query the
onefall_test_dsgtable to view the masking result on the Data Development page.SELECT * FROM onefall_test_dsg;The query result shows that the phone column is partially masked (middle four digits replaced with ****), the email column is encrypted as a hash string, and the card_no and address columns are completely masked and not visible.