MySQL主從中復(fù)制賬號(hào)密碼可以加密嗎?
2024-11-26 11:17 瀟湘隱者 閱讀(169) 評(píng)論(0) 收藏 舉報(bào)搭建MySQL主從復(fù)制后,你會(huì)發(fā)現(xiàn)復(fù)制賬號(hào)的密碼是明文存儲(chǔ)在mysq.mysql.slave_master_info這張系統(tǒng)表的User_password字段當(dāng)中,早期MySQL版本中,賬號(hào)密碼存儲(chǔ)在master.info文件中。如下案例所示:
mysql> select * from mysql.slave_master_info\G
*************************** 1. row ***************************
Number_of_lines: 33
Master_log_name: mysql_binlog.000001
Master_log_pos: 1165
Host: 192.168.9.154
User_name: repl
User_password: ReL@wpL#123456
Port: 3306
Connect_retry: 60
Enabled_ssl: 0
Ssl_ca:
Ssl_capath:
Ssl_cert:
Ssl_cipher:
Ssl_key:
Ssl_verify_server_cert: 0
Heartbeat: 30
Bind:
Ignored_server_ids: 0
Uuid: da5deebc-9b54-11ef-b5d0-0050569739e5
Retry_count: 86400
Ssl_crl:
Ssl_crlpath:
Enabled_auto_position: 0
Channel_name:
Tls_version:
Public_key_path:
Get_public_key: 1
Network_namespace:
Master_compression_algorithm: uncompressed
Master_zstd_compression_level: 3
Tls_ciphersuites: NULL
Source_connection_auto_failover: 0
Gtid_only: 0
1 row in set (0.00 sec)
mysql>
那么在搭建主從復(fù)制的時(shí)候,有沒有方法將這個(gè)賬號(hào)密碼加密呢?檢索了一些資料,在當(dāng)前這個(gè)時(shí)間點(diǎn),所有的MySQL版本都沒有提供方法將其加密。也就是說(shuō),當(dāng)前階段,沒有任何方法加密這個(gè)賬號(hào)密碼。確切的說(shuō)是官方?jīng)]有提供任何方法。完全忽略了這個(gè)安全隱患。
官方文檔[How To Encypt Replication Credentials In mysql.slave_master_info (Doc ID 2623399.1)]中也給出了簡(jiǎn)單答復(fù)。 至于如何規(guī)避密碼明文存儲(chǔ)的一些風(fēng)險(xiǎn)問題,官方給出的建議如下:
Ensure that the master info repository can be accessed only by the database administrator.
[...]
Use a restricted access mode to protect database backups that include log tables or log files containing passwords."
個(gè)人強(qiáng)烈建議在創(chuàng)建復(fù)制賬號(hào)時(shí),一定要嚴(yán)格限制這個(gè)賬號(hào)的IP地址,以及賬號(hào)的權(quán)限。不要授予過(guò)大的權(quán)限。
--在MySQL主/從庫(kù)中:創(chuàng)建數(shù)據(jù)同步的賬號(hào)(從庫(kù)也創(chuàng)建相同賬號(hào),方便切換)
create user repl@'192.168.xxx.xx%' identified by "xxxxxxx";
flush privileges;
grant replication slave on . to 'repl'@'192.168.xxx.xx%';
flush privileges;
浙公網(wǎng)安備 33010602011771號(hào)