From what I’ve seen, Transparent Data Encryption (TDE) for SQL Server isn’t as heavily used a feature as many of the HA/DR options, but if your company has a requirement for encryption at rest, it’s a great feature to be able to access out of the box. On the MySQL side, I had done extensive testing with Gazzang, this was managed at the OS level, versus TDE at the database level.
Some things to note with TDE in SQL Server:
- Requires SQL Server Enterprise Edition
- There is some overhead, approx 3-5% (I need to run performance tests to validate this, but this is what I’ve read)
- Any server where the database will be restored (either as a replica, or a standalone copy), will require the certificate restore & the Enterprise version of SQL Server
- If the certificate for the database is lost, the database is not recoverable
- Backup compression is not supported with TDE databases
- Your tempdb database will also automatically be encrypted if any databases on an instance are encrypted.
- You cannot add a TDE database to an availability group via the GUI, it must be added via T-SQL
I’m running my tests on a SQL 2012 Enterprise installation.
Initial Database Encryption
|
Step
|
Details
|
|
---|---|---|---|
1 | Backup database to be Encrypted |
The database to be encrypted must be backed up prior to the initial encryptions
|
|
2 | Create the Database Master Key |
A certificate is required to encrypt the instance
name key_length algorithm_desc create_date modify_date ##MS_DatabaseMasterKey## 256 AES_256 2014-07-02 16:33:12.370 2014-07-02 16:33:12.370 ##MS_ServiceMasterKey## 256 AES_256 2014-06-20 14:22:37.053 2014-06-20 14:22:37.053 |
|
3 | Create & Backup the certificate |
name pvt_key_encryption_type_desc subject start_date expiry_date pvt_key_last_backup_date TDETestDBCert ENCRYPTED_BY_MASTER_KEY TDETest DB Certficate 2014-07-02 20:39:34.000 2015-07-02 20:39:34.000 NULL |
|
4 | Create database Encryption Key |
|
|
5 | Backup the Certificate |
name pvt_key_encryption_type_desc subject start_date expiry_date pvt_key_last_backup_date TDETestDBCert ENCRYPTED_BY_MASTER_KEY TDETest DB Certficate 2014-07-02 20:39:34.000 2015-07-02 20:39:34.000 2014-07-02 20:46:55.740 |
|
6 | Encrypt Database |
Encryption State Key:
name is_encrypted encryption_state percent_complete key_algorithm key_length tempdb 0 3 0 AES 256 TESTTDE 1 3 0 AES 128 model 0 NULL NULL NULL NULL WingTipToys2012 0 NULL NULL NULL NULL AdventureWorks2012 0 NULL NULL NULL NULL master 0 NULL NULL NULL NULL msdb 0 NULL NULL NULL NULL Jupiter 0 NULL NULL NULL NULL Neptune 0 NULL NULL NULL NULL |
|
7 | Backup Encrypted Database |
Use standard backup process
|
Restoring Encrypted Database
A TDE database to be restored requires that the server have the certificate restored.
You will need to know the backed up certificate password, created in step 5 in the Initial Database Encryption section
Part 1: Restore Certificates
|
Step
|
Details
|
|
---|---|---|---|
1 |
Copy database & certificate backups to new host |
|
|
2 |
Create the Database Master Key on the new instance |
A certificate is required to encrypt the instance
name key_length algorithm_desc create_date modify_date ##MS_DatabaseMasterKey## 256 AES_256 2014-07-02 17:12:01.127 2014-07-02 17:12:01.127 ##MS_ServiceMasterKey## 256 AES_256 2014-06-13 16:13:05.383 2014-06-13 16:13:05.383 |
|
3 | Restore Certificate |
name pvt_key_encryption_type_desc subject start_date expiry_date pvt_key_last_backup_date TDETestDBCert ENCRYPTED_BY_MASTER_KEY TDETest DB Certficate 2014-07-02 20:39:34.000 2015-07-02 20:39:34.000 NULL |
|
4 | Backup the Certificate on the restored instance |
name pvt_key_encryption_type_desc subject start_date expiry_date pvt_key_last_backup_date TDETestDBCert ENCRYPTED_BY_MASTER_KEY TDETest DB Certficate 2014-07-02 20:39:34.000 2015-07-02 20:39:34.000 2014-07-02 21:16:54.673 |
Part 2 A – Restore Database (Standalone)
|
Step
|
Details
|
|
---|---|---|---|
1 |
Restore Database
|
Run Standard database restore
LogicalName PhysicalName Type FileGroupName Size MaxSize FileId CreateLSN DropLSN UniqueId ReadOnlyLSN ReadWriteLSN BackupSizeInBytes SourceBlockSize FileGroupId LogGroupGUID DifferentialBaseLSN DifferentialBaseGUID IsReadOnly IsPresent TDEThumbprint TESTTDE C:\Program Files\Microsoft SQL Server\MSSQL11.ALWAYSON\MSSQL\DATA\TESTTDE.mdf D PRIMARY 10485760 35184372080640 1 0 0 3DAD2405-E559-4E2E-B009-196F3DFCA37A 0 0 2424832 512 1 NULL 30000000033200197 3C8B27A5-69F9-4D00-AD03-B6BE6B43F5BD 0 1 0x527486CBFB44D8EF339195F76049DC95A436BEA8 TESTTDE_log C:\Program Files\Microsoft SQL Server\MSSQL11.ALWAYSON\MSSQL\DATA\TESTTDE_log.ldf L NULL 10485760 2199023255552 2 0 0 7265BDCF-E038-4EEF-A1A4-C8BFF652CCFE 0 0 0 512 0 NULL 0 00000000-0000-0000-0000-000000000000 0 1 NULL Processed 296 pages for database 'TESTTDE', file 'TESTTDE' on file 1. Processed 2 pages for database 'TESTTDE', file 'TESTTDE_log' on file 1. RESTORE DATABASE successfully processed 298 pages in 0.079 seconds (29.377 MB/sec). |
Part 2 B – Restore Database to Existing Availability Group
TDE databases cannot be managed by SSMS Availability Group Wizard, and must be configured by command line & manual restore.
|
Step
|
Details
|
|
---|---|---|---|
1 | Add Master to Primary in Availability Group | Assumptions:
|
|
2 | Backup Primary database and log |
|
|
3 |
Restore Database no recovery
|
|
|
4 | Add Secondary to Availability Group |
|
|
5 | Repeat on any additional Replicas | Repeat steps 3 (restore database with norecovery) and step 4 (add secondary to availability group) for any other replicas |
Additional Reference
Adding a TDE database to an Availability Group:
- http://blogs.msdn.com/b/alwaysonpro/archive/2014/01/28/how-to-enable-tde-encryption-on-a-database-in-an-availability-group.aspx
- http://www.mssqltips.com/sqlservertip/3146/configuring-transparent-data-encryption-with-sql-server-2012-availability-group/
- https://www.simple-talk.com/content/print.aspx?article=1517