Changes for page sql-tde

Last modified by Nikhil Singh on 2026/07/03 08:32

<
From version < 9.1 >
edited by Nikhil Singh
on 2025/02/28 13:57
To version < 8.1 >
edited by Nikhil Singh
on 2025/02/28 12:42
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,30 +1,19 @@
1 -= **1. Steps for Implementing Transparent Data Encryption (TDE) FROM SQL Server** =
1 += TDE(backup from smss to azure) =
2 2  
3 3  
4 -This document outlines the process of **encrypting SQL Server databases** using **Transparent Data Encryption (TDE)** and backing them up to **Azure Storage**. TDE ensures data at rest is encrypted, leveraging a **Master Key (MK)**, **TDE Certificate**, and **Database Encryption Key (DEK)** for encryption.
4 +1 Create master key in master database (set master key)
5 5  
6 -The process also includes creating a **credential** for secure backup to **Azure Blob Storage**, providing a scalable and secure solution for storing encrypted databases in the cloud.
6 +2 Create TDE certificate (encrypted by MK)
7 7  
8 +3 Backup the Certificate and private key, By encryption with a password ( did not do it in this case due to storage blog problems)
8 8  
9 -**~1. Create a Master Key in the master Database**
10 -The first step is to create a **Master Key** in the master database. This key will be used to encrypt other cryptographic objects, such as certificates and symmetric keys, within SQL Server.
10 +4 Choose DB to create the DEK ,Create database encryption key (DEK) with algorithm ( AES= 256) and encryption by certificate
11 11  
12 +5 Set encryption on for the database
12 12  
13 -**2. Create a TDE Certificate (Encrypted by the Master Key)**
14 -Next, generate a **TDE certificate** that will be used to encrypt the **Database Encryption Key (DEK)**. This certificate is encrypted by the **Master Key** created in step 1, providing an additional layer of security.
15 15  
15 +6 Create credential with SAS token
16 16  
17 -**3. Choose the Database to Create the Database Encryption Key (DEK)**
18 -For the selected database, create the **Database Encryption Key (DEK)**. The DEK will be encrypted by the **TDE certificate** and will use the **AES-256 encryption algorithm** to ensure data is securely encrypted at rest.
19 -
20 -
21 -**4. Enable Encryption for the Database**
22 -Once the **DEK** has been created, enable **TDE** for the database. This ensures that all data written to the database is automatically encrypted at rest, providing full protection for sensitive information.
23 -
24 -
25 -**5. Create a Credential with a SAS Token**
26 -Finally, create a **credential** that allows SQL Server to access Azure Blob Storage. This credential is created using a **Shared Access Signature (SAS) token**, which ensures secure and authenticated access to the storage account for backup purposes.
27 -
28 28  {{code language="sql"}}
29 29  drop credential [https://zagpebslab.blob.core.windows.net/sql-backups]
30 30  CREATE CREDENTIAL [https://zagpebslab.blob.core.windows.net/sql-backups]
... ... @@ -35,120 +35,96 @@
35 35  {{/code}}
36 36  
37 37  
38 -**~ 6. Use a Stored Procedure to Back Up to Azure Storage Account**
27 +7
39 39  
40 40  {{code language="sql"}}
41 41  EXECUTE dba.dbo.DatabaseBackup
42 -@Databases = 'dba',
43 -@URL = 'https://zagpebslab.blob.core.windows.net/sql-backups',
44 -@BackupType = 'Full',
45 -@CopyOnly = 'Y',
46 -@Compress = 'Y',
47 -@Verify = 'N'
31 + @Databases = @DatabaseName,
32 + @URL = @BackupContainerURL,
33 + @BackupType = 'Full',
34 + @CopyOnly = 'Y',
35 + @Compress = 'Y',
36 + @Verify = 'N';
48 48  {{/code}}
49 49  
50 -=== ===
39 +The backup was unable to be done from smss to azure ( the MI does not support encrypted DBs to be backed up from smss to azure)
51 51  
52 -=== Conclusion: Backup to Azure Storage Account with TDE Encrypted Databases ===
41 +We have unencrypted a database and backed it up from ssms to azure blob successfully
53 53  
54 -The attempt to back up an **encrypted database** (with Transparent Data Encryption - TDE) from **SQL Server Management Studio (SSMS)** to an Azure Storage Account was unsuccessful. This issue arises because **Azure does not permit TDE-encrypted databases to be backed up directly to Azure Storage using SSMS**.
55 55  
56 -However, after decrypting the database, we were able to successfully back it up to the Azure Storage Account via SSMS. This confirms that **backups can be performed on an unencrypted database**, but **not on an encrypted database**.
44 +Conclusion: Can be done with and unencrypted DB but not with an Encrypted one>
57 57  
58 58  
59 59  
60 60  
61 61  
62 -= **2. Enabling Transparent Data Encryption (TDE) Using Azure Key Vault** =
50 += **Using TDE directly from azure portal** =
63 63  
64 64  
65 -**Introduction:** This document outlines the process of enabling **Transparent Data Encryption (TDE)** on an **Azure SQL Managed Instance (SQL MI)** using a **Customer-Managed Key (CMK)** stored in **Azure Key Vault**. The encryption is managed using an asymmetric key from **Azure Key Vault**, ensuring that all data within the SQL Managed Instance is encrypted using a strong encryption algorithm.
53 +===== 1 Go to azure key vault ( DemoTestRudi) to generate a key =====
66 66  
67 67  
68 -===== **1. Generate a Key in Azure Key Vault** =====
56 +- Go to keys and click generate
69 69  
58 +- Name your key (mysqlmikey)
70 70  
71 -**- Navigate to Azure Key Vault:**
60 +- Choose a key type (RSA)
72 72  
73 -* Go to the **Azure Portal** and select **Key Vault** (DemoRudiTest).
62 +-Choose RSA key size (2048-bit)
74 74  
64 +Note:
75 75  
76 -**- Generate a New Key:**
77 -
78 -* Go to the **Keys** section and click **Generate** to create a new key.
79 -
80 -
81 -**- Configure Key Settings:**
82 -
83 -* **Name the Key**: Choose a name for your key, e.g., mysqlmikey.
84 -* **Key Type**: Select **RSA** as the key type.
85 -* **RSA Key Size**: Choose an **RSA key size** of **2048-bit**. (optional)
86 -
87 - Note:
88 -
89 89  * switching from 2048-bit RSA to 4096-bit RSA for TDE will affect performance, but the actual impact might be minor, especially on modern hardware and typical workloads.
90 90  * **It will likely affect CPU usage** more than disk I/O, and the impact might be more noticeable during key management operations (key generation, encryption, etc.).
91 91  * If your database is not under heavy load and your hardware can handle the extra processing, the trade-off for better security may be worth it.
92 92  
70 +- Click create
93 93  
94 -**- Create the Key:**
95 95  
96 -* Click **Create** to generate the key.
73 +[[image:image-20250228120622-1.png||height="236" width="542"]]
97 97  
98 98  
76 +===== 2 Enable TDE =====
99 99  
100 100  
101 -===== **2. Enable TDE on the SQL Managed Instance** =====
79 +- Go to your Managed instance ( sqlmi-ebs-lab)
102 102  
103 -===== =====
81 +- Click on security and choose Transparent data encryption
104 104  
105 -**- Navigate to Your Managed Instance:**
83 +- Select the type of managed key ( Customer-managed key0
106 106  
107 -* Go to your **SQL Managed Instance** (sqlmi-ebs-lab).
85 +- Select the key from the key vault we generated in the key vault( mysqlmikey)
108 108  
87 +- Make the key the default TDE protector
109 109  
110 -**- Enable Transparent Data Encryption (TDE):**
89 +-Click save
111 111  
112 -* Under **Security**, select **Transparent Data Encryption**.
113 113  
92 +[[image:image-20250228122106-2.png||height="19" width="241"]]
114 114  
115 -**- Configure TDE with a Customer-Managed Key (CMK):**
116 116  
117 -* Select **Customer-managed key** as the encryption type.
118 -* Choose the key you created earlier from **Azure Key Vault** (mysqlmikey).
95 +- TDE has now been enabled on the Managed instance
119 119  
120 120  
98 +Conclusion: All the databases have been encrypted by an asymmetric key. The key is the same for each database ( same encryption thumbprint).
121 121  
122 -**- Set the Key as Default TDE Protector:**
100 +We are now able to backup databases from SSMS to Azure storage.
123 123  
124 -* Make the key the **default TDE protector** for your instance.
125 125  
126 126  
127 -**- Save Configuration:**
104 +=== Backup specific databases using SQL server agent jobs ===
128 128  
129 -* Click **Save** to apply the changes.
130 130  
107 +we are creating a job to automatically backup only the DBA databases in the instance via the SQL server agent.
131 131  
109 +The backup will be done daily at 3am. The backups will be backed up in the Azure storage account.
132 132  
133 -=== **Conclusion** ===
134 134  
135 -After following these steps, **TDE** has been successfully enabled on your **SQL Managed Instance** using an **asymmetric key** stored in **Azure Key Vault**. All databases within the instance are now encrypted using the same encryption key (identified by the same encryption thumbprint). You can now securely back up these encrypted databases from **SSMS** to **Azure Storage**.
112 +1 Create the script
136 136  
137 -This process ensures that your data is protected both at rest and during backup, offering enhanced security for your managed databases in the cloud.
138 138  
115 +=== **1. Declaring Variables** ===
139 139  
140 -
141 -=== **1. Backup Specific Databases Using SQL Server Agent Jobs** ===
142 -
143 -This document describes the process of creating an automated **SQL Server Agent Job** to back up only the **DBA databases** in a SQL Server instance. The backups will occur **daily at 3:00 AM** and will be stored in an **Azure Storage Account** for secure and reliable cloud storage.
144 -
145 -----
146 -
147 -==== **1. Create the Backup Script** ====
148 -
149 -
150 -====== **- Declaring Variables** ======
151 -
152 152  {{code language="sql"}}
153 153  DECLARE @DatabaseName NVARCHAR(128)
154 154  DECLARE @BackupContainerURL NVARCHAR(512)
... ... @@ -161,7 +161,7 @@
161 161  
162 162  ----
163 163  
164 -====== **2. Setting the Azure Blob Storage URL** ======
129 +=== **2. Setting the Azure Blob Storage URL** ===
165 165  
166 166  {{code language="sql"}}
167 167  SET @BackupContainerURL = 'https://<your_storage_account>.blob.core.windows.net/sql-backups/'
... ... @@ -170,7 +170,7 @@
170 170  
171 171  ----
172 172  
173 -====== **3. Declaring the Cursor** ======
138 +=== **3. Declaring the Cursor** ===
174 174  
175 175  
176 176  {{code language="sql"}}
... ... @@ -187,7 +187,7 @@
187 187  
188 188  ----
189 189  
190 -====== **4. Opening the Cursor** ======
155 +=== **4. Opening the Cursor** ===
191 191  
192 192  {{code language="sql"}}
193 193  OPEN db_cursor
... ... @@ -201,7 +201,7 @@
201 201  
202 202  ----
203 203  
204 -====== **5. Looping Through Databases** ======
169 +=== **5. Looping Through Databases** ===
205 205  
206 206  {{code language="sql"}}
207 207  -- Loop through each database and execute the stored procedure
... ... @@ -239,7 +239,7 @@
239 239  
240 240  ----
241 241  
242 -====== **6. Fetch the Next Database** ======
207 +=== **6. Fetch the Next Database** ===
243 243  
244 244  {{code language="sql"}}
245 245   -- Fetch the next database in the cursor
... ... @@ -253,7 +253,7 @@
253 253  
254 254  ----
255 255  
256 -====== **7. Closing and Deallocating the Cursor** ======
221 +=== **7. Closing and Deallocating the Cursor** ===
257 257  
258 258  {{code language="sql"}}
259 259  -- Close and deallocate the cursor to clean up resources
... ... @@ -266,10 +266,8 @@
266 266  * **CLOSE db_cursor**: This closes the cursor once the loop finishes processing all databases.
267 267  * **DEALLOCATE db_cursor**: This deallocates the cursor, freeing up any resources used by the cursor. It’s a good practice to always deallocate cursors to avoid resource leaks.
268 268  
269 -(% class="wikigeneratedid" %)
270 -====== ======
271 271  
272 -====== **8. Full Script** ======
235 +===== 8. Full Script =====
273 273  
274 274  
275 275  {{code language="sql"}}
... ... @@ -308,85 +308,54 @@
308 308  {{/code}}
309 309  
310 310  
274 +=== 2. Set up a new job ===
311 311  
312 312  
313 -=== **2. Set Up a New Job in SQL Server Agent** ===
277 +- Go to SSMS and click on SQL Server Agent
314 314  
315 -To automate the backup process of the **DBA databases**, follow the steps below to create a new job in SQL Server Agent.
279 + Drop down menu and left click jobs and select new job
316 316  
317 -----
318 318  
319 -====== **Step 1: Create a New Job** ======
282 +====== General: ======
320 320  
321 -1. **Open SQL Server Management Studio (SSMS)**:
322 -1*. In the **Object Explorer**, expand the **SQL Server Agent** node.
323 -1*. Right-click on **Jobs** and select **New Job**.
284 +- Enter Job name (DBA databases backup)
324 324  
325 -----
286 +-  Owner (ebssqladmin)
326 326  
327 -====== **Step 2: Define Job Properties** ======
288 + Category (Database maintenance)
328 328  
329 -In the **New Job** window, configure the job properties:
290 + - Description (Description of the job)
330 330  
331 -* **General Tab**:
332 -** **Job Name**: Enter a descriptive name for the job, such as DBA Databases Backup.
333 -** **Owner**: Specify the job owner (ebssqladmin).
334 -** **Category**: Select Database Maintenance as the category for the job.
335 -** **Description**: Provide a brief description of the job (Automated backup of DBA databases to Azure Storage").
336 336  
337 -----
293 +====== Steps: Create the steps for the job to follow ======
338 338  
339 -====== **Step 3: Create the Job Steps** ======
295 + - Step name (Backup only DBA database)
340 340  
341 -The job will perform the backup through **Transact-SQL** (T-SQL) commands. Set up the following steps:
297 + - Type (Transact-SQL script)
342 342  
343 -1. **Step Name**: Enter a descriptive step name, such as Backup Only DBA Databases.
344 -1. **Type**: Select Transact-SQL Script (T-SQL).
345 -1. **Database**: Choose the master database, as the script will be run in the context of the master database.
346 -1. **Command**: Paste the backup script you created earlier, which automates the backup of the DBA databases.
299 + - Database (master)
347 347  
348 -----
301 + - Command (paste the script we created)
349 349  
350 -====== **Step 4: Set the Job Schedule** ======
351 351  
352 -Now, configure the schedule for the job to run daily at 3:00 AM:
304 + Schedule: Create a schedule for the job to run
353 353  
354 -1. **Schedule Name**: Name the schedule (DBA Database Backup).
355 -1. **Schedule Type**: Choose Recurring for a regular schedule.
356 -1. (((
357 -**Frequency**:
306 + - Name (DBA database backup)
358 358  
359 -* **Occurs**: Select Daily.
360 -* **Recurs Every**: Set it to **1 day** to run the job every day at the same time.
361 -)))
362 -1. (((
363 -**Daily Frequency**:
308 + - Schedule Type (recurring)
364 364  
365 -* Set the **time** for the backup to start, such as **3:00 AM**.
366 -)))
310 + - Frequency (Occurs: Daily)
367 367  
368 -----
312 + (Recurs every: 1 day(s))
369 369  
370 -=== **Conclusion** ===
371 371  
372 -The SQL Server Agent job is now configured to automatically back up the **DBA databases** daily to an **Azure Storage Account**. The job will only back up databases that start with 'dba', and it handles encrypted databases with **Transparent Data Encryption (TDE)**. This ensures secure, encrypted backups are stored in the cloud without requiring manual intervention.
373 373  
374 -(% class="wikigeneratedid" %)
375 -=== ===
376 376  
377 -===== Note: We could use the job activity monitor to see if the job executed successfully. =====
378 378  
379 379  
380 380  
381 381  
382 382  
383 -
384 -
385 -
386 -
387 -
388 -
389 -
390 390  1 CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'YourStrongPasswordHere!';
391 391  GO
392 392  

Need help?

If you need help with XWiki you can contact: