Latest Entries »

Anyone who is a DBA or SQL person already knows what this is and how to implement it. I am writing this post to help those of us who are tossed into the database world without really being a DBA. As I took over new roles in my career like Forefront Identity Manager, I wanted to learn how to know the most about the engine driving the product. The engine to FIM along with many other great Microsoft products is SQL Server. This is a relational database which is different from say Microsoft Exchange which uses ESE (Extensible Storage Engine). ESE draws it’s information from “base types” and has no knowledge of any structure or schema. A relational database like SQL all structures are part of the meta-data, which is the database itself. When looking at something like FIM there in many times lots of personal information since the role of the product is to provision, de-provision, modify and synchronize user accounts and groups.

SQL Server databases in native form are unencrypted and easily viewable using a wide range of tools and methods. One way to view this would be opening the database file in Microsoft Notepad. This can be a huge liability if you have data stored in the unencrypted database that is sensitive. There are different levels of encryption that you can use to secure a database; this document will talk about Transparent Data Encryption. The other ways to encrypt data in SQL Server are using Symmetric Keys, Certificates and Asymmetric Keys. These methods are called cell based encryption. TDE gives you full database encryption, also there are Windows file based encryption methods (Bit locker and Encrypting File System “EFS”)

Transparent Data Encryption (TDE) was introduced in SQL Server 2008, as a feature of the Enterprise Edition. The Developer Edition of SQL Server 2008 also offers TDE, but its license limits its use to development and testing only. TDE’s specific purpose is to protect data by encrypting the physical files of the database, rather than the data. These physical files include the database file, the transaction log file and the backup files. The protection of the database files is accomplished through an encryption key hierarchy that exists externally from the database in which TDE has been enabled.

Transparent Data Encryption Features

Advantages and Disadvantages of TDE

TDE vs. Cell Level Encryption

Comparing TDE to cell-level encryption is a bit like comparing apples to oranges. They are solutions for different technical designs. TDE offers general protection to the database while cell-level encryption offers specific protection to data. A highly secure design would be to use TDE in conjunction with other encryption methods, for a layered approach to protection. If the amount of data that must be encrypted is very small or if the application can be custom designed to use it and performance is not a concern, cell-level encryption is recommended over TDE. Otherwise, TDE is recommended for encrypting existing applications or for performance sensitive applications. Cell-level encryption is available in all SQL Server editions (2005 and newer) while TDE is available only in SQL Server 2008 Enterprise Edition and SQL Server 2008 Developer Edition.


  • Implementation of TDE does not require any schema modifications.
  • Since the physical data files and not the data itself are encrypted, the primary keys and indexes on the data are unaffected, and so optimal query execution can be maintained.
  • The performance impact on the database is minimal. In their whitepaper titled “Database Encryption in SQL Server 2008 Enterprise Edition“, Microsoft estimates the performance degradation for TDE to be 3-5%, while cell-level encryption is estimated to be 20-28%.
  • The decryption process is invisible to the end user.


  • Use of TDE renders any benefits to be gained from backup compression, as the backup files will be only minimally compressed. It is not recommended to use these two features together on the same database.
  • TDE does not provide the same granular control, specific to a user or database role, as is offered by cell-level encryption.
  • TDE is available only with SQL Server 2008, Enterprise Edition.
  • In a replicated data design the data transmitted to the mirror is not encrypted, both the publisher and subscriber would need to have TDE enabled on the replicated database.

Considerations when Implementing TDE

Prior to implementing TDE, there are several issues to take into consideration.

Master Key Interdependency

The process of implementing TDE involves the creation of a database master key and certificate on the master database. Only one database master key can be created for a given database so any other user databases that share the instance, and have TDE implemented, will share a dependency upon the master database master key. This interdependency increases the importance of performing a backup of the master database master key to ensure the continued accessibility of the TDE-enabled databases.

TempDB Impact

When TDE is initially implemented, the physical file of the TempDB system database is also encrypted. Since the TempDB database contains temporary data from the TDE-enabled database, its encryption is required to maintain full protection by this feature; otherwise the information that is temporarily stored in the TempDB database from the TDE enabled databases would be exposed through the physical files of TempDB.

Once the TempDB database is encrypted, any reference and use of this database by other databases, regardless of whether they have TDE enabled or not, will require encryption and decryption. While this encryption and decryption of the TempDB database files remains transparent to the user, it does have a minimal performance impact on the entire instance. Microsoft has estimated the entire impact of TDE on a SQL Server instance to be 3-5% depending on the server environment and data volume.


The FILESTREAM data type stores large unstructured objects, such as documents and images, in an integrated physical file that is separate from the database file. When TDE is implemented on a user database that contains FILESTREAM data, the FILESTREAM files remain unencrypted.

Encryption & Decryption

TDE is designed to protect data by encrypting the physical data files rather than the data itself. This level of protection prevents the data and backup files from being opened in a text editor like Microsoft Notepad to expose the file’s contents.

TDE encryption occurs prior to writing data to disk, and the data is decrypted when it is queried and recalled into memory. This encryption and decryption occurs without any additional coding or data type modifications; hence the name “Transparent Data Encryption”. Alongside TDE, you should consider applying additional supporting layers of protection to your sensitive data, to ensure complete protection from unauthorized disclosure. For example, you may wish to implement, in addition to TDE, encrypted database connections, cell-level encryption, or one-way encryption. File level encryption is another option. For data in transit externally from the database, you may want to look at your security from the network aspect (Firewalls, Access Control Lists, DMZ’s).

Backup Keys and Certificate

TDE prevents the backup files from being opened by a plain text editor. It also limits the recovery of the database backup file to the instance that holds the encryption key hierarchy that was in existence at the time the backup was created. Backup files of databases with TDE enabled are encrypted using a key hierarchy that includes the service master key of the SQL Server instance, the database master key and certificate for the master database.

Despite this dependency, none of these keys are included with the standard database backup, and must be backed up separately via the following commands:

  • BACKUP SERVICE MASTER KEY to backup of the service master key.
  • BACKUP MASTER KEY to backup of a database master key.
  • BACKUP CERTIFICATE to backup the certificate.

In order to restore the encrypted data to another instance of SQL Server, a user needs to recover the service master key backup file, the master database master key backup file and the master database certificate private key, prior to recovering the database backup file. The database encryption key that is created in the user database, where TDE has been implemented, is included in the standard database backup. When the service master key and database master key are backed up, it is recommended to store their backup files in a separate location from the database files.

Replication Databases

If the TDE enabled database is part of a replication setup, the subscribing database must also have TDE implemented. The data that is traveling between the databases will be in plain text and is vulnerable to unauthorized disclosure. Encrypting connections, such as secure socket layers (SSL) or Internet protocol security (IPSec) would be a method to secure data end to end. Also access control lists would be a method to limit communications between only servers part of the subscription to the database.

How to Implement Transparent Data Encryption

Let’s set up TDE on our example user database called “AT”. Our TDE implementation, in comparison to cell-level encryption, will be very simple. There are no modifications to the schema required, there are no permissions that need to be granted to database users and roles in order to use TDE, and there are no additional database objects that must be created to perform the encryption and decryption methods. What we will need is Control permissions on the Master and AT databases.

Backup before proceeding

It is a best practice to back up a database prior to making modifications. However, it is especially important when implementing TDE; this will be the quickest way to revert the database should the TDE implementation need to be reversed. The image below shows the T-SQL statement backup expression for the “AT” database. You could also use a maintenance plan if you have one setup to back up the database.




NAME =’AT-Full Database Backup’,






Create the Master Database Key

The first step is to create a database master key for the master database, using the CREATE MASTER KEY command, as shown in image 2.

USE Master;





Create the Self-Signed Certificate

The next step is to create a self-signed certificate that is protected by the database master key of our master database.

USE Master;



WITHSUBJECT=’My Server Cert for TDE’;


Create the AT Database Encryption Key

Next we will create the Database Encryption Key.







Backup the Certificate and Key

Our next step will be to back up the certificate and Key. This is very important; once you have run this command the key and certificate will be stored in the directory you specified. A best practice would be to copy these off to a remote location. A file server in a different datacenter would be the best option.

USE Master;








Enable TDE on the AT Database

Our final step is to turn on TDE on the AT database.






Verifying TDE

Once TDE is implemented there are a few ways you can verify that these steps indeed succeeded.

Using Dynamic Management Views

Dynamic management views (DMV) are built-in views that provide metadata regarding the settings, health and properties of SQL Server instances and databases. The “sys.dm_database_encryption_keys” DMV presents information about the database encryption keys used in a given database, as well as the encryption state of the database.

USE Master;










LEFT OUTER JOIN sys.dm_database_encryption_keys dm

ONdb.database_id = dm.database_id;


Through the use of a query in which the “sys.dm_database_encryption_keys” DMV and the “sys.databases catalog” view are joined through the database_id column, we are able to determine the success of the TDE implementation, as demonstrated in image below.


Another step to verify would be to back up the TDE enabled user database, then try and open it with a text editor. If TDE in implemented correctly your data should look like the image below.


Reversing TDE

To remove TDE before any transactions have occurred perform the following steps:

1. Restore the backup of the “AT” database that was created before TDE was implemented.

2. Drop the certificate that was created in the Master database. Remember the interdependency on key; if you enabled TDE on other user databases within this instance you should not drop the certificate.

3. Drop the database master key that was created in the Master database. Same rules apply about the interdependency on the master key; if you have other user databases using TDE do not drop the master key.

4. Restart the instance in which the “AT” database resides. If there are not any other user databases on the instance that have TDE implemented, this action will force the recreation of the TempDB database in an unencrypted format.

To remove TDE after transactions have occurred perform the following steps:

1. Alter the “AT” databaseto have the ENCRYPTION option set to the value of OFF.

2. Wait until the decryption process is complete. Use the sys.dm_database_encryption_keys DMV to determine its status. A value of “1″ returned in the encryption_status column indicates that the decryption is complete.

3. Drop the database encryption key for the “AT” database.

4. Restart the instance in which the “AT” database resides. If there are not any other user databases on the instance that have TDE implemented, this action will force the recreation of the TempDB database in an unencrypted format.

In my opinion TDE offers a big bang for a small buck so to speak, you are able to implement a low performance cost solution that provides a huge upgrade in security compared to the default which is no encryption of the database and database backups. There are limitations like not having the granular control of cell based encryption that level of control comes with its own draw backs. The short answer is there is no one solution that fits all scenarios from the research I have done. An example would be a homegrown financial application that needs the highest level of security on certain tables would be a better fit for cell based encryption since you would have the option of designing the database to have the schema modifications needed and indexes created to work with cell based encryption. Another example would be a COTS application like Forefront Identity Manager 2010, you want some level of encryption but you can’t modify the schema and performance of the database is at a premium. Using either of these methods should also be combined with other security best practices like network security using firewalls; access controls lists, and file level security. Limiting the attack surface along with encrypting what is exposed are fundamental techniques in keeping data secure.

So I stumbled across an issue worth sharing last week. When installing TMG 2010 for
a Lync 2010 deployment I ran into an issue with TMG not being able to identify
the network adapters.

All servers in this deployment were hosted on VMware. The OS was 2008 R2 x64. I was
able to install TMG with no problems. I was able to define the internal network
(which was pulled from the internal vmxnet adapter, showing TMG did recognize
it at some point). I was given the option to define networks, ranges, IP’s.
Everything finished with the install with no errors, no events of any kind in
the event log showing there is any issue.

Next I launch TMG for the first time. Click on Configure Network Settings. At the
network template screen where you choose your topology of your network you are
given four choices (Edge Firewall, 3-Leg Perimeter, Back Firewall, Single
Network Adapter) problem here is that everything is greyed out. I would get an
error stating that TMG was unable to identify any network adapters. The strange
thing is that clearing during the defining the internal network stage TMG did
find the adapters.

This took place while I had someone from Microsoft onsite to work on some other Lync
2010 issues so between the two of us we could not figure it out. I updated to
Service Pack 1, I updated to Update 1 for SP1 no change. I found a hotfix that
would address an issue if your address was 128.8.x.x which ours were, so I
applied that (hotfix 427944). That did not work. So as a last try I removed the
vmxnet adapters, replaced them with Intel Pro 1000′s and did a reinstall of TMG
and everything worked just fine.

I found a few things on other blogs that point to an issue with the vmxnet 3
adapters and network load balancing but I was not anywhere near getting to that
point of the setup when I was seeing this issue. Just something to help you out
if you are installing TMG 2010 on VMware you may need to use a different
adapter other the vmxnet 3′s. If anyone has seen this issue please drop me a
line I would love to get other’s feedback on this.

The Run History is stored in the FIM database, and contributes massively to the growth the database. If you don’t regularly delete the Run History, your database files will grow and grow until the disk is full. We all know what happens when your database drive is out of space. Clearing the History also requires large amounts of free space on the volume holding the transaction log file. This file needs to be expanded in the clearing process – and the more you’re trying to clear, the more disk space will be needed. So the best thing to do is keep this under control. It is a simple process but one that gets overlooked sometimes.

You can clear the run history manually in the FIM GUI. I like to clear it using PowerShell. Below is a script I use. Simply add in the date you want to clear up to and the server name. I like to keep 7-10 days of run history but this depends on how often you are doing runs. I try and keep 3 to 5 runs a week, I am working with MA’s that have 3.5 million objects so it is hard to get this run every day. If you want to be hands off you can set this script to automate using task scheduler but I would advise to keep an eye on this to make sure your runs are clearing as expected.



$DeleteDay = Get-Date

If($args.count -gt 0)


$DayDiff = New-Object System.TimeSpan $args[0], 0, 0, 0, 0

$DeleteDay = $DeleteDay.Subtract($DayDiff)


Write-Host “Deleting run history earlier than or equal to:” $DeleteDay.toString(‘MM/dd/yyyy’)

$lstSrv = @(get-wmiobject -class “MIIS_SERVER” -namespace “rootMicrosoftIdentityIntegrationServer” -computer “.”)

Write-Host “Result: ” $lstSrv[0].ClearRuns($DeleteDay.toString(‘yyyy-MM-dd’)).ReturnValue




Write-Host “`nError: $($_.Exception.Message)`n” -foregroundcolor white -backgroundcolor darkred





Get every new post delivered to your Inbox.

%d bloggers like this: