[MariaDB] 보안 취약점 점검 #4 비밀번호 정책 적용
이전 글에서 비밀번호 검증 관련 플러그인설치 한것에 정책을 확인하고 적용해 보도록 하겠습니다.
Simple Password Check Plugin
기본 설정된 정책을 확인해 보겠습니다.
플러그인이 설치 되지 않았다면 https://opensrc.tistory.com/256 Simple Password Check 부분을 참고 해서 설치 하셔야 합니다.
MariaDB [(none)]> show global variables like 'simple_password%';
+-----------------------------------------+-------+
| Variable_name | Value |
+-----------------------------------------+-------+
| simple_password_check_digits | 1 |
| simple_password_check_letters_same_case | 1 |
| simple_password_check_minimal_length | 8 |
| simple_password_check_other_characters | 1 |
+-----------------------------------------+-------+
4 rows in set (0.005 sec)
MariaDB [(none)]>
해당 플러그인을 설치한 이후에 기본 정책입니다.
- 숫자 1자리 이상 (simple_password_check_digits=1)
- 대/소문자 1자리 이상 (simple_password_check_letters_same_case=1)
- 비밀번호 최소 길이 8자 이상 (simple_password_check_minimal_length=8)
- 특수문자 1자리 이상 (simple_password_check_other_characters=1)
이전 쳅터 에서 정한 시나리오 대로 조금 더 강화해 도보록 하겠습니다.
- 숫자 2자리 이상
- 대/소문자 2자리 이상
- 비밀번호 최소 길이 10자 이상
- 특수문자 2자리 이상
포함으로 변경 하도록 하겠습니다.
온라인 가동중에 변경이 필요 하면 MariaDB 콘솔에서 아래와같이 설정합니다.
MariaDB [(none)]> set global simple_password_check_digits = 2;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> set global simple_password_check_letters_same_case = 2;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> set global simple_password_check_minimal_length = 10;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> set global simple_password_check_other_characters = 2;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show global variables like 'simple_password%';
+-----------------------------------------+-------+
| Variable_name | Value |
+-----------------------------------------+-------+
| simple_password_check_digits | 2 |
| simple_password_check_letters_same_case | 2 |
| simple_password_check_minimal_length | 10 |
| simple_password_check_other_characters | 2 |
+-----------------------------------------+-------+
4 rows in set (0.005 sec)
MariaDB [(none)]>
※ 이설정은 DB를 재시작 하게 되면 최기화 되므로 MariaDB 설정 파일 DB가동시 적용 될 수 있도록 기입 해줘야 합니다.
제가 설치한 버전은 설정 파일들이 /etc/mysql 존재 합니다.
$ ls -al /etc/mysql
total 32
drwxr-xr-x 4 root root 4096 Feb 25 18:26 .
drwxr-xr-x 110 root root 4096 Feb 25 00:51 ..
drwxr-xr-x 2 root root 4096 Feb 24 01:37 conf.d
-rwxr-xr-x 1 root root 1758 Aug 17 2024 debian-start
-rw------- 1 root root 544 Feb 24 01:38 debian.cnf
-rw-r--r-- 1 root root 1324 Feb 25 18:26 mariadb.cnf
drwxr-xr-x 2 root root 4096 Feb 25 00:51 mariadb.conf.d
lrwxrwxrwx 1 root root 24 Oct 20 2020 my.cnf -> /etc/alternatives/my.cnf
-rw-r--r-- 1 root root 839 Oct 20 2020 my.cnf.fallback
$
여러가지 상황에 따라 특정 상황에만 적용 하고 싶으면 mariadb.conf.d 디렉토리에 있는 파일에 기술하시고
이 케이스는 전체 MariaDB 데몬에 적용을 원하기 때문에 심볼릭 링크로 잡혀 있는 my.cnf 파일에 기술 하도록 하겠습니다.
$ sudo vi /etc/mysql/my.cnf
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock
[mysqld]
simple_password_check = on
simple_password_check_digits = 2
simple_password_check_letters_same_case = 2
simple_password_check_minimal_length = 10
simple_password_check_other_characters = 2
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
~
~
~
$
[mysqld] 포함 추가한 내용이 MariaDB 시작시 적용 되도록 했습니다.
순차적으로 적용 될 것 이기에 아래에 includedir 에 지정된 설정파일에서 해당 변수를 재정의를 한다면 재정의 된 값으로 설정 될 것 입니다.
Password Reuse Check Plugin
플러그인 설치후 초기 비밀번호 재사용 관련 초기값을 살펴 보겠습니다.
MariaDB [(none)]> show global variables like 'password_reuse%';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| password_reuse_check_interval | 0 |
+-------------------------------+-------+
1 row in set (0.006 sec)
MariaDB [(none)]>
0으로 설정되어 있는 것은 비밀번호 재상용을 체크하지 않겠다는 의미 입니다.
password_reuse_check_interval 값은 사용한 비밀번호 기록 기간을 일자로 제한합니다.
이 값이 0이면 한번 사용한 비밀번호는 영구히 사용할 수 없습니다.
이 값을 3으로 설정하면 한번 사용한 비밀번호는 3일동안 사용 할 수 없습니다
온라인 가동중에 변경이 필요하면 아래와 같이 적용합니다.
MariaDB [(none)]> set global password_reuse_check_interval = 3;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show global variables like 'password_reuse%';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| password_reuse_check_interval | 3 |
+-------------------------------+-------+
1 row in set (0.006 sec)
MariaDB [(none)]>
이것 역시 DB가 재 가동되면 Default 값(0)으로 초기화 되므로 my.cnf에 추가해 줘야 합니다.
$ sudo vi /etc/mysql/my.cnf
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock
[mariadb]
simple_password_check = on
simple_password_check_digits = 2
simple_password_check_letters_same_case = 2
simple_password_check_minimal_length = 10
simple_password_check_other_characters = 2
password_reuse_check_interval = 3
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
$
Cracklib Password Check Plugin
별도의 추가 설정 필요 없음
다음 편에는 실제 사용자를 생성하고 권한을 부여해보도록 하겠습니다.
끝.