Integrating CAKM for Microsoft SQL Server EKM with SQL Server High Availability (Always ON) Groups
The Always ON Availability Groups feature is a high-availability and disaster recovery solution that provides an enterprise-level alternative to database mirroring.
Introduced in MSSQL Server 2012, Always ON Availability Groups maximizes the availability of a set of user databases for an enterprise. An Availability Group supports a failover environment for a discrete set of user databases, known as availability databases that fail over together.
An Availability Group supports a set of read-write primary databases and one to eight set of corresponding secondary databases. Optionally, secondary databases can be made available for read only access and/or some backup operations.
To perform this integration, you need CAKM for Microsoft SQL Server EKM Provider/Connector.
Note
CAKM for Microsoft SQL Server EKM Provider must be installed on every node. This feature is available on the Enterprise, Evaluation, and Developer edition of MSSQL Server.
MSSQL Server Setup
MSSQL Server must be installed and configured as nodes in a Windows Server Failover Cluster (WSFC) for an EKM provider to be used for Always On availability groups and SQL Server failover clustering. For more information, refer to the Microsoft documentation.
Column Encryption
To perform column encryption, perform the following steps on all the SQL Server nodes that will be part of the Always On group.
Creating EKM Provider and Credentials
Enable the EKM provider:
Create the cryptographic provider:
For example:
Create a credential and add the credential to connected database user (domain user):
For example:
Creating the Always On Availability Group
Open the Microsoft SQL Server Management Studio on primary replica and create a database first and then take full backup of that database on a shared location that is accessible by all SQL Server nodes.
Open the Always On Availability Group Creation wizard and follow the instructions to create the Always On Availability Group. For detailed steps and prerequisites, refer to the Microsoft online documentation for creating the Always On Availability Group.
After successful creation of the group, the dashboard displays all the participating nodes. An example of a dashboard is shown below. For demonstration, two nodes are added: primary and secondary.
Performing Column Encryption
Note
Steps 1-4 should be performed on the primary node.
To perform column encryption:
Create symmetric/asymmetric keys for the database.
Using a Symmetric Key:
For example:
Using an Asymmetric Key:
For example:
Create a table in the database.
Encrypt the column using symmetric or asymmetric keys.
Using Symmetric Key
Using Asymmetric Key
For example:
Decrypt the column using symmetric or asymmetric keys.
Using a Symmetric Key
Using an Asymmetric Key
Login to the secondary node.
Verify that output is the same as that on the primary replica.
Creating Symmetric Key Encrypted by Asymmetric Key on CAKM for Microsoft SQL Server EKM
To create a symmetric key encrypted by an asymmetric key on CAKM for Microsoft SQL Server EKM, open the SMS on primary replica:
Execute the following command from SQL query window.
where
SQL_EKM_RSA_2048_Key
is an existing asymmetric key.Open the key before using it. Execute the following command to open the symmetric key.
Encrypt the data using the key1.
Decrypt the data using the key1.
Close the symmetric key.
Now execute the steps 2-5 on secondary replica and verify if the output is same as primary node.
Enable Transparent Database Encryption on Always On Group
To enable transparent data encryption on the SQL Server databases:
Enable TDE on primary node
Restore the database on secondary node
Enabling TDE
Create an asymmetric key in the master database.
Login to secondary node and create the same asymmetric key.
Create a new credential.
Create a login using the asymmetric key created above.
Add the credential to the login created above.
Execute steps 2-5 on all the secondary nodes. It is required because TDE encryption key, credential, and login are created in the master database and it is not a part of the Availability Group.
Create a database and its encryption key on primary node.
Enable Database Encryption.
To query the status of database encryption, TDE key change and its percentage completion.
Note
Before adding the already encrypted database into availability group, take the full backup of the database on shared location that is accessible by all secondary nodes.
Log in to Primary node and add the database into the availability group.
For example:
This command will add the database into the availability group but it will not be available on the secondary node.
Adding Database on Secondary Node
Login to the secondary node and restore the database with
NO RECOVERY
option.Login to the secondary node and add the database in availability group.
For example:
Query the status of database encryption and its percentage completion on the secondary node.
Transparent Database Encryption (TDE) Key Rotation
Create an asymmetric key using CAKM for Microsoft SQL EKM Provider on primary node.
Create same asymmetric key using CAKM for Microsoft SQL EKM Provider on the secondary node.
Create a credential for CAKM for Microsoft SQL EKM Provider.
Create a login based on the asymmetric key created above.
Map the credential created above to the login created above.
Execute steps 2-5 for all secondary nodes. It is required because TDE encryption key, credential, and login are created in the master database and it is not a part of Availability Groups. Therefore, you need to create the same key, credential, and login in the master database of all the secondary nodes to access the encrypted tables created in the database.
Perform Transparent Database Encryption Key Rotation on the primary node.
To query the status of database encryption, TDE key change, and its percentage completion.