CERTIFICATE PROVISIONING FOR MICROSOFT SQL SERVER
Symptom
SUMMARY
The following steps are presented to assist a systems administrator in automating certificate installation and configuration for use Microsoft SQL Server on a Windows host. This is divided into two parts:
- CAPI provisioning - installation of certificate on Windows host in its CAPI store, and
- Configuration of MS SQL Server (via Windows Registry) to use the certificate.
It is assumed that the reader has a good understanding Windows CAPI store and hand-on experience of using Venafi Trust Protection Platform.
CAPI PROVISIONING
Ensure your environment meets pre-requisites described in product documentation(https://docs.venafi.com).
Certificate Requirements
Microsoft SQL Server uses a TLS certificate for encrypting data that is transmitted across the network between the SQL instance and the client application. The certificate must meet the following requirements:
- The certificate must be valid and placed in Local Computer certificate store.
- Enhanced Key Usage property of the certificate must specify Server Authentication indicating that it is used for server authentication
- The certificate's key usage property (KEY_USAGE) to include key encipherment
- The Subject property of the certificate to include the common name attribute that's set to name or FQDN of the MS SQL Server host. The same applies to the DNS name field in the Subject Alternate Name (SAN) property.
- If the certificate is used on clustered deployment, common name should be set to FQDN of the virtual server.
- If the certificate is used on Availability Groups, the common name should be set to FQDN of the listener address and each of the nodes FQDN set to SAN DNS field.
Create and configure CAPI Installation
Follow the steps below to create and configure CAPI Installation using Aperture. These instructions assume there is an existing certificate.
- Login into Aperture and locate (or search for) the certificate in the inventory.
- Click on the certificate list to view the details page.
- Select Actions Add Installation
- When presented with selection of choices, select Track, validate and automate installation of this certificate.
- If the device object (representing MS Windows host) does not exist, select Create New Device. Here it is assumed the device exist, select it by device name as shown, and select Windows CAPI and IIS as Installation Type, and click Add Installation, followed by selecting Yes, Configure Location as shown:
- Name the CAPI installation by over-typing the Name field
- Scroll down to examine the remaining fields.
- Hostname- FQDN or hostname that is identified by AD computer account.
- Select Device Credential object, the domain service account with Local Administrator membership.
- Private Key Trustee- by default, SQL server will set itself up to run as the NT Service\MSSQLSERVER user. In order for SQL to have the rights it needs to the private key in the CAPI store, the CAPI driver must be configured to set that user account as the private key trustee.
- IIS Setting- since this certificate is not for use with IIS, select No.
- Click Save Installation Settings.
Configuring Microsoft SQL Using TPP Workflow Injection
Microsoft SQL server uses a certificate within the standard Windows machine CAPI store. Configuration of TLS for SQL is done by creating a registry entry to indicate the certificate to be used, and one registry entry to enable the encryption. This can be accomplished using TPPs workflow injection to execute a PowerShell script immediately following the provisioning of the certificate into the CAPI store by TPP. The required setup is documented below, as well as a copy of the PowerShell script.
Download the Command-Injection PowerShell Script
The "Configure_SQLTLS.ps1" PowerShell script can be downloaded from this KB's attached files at the bottom of the page.
Create TPP Workflow Object
Execution of post-provisioning tasks are configured using a specialized workflow object, with the Inject Command option selected. Before the workflow injection can be applied to any provisioning process, the workflow object must first be created. It is recommended to create one or more dedicated policies to store workflow objects in. This allows for more restrictive permissions to be applied to the workflow objects, so they are not modified by less privileged users.
The workflow object should be configured as follows:
Stage 1100 is a stage dedicated to post-provisioning actions, typically referred to the Restart Application stage. Using Stage 1100 ensures that the provisioning of the certificate was completed successfully.
The best-practice for executing scripts during command injection is to place the script on a share which is accessible by the user performing the injection command. (The same credential used for provisioning). The script may also be placed at a known location on the target system as well. Small sets of commands may be typed directly into the Commands text box, however, there is a limitation on length allowed (around 2000 total characters) and there can also be difficulties with using variable substitution since the $ character is a special character to TPP allowing macro substitution.
Injection Commands
The actual injection command is as follows:
& c:\temp\Configure_SQLTLS.ps1 "$CertificateField[$Config[$SelfDN$,Certificate]$,Thumbprint]$"
This command should be entered on a single line. The & character tells PowerShell to execute the following string as a script. The last parameter is a Venafi TPP macro, which evaluates into the thumbprint of the certificate being provisioned.
NOTE: The c:\temp\Configure_SQLTLS.ps1 value should be updated to point to the path where the PowerShell script has been placed.
Apply Workflow Object
Once the workflow object has been created, it must be applied to the specific devices which it will act on. This is done via policy, on the Workflow tab. A workflow object can be applied to many policies, and they are cumulative as child policies inherit workflows from parent policies.
Testing Database TLS Connections
To ensure that your connections are being encrypted, launch SQL Server Management Studio (SSMS), connect to the instance (you may need to tick the "Encrypt Connection" option if you're controlling encryption on the client) and execute the following query:
SELECT encrypt_option FROM sys.dm_exec_connectionsWHERE session_id = @@SPID
If encryption is working correctly, TRUE will be returned.
Environment
TPP/TLSPDC