{"id":98088,"date":"2020-10-24T02:42:34","date_gmt":"2020-10-24T00:42:34","guid":{"rendered":"https:\/\/prohoster.info\/blog\/administrirovanie\/shifrovanie-v-mysql-rotacziya-master-key"},"modified":"2020-11-18T00:58:48","modified_gmt":"2020-11-17T22:58:48","slug":"shifrovanie-v-mysql-rotacziya-master-key","status":"publish","type":"post","link":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/shifrovanie-v-mysql-rotacziya-master-key","title":{"rendered":"Encryption in MySQL: rotating the Master Key","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<\/p>\n<p><strong><em>As we approach the start of a new course enrollment&nbsp;<\/em><\/strong><noindex><a rel=\"nofollow\" href=\"https:\/\/otus.pw\/dADq\/\"><strong><em>\"Databases\"<\/em><\/strong><\/a><\/noindex><strong><em>&nbsp;we continue to publish a series of articles on encryption in MySQL.<\/em><\/strong><\/p>\n<p>In the previous article of this series, we discussed, <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/524050\/\"><u>how encryption with the Master Key works.<\/u><\/a><\/noindex>Today, based on the knowledge gained earlier, we will look at the rotation of master keys.<\/p>\n<p>Master key rotation involves generating a new master key, which is then used to re-encrypt the keys of the tablespaces (stored in the headers of the tablespaces).<\/p>\n<p>Let's recall what the header of an encrypted tablespace looks like:<\/p>\n<p><img decoding=\"async\" alt=\"Encryption in MySQL: rotating the Master Key\" src=\"\/wp-content\/uploads\/2020\/10\/24057c50b96236c5ee2647aeca4b575f.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p>From the previous article, we know that the server reads the headers of all encrypted tablespaces at startup and remembers the highest KEY ID. For instance, if we have three tables with KEY<em>ID = 3 and one table with KEY<\/em>ID = 4, so the maximum key identifier will be 4. Let's call this KEY ID \u2014 MAX KEY ID.<\/p>\n<h3>How master key rotation works<\/h3>\n<p>1. The user executes ALTER INNODB MASTER KEY.<\/p>\n<p>2. The server requests the key storage (keyring) to generate a new master key with the server's UUID and KEY<em>ID, which is equal to MAX<\/em>KEY<em>ID increased by one. Thus, we get the master key identifier equal to INNODB<\/em>KEY-UUID- (MAX<em>KEY<\/em>ID + 1). Upon successful generation of the master key, MAX KEY ID is increased by one (i.e., MAX<em>KEY<\/em>ID = MAX<em>KEY<\/em>ID + 1).<\/p>\n<p>3. The server scans all tablespaces encrypted with the master key, and for each tablespace:<\/p>\n<ul>\n<li>\n<p>encrypts the tablespace key with the new master key;<\/p>\n<\/li>\n<li>\n<p>updates the key identifier to the new MAX<em>KEY<\/em>ID;<\/p>\n<\/li>\n<li>\n<p>if the UUID differs from the server\u2019s UUID, it updates the server\u2019s UUID.<\/p>\n<\/li>\n<\/ul>\n<p>As we know, the master key identifier (Master Key ID) used to decrypt the table consists of a UUID and KEY ID read from the header of the tablespace. What we are doing now is updating this information in the tablespace encryption header so that the server receives the correct master key.<\/p>\n<p>If we have tablespaces obtained from different locations, such as different backups, they may use different master keys. All these master keys will need to be retrieved from the storage when starting the server. This can slow down the server startup, especially if a keystore is being used. By rotating the master key, we re-encrypt the keys of the tablespaces with a single master key that is the same for all tablespaces. Now, upon startup, the server only needs to retrieve one master key.<\/p>\n<p>This is, of course, just a nice side effect. The main goal of master key rotation is to make our server more secure. In the event that the master key has been somehow stolen from the storage (for example, from the Vault Server), a new master key can be generated, and the keys of the tablespaces can be re-encrypted, rendering the stolen key invalid. We are safe\u2026 almost.<\/p>\n<p>In the previous article, I mentioned that after the theft of the tablespace key, a third party could use it to decrypt data, provided they have access to our disk. In the case of the theft of the main key and access to the encrypted data, the stolen main key can be used to decrypt the tablespace key and obtain the decrypted data. As we can see, rotating the main key does not help in this case. We re-encrypt the tablespace key with a new main key, but the actual key used for encrypting\/decrypting the data remains the same. Therefore, the 'hacker' can continue to use it for decrypting the data. Previously, I hinted that <noindex><a rel=\"nofollow\" href=\"https:\/\/www.percona.com\/software\/mysql-database\/percona-server\"><u>Percona Server for MySQL<\/u><\/a><\/noindex> it can perform true re-encryption of tablespaces, not just simple re-encryption of the tablespace key. This feature is called encryption threads. However, at this time, this functionality is still experimental.<\/p>\n<p>Master key rotation is useful when the master key is stolen, but the attacker does not have the ability to use it and decrypt the tablespace keys.<\/p>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/otus.pw\/dADq\/\"><strong>Sign up for a free demo lesson.<\/strong><\/a><\/noindex><\/p>\n<h4>Read more:<\/h4>\n<ul>\n<li>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/522092\/\">Encryption in MySQL: key storage<\/a><\/noindex><\/p>\n<\/li>\n<li>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/524050\/\">Encryption in MySQL: Using Master Key<\/a><\/noindex><\/p>\n<\/li>\n<\/ul>\n<p>Source: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/524624\/\">habr.com<\/a> <\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043d\u0430 \u043a\u0443\u0440\u0441&nbsp;\u00ab\u0411\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445\u00bb&nbsp;\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 MySQL. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c (Master Key). \u0421\u0435\u0433\u043e\u0434\u043d\u044f, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u043d\u0435\u0435 \u0437\u043d\u0430\u043d\u0438\u044f\u0445, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u043e\u0442\u0430\u0446\u0438\u044e \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439. \u0420\u043e\u0442\u0430\u0446\u0438\u044f \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0438 \u044d\u0442\u0438\u043c \u043d\u043e\u0432\u044b\u043c [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":98089,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-98088","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043d\u0430 \u043a\u0443\u0440\u0441 \u00ab\u0411\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445\u00bb \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/shifrovanie-v-mysql-rotacziya-master-key\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0428\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 MySQL: \u0440\u043e\u0442\u0430\u0446\u0438\u044f Master Key | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043d\u0430 \u043a\u0443\u0440\u0441 \u00ab\u0411\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445\u00bb \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/shifrovanie-v-mysql-rotacziya-master-key\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-10-24T00:42:34+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-11-17T22:58:48+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Encryption in MySQL: Master Key Rotation | ProHoster","description":"In anticipation of the new enrollment for the \"Databases\" course, we continue.","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/shifrovanie-v-mysql-rotacziya-master-key","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0428\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 MySQL: \u0440\u043e\u0442\u0430\u0446\u0438\u044f Master Key | ProHoster","og:description":"\u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043d\u0430 \u043a\u0443\u0440\u0441 \u00ab\u0411\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445\u00bb \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c.","og:url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/shifrovanie-v-mysql-rotacziya-master-key","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2020-10-24T00:42:34+00:00","article:modified_time":"2020-11-17T22:58:48+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"98088","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":null,"breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 10:05:50","updated":"2022-10-03 07:13:53","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/98088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=98088"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/98088\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media\/98089"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=98088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=98088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=98088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}