Mask data
You can use a Cyral policy to mask the results of queries to protect information and comply with privacy regulations. To set this up, you'll add one or more masking commands in the data block of your Cyral policy.
note
Masking is supported on Redshift and Denodo repositories. An early-access version of masking is available for Snowflake repositories. Contact Cyral support to set up masking in Snowflake.
About masking
Each mask describes a transformation to be applied to a specific
field's data when a user queries that field. For instance, a policy
can specify that when user bob tries to read a credit card number (for
example, from a column you've labeled as "CCN" in your Cyral data map
and policy), his query will instead return the constant ***
. The
example policy below illustrates this:
data:
- CCN
- TAXID
rules:
- identities:
users: [bob]
reads:
- data:
- constant_mask(CCN, "***")
- null_mask(TAXID)
rows: any
In the example above, the mask rule, constant_mask(CCN, "***")
means
that the columns that correspond to the CCN
label will have their data
replaced with a constant value (in this case, ***
) in query results.
As the name implies, constant_mask forces the replacement of the
field’s value with a constant value you've specified.
To show the effect of the above policy, let's look first at the results without the policy applied:
bob=# select ccn from credit_card_data; # masking policy disabled
ccn
---------------------
4444-3333-2222-1111
4484-6000-0000-0004
4035-5010-0000-0008
Now, let's see the results with the policy in effect:
bob=# select ccn from credit_card_data; # masking policy enabled
ccn
-----
***
***
***
Enable masking on your repository
Before your policies can enforce masking rules, you must enable the Cyral masking capability on each repository that you want to protect. Follow the steps in both sections below to do this.
Turn on masking for the repository in Cyral
- In the Cyral control plane UI, click Data Repos, click the name of your repository, and click Config and Policy Enforcement.
- Turn
ON
Enable policy enforcements and turnON
Enable data masking.
warning
Your setup is not complete. You must install the helper function in your database as described below!
Install the Cyral mask helper in your database
Prerequisite: Make sure you have turned on masking for the repository in Cyral.
- Install the Cyral
mask
helper function in your database. To do this:- Make sure you have an SQL user account on the repository with
at least the following permissions:
- the
CREATE SCHEMA
privilege - the privilege to install a user-defined function (UDF) or equivalent (often the
USAGE
privilege grants this) - on Snowflake only: The
CREATE DATABASE
privilege
- the
- Using the account described above, connect to your repository through the Cyral sidecar. For this,
you must use psql or any client that uses the JDBC driver
with
enableQueryMode=simple
. - Run
cyral install mask;
- Make sure you have an SQL user account on the repository with
at least the following permissions:
- Proceed to Add a masking rule in your policy, below.
note
Installing the Cyral mask function creates a schema called cyral
in
your repository. The Cyral mask function belongs to this schema.
Manage the Cyral mask function
To check the status of the Cyral mask function on any repository, type
cyral describe mask
at the SQL prompt.
Remove the Cyral mask function
To remove the Cyral mask function, run the command cyral uninstall
mask
at the SQL prompt.
Add a masking rule in your policy
In your Cyral policy, add your masking rules in the data
section of a
contexted rule
In the data
block, instead of simply declaring the data label to be
protected, you will specify a mask type (mask
, constant_mask
,
null_mask
) followed in parentheses by the name of the
data label to be masked. If the mask requires
an argument, add a comma after the label name, and then the argument.
<mask_type>(<label>, <mask_argument>)
To mask more than one label for a user or group, include additional mask declarations in the data block. For example:
data:
- EMAIL
- CCN
rules:
- identities:
users: [bob]
reads:
- data:
- mask(EMAIL)
- constant_mask(CCN, "***")
tip
You can use masking along with other Cyral policy actions to protect your data. See policy enforcement actions to understand how these different actions interact when a user tries to access data.
Mask types
Cyral supports the following types of masks:
mask: Cyral replaces the field's contents with a semi-randomized string that preserves all hyphens, dots, and other punctuation in the string. Numbers are replaced with randomly chosen numbers, and letters with randomly chosen letters. Letter case is preserved, meaning lowercase letters are replaced with random lowercase letters, and uppercase with random uppercase letters. This transformation happens for each element individually.For example, two email addresses, even if identical, would be transformed to two different strings.
- Example: A mask declared as
mask(EMAIL)
might replace an address ofMyEmail123@cyral.com
withZaFxbcd517@dzbxq.pqd
.
- Example: A mask declared as
constant_mask: Cyral replaces the field's contents with the value that you provide. Specify the replacement value as the second argument, in double quotes.
- Example: A mask declared as
constant_mask(CCF, "***")
would replace aCCF
value of4111111212121212
with a return value of***
.
- Example: A mask declared as
null_mask: Cyral replaces the field's contents with a null value.
- Example: A mask declared as
null_mask(CCN)
would replace aCCN
value of4111111212121212
with a NULL return value.
- Example: A mask declared as