gpt4 book ai didi

mysql - MariaDB 通过 AWS KMS 插件进行静态加密 - key 轮换不起作用?

转载 作者:行者123 更新时间:2023-11-30 21:42:53 32 4
gpt4 key购买 nike

我已经设置了MariaDB for encryption at rest通过 AWS Key Management Service (KMS) Plugin .

除了键循环外,一切似乎都正常。

我已经根据附加的配置文件配置了以下选项:

/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 将所有 key 设置为轮换,并使用 innodb_encryption_rotate_key_age = 1 将 key 年龄设置为 1,但我可以看到从 /var/lib/mysql/ 中的 key 来看,尽管这些设置已经存在多天,但 key 的版本 1 仍在使用:

/var/lib/mysql/aws-kms-key.1.1
/var/lib/mysql/aws-kms-key.2.1

(注意:文件名最后的.n后缀代表 key 版本)

我唯一能想到的是,我对以天为单位的 innodb_encryption_rotate_key_age 的理解不正确?这个选项的文档可以在下面看到,并且根本没有提到这个数值使用的是什么测量单位?

innodb_encryption_rotate_key_age

Description: Re-encrypt in background any page having a key older than >this. When setting up Encryption, this variable must be set to a non-zero >value. Otherwise, when you enable encryption through innodb_encrypt_tables >MariaDB won't be able to automatically encrypt any unencrypted tables.

谁能解释为什么会这样以及为什么我的 key 没有轮换?

MariaDB 版本

mysql --version
mysql Ver 15.1 Distrib 10.2.15-MariaDB, for Linux (x86_64) using readline 5.1`

AWS KMS 插件版本

yum list installed | grep mariadb
MariaDB-aws-key-management.x86_64 10.2.15-1.el7.centos @mariadb-main

最佳答案

基本旋转

作为解决方法,您可以通过全局变量触发轮换。正如您所描述的,MariaDB 和/或插件似乎没有根据配置值采取任何行动。这样做的好处是您不必重新启动数据库。

  1. 不要忘记从配置中删除 aws_key_management_rotate_key,因为您不需要它。
  2. 通过从控制台设置全局值来触发轮换。请注意,您不需要在旋转后手动将其重置为 0。该插件将报告生成一组新的(版本)数据 key 。
MariaDB [(none)]> SET @@GLOBAL.aws_key_management_rotate_key=-1;
Query OK, 0 rows affected, 4 warnings (0.875 sec)

MariaDB [(none)]> SELECT @@GLOBAL.aws_key_management_rotate_key;
+----------------------------------------+
| @@GLOBAL.aws_key_management_rotate_key |
+----------------------------------------+
| 0 |
+----------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> SHOW WARNINGS;
+-------+------+---------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------------------------------------+
| Note | 1105 | AWS KMS plugin: generated encrypted datakey for key id=1, version=2 |
| Note | 1105 | AWS KMS plugin: loaded key 1, version 2, key length 256 bit |
| Note | 1105 | AWS KMS plugin: generated encrypted datakey for key id=2, version=2 |
| Note | 1105 | AWS KMS plugin: loaded key 2, version 2, key length 256 bit |
+-------+------+---------------------------------------------------------------------+
4 rows in set (0.000 sec)

引用:https://mariadb.com/kb/en/library/aws-key-management-encryption-plugin/#rotating-keys

陷阱 #1:允许版本老化

不幸的是,这还没有结束。默认情况下,版本 2 将用于加密新页面,但是使用先前版本加密的页面不会像预期的那样在后台重新加密。这是由于设置 innodb_encryption_rotate_key_age=0 禁用 后台加密,而不是强制 0 key-version age。因此,我们可以设置的最小年龄间隔是 1,这允许数据库使用以前的版本(在我的例子中是版本 1)进行加密。

  1. 检查 innodb 表空间加密。 MIN_KEY_VERSION 表示:

    Minimum key version used to encrypt a page in the tablespace. Different pages may be encrypted with different key versions.

MariaDB [test]> SELECT NAME, MIN_KEY_VERSION, CURRENT_KEY_VERSION, ROTATING_OR_FLUSHING FROM information_schema.INNODB_TABLESPACES_ENCRYPTION;
+----------------------------+-----------------+---------------------+----------------------+
| NAME | MIN_KEY_VERSION | CURRENT_KEY_VERSION | ROTATING_OR_FLUSHING |
+----------------------------+-----------------+---------------------+----------------------+
| innodb_system | 1 | 2 | 0 |
| mysql/gtid_slave_pos | 1 | 2 | 0 |
| mysql/innodb_index_stats | 1 | 2 | 0 |
| mysql/innodb_table_stats | 1 | 2 | 0 |
| mysql/transaction_registry | 1 | 2 | 0 |
| test/tbl | 1 | 2 | 0 |
+----------------------------+-----------------+---------------------+----------------------+
6 rows in set (0.000 sec)
  1. 再次从步骤 2 开始重复循环,使 MIN_KEY_VERSION 至少 2。这也意味着,您需要保留 key 的版本 2 和版本 3。

引用:https://mariadb.com/kb/en/library/information-schema-innodb_tablespaces_encryption-table/

陷阱 #2:重做日志

重做日志仍然使用之前的 key 版本加密,如果旧 key 丢失,MariaDB 将无法启动。

 0 [ERROR] mysqld: can't open file aws-kms-key.1.1
0 [Warning] mysqld: AWS KMS plugin: key 1, version 1 could not be decrypted
0 [ERROR] InnoDB: Obtaining redo log encryption key version 1 failed (2385237688). Maybe the key or the required encryption key management plugin was not found.
...
0 [ERROR] InnoDB: No valid checkpoint found (corrupted redo log). You can try --innodb-force-recovery=6 as a last resort.
...
0 [ERROR] Unknown/unsupported storage engine: InnoDB
0 [ERROR] Aborting

Key rotation for the InnoDB redo log is only supported in MariaDB 10.4.0 and later. See MDEV-12041 about that.

引用:https://mariadb.com/kb/en/library/encrypting-data-for-innodb-xtradb/#key-rotation

关于mysql - MariaDB 通过 AWS KMS 插件进行静态加密 - key 轮换不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50793715/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com