Tuesday, October 21, 2008

SQL Server 2008 Transparent Data Encryption


Whether we like it or not, DBAs are becoming security experts. It’s not a job we want, but it’s been thrust upon us as we are the protectors of the organization’s data. Whether required by law, or just for self-protection, more and more of the data in our databases need to be encrypted.
In SQL Server 2000 and earlier, if we wanted to encrypt data in our databases, this usually meant client-side encryption, where all the encryption and decryption occurred in the application, not in the database. This required custom-written applications.
In SQL Server 2005, column-level (sometimes called cell-level) encryption became available. Now, encryption could occur within the database, but it was not easy to use, offered poor performance, and it required a re-architecture of the application, along with changes to the database schema. Even with these downsides, column-level encryption offered some advantages: such as granular security; data is encrypted in memory and disk; and explicit key management, which allows different users to protect their own data using their own keys, even preventing the DBA from seeing a user’s data. Even so, the disadvantages were so great that only the most sensitive columns of a table were generally encrypted, which meant that much of the data in a database was still left unencrypted.
In SQL Server 2008 (Enterprise Edition only), a new form of database encryption has been introduced: Transparent Data Encryption (TDE), which includes these major features:
  • Encrypts the Entire Database: With essentially a flip of a switch, the entire contents of MDF files, LDF files, snapshots, tempdb, and backups are encrypted. Encryption occurs in real-time as data is written from memory to disk, and decryption occurs when data is read from disk and moved into memory. Encryption is done at the database level, so you can choose to encrypt as few or as many databases as you want. The major benefit of encrypting a database with TDE is that if a database or backup is stolen, it can’t be attached or restored to another server without the original encryption certificate and master key. This prevents those nasty situations you hear about in the news where a backup of a database has been shipped from one location to another and is “lost,” which potentially exposes a company to liability issues.
  • Easy to Implement and Administer: As its name implies, Transparent Data Encryption is transparent to applications. This means that your applications, and database schema, don’t have to be modified to take advantage of TDE. In addition, initial setup and key management is simple and requires little ongoing maintenance.
  • Uses Minimal Server Resources to Encrypt Data: While additional CPU resources are required to implement TDE, overall, it offers much better performance that column-level encryption. The performance hit averages only about 3-5%, according to Microsoft.
While TDE offers many benefits over other types of encryption, it has some of its own limitations, which are important to consider. These include:
  • TDE does not protect data in memory, so sensitive data can be seen by anyone who has DBO rights to a database, or SA rights to the SQL Server instance. In other words, TDE cannot prevent DBAs from viewing any data they want to see.
  • TDE is not granular. Then entire database in encrypted.
  • TDE does not protect communications between client applications and SQL Server, so other encryption methods must be used to protect data flowing over the network.
  • FILESTREAM data is not encrypted.
  • When any one database on a SQL Server instance has TDE turned on, then the tempdb database is automatically encrypted, which can contribute to poor performance for both encrypted and non-encrypted databases running on the same instance.
  • Although fewer resources are required to implement TDE than column-level encryption, it still incurs some overhead, which may prevent it from being used on SQL Servers that are experiencing CPU bottlenecks.
  • Databases encrypted with TDE can’t take advantage of SQL Server 2008’s new backup compression. If you want to take advantage of both backup compression and encryption, you will have to use a third-party application, such as SQL Backup, which allows you to perform both of these tasks without penalty.
For some organizations, they might want to consider implementing both column-level encryption (which still is available in SQL Server 2008) along with TDE for a database. While more complex to set up and administer, this combination offers greater security and encryption granularity than does either method used alone.

How Transparent Data Encryption Works

TDE is able to minimize resource utilization and hide its activities from user applications and the Relational Engine because all encryption/decryption occurs when data pages are moved between the buffer pool and disk.
Let’s say that TDE has been turned on for a database that includes a single MDF file, a single LDF file, and tempdb. As I mentioned earlier, whenever any database on a SQL Server instance is encrypted using TDE, then the tempdb database for that instance is also encrypted.
As SQL Server moves data pages from the buffer pool to the MDF file, the LDF file, or tempdb, the data is encrypted in real-time before it is written to disk. On the flip side, as data pages are moved from the MDF file or tempdb to the buffer pool, they are decrypted. In other words, when data is on disk, it is encrypted, but when data in memory, it is not encrypted.
When a backup is made of an encrypted database, it cannot be restored unless the DBA has access to the certificate and master key that was used to encrypt the database. This prevents anyone from stealing a backup and restoring it on a different SQL Server. The same goes for when you detach and reattach a database to a different SQL Server.
TDE supports several different encryption options, such as AES with 128-bit, 192-bit, or 256-bit keys or 3 Key Triple DES. You make your choice when implementing TDE.

How to Implement Transparent Data Encryption

Now, let’s take a brief look at how to turn on TDE for a database. This can only be done using Transact-SQL code, as SSMS (SQL Server Management Studio) has no option to perform this task. Before we drill down into the details, let’s look at the four key steps required to turn on TDE. They include:
  • Create a Master Key: A master key is first created. This key, which is accessible with a password, is used to protect a certificate, which we will create in the next step. This key is stored in the master database in an encrypted format.
  • Create or Obtain a Certificate Protected by the Master Key: This certificate is used to protect the database encryption key we will create in the next step. In addition, this certificate is protected by the master key we created in the previous step. The certificate is stored in the master database in an encrypted format.
  • Create a Database Encryption Key: This is the key that will be used by SQL Server to actually encrypt the data. It is protected by the certificate created in the previous step. This key is stored in the database that is encrypted, and is stored in an encrypted format.
  • Turn TDE On: Once all the above has been created, a command is run to tell SQL Server to begin encrypting all of the data using the database encryption key created in the previous step. This process may take some time, depending on the size of the database. Ideally, the database should not be used in production until the database has completed the initial encryption process.

Creating a Master Key
Assuming one has not already been created for another reason, the first step is to create a master key. The master key is a symmetric key used to protect the private keys of certificates and asymmetric keys. In this particular case, the master key is used to protect the certificate which will be created in the next step. When a master key is created, it is encrypted using the Triple DES encryption method and protected by a user-provided password.
To create a master key, run the following code:
--Create a master key
--The master key must be created within the master database
USE master ;
CREATE MASTER KEY ENCRYPTION BY PASSWORD =
'User-Provided Password' ;
GO
Obviously, the password you provide should be very obscure, and you will want to document in a secure location.
Create or Obtain a Certificate Protected by the Master Key
For this example, we are going to create a new certificate, although you can use a pre-existing certificate if available. The certificate is used to protect the database encryption key that we will create next. In addition, this certificate is protected by the master key created in the previous step.
--Create a certificate by the name of TDECert
USE master ;
CREATE CERTIFICATE TDECert WITH SUBJECT = 'TDE Certificate' ;
GO
Create a Database Encryption Key
Now that the certificate has been created, the next step is to create a database encryption key and protect it with the certificate we created in the last step. This is the encryption key that is used by the database to encrypt all of the data. It is during this step that you choose which encryption method is used to encrypt your database.
--Create Database Encryption Key Inside Database to Be Encrypted,
--and Protect It with the Certificate
USE AdventureWorks ;
GO
CREATE DATABASE ENCRYPTION KEY WITH
ALGORITHM = AES_256 ENCRYPTION BY
SERVER CERTIFICATE TDECert ;
GO
Backup the Private Encryption Key and Certificate
Once you have created the master key and certificate, they should be backed up immediately. If you lose these, you can’t move or restore the database.
--Backup the private key and certificate to two separate disk files
USE master ;
GO
BACKUP CERTIFICATE TDECert TO FILE =
'c:\certificate_backups\AdventureWorks_Certificate.cer'
WITH PRIVATE KEY ( FILE =
'c:\certificate_backups\NorthwindCert_Key.pvk',
ENCRYPTION BY PASSWORD =
'User-Provided Password' ) ;
GO
When this command is run, the master key and the certificate are taken from the master database and written to separate files (both in an encrypted format).
Turn TDE On
The last step is to turn TDE on. Once you run the following command, the database will begin to encrypt itself. Depending on the size of the database, and the hardware running it, this process could be lengthy. While it is possible to keep the database in production during this process, it will cause some user blocking and performance will suffer. Because of this, ideally you should only turn TDE on when the database is not being used.
--Turn TDE on
USE AdventureWorks
ALTER DATABASE AdventureWorks
SET ENCRYPTION ON ;
GO
If you want to watch the progress of the encryption, run this statement:
SELECT DB_NAME(database_id), encryption_state
FROM sys.dm_database_encryption_keys ;
GO
When the statement above is run, a state is returned. A database encryption state of “2” means that encryption has begun, and an encryption state of “3” indicates that encryption has completed. Once the tempdb database and the user database you are encrypting reach a state of “3,” you are ready to put them back into production.
From this point on, the entire user database, and tempdb database will be encrypted, although your applications will never know the difference.

Summary

If you got lost with all the keys and certificates required to implement TDE, you are not alone. It is a complex topic and beyond the scope of this chapter. The focus of this chapter was to provide you an overview of what TDE is, how it works, and how to implement it. Because of the complexity involved in using TDE, you should only implement this technology when you full understand its many complexities and after thorough testing in a test environment.
reference :- http://www.simple-talk.com/community/blogs/brad_mcgehee/archive/2008/09/21/69659.aspx

Monday, October 6, 2008

Add or remove a secondary axis in a chart (Excel)


When the values in a 2-D chart vary widely from data series to data series, or when you have mixed types of data (for example, price and volume), you can plot one or more data series on a secondary vertical (value) axis. The scale of the secondary vertical axis reflects the values for the associated data series.
Formatted combination chart
After you add a secondary vertical axis to a 2-D chart, you can also add a secondary horizontal (category) axis, which may be useful in an xy (scatter) chart or bubble chart.
To help distinguish the data that is plotted along the secondary axis, you can change the chart type for just one data series. For example, you could change one data series to a line chart.
 IMPORTANT   To complete the following procedures, you must have an existing 2-D chart. Secondary axes are not supported in 3-D charts. For more information about how to create a chart, see Create a chart.
What do you want to do?


Add a secondary vertical axis

You can plot data on a secondary vertical axis one data series at a time. To plot more than one data series on the secondary vertical axis, repeat this procedure for each data series that you want to display on the secondary vertical axis.
  1. In a chart, click the data series that you want to plot on a secondary vertical axis, or do the following to select the data series from a list of chart elements:
    1. Click the chart.
      This displays the Chart Tools, adding the DesignLayout, andFormat tabs.
    2. On the Format tab, in the Current Selection group, click the arrow in the Chart Elements box, and then click the data series that you want to plot along a secondary vertical axis.
    3. Excel Ribbon Image
  2. On the Format tab, in the Current Selection group, click Format Selection.
    The Format Data Series dialog box is displayed.
     NOTE   If a different dialog box is displayed, repeat step 1 and make sure that you select a data series in the chart.
  3. On the Series Options tab, under Plot Series On, click Secondary Axis and then click Close.
    A secondary vertical axis is displayed in the chart.
  4. To change the display of the secondary vertical axis, do the following:
    1. On the Layout tab, in the Axes group, click Axes.
    2. Click Secondary Vertical Axis, and then click the display option that you want.
  5. To change the axis options of the secondary vertical axis, do the following:
    1. Right-click the secondary vertical axis, and then click Format Axis.
    2. Under Axis Options, select the options that you want to use.
 TIP   To help distinguish the secondary axis, you can change the chart type for just one data series. For example, you can change one data series to a line chart. For more information, see Present your data in a combination chart.

Add a secondary horizontal axis

To complete this procedure, you must have a chart that displays a secondary vertical axis. To add a secondary vertical axis, see Add a secondary vertical axis.
  1. Click a chart that displays a secondary vertical axis.
    This displays the Chart Tools, adding the DesignLayout, and Format tabs.
  2. On the Layout tab, in the Axes group, click Axes.
    Excel Ribbon Image
  3. Click Secondary Horizontal Axis, and then click the display option that you want.

Change the chart type of a data series

  1. In a chart, click the data series that you want to change, or do the following to select the data series from a list of chart elements:
    1. Click the chart.
      This displays the Chart Tools, adding the DesignLayout, andFormat tabs.
    2. On the Format tab, in the Current Selection group, click the arrow in the Chart Elements box, and then click the data series that you want to change.
      Excel Ribbon Image
  2. On the Design tab, in the Type group, click Change Chart Type.
    Excel Ribbon Image
  3. Click a chart type in the first box, and then click the chart subtype that you want to use in the second box.

Remove a secondary axis

  1. Click the chart that displays the secondary axis that you want to remove.
    This displays the Chart Tools, adding the DesignLayout, and Format tabs.
  2. Do one of the following:
    • On the Layout tab, in the Axes group, click Axes, click Secondary Vertical Axis or Secondary Horizontal Axis, and then click None.
      Excel Ribbon Image
    • Click the secondary axis that you want to delete, and then press DELETE.
    • Right-click the secondary axis, and then click Delete.
     TIP   You can also remove secondary axes immediately after you add them by clicking Undo Button image on the Quick Access Toolbar, or by pressing CTRL+Z.

Setting Trace Flags using the Configuration Manager


How to set trace flag 4616 in Sql Server ?

As from DynamicsNAV 5.0, when you want to use Sql Server you need to set trace flag 4616, otherwise an error will occur when you try to connect a Dynamics 5.0 client to a Sql Server database.
What is a trace flag in Sql Server?
Trace flags are used to enable specific properties or to change the behaviour of Sql Server.
What does trace flag 4616 do ?
Well, it makes server-level metadata visible to application roles. In SQL Server 2005, an application role cannot access metadata outside its own database because application roles are not associated with a server-level principal. This is a change of behavior from earlier versions of SQL Server. Setting this global flag disables the new restrictions, and allows for application roles to access server-level metadata.
How do you enable a trace flag in Sql Server 2005 ?
There are several ways to enable or disable a trace flag in Sql Server. Maybe the easiest way is to do it in the Sql Server Configuration Manager:
4616_1



In the Configuration Manager you then go to the properties of the Sql Server service (default is MSSQLSERVER):
4616_2







In the Advanced tab, select the StartUp parameters and add ;-T4616 at the end and then click on Ok:
4616_3















Now we have added the trace flag. It will be enabled as soon as we restart the Sql Server service:
4616_4