An Introduction to Dictionary Operations in Data Masking Component

 

이 블로그 포스트에서는 Percona Server for MySQL 에서 사용 가능한 Data Masking Component 의 dictionary 작업에 대한 일반적인 사용 시나리오를 설명하겠습니다. 이 Component 는 Oracle 의 enterprise 버전에 대한 open source 대안으로 제공됩니다.

특히 우리는 다음 기능들을 살펴볼 것입니다.

  • gen_dictionary() – dictionary 에서 무작위 용어를 반환하는 함수
  • gen_blocklist() – 한 dictionary 의 용어를 다른 dictionary 에서 무작위로 선택된 용어로 대체하는 함수

 

data

 

Generating random terms – gen_dictionary()

 

예를 들어, 미리 정의된 값 집합(dictionary)에서 무작위 단어를 가져와야 하는 경우, 먼저 해당 dictionary 를 생성해야 합니다. 간단한 예로, “colors”라는 dictionary 을 만들고 무지개의 7가지 색상을 채워 넣어 보겠습니다.

아래의 모든 예제는 Data Masking Component 를 설치했을 뿐만 아니라, mysql.masking_dictionaries 테이블을 생성하고, 현재 MySQL 사용자에게 “MASKING_DICTIONARIES_ADMIN” 권한을 부여했으며, 또한 지침에 따라 mysql.session@localhost 사용자에게 필요한 권한도 부여했다는 것을 전제로 합니다.

 

SELECT masking_dictionary_term_add('colors', 'red');

SELECT masking_dictionary_term_add('colors', 'orange');

SELECT masking_dictionary_term_add('colors', 'yellow');

SELECT masking_dictionary_term_add('colors', 'green');

SELECT masking_dictionary_term_add('colors', 'blue');

SELECT masking_dictionary_term_add('colors', 'indigo');

SELECT masking_dictionary_term_add('colors', 'violet');

 

이제 무작위 색상을 하나 얻고자 한다면, 다음 쿼리를 실행할 수 있습니다:

SELECT gen_dictionary('colors') AS random_color;

 

가능한 결과 중 하나는 다음과 같을 수 있습니다:

 

+--------------+
| random_color |
+--------------+
| orange       |
+--------------+
1 row in set (0.01 sec)

 

또는, 더 복잡한 시나리오에서 무작위 색상 10개가 필요할 경우, 다음 쿼리를 실행할 수 있습니다:

 

SELECT gen_dictionary('colors') AS random_color FROM PERCONA_SEQUENCE_TABLE(10) AS tt;

 

 

+--------------+
| random_color |
+--------------+
| violet       |
| violet       |
| green        |
| yellow       |
| blue         |
| violet       |
| red          |
| red          |
| violet       |
| yellow       |
+--------------+
10 rows in set (0.01 sec)

 

 

Generating random terms – gen_dictionary()

 

다음 예제들에서는 “tbl” 이라는 테이블을 생성하고, id 와 무작위 색상으로 채워 넣겠습니다.

 

CREATE TABLE tbl AS SELECT tt.value + 1 AS id, gen_dictionary('colors') AS random_color

  FROM PERCONA_SEQUENCE_TABLE(10) AS tt;

 

 

SELECT * FROM tbl;

 

+----+--------------+
| id | random_color |
+----+--------------+
|  1 | indigo       |
|  2 | yellow       |
|  3 | red          |
|  4 | violet       |
|  5 | orange       |
|  6 | green        |
|  7 | red          |
|  8 | violet       |
|  9 | red          |
| 10 | violet       |
+----+--------------+
10 rows in set (0.00 sec)

그런 다음 짝수 “id” 를 가진 row 의 “random_color” 값을 역순으로 표기하여 원본 색상과 다른 값이 혼합되도록 수정 하겠습니다.

 

UPDATE tbl SET random_color = REVERSE(random_color) WHERE id % 2 = 0;

 

 

SELECT * FROM tbl;

 

+----+--------------+
| id | random_color |
+----+--------------+
|  1 | indigo       |
|  2 | wolley       |
|  3 | red          |
|  4 | teloiv       |
|  5 | orange       |
|  6 | neerg        |
|  7 | red          |
|  8 | teloiv       |
|  9 | red          |
| 10 | teloiv       |
+----+--------------+
10 rows in set (0.00 sec)

이제 색상 이름이 매우 민감한 정보로 간주되어, “tbl” 테이블에서 데이터를 조회할 때 절대 외부에 노출되어서는 안 되는 상황을 가정해 봅시다.

이를 위해 “masked_colors”라는 또 다른 사전을 생성하겠습니다.

 

SELECT masking_dictionary_term_add('masked_colors', 'colorA');

SELECT masking_dictionary_term_add('masked_colors', 'colorB');

SELECT masking_dictionary_term_add('masked_colors', 'colorC');

 

여기서 주의할 점은, “masked_colors” 의 고유 항목 수(3개)가 원본 “colors” 의 항목 수(7개)와 다르다는 점에 유의하세요. 이 예제에서는 의도적으로 이런 방식으로 구성했습니다.

이제 원본 색상을 masking 하는 본래의 작업으로 돌아와서, “gen_blocklist()” 함수를 사용하기만 하면 됩니다.

 

SELECT id, gen_blocklist(random_color, 'colors', 'masked_colors') AS masked_colors FROM tbl;

 

+----+---------------+
| id | masked_colors |
+----+---------------+
|  1 | colorA        |
|  2 | wolley        |
|  3 | colorC        |
|  4 | teloiv        |
|  5 | colorC        |
|  6 | neerg         |
|  7 | colorC        |
|  8 | teloiv        |
|  9 | colorB        |
| 10 | teloiv        |
+----+---------------+
10 rows in set (0.00 sec) 

여기서 발생한 일은, “colors” dictionary 에 있는 각 용어가 “masked_colors” dictionary 의 무작위 용어로 masking(대체)되었다는 것입니다. 동시에, 알 수 없는 값들(이전에 우리가 역순으로 바꾼 것들)은 변경되지 않았습니다. 또한, 두 dictionary 간에 직접적이고 명확한 1:1 매핑이 존재하지 않는다는 점에 주목해야 합니다. 무작위 요소가 이 과정에서 중요한 역할을 하며, 쿼리의 출력 결과는 매번 실행할 때마다 달라질 수 있습니다. 이번 실행에서는, id 가 7 과 9 인 row 에 동일한 색상 “red” 가 각각 “colorC” 와 “colorB” 로 masking 되었습니다. 반면에, 서로 다른 색상 “red”(id 3)와 “orange”(id 5)는 동일한 masking 값인 “colorC” 로 변환되었습니다.

 

 

Conclusion

 

비록 이 예제들이 본질적으로 다소 인위적이며, 실제 상황은 훨씬 더 복잡할 수 있지만, 이번 블로그 게시물에서 보여준 내용은 실제 운영 환경을 위한 맞춤형 Data Masking 솔루션 개발의 출발점이 될 수 있습니다. 또한, 이러한 dictionary-based operations(사전 기반 연산) 은 Percona Server for MySQL 8.0.41 / 8.4.4 에서 눈에 띄게 빨라졌기 때문에, 훨씬 더 대규모의 데이터세트에도 적용할 수 있습니다. 더 자세한 내용은 “Dictionary term cache in Data Masking Component” 블로그 게시물을 참고하세요.

 

 

블로그 원문 : https://www.percona.com/blog/introduction-to-dictionary-operations-in-data-masking-component/    

 

 

자유롭게 댓글을 달아주세요! 언제나 환영합니다.
기타 문의:  info@neoclova.co.kr
네오클로바 기술블로그 홈 바로가기: https://neoclova.net
네오클로바 홈페이지: http://neoclova.co.kr

Similar Posts

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다