Changes for page sql-tde
Last modified by Nikhil Singh on 2026/07/03 08:32
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Attachments (0 modified, 0 added, 1 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,33 +1,19 @@ 1 -= **1. StepsforImplementingTransparentData Encryption(TDE) FROM SQL Server**=1 += TDE(backup from smss to azure) = 2 2 3 3 4 - Thisdocument outlines the process of **encrypting SQL Server databases**using **TransparentData Encryption(TDE)** and backing them up to **Azure Storage**. TDE ensures data at rest is encrypted,leveraginga**MasterKey (MK)**, **TDE Certificate**, and**DatabaseEncryptionKey (DEK)** for encryption.4 +1 Create master key in master database (set master key) 5 5 6 - Theprocessalso includes creating a **credential**forsecurebackup to **Azure Blob Storage**, providing a scalableand secure solutionfor storing encrypteddatabasesin 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,108 +38,96 @@ 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 toAzureStorageAccount 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 backit up tothe Azure Storage AccountviaSSMS. This confirmsthat**backups canbe performedon anunencrypteddatabase**,but**notonanencrypteddatabase**.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 TransparentData Encryption(TDE) Using AzureKey Vault** =50 += **Using TDE directly from azure portal** = 66 66 67 67 68 - **Introduction:**Thisdocumentoutlines the processof enabling **Transparent Data Encryption (TDE)** on an **AzureSQL Managed Instance (SQL MI)** using a **Customer-Managed Key(CMK)** stored in **Azure Key Vault**.Theencryption ismanaged using an asymmetric key from **AzureKey Vault**, ensuringthat alldata withintheSQL Managed Instanceis encryptedusingastrongencryptionalgorithm.53 +===== 1 Go to azure key vault ( DemoTestRudi) to generate a key ===== 69 69 70 70 71 - =====**1.Generatea KeyinAzureKey Vault**=====56 +- Go to keys and click generate 72 72 58 +- Name your key (mysqlmikey) 73 73 74 - **-NavigatetoAzureKeyVault:**60 +- Choose a key type (RSA) 75 75 76 - * Gotothe**AzurePortal** andselect**Key Vault**(DemoRudiTest).62 +-Choose RSA key size (2048-bit) 77 77 78 - **- Generatea 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 - **- Createthe 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 -===== **2. Enable TDE on the SQL Managed Instance** ===== 100 100 101 -===== ===== 76 +===== 2 Enable TDE ===== 102 102 103 -**- Navigate to Your Managed Instance:** 104 104 105 - *Go to your**SQLManagedInstance**(sqlmi-ebs-lab).79 +- Go to your Managed instance ( sqlmi-ebs-lab) 106 106 107 - **-Enable TransparentDataEncryption(TDE):**81 +- Click on security and choose Transparent data encryption 108 108 109 - *Under **Security**,select**TransparentData Encryption**.83 +- Select the type of managed key ( Customer-managed key0 110 110 111 - **-ConfigureTDEwithaCustomer-ManagedKey (CMK):**85 +- Select the key from the key vault we generated in the key vault( mysqlmikey) 112 112 113 -* Select **Customer-managed key** as the encryption type. 114 -* Choose the key you created earlier from **Azure Key Vault** (mysqlmikey). 87 +- Make the key the default TDE protector 115 115 116 - **-Set the Key asDefault TDE Protector:**89 +-Click save 117 117 118 -* Make the key the **default TDE protector** for your instance. 119 119 120 - **- SaveConfiguration:**92 +[[image:image-20250228122106-2.png||height="19" width="241"]] 121 121 122 -* Click **Save** to apply the changes. 123 123 124 - ===**Conclusion**===95 +- TDE has now been enabled on the Managed instance 125 125 126 -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**. 127 127 128 - This process ensures thatyourdataisprotected bothatrestand during backup,offeringenhancedsecurityforyour manageddatabases in the cloud.98 +Conclusion: All the databases have been encrypted by an asymmetric key. The key is the same for each database ( same encryption thumbprint). 129 129 100 +We are now able to backup databases from SSMS to Azure storage. 130 130 131 131 132 -=== **1. Backup Specific Databases Using SQL Server Agent Jobs** === 133 133 134 - Thisdocumentdescribes theprocess ofcreating an automated **SQL Server Agent Job** to backup only the **DBAdatabases**inaSQLServerinstance. The backups will occur **daily at 3:00 AM** and will be stored in an **Azure StorageAccount**for secure and reliable cloudstorage.104 +=== Backup specific databases using SQL server agent jobs === 135 135 136 ----- 137 137 138 - ====**1.CreatetheBackupScript**====107 +we are creating a job to automatically backup only the DBA databases in the instance via the SQL server agent. 139 139 109 +The backup will be done daily at 3am. The backups will be backed up in the Azure storage account. 140 140 141 -====== **- Declaring Variables** ====== 142 142 112 +1 Create the script 113 + 114 + 115 +=== **1. Declaring Variables** === 116 + 143 143 {{code language="sql"}} 144 144 DECLARE @DatabaseName NVARCHAR(128) 145 145 DECLARE @BackupContainerURL NVARCHAR(512) ... ... @@ -152,7 +152,7 @@ 152 152 153 153 ---- 154 154 155 -=== ===**2. Setting the Azure Blob Storage URL** ======129 +=== **2. Setting the Azure Blob Storage URL** === 156 156 157 157 {{code language="sql"}} 158 158 SET @BackupContainerURL = 'https://<your_storage_account>.blob.core.windows.net/sql-backups/' ... ... @@ -161,7 +161,7 @@ 161 161 162 162 ---- 163 163 164 -=== ===**3. Declaring the Cursor** ======138 +=== **3. Declaring the Cursor** === 165 165 166 166 167 167 {{code language="sql"}} ... ... @@ -178,7 +178,7 @@ 178 178 179 179 ---- 180 180 181 -=== ===**4. Opening the Cursor** ======155 +=== **4. Opening the Cursor** === 182 182 183 183 {{code language="sql"}} 184 184 OPEN db_cursor ... ... @@ -192,7 +192,7 @@ 192 192 193 193 ---- 194 194 195 -=== ===**5. Looping Through Databases** ======169 +=== **5. Looping Through Databases** === 196 196 197 197 {{code language="sql"}} 198 198 -- Loop through each database and execute the stored procedure ... ... @@ -230,7 +230,7 @@ 230 230 231 231 ---- 232 232 233 -=== ===**6. Fetch the Next Database** ======207 +=== **6. Fetch the Next Database** === 234 234 235 235 {{code language="sql"}} 236 236 -- Fetch the next database in the cursor ... ... @@ -244,7 +244,7 @@ 244 244 245 245 ---- 246 246 247 -=== ===**7. Closing and Deallocating the Cursor** ======221 +=== **7. Closing and Deallocating the Cursor** === 248 248 249 249 {{code language="sql"}} 250 250 -- Close and deallocate the cursor to clean up resources ... ... @@ -257,9 +257,8 @@ 257 257 * **CLOSE db_cursor**: This closes the cursor once the loop finishes processing all databases. 258 258 * **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. 259 259 260 -====== ====== 261 261 262 -===== =**8. Full Script**======235 +===== 8. Full Script ===== 263 263 264 264 265 265 {{code language="sql"}} ... ... @@ -298,84 +298,54 @@ 298 298 {{/code}} 299 299 300 300 274 +=== 2. Set up a new job === 301 301 302 302 303 - ===**2.SetUpaNewJob in SQL Server Agent**===277 +- Go to SSMS and click on SQL Server Agent 304 304 305 - Toautomatethe backupprocess ofthe**DBAdatabases**,followthesteps below to createanew jobin SQL Server Agent.279 + Drop down menu and left click jobs and select new job 306 306 307 ----- 308 308 309 -====== **Step1: CreateaNew Job**======282 +====== General: ====== 310 310 311 -1. **Open SQL Server Management Studio (SSMS)**: 312 -1*. In the **Object Explorer**, expand the **SQL Server Agent** node. 313 -1*. Right-click on **Jobs** and select **New Job**. 284 +- Enter Job name (DBA databases backup) 314 314 315 -- ---286 +- Owner (ebssqladmin) 316 316 317 - ======**Step2:Define Job Properties** ======288 +- Category (Database maintenance) 318 318 319 - Inthe**New Job** window,configurethe jobproperties:290 + - Description (Description of the job) 320 320 321 -* **General Tab**: 322 -** **Job Name**: Enter a descriptive name for the job, such as DBA Databases Backup. 323 -** **Owner**: Specify the job owner (ebssqladmin). 324 -** **Category**: Select Database Maintenance as the category for the job. 325 -** **Description**: Provide a brief description of the job (Automated backup of DBA databases to Azure Storage"). 326 326 327 - ----293 +====== Steps: Create the steps for the job to follow ====== 328 328 329 - ======**Step3: CreatetheJobSteps** ======295 + - Step name (Backup only DBA database) 330 330 331 - Thejobwillperformthe backup through **Transact-SQL**(T-SQL) commands. Set up the following steps:297 + - Type (Transact-SQL script) 332 332 333 -1. **Step Name**: Enter a descriptive step name, such as Backup Only DBA Databases. 334 -1. **Type**: Select Transact-SQL Script (T-SQL). 335 -1. **Database**: Choose the master database, as the script will be run in the context of the master database. 336 -1. **Command**: Paste the backup script you created earlier, which automates the backup of the DBA databases. 299 + - Database (master) 337 337 338 -- ---301 + - Command (paste the script we created) 339 339 340 -====== **Step 4: Set the Job Schedule** ====== 341 341 342 - Now,configure the schedule for the job to rundaily at 3:00 AM:304 + Schedule: Create a schedule for the job to run 343 343 344 -1. **Schedule Name**: Name the schedule (DBA Database Backup). 345 -1. **Schedule Type**: Choose Recurring for a regular schedule. 346 -1. ((( 347 -**Frequency**: 306 + - Name (DBA database backup) 348 348 349 -* **Occurs**: Select Daily. 350 -* **Recurs Every**: Set it to **1 day** to run the job every day at the same time. 351 -))) 352 -1. ((( 353 -**Daily Frequency**: 308 + - Schedule Type (recurring) 354 354 355 -* Set the **time** for the backup to start, such as **3:00 AM**. 356 -))) 310 + - Frequency (Occurs: Daily) 357 357 358 - ----312 + (Recurs every: 1 day(s)) 359 359 360 -=== **Conclusion** === 361 361 362 -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. 363 363 364 -=== === 365 365 366 -===== Note: We could use the job activity monitor to see if the job executed successfully. ===== 367 367 368 368 369 369 370 370 371 371 372 - 373 - 374 - 375 - 376 - 377 - 378 - 379 379 1 CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'YourStrongPasswordHere!'; 380 380 GO 381 381 ... ... @@ -672,3 +672,5 @@ 672 672 {{/code}} 673 673 674 674 618 + 619 +
- image-20250305152543-1.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.rudim - Size
-
... ... @@ -1,1 +1,0 @@ 1 -19.6 KB - Content