
In a recent post, I described some of the security benefits of using Transport Layer Security (TLS) with Microsoft SQL Server. Configuration changes are required to take full advantage of these capabilities. By default, SQL Server uses an unmanaged, self-signed certificate, which provides little security value. The best practice is to use a certificate issued by the organization’s enterprise PKI. In this guide, I’ll demonstrate how to prepare and deploy a certificate template for SQL server using Active Directory Certificate Services (AD CS), enroll for the certificate, and configure SQL server to use the new certificate for TLS connections.
Note: I have recorded a video demonstration for enabling TLS in Microsoft SQL Server 2022 on my YouTube channel here. Enjoy!
Certificate Requirements
The minimum recommended requirements for a TLS certificate for SQL Server 2022 are:
- Subject Name = Server’s fully qualified domain name or the alias name of the cluster
- 2048-bit RSA key with SHA256
- Server Authentication EKU (1.3.6.1.5.5.7.3.1)
Certificate Template
Administrators must prepare a certificate template in Active Directory (AD) adhering to the requirements listed above. On an issuing certification authority (CA) or an administrative workstation with the Remote Server Administration Tools (RSAT) installed, open the Certificate Templates management console (certtmpl.msc) and perform the following steps.
- Right-click the default Web Server template and choose Duplicate Template.
- Select the Compatibility tab.
- In the Compatibility Settings section, select the latest version of Windows Server supported by your issuing CA servers from the Certification Authority drop-down list.
- Select Windows 10/Windows Server 2016 from the Certificate recipient drop-down list.
- Select the General tab.
- Enter a descriptive name in the Template display name field.
- Select a validity period of 1 year with a renewal period of 6 weeks.
- Select the Cryptography tab.
- Select Key Storage Provider from the Provider Category drop-down list.
- Select RSA from the Algorithm name drop-down list.
- Enter 2048 in the Minimum key size field.
- Select SHA256 from the Request hash drop-down list.
- Select the Issuance Requirements tab.
- Check the box next to CA certificate manager approval.
- Select the Subject Name tab.
- Select Supply in the request.
- Select the Extensions tab.
- Select Application Policies.
- Ensure that Server Authentication is the only application policy listed.
- Select the Security tab.
- Click Add.
- Grant Read and Enroll permissions to the SQL Server security group or the SQL server’s computer account.
- Ensure no other users/groups have enroll permission.
Once complete, publish the certificate template on all issuing CA servers in the organization.
Enroll Certificate
The certificate enrollment process involves several steps.
Request Certificate
To enroll for a new TLS certificate, open the computer certificate management console (certlm.msc) on the SQL server and perform the following steps.
- Right-click on the Personal folder and choose All Tasks > Request New Certificate.
- Click Next.
- Click Next.
- Check the box next to the SQL server certificate template.
- Click the More information is required to enroll for this certificate. Click here to configure settings link.
- Select the Subject tab.
- In the Subject Name section, select Common Name from the Type drop-down list.
- Enter the SQL server’s fully qualified domain name (FQDN) or the alias name of the SQL cluster in the Value field.
- Click Add.
- In the Alternative name section, select DNS from the Type drop-down list.
- Enter the SQL server’s fully qualified domain name (FQDN) or the alias name of the SQL cluster in the Value field.
- Click Add.
- [OPTIONAL] Enter the SQL server’s single-label hostname in the Value field.
Note: Adding the single-label hostname to the Subject Alternative Name list allows administrators or applications to connect to the SQL server using its short name (NetBIOS name) without resulting in a subject name mismatch error.
- Click Add.
- Click Ok.
- Click Enroll. The status should indicate that enrollment is pending.
- Click Finish.
Approve Certificate
Once the certificate request is made, the request must now be approved. On an issuing certification authority (CA), or an administrative workstation with the Remote Server Administration Tools (RSAT) installed, open the Certification Authority management console (certsrv.msc) and perform the following steps.
- Expand the CA.
- Select Pending Requests.
- Note the request ID for the pending request. After approval, the request ID will be required later to retrieve the certificate.
- Right-click the pending request and choose All Tasks > Issue.
Important Note: I am performing the above tasks in a test lab environment. On a properly configured CA in a production environment, the requestor should not be able to approve their own request. In your environment, you may need to request that a CA administrator review and approve your request.
Install Certificate
Once the certificate has been approved and issued, open an elevated PowerShell or command window on the SQL server and perform the following steps.
- Enter certreq.exe -retrieve <request ID>.
- Select the CA where the certificate was issued.
- Click Ok.
- Select a location and enter a name for the file in the File name field.
- Click Save.
- Enter certreq.exe -accept <path to certificate file>.
Configure Certificate
Once the certificate has been enrolled on the SQL server, expand Personal > Certificates and refresh the view to confirm certificate enrollment. Next, perform the following steps.
- Right-click the SQL server certificate and choose All Tasks > Manage Private Keys.
- Click Add.
- Enter the name of the SQL server domain service account and click Check Names.
- If using the default SQL server service account, perform the following steps.
- Click on Locations.
- Select the local server.
- Click Ok.
- Enter NT Service\MSSQLSERVER and click Check Names.
- Click Ok.
- Uncheck Full control. The only permission required is Read.
- Click Ok.
SQL Configuration
Next, the new certificate must be assigned to the SQL Server service. Open the SQL Server Configuration Manager (sqlservermanager16.msc) and perform the following steps.
- Expand SQL Server Network Configuration.
- Right-click Protocols for MSSQLSERVER and choose Properties.
- Select the Certificate tab.
- Select the new certificate from the Certificate drop-down list.
- Select the Flags tab.
- Select Yes next to Force Strict Encryption.
- Click Ok.
Restart the SQL Server service for the changes to take effect.
Important Note: Selecting Force Strict Encryption will force encryption and certificate validation for all clients connecting to the SQL server. It will override any settings to bypass encryption or certificate checks. Force Strict Encryption may not be compatible with older applications or drivers. Please test thoroughly before enabling this setting.
Video
I’ve published a demonstration video for configuring TLS on Microsoft SQL Server 2022 on YouTube. You can find the video here.
Summary
After completing the configuration steps above, administrators can be assured that all communication between clients and the SQL server is fully protected with TLS using modern cryptography and their enterprise-managed certificate. With TLS enabled for SQL server communication, security is enhanced by encrypting data in transit, ensuring authentication, and protecting sensitive information from interception. In addition, this configuration helps meet compliance requirements.