简体   繁体   English

迁移后是否不需要还原SQL服务主密钥即可解密数据?

[英]Restore of SQL service master key not required to decrypt data after migration?

This is a bit of the opposite of how this question is usually asked-- I used the following to create a database master key, a certificate, and a symmetric key: 这与通常问这个问题的方式有点相反-我使用以下内容创建数据库主密钥,证书和对称密钥:

Here's how I created the certs/keys (obviously with real passwords): 这是我创建证书/密钥的方法(显然是使用真实密码):

CREATE MASTER KEY ENCRYPTION
BY PASSWORD = '123456'

CREATE CERTIFICATE EncryptionCert
WITH SUBJECT = 'EncryptionCert'

CREATE SYMMETRIC KEY SymmetricKey
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE EncryptionCert;

I then encrypted some data using that key, backed up the database, and restored it to a different box. 然后,我使用该密钥加密了一些数据,备份了数据库,并将其还原到另一个盒子中。

My expectation was that I wouldn't be able decrypt the data until I first migrated the service master key from the old box, but I actually was able to do that immediately after restoring without providing a single cert or password. 我的期望是,直到我第一次从旧盒子中迁移服务主密钥之前,我才能解密数据,但是实际上,还原后我能够立即做到这一点,而无需提供单个证书或密码。

I deduced that this was happening because I was using an Amazon EC2 image to create the box, so I'm assuming that EVERY box created from that image had the same service master key. 我推论这是因为我使用Amazon EC2映像来创建盒子,所以我假设从该映像创建的每个盒子都具有相同的服务主密钥。

To try to force the service key to change, I ran: 为了尝试强制更改服务密钥,我运行了:

alter service master key regenerate

on both boxes. 在两个盒子上。

I started over with a new database, new keys/certs etc, and this time, when I moved the backup to the new box, I wasn't able to automatically read the data, but I had to first provide the password for the database master key that I created. 我从一个新的数据库,新的密钥/证书等开始,这一次,当我将备份移到新的盒子时,我无法自动读取数据,但是我必须首先提供数据库的密码我创建的主密钥。 Once I did that, I was able to get to the data. 一旦完成该操作,便可以获取数据。

From everything I read, I would have thought that I wouldn't be able to decrypt the master key without moving the service master key first. 从我阅读的所有内容中,我会认为,如果不先移动服务主密钥,就无法解密主密钥。

I'm concerned that the service master key not being required is still due to an oddity of my test environment, and that I might get screwed in a year when I try to do this for real. 我担心不需要使用服务主密钥仍然是由于我的测试环境很奇怪,并且当我尝试真正实现这一目标时,我可能会陷入困境。

Can anyone shed light on what's happening here? 任何人都可以了解这里发生的事情吗? Did something change in SQL that made it unnecessary to move the service master key, or did I create the database master key in a way that made moving it unnecessary? SQL中是否发生了某些更改,从而不必移动服务主密钥,或者是否以不需要移动服务主密钥的方式创建了数据库主密钥? Or am I getting back potentially false results? 还是我会得到可能错误的结果?

Matt Bowler has en excellent article on database encryption. 马特·鲍勒(Matt Bowler)在关于数据库加密的精彩文章中发表了精彩的文章 The issue may be the way the Server Master Key is encrypted. 问题可能是服务器主密钥被加密的方式。 Is it possible that your instances are run by the same service account? 您的实例是否可能由同一服务帐户运行?

Service Master Key: At the top of the key hierarchy is the Service Master Key. 服务主密钥:服务主密钥位于密钥层次结构的顶部。 There is one per SQL Server instance, it is a symmetric key, and it is stored in the master database. 每个SQL Server实例有一个,它是一个对称密钥,并且存储在master数据库中。 Used to encrypt Database Master Keys, Linked Server passwords and Credentials it is generated at first SQL Server startup. 用于加密数据库主密钥,链接服务器的密码和凭据,它是在第一次SQL Server启动时生成的。

There are no user configurable passwords associated with this key – it is encrypted by the SQL Server service account and the local machine key. 没有与此密钥相关的用户可配置密码- 它由SQL Server服务帐户和本地计算机密钥加密。 On startup SQL Server can open the Service Master Key with either of these decryptions. 在启动时,SQL Server可以使用这些解密之一打开服务主密钥。 If one of them fails – SQL Server will use the other one and 'fix' the failed decryption (if both fail – SQL Server will error). 如果其中一个失败– SQL Server将使用另一个失败并“修复”失败的解密 (如果两个都失败– SQL Server将出错)。 This is to account for situations like clusters where the local machine key will be different after a failover. 这是为了解决诸如群集之类的情况,其中故障转移后本地计算机密钥将有所不同。 This is also one reason why service accounts should be changed using SQL Server Configuration Manager – because then the Service Master Key encryption is regenerated correctly. 这也是为什么要使用SQL Server Configuration Manager更改服务帐户的原因之一,因为这样可以正确地重新生成服务主密钥加密。

http://mattsql.wordpress.com/2012/11/13/migrating-sql-server-databases-that-use-database-master-keys/ http://mattsql.wordpress.com/2012/11/13/migrating-sql-server-databases-that-use-database-master-keys/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM