If you’re ever planning to allow external connections to a SQL Server, one of the first things to ensure is that the data is encrypted at rest and in transit.
SQL Server has an option where we can force all connections on a SQL Server to be encrypted, which ensures us that we’re achieving encryption for our SQL connectivity.
This post follows Microsoft Docs – Enable Encrypted Connections to the Database engine. It’s quite a complex piece so a full read of this would be necessary before planning this change.
The certificate must be issued for Server Authentication. The name of the certificate must be the fully qualified domain name (FQDN) of the computer.
The above is a little note in amongst a bunch of pertinent info, found here; Microsoft Docs – Enable Encrypted Connections – Remarks
I’m using a New-SelfSignedCertificate for this tutorial and creating it with PowerShell.
Before running the following PowerShell script, amend .pfk output file location & DNS Names.
New-SelfSignedCertificate -DnsName lab-sql1.whyte.net -CertStoreLocation cert:\LocalMachine\My -FriendlyName lab-sql1-cert -KeySpec KeyExchange -NotAfter (get-date).AddYears(99) $thumbprint = $(Get-ChildItem Cert:\LocalMachine\My).thumbprint $Pwd = ConvertTo-SecureString -String "Str0ngePassword1!" -Force -AsPlainText Export-PfxCertificate -Cert "Cert:\LocalMachine\My\$thumbprint" -FilePath "C:\temp_certificates\lab-sql1pk.pfx" -Password $Pwd -Force
Open MMC and add the Certificates (Local Computer) Snap-in.
Expand Trusted Root Certification Authorities, right-click & select All Tasks > Import…
Navigate to the .pfx file.
Enter a password & continue.
Finish up the wizard.
Have a look at the new certificate within MMC.
Open SQL Server Configuration Manager, then right-click Protocols for MSSQLSERVER and select Properties.
Open the Certificate tab and you should be able to view & select the new certificate from the drop-down menu.
Click to Apply & Ok out of the window – I’m doing the Forcing of Encryption separate (below).
You’ll get this prompt.
Restart the SQL Services from the configuration manager. If your services don’t start back up again, then ensure the service accounts have the appropriate permissions. For this demo, my AD Service Accounts are members of the local Administrators group.
Right click Protocols for MSSQLSERVER, select Properties and within the Flags tab enable the Force Encryption option.
Restart the SQL Services.
Open a local and/or remote query session. You may have to ensure the Encrypt connection & Trust server certificate options are checked.
Now query sys.dm_exec_connections to check the encryption_option of all SQL connections.
SELECT * FROM sys.dm_exec_connections