|
| 1 | +--- |
| 2 | +title: Turn on transparent data encryption in Azure Arc-enabled SQL Managed Instance (preview) |
| 3 | +description: How-to guide to turn on transparent data encryption in an Azure Arc-enabled SQL Managed Instance (preview) |
| 4 | +author: GuptaSeattle |
| 5 | +ms.author: guptapra |
| 6 | +services: azure-arc |
| 7 | +ms.service: azure-arc |
| 8 | +ms.subservice: azure-arc-data-sqlmi |
| 9 | +ms.reviewer: mikeray |
| 10 | +ms.topic: how-to |
| 11 | +ms.date: 01/20/2023 |
| 12 | +ms.custom: template-how-to, event-tier1-build-2022 |
| 13 | +--- |
| 14 | + |
| 15 | +# Enable transparent data encryption on Azure Arc-enabled SQL Managed Instance (preview) |
| 16 | + |
| 17 | +This article describes how to enable and disable transparent data encryption (TDE) at-rest on an Azure Arc-enabled SQL Managed Instance. In this article, the term *managed instance* refers to a deployment of Azure Arc-enabled SQL Managed Instance and enabling/disabling TDE will apply to all databases running on a managed instance. |
| 18 | + |
| 19 | +Enabling service-managed transparent data encryption will require the managed instance to use a service-managed database master key as well as the service-managed server certificate. These credentials will be automatically created when service-managed transparent data encryption is enabled. For more info on TDE, please refer to [Transparent data encryption](/sql/relational-databases/security/encryption/transparent-data-encryption). |
| 20 | + |
| 21 | + |
| 22 | +Turning on the TDE feature does the following: |
| 23 | + |
| 24 | +- All existing databases will now be automatically encrypted. |
| 25 | +- All newly created databases will get automatically encrypted. |
| 26 | + |
| 27 | +[!INCLUDE [azure-arc-data-preview](../../../includes/azure-arc-data-preview.md)] |
| 28 | + |
| 29 | +## Prerequisites |
| 30 | + |
| 31 | +Before you proceed with this article, you must have an Azure Arc-enabled SQL Managed Instance resource created and connect to it. |
| 32 | + |
| 33 | +- [An Azure Arc-enabled SQL Managed Instance created](./create-sql-managed-instance.md) |
| 34 | +- [Connect to Azure Arc-enabled SQL Managed Instance](./connect-managed-instance.md) |
| 35 | + |
| 36 | +## Limitations |
| 37 | + |
| 38 | +The following limitations must be considered when deploying Service-Managed TDE: |
| 39 | + |
| 40 | +- Only General Purpose Tier is supported. |
| 41 | +- Failover Groups are not supported. |
| 42 | + |
| 43 | +## Turn on transparent data encryption on the managed instance |
| 44 | +### Prerequisites |
| 45 | + |
| 46 | +Turning on TDE on the managed instance will result in the following operations taking place: |
| 47 | + |
| 48 | +1. Adding the service-managed database master key in the `master` database. |
| 49 | +2. Adding the service-managed certificate protector. |
| 50 | +3. Adding the associated Database Encryption Keys (DEK) on all databases on the managed instance. |
| 51 | +4. Enabling encryption on all databases on the managed instance. |
| 52 | + |
| 53 | +### [Service-managed mode](#tab/service-managed-mode) |
| 54 | + |
| 55 | +Run kubectl patch to enable service-managed TDE |
| 56 | + |
| 57 | +```console |
| 58 | +kubectl patch sqlmi <sqlmi-name> --namespace <namespace> --type merge --patch '{ "spec": { "security": { "transparentDataEncryption": { "mode": "ServiceManaged" } } } }' |
| 59 | +``` |
| 60 | + |
| 61 | +Example: |
| 62 | + |
| 63 | +```console |
| 64 | +kubectl patch sqlmi contososqlmi --namespace arc --type merge --patch '{ "spec": { "security": { "transparentDataEncryption": { "mode": "ServiceManaged" } } } }' |
| 65 | +``` |
| 66 | +--- |
| 67 | + |
| 68 | +## Turn off transparent data encryption on the managed instance |
| 69 | + |
| 70 | +Turning off TDE on the managed instance will result in the following operations taking place: |
| 71 | + |
| 72 | +1. Disabling encryption on all databases on the managed instance. |
| 73 | +2. Dropping the associated DEKs on all databases on the managed instance. |
| 74 | +3. Dropping the service-managed certificate protector. |
| 75 | +4. Dropping the service-managed database master key in the `master` database. |
| 76 | + |
| 77 | +### [Service-managed mode](#tab/service-managed-mode) |
| 78 | + |
| 79 | +Run kubectl patch to disable service-managed TDE |
| 80 | + |
| 81 | +```console |
| 82 | +kubectl patch sqlmi <sqlmi-name> --namespace <namespace> --type merge --patch '{ "spec": { "security": { "transparentDataEncryption": { "mode": null } } } }' |
| 83 | +``` |
| 84 | + |
| 85 | +Example: |
| 86 | +```console |
| 87 | +kubectl patch sqlmi contososqlmi --namespace arc --type merge --patch '{ "spec": { "security": { "transparentDataEncryption": { "mode": null } } } }' |
| 88 | +``` |
| 89 | +--- |
| 90 | + |
| 91 | +## Back up a transparent data encryption credential |
| 92 | + |
| 93 | +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: |
| 94 | + |
| 95 | +> [!NOTE] |
| 96 | +> 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. |
| 97 | +
|
| 98 | +1. Back up the certificate from the container to `/var/opt/mssql/data`. |
| 99 | + |
| 100 | + ```sql |
| 101 | + USE master; |
| 102 | + GO |
| 103 | + |
| 104 | + BACKUP CERTIFICATE <cert-name> TO FILE = '<cert-path>' |
| 105 | + WITH PRIVATE KEY ( FILE = '<private-key-path>', |
| 106 | + ENCRYPTION BY PASSWORD = '<UseStrongPasswordHere>'); |
| 107 | + ``` |
| 108 | + |
| 109 | + Example: |
| 110 | + |
| 111 | + ```sql |
| 112 | + USE master; |
| 113 | + GO |
| 114 | + |
| 115 | + BACKUP CERTIFICATE MyServerCert TO FILE = '/var/opt/mssql/data/servercert.crt' |
| 116 | + WITH PRIVATE KEY ( FILE = '/var/opt/mssql/data/servercert.key', |
| 117 | + ENCRYPTION BY PASSWORD = '<UseStrongPasswordHere>'); |
| 118 | + ``` |
| 119 | + |
| 120 | +2. Copy the certificate from the container to your file system. |
| 121 | + |
| 122 | + ### [Windows](#tab/windows) |
| 123 | + |
| 124 | + ```console |
| 125 | + kubectl exec -n <namespace> -c arc-sqlmi <pod-name> -- cat <pod-certificate-path> > <local-certificate-path> |
| 126 | + ``` |
| 127 | + |
| 128 | + Example: |
| 129 | + |
| 130 | + ```console |
| 131 | + kubectl exec -n arc-ns -c arc-sqlmi sql-0 -- cat /var/opt/mssql/data/servercert.crt > $HOME\sqlcerts\servercert.crt |
| 132 | + ``` |
| 133 | + |
| 134 | + ### [Linux](#tab/linux) |
| 135 | + ```console |
| 136 | + kubectl cp --namespace <namespace> --container arc-sqlmi <pod-name>:<pod-certificate-path> <local-certificate-path> |
| 137 | + ``` |
| 138 | + |
| 139 | + Example: |
| 140 | + |
| 141 | + ```console |
| 142 | + kubectl cp --namespace arc-ns --container arc-sqlmi sql-0:/var/opt/mssql/data/servercert.crt $HOME/sqlcerts/servercert.crt |
| 143 | + ``` |
| 144 | + --- |
| 145 | + |
| 146 | +3. Copy the private key from the container to your file system. |
| 147 | + |
| 148 | + ### [Windows](#tab/windows) |
| 149 | + ```console |
| 150 | + kubectl exec -n <namespace> -c arc-sqlmi <pod-name> -- cat <pod-private-key-path> > <local-private-key-path> |
| 151 | + ``` |
| 152 | + |
| 153 | + Example: |
| 154 | + |
| 155 | + ```console |
| 156 | + kubectl exec -n arc-ns -c arc-sqlmi sql-0 -- cat /var/opt/mssql/data/servercert.key > $HOME\sqlcerts\servercert.key |
| 157 | + ``` |
| 158 | + |
| 159 | + ### [Linux](#tab/linux) |
| 160 | + ```console |
| 161 | + kubectl cp --namespace <namespace> --container arc-sqlmi <pod-name>:<pod-private-key-path> <local-private-key-path> |
| 162 | + ``` |
| 163 | + |
| 164 | + Example: |
| 165 | + |
| 166 | + ```console |
| 167 | + kubectl cp --namespace arc-ns --container arc-sqlmi sql-0:/var/opt/mssql/data/servercert.key $HOME/sqlcerts/servercert.key |
| 168 | + ``` |
| 169 | + --- |
| 170 | + |
| 171 | +4. Delete the certificate and private key from the container. |
| 172 | + |
| 173 | + ```console |
| 174 | + kubectl exec -it --namespace <namespace> --container arc-sqlmi <pod-name> -- bash -c "rm <certificate-path> <private-key-path> |
| 175 | + ``` |
| 176 | + |
| 177 | + Example: |
| 178 | + |
| 179 | + ```console |
| 180 | + 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" |
| 181 | + ``` |
| 182 | + |
| 183 | +## Restore a transparent data encryption credential to a managed instance |
| 184 | + |
| 185 | +Similar to above, to restore the credentials, copy them into the container and run the corresponding T-SQL afterwards. |
| 186 | + |
| 187 | + |
| 188 | +> [!NOTE] |
| 189 | +> 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. |
| 190 | +> 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. |
| 191 | +
|
| 192 | +1. Copy the certificate from your file system to the container. |
| 193 | + ### [Windows](#tab/windows) |
| 194 | + ```console |
| 195 | + type <local-certificate-path> | kubectl exec -i -n <namespace> -c arc-sqlmi <pod-name> -- tee <pod-certificate-path> |
| 196 | + ``` |
| 197 | + |
| 198 | + Example: |
| 199 | + |
| 200 | + ```console |
| 201 | + type $HOME\sqlcerts\servercert.crt | kubectl exec -i -n arc-ns -c arc-sqlmi sql-0 -- tee /var/opt/mssql/data/servercert.crt |
| 202 | + ``` |
| 203 | + |
| 204 | + ### [Linux](#tab/linux) |
| 205 | + ```console |
| 206 | + kubectl cp --namespace <namespace> --container arc-sqlmi <local-certificate-path> <pod-name>:<pod-certificate-path> |
| 207 | + ``` |
| 208 | + |
| 209 | + Example: |
| 210 | + |
| 211 | + ```console |
| 212 | + kubectl cp --namespace arc-ns --container arc-sqlmi $HOME/sqlcerts/servercert.crt sql-0:/var/opt/mssql/data/servercert.crt |
| 213 | + ``` |
| 214 | + --- |
| 215 | + |
| 216 | +2. Copy the private key from your file system to the container. |
| 217 | + ### [Windows](#tab/windows) |
| 218 | + ```console |
| 219 | + type <local-private-key-path> | kubectl exec -i -n <namespace> -c arc-sqlmi <pod-name> -- tee <pod-private-key-path> |
| 220 | + ``` |
| 221 | + |
| 222 | + Example: |
| 223 | + |
| 224 | + ```console |
| 225 | + type $HOME\sqlcerts\servercert.key | kubectl exec -i -n arc-ns -c arc-sqlmi sql-0 -- tee /var/opt/mssql/data/servercert.key |
| 226 | + ``` |
| 227 | + |
| 228 | + ### [Linux](#tab/linux) |
| 229 | + ```console |
| 230 | + kubectl cp --namespace <namespace> --container arc-sqlmi <local-private-key-path> <pod-name>:<pod-private-key-path> |
| 231 | + ``` |
| 232 | + |
| 233 | + Example: |
| 234 | + |
| 235 | + ```console |
| 236 | + kubectl cp --namespace arc-ns --container arc-sqlmi $HOME/sqlcerts/servercert.key sql-0:/var/opt/mssql/data/servercert.key |
| 237 | + ``` |
| 238 | + --- |
| 239 | + |
| 240 | +3. Create the certificate using file paths from `/var/opt/mssql/data`. |
| 241 | + |
| 242 | + ```sql |
| 243 | + USE master; |
| 244 | + GO |
| 245 | + |
| 246 | + CREATE CERTIFICATE <certicate-name> |
| 247 | + FROM FILE = '<certificate-path>' |
| 248 | + WITH PRIVATE KEY ( FILE = '<private-key-path>', |
| 249 | + DECRYPTION BY PASSWORD = '<UseStrongPasswordHere>' ); |
| 250 | + ``` |
| 251 | + |
| 252 | + Example: |
| 253 | + |
| 254 | + ```sql |
| 255 | + USE master; |
| 256 | + GO |
| 257 | + |
| 258 | + CREATE CERTIFICATE MyServerCertRestored |
| 259 | + FROM FILE = '/var/opt/mssql/data/servercert.crt' |
| 260 | + WITH PRIVATE KEY ( FILE = '/var/opt/mssql/data/servercert.key', |
| 261 | + DECRYPTION BY PASSWORD = '<UseStrongPasswordHere>' ); |
| 262 | + ``` |
| 263 | + |
| 264 | +4. Delete the certificate and private key from the container. |
| 265 | + |
| 266 | + ```console |
| 267 | + kubectl exec -it --namespace <namespace> --container arc-sqlmi <pod-name> -- bash -c "rm <certificate-path> <private-key-path> |
| 268 | + ``` |
| 269 | + |
| 270 | + Example: |
| 271 | + |
| 272 | + ```console |
| 273 | + 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" |
| 274 | + ``` |
| 275 | + |
| 276 | +## Next steps |
| 277 | + |
| 278 | +[Transparent data encryption](/sql/relational-databases/security/encryption/transparent-data-encryption) |
0 commit comments