Skip to content

[Proposal] Support data masking #6260

Description

@qidaye

Background

Data has different needs for different levels and business scenarios, and some scenarios require data desensitization to achieve information security. In order to prevent data information leakage and avoid attacks such as eavesdropping and interception, the data going out from the database is required to be desensitized, so the desensitization function needs to be implemented inside the system.

Requirements

For cell phone number, bank card number, ID card number, name, etc. need to be desensitized, to achieve a variety of desensitization functions, desensitization example

13800000000138****0000

Design

Implement a new function type, AliasFunction, of Function.

Capable of adapting to multiple scenarios and meeting the needs of multiple users, requiring only one development definition by the user's administrator based on the scenario.

Syntax

  1. create alias function
create alias function id_masking(bigint) with parameter(id) as concat(left(id,3),'****',right(id,4));
  1. view function
mysql> show functions;
+---------------+
| Function Name |
+---------------+
| id_masking |
+---------------+1 row inset (0.00 sec)
mysql> show full functions\G
***************************1. row ***************************
Signature: id_masking(BIGINT)
Return Type: VARCHAR
Function Type: Alias
Intermediate Type: NULL
Properties: {"parameter":"id","origin_function":"concat(left(`id`, 3), `****`, right(`id`, 4))"}
1 row inset (0.00 sec)
  1. View the create statement
mysql> show create function id_masking(int)\G
***************************1. row ***************************
Function Signature: id_masking(BIGINT)
Create Function: CREATE ALIAS FUNCTION id_masking(BIGINT) WITH PARAMETER(id) AS concat(left(`id`, 3), '****', right(`id`, 4));
1 row inset (0.00 sec)
  1. Use function
mysql>select id_masking(13812345678);
+-------------------------+
| id_masking(13812345678) |
+-------------------------+
| 138****5678 |
+-------------------------+1 row inset (0.01 sec)
mysql>select id_masking(k1) from t3;
+------------------+
| id_masking(`k1`) |
+------------------+
| 100****7000 |
| 123****5678 |
+------------------+2 rows inset (0.01 sec)
  1. Builtin alias function

Add a builtin alias function digital_masking(bigint) = concat(left(id,3),'****',right(id,4)).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions