Changes for page sql-tde

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

<
From version < 10.1 >
edited by Rudi Marais
on 2025/03/05 13:24
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
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.rudim
1 +XWiki.nikhils
Content
... ... @@ -1,33 +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 -[[image:image-20250305152543-1.png]]
10 +4 Choose DB to create the DEK ,Create database encryption key (DEK) with algorithm ( AES= 256) and encryption by certificate
10 10  
12 +5 Set encryption on for the database
11 11  
12 -**~1. Create a Master Key in the master Database**
13 -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.
14 14  
15 +6 Create credential with SAS token
15 15  
16 -**2. Create a TDE Certificate (Encrypted by the Master Key)**
17 -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.
18 -
19 -
20 -**3. Choose the Database to Create the Database Encryption Key (DEK)**
21 -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.
22 -
23 -
24 -**4. Enable Encryption for the Database**
25 -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.
26 -
27 -
28 -**5. Create a Credential with a SAS Token**
29 -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.
30 -
31 31  {{code language="sql"}}
32 32  drop credential [https://zagpebslab.blob.core.windows.net/sql-backups]
33 33  CREATE CREDENTIAL [https://zagpebslab.blob.core.windows.net/sql-backups]
... ... @@ -38,110 +38,95 @@
38 38  {{/code}}
39 39  
40 40  
41 -**~ 6. Use a Stored Procedure to Back Up to Azure Storage Account**
27 +7
42 42  
43 43  {{code language="sql"}}
44 44  EXECUTE dba.dbo.DatabaseBackup
45 -@Databases = 'dba',
46 -@URL = 'https://zagpebslab.blob.core.windows.net/sql-backups',
47 -@BackupType = 'Full',
48 -@CopyOnly = 'Y',
49 -@Compress = 'Y',
50 -@Verify = 'N'
31 + @Databases = @DatabaseName,
32 + @URL = @BackupContainerURL,
33 + @BackupType = 'Full',
34 + @CopyOnly = 'Y',
35 + @Compress = 'Y',
36 + @Verify = 'N';
51 51  {{/code}}
52 52  
53 -=== ===
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)
54 54  
55 -=== 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
56 56  
57 -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**.
58 58  
59 -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>
60 60  
61 61  
62 62  
63 63  
64 64  
65 -= **2. Enabling Transparent Data Encryption (TDE) Using Azure Key Vault** =
50 += **Using TDE directly from azure portal** =
66 66  
67 67  
68 -**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 =====
69 69  
70 70  
71 -===== **1. Generate a Key in Azure Key Vault** =====
56 +- Go to keys and click generate
72 72  
58 +- Name your key (mysqlmikey)
73 73  
74 -**- Navigate to Azure Key Vault:**
60 +- Choose a key type (RSA)
75 75  
76 -* Go to the **Azure Portal** and select **Key Vault** (DemoRudiTest).
62 +-Choose RSA key size (2048-bit)
77 77  
78 -**- Generate a New Key:**
64 +Note:
79 79  
80 -* Go to the **Keys** section and click **Generate** to create a new key.
81 -
82 -**- Configure Key Settings:**
83 -
84 -* **Name the Key**: Choose a name for your key, e.g., mysqlmikey.
85 -* **Key Type**: Select **RSA** as the key type.
86 -* **RSA Key Size**: Choose an **RSA key size** of **2048-bit**. (optional)
87 -
88 - Note:
89 -
90 90  * 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.
91 91  * **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.).
92 92  * 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.
93 93  
94 -**- Create the Key:**
70 +- Click create
95 95  
96 -* Click **Create** to generate the key.
97 97  
73 +[[image:image-20250228120622-1.png||height="236" width="542"]]
98 98  
99 99  
100 -===== **2. Enable TDE on the SQL Managed Instance** =====
76 +===== 2 Enable TDE =====
101 101  
102 -===== =====
103 103  
104 -**- Navigate to Your Managed Instance:**
79 +- Go to your Managed instance ( sqlmi-ebs-lab)
105 105  
106 -* Go to your **SQL Managed Instance** (sqlmi-ebs-lab).
81 +- Click on security and choose Transparent data encryption
107 107  
108 -**- Enable Transparent Data Encryption (TDE):**
83 +- Select the type of managed key ( Customer-managed key0
109 109  
110 -* Under **Security**, select **Transparent Data Encryption**.
85 +- Select the key from the key vault we generated in the key vault( mysqlmikey)
111 111  
112 -**- Configure TDE with a Customer-Managed Key (CMK):**
87 +- Make the key the default TDE protector
113 113  
114 -* Select **Customer-managed key** as the encryption type.
115 -* Choose the key you created earlier from **Azure Key Vault** (mysqlmikey).
89 +-Click save
116 116  
117 117  
118 -**- Set the Key as Default TDE Protector:**
92 +[[image:image-20250228122106-2.png||height="19" width="241"]]
119 119  
120 -* Make the key the **default TDE protector** for your instance.
121 121  
122 -**- Save Configuration:**
95 +- TDE has now been enabled on the Managed instance
123 123  
124 -* Click **Save** to apply the changes.
125 125  
98 +Conclusion: All the databases have been encrypted by an asymmetric key. The key is the same for each database ( same encryption thumbprint).
126 126  
127 -=== **Conclusion** ===
100 +We are now able to backup databases from SSMS to Azure storage.
128 128  
129 -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**.
130 130  
131 -This process ensures that your data is protected both at rest and during backup, offering enhanced security for your managed databases in the cloud.
132 132  
104 +=== Backup specific databases using SQL server agent jobs ===
133 133  
134 134  
135 -=== **1. Backup Specific Databases Using SQL Server Agent Jobs** ===
107 +we are creating a job to automatically backup only the DBA databases in the instance via the SQL server agent.
136 136  
137 -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.
109 +The backup will be done daily at 3am. The backups will be backed up in the Azure storage account.
138 138  
139 -----
140 140  
141 -==== **1. Create the Backup Script** ====
112 +1 Create the script
142 142  
143 143  
144 -====== **- Declaring Variables** ======
115 +=== **1. Declaring Variables** ===
145 145  
146 146  {{code language="sql"}}
147 147  DECLARE @DatabaseName NVARCHAR(128)
... ... @@ -155,7 +155,7 @@
155 155  
156 156  ----
157 157  
158 -====== **2. Setting the Azure Blob Storage URL** ======
129 +=== **2. Setting the Azure Blob Storage URL** ===
159 159  
160 160  {{code language="sql"}}
161 161  SET @BackupContainerURL = 'https://<your_storage_account>.blob.core.windows.net/sql-backups/'
... ... @@ -164,7 +164,7 @@
164 164  
165 165  ----
166 166  
167 -====== **3. Declaring the Cursor** ======
138 +=== **3. Declaring the Cursor** ===
168 168  
169 169  
170 170  {{code language="sql"}}
... ... @@ -181,7 +181,7 @@
181 181  
182 182  ----
183 183  
184 -====== **4. Opening the Cursor** ======
155 +=== **4. Opening the Cursor** ===
185 185  
186 186  {{code language="sql"}}
187 187  OPEN db_cursor
... ... @@ -195,7 +195,7 @@
195 195  
196 196  ----
197 197  
198 -====== **5. Looping Through Databases** ======
169 +=== **5. Looping Through Databases** ===
199 199  
200 200  {{code language="sql"}}
201 201  -- Loop through each database and execute the stored procedure
... ... @@ -233,7 +233,7 @@
233 233  
234 234  ----
235 235  
236 -====== **6. Fetch the Next Database** ======
207 +=== **6. Fetch the Next Database** ===
237 237  
238 238  {{code language="sql"}}
239 239   -- Fetch the next database in the cursor
... ... @@ -247,7 +247,7 @@
247 247  
248 248  ----
249 249  
250 -====== **7. Closing and Deallocating the Cursor** ======
221 +=== **7. Closing and Deallocating the Cursor** ===
251 251  
252 252  {{code language="sql"}}
253 253  -- Close and deallocate the cursor to clean up resources
... ... @@ -260,9 +260,8 @@
260 260  * **CLOSE db_cursor**: This closes the cursor once the loop finishes processing all databases.
261 261  * **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.
262 262  
263 -====== ======
264 264  
265 -====== **8. Full Script** ======
235 +===== 8. Full Script =====
266 266  
267 267  
268 268  {{code language="sql"}}
... ... @@ -301,84 +301,54 @@
301 301  {{/code}}
302 302  
303 303  
274 +=== 2. Set up a new job ===
304 304  
305 305  
306 -=== **2. Set Up a New Job in SQL Server Agent** ===
277 +- Go to SSMS and click on SQL Server Agent
307 307  
308 -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
309 309  
310 -----
311 311  
312 -====== **Step 1: Create a New Job** ======
282 +====== General: ======
313 313  
314 -1. **Open SQL Server Management Studio (SSMS)**:
315 -1*. In the **Object Explorer**, expand the **SQL Server Agent** node.
316 -1*. Right-click on **Jobs** and select **New Job**.
284 +- Enter Job name (DBA databases backup)
317 317  
318 -----
286 +-  Owner (ebssqladmin)
319 319  
320 -====== **Step 2: Define Job Properties** ======
288 + Category (Database maintenance)
321 321  
322 -In the **New Job** window, configure the job properties:
290 + - Description (Description of the job)
323 323  
324 -* **General Tab**:
325 -** **Job Name**: Enter a descriptive name for the job, such as DBA Databases Backup.
326 -** **Owner**: Specify the job owner (ebssqladmin).
327 -** **Category**: Select Database Maintenance as the category for the job.
328 -** **Description**: Provide a brief description of the job (Automated backup of DBA databases to Azure Storage").
329 329  
330 -----
293 +====== Steps: Create the steps for the job to follow ======
331 331  
332 -====== **Step 3: Create the Job Steps** ======
295 + - Step name (Backup only DBA database)
333 333  
334 -The job will perform the backup through **Transact-SQL** (T-SQL) commands. Set up the following steps:
297 + - Type (Transact-SQL script)
335 335  
336 -1. **Step Name**: Enter a descriptive step name, such as Backup Only DBA Databases.
337 -1. **Type**: Select Transact-SQL Script (T-SQL).
338 -1. **Database**: Choose the master database, as the script will be run in the context of the master database.
339 -1. **Command**: Paste the backup script you created earlier, which automates the backup of the DBA databases.
299 + - Database (master)
340 340  
341 -----
301 + - Command (paste the script we created)
342 342  
343 -====== **Step 4: Set the Job Schedule** ======
344 344  
345 -Now, configure the schedule for the job to run daily at 3:00 AM:
304 + Schedule: Create a schedule for the job to run
346 346  
347 -1. **Schedule Name**: Name the schedule (DBA Database Backup).
348 -1. **Schedule Type**: Choose Recurring for a regular schedule.
349 -1. (((
350 -**Frequency**:
306 + - Name (DBA database backup)
351 351  
352 -* **Occurs**: Select Daily.
353 -* **Recurs Every**: Set it to **1 day** to run the job every day at the same time.
354 -)))
355 -1. (((
356 -**Daily Frequency**:
308 + - Schedule Type (recurring)
357 357  
358 -* Set the **time** for the backup to start, such as **3:00 AM**.
359 -)))
310 + - Frequency (Occurs: Daily)
360 360  
361 -----
312 + (Recurs every: 1 day(s))
362 362  
363 -=== **Conclusion** ===
364 364  
365 -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.
366 366  
367 -=== ===
368 368  
369 -===== Note: We could use the job activity monitor to see if the job executed successfully. =====
370 370  
371 371  
372 372  
373 373  
374 374  
375 -
376 -
377 -
378 -
379 -
380 -
381 -
382 382  1 CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'YourStrongPasswordHere!';
383 383  GO
384 384  
... ... @@ -676,3 +676,4 @@
676 676  
677 677  
678 678  
619 +
image-20250305152543-1.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.rudim
Size
... ... @@ -1,1 +1,0 @@
1 -19.6 KB
Content

Need help?

If you need help with XWiki you can contact: