我通过AWS Key Management Service (KMS) Plugin设置了MariaDB for encryption at rest .
除了关键骑行之外,一切似乎都有效 .
我根据附加的配置文件配置了以下选项:
/etc/my.cnf
[mysqld]
# InnoDB/XtraDB Encryption
innodb_encrypt_tables = On
innodb_encrypt_log = On
innodb_encryption_threads = 8
innodb_encryption_rotate_key_age = 1
innodb_encryption_rotation_iops = 100
/etc/my.cnf.d/aws_key_management.cnf
[mariadb]
# Load the AWs plugin and enable it for use
plugin-load-add=aws_key_management.so
# Link to the AWS KMS 'Customer Master Key' used to decrypt MariaDB
encryption keys on disk
# during MariaDB start up and save the decrypted keys into memory
aws_key_management_master_key_id = alias/MariaDB-Encryption-Key
# Specify the AWS region our KMS key is stored in
aws_key_management_region = eu-west-2
# Specify the key specification
aws_key_management_key_spec = AES_256
# Rotate all keys
aws_key_management_rotate_key = -1
# Change the plugins log level
# Options: "Off" (default), "Fatal", "Error", "Warn", "Info",
"Debug", and "Trace".
aws_key_management_log_level = Warn
!include /etc/my.cnf.d/enable_encryption.preset
如您所见,我已使用 aws_key_management_rotate_key = -1
将所有键设置为旋转,并使用 innodb_encryption_rotate_key_age = 1
将键时间设置为1,但我可以从 /var/lib/mysql/
中的键中看到,尽管这些设置已经到位,但仍然使用了键1的版本1多天:
/var/lib/mysql/aws-kms-key.1.1
/var/lib/mysql/aws-kms-key.2.1
( Note :文件名的最后.n后缀代表密钥版本)
我唯一能想到的是,我对 innodb_encryption_rotate_key_age
的理解是在几天内测量不正确的?此选项的文档可以在下面看到,并且根本不参考该数值使用的测量单位?
innodb_encryption_rotate_key_age说明:在后台重新加密任何密钥早于> this的页面 . 设置加密时,必须将此变量设置为非零>值 . 否则,当您通过innodb_encrypt_tables启用加密时> MariaDB将无法自动加密任何未加密的表 .
任何人都可以解释为什么会这样,为什么我的钥匙不旋转?
MariaDB Version
mysql --version
mysql Ver 15.1 Distrib 10.2.15-MariaDB, for Linux (x86_64) using readline 5.1`
AWS KMS Plugin Version
yum list installed | grep mariadb
MariaDB-aws-key-management.x86_64 10.2.15-1.el7.centos @mariadb-main
1 回答
基本旋转
作为解决方法,您可以通过全局变量触发旋转 . 正如您所描述的,MariaDB和/或插件似乎不会根据配置值采取任何操作 . 这样做的好处是,您不必重新启动数据库 .
不要忘记从配置中删除
aws_key_management_rotate_key
,因为您不需要它 .通过从控制台设置全局值来触发旋转 . 请注意,旋转后无需手动重置0 . 该插件将报告生成一组新的数据键(版本) .
参考:https://mariadb.com/kb/en/library/aws-key-management-encryption-plugin/#rotating-keys
陷阱#1:允许版本老化
不幸的是,这还没结束 . 现在,默认情况下,版本2将用于加密新页面,但是使用先前版本加密的页面将不会在后台重新加密,正如人们所期望的那样 . 这是因为设置
innodb_encryption_rotate_key_age=0
禁用后台加密,而不是强制0
键版本年龄 . 因此,我们可以设置的最小年龄差距是1
,它允许使用先前版本(在我的情况下为版本1)进行db加密 .2
. 这也意味着,您需要保留密钥的版本2和版本3 .参考:https://mariadb.com/kb/en/library/information-schema-innodb_tablespaces_encryption-table/
陷阱#2:重做日志
重做日志仍然使用以前的密钥版本加密,如果旧密钥丢失,MariaDB将无法启动 .
参考:https://mariadb.com/kb/en/library/encrypting-data-for-innodb-xtradb/#key-rotation