Enable transparent data encryption on SQL Managed Instance enabled by Azure Arc (preview)
This article describes how to enable and disable transparent data encryption (TDE) at-rest on a SQL Managed Instance enabled by Azure Arc. In this article, the term managed instance refers to a deployment of SQL Managed Instance enabled by Azure Arc and enabling/disabling TDE will apply to all databases running on a managed instance.
For more info on TDE, please refer to Transparent data encryption.
Turning on the TDE feature does the following:
- All existing databases will now be automatically encrypted.
- All newly created databases will get automatically encrypted.
Note
As a preview feature, the technology presented in this article is subject to Supplemental Terms of Use for Microsoft Azure Previews.
The latest updates are available in the release notes.
Prerequisites
Before you proceed with this article, you must have a SQL Managed Instance enabled by Azure Arc resource created and connect to it.
- Create a SQL Managed Instance enabled by Azure Arc
- Connect to SQL Managed Instance enabled by Azure Arc
Limitations
The following limitations apply when you enable automatic TDE:
- Only General Purpose Tier is supported.
- Failover groups aren't supported.
Create a managed instance with TDE enabled (Azure CLI)
The following example creates a SQL Managed Instance enabled by Azure Arc with one replica, TDE enabled:
az sql mi-arc create --name sqlmi-tde --k8s-namespace arc --tde-mode ServiceManaged --use-k8s
Turn on TDE on the managed instance
When TDE is enabled on Arc-enabled SQL Managed Instance, the data service automatically does the following tasks:
- Adds the service-managed database master key in the
master
database. - Adds the service-managed certificate protector.
- Adds the associated Database Encryption Keys (DEK) on all databases on the managed instance.
- Enables encryption on all databases on the managed instance.
You can set SQL Managed Instance enabled by Azure Arc TDE in one of two modes:
- Service-managed
- Customer-managed
In service-managed mode, TDE requires the managed instance to use a service-managed database master key as well as the service-managed server certificate. These credentials are automatically created when service-managed TDE is enabled.
In customer-managed mode, TDE uses a service-managed database master key and uses keys you provide for the server certificate. To configure customer-managed mode:
- Create a certificate.
- Store the certificate as a secret in the same Kubernetes namespace as the instance.
Enable
The following section explains how to enable TDE in service-managed mode.
To enable TDE in service managed mode, run the following command:
az sql mi-arc update --tde-mode ServiceManaged
Turn off TDE on the managed instance
When TDE is disabled on Arc-enabled SQL Managed Instance, the data service automatically does the following tasks:
- Disables encryption on all databases on the managed instance.
- Drops the associated DEKs on all databases on the managed instance.
- Drops the service-managed certificate protector.
- Drops the service-managed database master key in the
master
database.
To disable TDE:
az sql mi-arc update --tde-mode Disabled
Back up a TDE credential
When you back up credentials from the managed instance, the credentials are stored within the container. To store credentials on a persistent volume, specify the mount path in the container. For example, var/opt/mssql/data
. The following example backs up a certificate from the managed instance:
Note
If the kubectl cp
command is run from Windows, the command may fail when using absolute Windows paths. Use relative paths or the commands specified below.
Back up the certificate from the container to
/var/opt/mssql/data
.USE master; GO BACKUP CERTIFICATE <cert-name> TO FILE = '<cert-path>' WITH PRIVATE KEY ( FILE = '<private-key-path>', ENCRYPTION BY PASSWORD = '<UseStrongPasswordHere>');
Example:
USE master; GO BACKUP CERTIFICATE MyServerCert TO FILE = '/var/opt/mssql/data/servercert.crt' WITH PRIVATE KEY ( FILE = '/var/opt/mssql/data/servercert.key', ENCRYPTION BY PASSWORD = '<UseStrongPasswordHere>');
Copy the certificate from the container to your file system.
Copy the private key from the container to your file system.
Delete the certificate and private key from the container.
kubectl exec -it --namespace <namespace> --container arc-sqlmi <pod-name> -- bash -c "rm <certificate-path> <private-key-path>
Example:
kubectl exec -it --namespace arc-ns --container arc-sqlmi sql-0 -- bash -c "rm /var/opt/mssql/data/servercert.crt /var/opt/mssql/data/servercert.key"
Restore a TDE credential to a managed instance
Similar to above, to restore the credentials, copy them into the container and run the corresponding T-SQL afterwards.
Note
If the kubectl cp
command is run from Windows, the command may fail when using absolute Windows paths. Use relative paths or the commands specified below.
To restore database backups that have been taken before enabling TDE, you would need to disable TDE on the SQL Managed Instance, restore the database backup and enable TDE again.
Copy the certificate from your file system to the container.
Copy the private key from your file system to the container.
Create the certificate using file paths from
/var/opt/mssql/data
.USE master; GO CREATE CERTIFICATE <certicate-name> FROM FILE = '<certificate-path>' WITH PRIVATE KEY ( FILE = '<private-key-path>', DECRYPTION BY PASSWORD = '<UseStrongPasswordHere>' );
Example:
USE master; GO CREATE CERTIFICATE MyServerCertRestored FROM FILE = '/var/opt/mssql/data/servercert.crt' WITH PRIVATE KEY ( FILE = '/var/opt/mssql/data/servercert.key', DECRYPTION BY PASSWORD = '<UseStrongPasswordHere>' );
Delete the certificate and private key from the container.
kubectl exec -it --namespace <namespace> --container arc-sqlmi <pod-name> -- bash -c "rm <certificate-path> <private-key-path>
Example:
kubectl exec -it --namespace arc-ns --container arc-sqlmi sql-0 -- bash -c "rm /var/opt/mssql/data/servercert.crt /var/opt/mssql/data/servercert.key"