Data Masking With Percona Server for MySQLData masking is a handy tool to obscure sensitive information.  Percona Server for MySQL is a free, fully compatible, enhanced, and open source drop-in replacement for any MySQL database. It provides superior performance, scalability, and instrumentation including data masking. With Percona Server for MySQL, you get the enterprise features without the cost.  

So how does data masking work? The server obscures the output so that the sensitive data is not displayed.  As you will see in later examples, there are many options to help you with your data masking needs.

Installation

Installation is easy as all you need to do is to load a shared object library from a MySQL client program with INSTALL PLUGIN data_masking SONAME ‘data_masking.so’;

Basic usage

We will start by looking at the MASK_INNER() and MASK_OUTER() functions. First, we will need some data to work with. The following creates a two-column table and populates it with some data.

Note that for the second row the leading zero will be stripped off so that ‘987654321’ is stored not ‘0987654321’. This is why you see CHAR() data types occasionally where you would expect an INT().

The MASK_INNER() will mask, with either the character of your choice or use the default of an octothorpe (#), the inner characters of a column. And MASK_OUTER() masks the data on either end of the column.

The CONVERT() function is used to ensure that multi-byte character sets do not overwhelm the receiving functions.

SSN numbers

Social Security Numbers (SSN) are not supposed to be used as a general identifier despite them being used that way. There is a special data mask just for SSNs. Again we need some sample data and please note that the mask will complain if it is not working with eleven characters.

The MASK_SSN() is like the previous data masks save that it only returns the last four numbers.

Credit card numbers

Credit card numbers get their own masking function. The credit card number itself, known as the Primary Account Number or PAN, is routinely masked to return only the last four digits. To see how this works, we alter our employee table for a new column to house the 16-digit credit card, er, PAN, number.

And now we can try MASK_CC().

Using a view with a mask

You may be asking how you can mask the sensitive data when they have access to the underlying table. The traditional way to protect the raw data is with a VIEW. The VIEW can have different privileges than the person using it. Best of all is that the VIEW can be treated like a table by the user even if they have restricted access to the data. And you can combine a VIEW with a mask to protect the data. The trick is that you have to set up, use, and maintain the use of the VIEW.

To create a user with no privs, but can see masked data, we need to start with a ‘bare bones’ account. The account ‘nopriv’ was set up with no grants and if we try to access anything in the schema with our sensitive data with this account it will be unsuccessful.

Now as ‘root’ or some similarly privileged account we can create a VIEW in the schema we are using.

Now we can give the unprivileged access to the VIEW we created. Remember to do this from a privileged account!

Now we have to log out of our unprivileged account and log in again to get the new privilege in effect. You can now, as the unprivileged user, get masked data from the sensitive employee table. This account cannot see the actual data in the table but it can get what is allowed via the view. This can be very handy.

Wrap up

Data masking is a powerful technique to keep sensitive data protected. And Percona provides this feature with the free, open source Percona Server for MySQL software. You will need to purchase a subscription from their vendors if you wish to use data masking with Oracle’s Enterprise Edition or MariaDB’s MaxScale.

Percona Distribution for MySQL is the most complete, stable, scalable, and secure, open-source MySQL solution available, delivering enterprise-grade database environments for your most critical business applications… and it’s free to use!

Download Percona Distribution for MySQL Today

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
lefred

what aren’t you using the component infrastructure to extend MySQL?