[MDEV-14180] Automatically disable key rotation checks for file_key_management plugin Created: 2017-10-27 Updated: 2022-09-30 Resolved: 2021-06-15 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Encryption, Storage Engine - InnoDB, Storage Engine - XtraDB |
| Affects Version/s: | 10.1, 10.2, 10.3, 10.4, 10.5, 10.6 |
| Fix Version/s: | 10.2.40, 10.3.31, 10.4.21, 10.5.12, 10.6.3 |
| Type: | Bug | Priority: | Major |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Thirunarayanan Balathandayuthapani |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | encryption, file_key_management, innodb, innodb_encryption_threads | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
There have been several bug reports about how the background encryption threads can use a lot of CPU. Prior analysis suggested those this is primarily caused by the operations that check for key rotation. As part of The default value of innodb_encryption_rotate_key_age is 1, so key rotation checks will be enabled by default. The problem is that many encryption users will be using {file_key_management}} plugin, which doesn't even support key rotations. Many of these users are not aware that they should set innodb_encryption_rotate_key_age to 0, so their background threads will be using more CPU than is necessary. Would it be possible to automatically disable key rotation checks for file_key_management plugin (and maybe other plugins that don't support key rotation)? |
| Comments |
| Comment by Sergei Golubchik [ 2017-10-28 ] | ||||||||||||||||||||
|
As far as I can see, there is no need to do key rotation if innodb-encryption-rotate-key-age=1 and latest key version is 1 (which is always the case with file_key_management plugin). There is a need to encrypt existing tables, but I suppose | ||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2017-11-07 ] | ||||||||||||||||||||
|
This is not as easy as it sounds. To find out does table need to be encrypted or not when innodb-encryption-rotate-key-age=1 requires that we read at least page 0 from table tablespace. That is required to be done for every tablespace i.e. for big db's that could mean we are reading 10k-100k pages. Secondly, InnoDB does not really know what encryption plugin we are using, thus this would require a change to encryption plugin interface e.g. encryption_supports_key_rotation() function that we could call. Do not really know if you can say key_version = 1 ==> file_key_management_plugin is used? | ||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-11-07 ] | ||||||||||||||||||||
|
I mean, normally, if innodb-encryption-rotate-key-age=1, innodb needs to scan the tablespace to see if any of the pages is encrypted with the old key. But "old" means "more than innodb-encryption-rotate-key-age behind the current key version". So if the current key version is 1, there is no need to scan the tablespace. This optimization does not require changing defaults and does not require extending the encryption API. InnoDB does not need to know what encryption plugin is used either. | ||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-11-07 ] | ||||||||||||||||||||
|
Generally if current key version is less or equal than innodb-encryption-rotate-key-age, there is no need to scan. But innodb-encryption-rotate-key-age=key_version=1 is the most important practical use case. | ||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2019-04-25 ] | ||||||||||||||||||||
|
This is not a fully ready version and intentionally contains only xtradb implementation. I commit this for feedback as it uses quite radical idea but in my understanding there is not very good alternatives. Using fil_system list has a problem that already processed tablespaces can't be removed causing periodic check also for tablespaces not needing any operation anymore. https://github.com/MariaDB/server/commit/1a29767cd9a78ac396c4f1b4ae2f570cc3289c1f | ||||||||||||||||||||
| Comment by Marko Mäkelä [ 2019-04-25 ] | ||||||||||||||||||||
|
I sent a few comments. Here are some more generic comments: The title of the commit message is truncated, and there are some grammatical errors, such as writing "unnecessary" instead of "unnecessarily". Apparently, the call to encryption_can_rotate() will determine if key rotation is supported. I would suggest to use a global variable for this instead, to be set when the encryption plugin is initialized. That should not require any changes to the encryption plugin function interface. I am confused by the commit message. Where exactly does the following take place:
We do not want to read the first page of each data file at startup, to determine encryption status. Users would for sure be hurt by that. See I feel that there is some overlap between your changes and | ||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2019-04-25 ] | ||||||||||||||||||||
|
Idea is not to read the first page of each data file at startup, nothing is changed on that area. Whenever a new database is used e.g. in use db1; InnoDB will open all tables on that database and on fil_node_open_file we do read page 0 and there I added also insert that tablespace to key rotation list. Can you explain how how we can avoid change the function interface of encryption plugins ? Actually we could avoid it with innodb_encryption_rotate_key_age=0 but that does not solve the default configuration case. | ||||||||||||||||||||
| Comment by Marko Mäkelä [ 2019-04-26 ] | ||||||||||||||||||||
|
Sorry, my comment was truncated. I edited it to clarify how exactly we can avoid changing the function interface. I do not think that executing use db1 will invoke anything in InnoDB. The mysql client can execute additional statements behind the scenes unless it is invoked as mysql --no-auto-rehash. | ||||||||||||||||||||
| Comment by Jan Lindström (Inactive) [ 2019-04-27 ] | ||||||||||||||||||||
|
Branch: bb-10.1- TODO:
| ||||||||||||||||||||
| Comment by Matthias Leich [ 2021-03-09 ] | ||||||||||||||||||||
|
origin/bb-10.6- | ||||||||||||||||||||
| Comment by Thirunarayanan Balathandayuthapani [ 2021-03-09 ] | ||||||||||||||||||||
|
Patch is in bb-10.6- | ||||||||||||||||||||
| Comment by Sergei Golubchik [ 2021-04-28 ] | ||||||||||||||||||||
|
thiru, what about this change to your patch:
and removing all changes outside of storage/innobase ? | ||||||||||||||||||||
| Comment by Thirunarayanan Balathandayuthapani [ 2021-05-17 ] | ||||||||||||||||||||
|
Patch is in bb-10.6- | ||||||||||||||||||||
| Comment by Marko Mäkelä [ 2021-05-21 ] | ||||||||||||||||||||
|
Thank you. I posted some review comments. I would like to know how you tested this with both types of encryption plugins (with regard to supporting multiple key versions). |