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, 1 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,19 +1,33 @@ 1 -= TDE(backup from smsstoazure)=1 += **1. Steps for Implementing Transparent Data Encryption (TDE) FROM SQL Server** = 2 2 3 3 4 - 1Createmasterkey inmaster database(setmasterkey)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. 5 5 6 - 2CreateTDEcertificate(encrypted byMK)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. 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) 9 9 10 - 4 Choose DB to create the DEK ,Create database encryption key (DEK) withalgorithm( AES= 256)andencryptionby certificate9 +[[image:image-20250305152543-1.png]] 11 11 12 -5 Set encryption on for the database 13 13 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 16 16 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 + 17 17 {{code language="sql"}} 18 18 drop credential [https://zagpebslab.blob.core.windows.net/sql-backups] 19 19 CREATE CREDENTIAL [https://zagpebslab.blob.core.windows.net/sql-backups] ... ... @@ -24,96 +24,108 @@ 24 24 {{/code}} 25 25 26 26 27 - 741 +**~ 6. Use a Stored Procedure to Back Up to Azure Storage Account** 28 28 29 29 {{code language="sql"}} 30 30 EXECUTE dba.dbo.DatabaseBackup 31 - @Databases =@DatabaseName,32 - @URL =@BackupContainerURL,33 - @BackupType = 'Full',34 - @CopyOnly = 'Y',35 - @Compress = 'Y',36 - @Verify = 'N';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' 37 37 {{/code}} 38 38 39 - Thebackupwas unable to be done from smss to azure ( the MI does not support encrypted DBs to be backed up from smss to azure)53 +=== === 40 40 41 - Wehave unencrypted a database andbacked itupfrom ssmstoazureblobsuccessfully55 +=== Conclusion: Backup to Azure Storage Account with TDE Encrypted Databases === 42 42 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**. 43 43 44 - Conclusion:Canbedonewith and unencryptedDBbut notwithanEncryptedone>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**. 45 45 46 46 47 47 48 48 49 49 50 -= ** Using TDE directlyfromazureportal** =65 += **2. Enabling Transparent Data Encryption (TDE) Using Azure Key Vault** = 51 51 52 52 53 - =====1Go to azurekeyvault(DemoTestRudi)togenerate akey=====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. 54 54 55 55 56 - -Gotokeysandclickgenerate71 +===== **1. Generate a Key in Azure Key Vault** ===== 57 57 58 -- Name your key (mysqlmikey) 59 59 60 -- Chooseakeytype(RSA)74 +**- Navigate to Azure Key Vault:** 61 61 62 - -ChooseRSAkeysize (2048-bit)76 +* Go to the **Azure Portal** and select **Key Vault** (DemoRudiTest). 63 63 64 - Note:78 +**- Generate a New Key:** 65 65 66 -* 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. 67 -* **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.). 68 -* 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. 80 +* Go to the **Keys** section and click **Generate** to create a new key. 69 69 70 -- C lick create82 +**- Configure Key Settings:** 71 71 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) 72 72 73 - [[image:image-20250228120622-1.png||height="236"width="542"]]88 + Note: 74 74 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 +* **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 +* 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. 75 75 76 - =====2 EnableTDE=====94 +**- Create the Key:** 77 77 96 +* Click **Create** to generate the key. 78 78 79 -- Go to your Managed instance ( sqlmi-ebs-lab) 80 80 81 - -ClickonsecurityandchooseTransparentdataencryption99 +===== **2. Enable TDE on the SQL Managed Instance** ===== 82 82 83 - -Selectthe type of managed key ( Customer-managed key0101 +===== ===== 84 84 85 -- Selectthekey fromthe key vaultwe generatedinthe key vault( mysqlmikey)103 +**- Navigate to Your Managed Instance:** 86 86 87 - -MakethekeythedefaultTDE protector105 +* Go to your **SQL Managed Instance** (sqlmi-ebs-lab). 88 88 89 -- Clicksave107 +**- Enable Transparent Data Encryption (TDE):** 90 90 109 +* Under **Security**, select **Transparent Data Encryption**. 91 91 92 - [[image:image-20250228122106-2.png||height="19" width="241"]]111 +**- Configure TDE with a Customer-Managed Key (CMK):** 93 93 113 +* Select **Customer-managed key** as the encryption type. 114 +* Choose the key you created earlier from **Azure Key Vault** (mysqlmikey). 94 94 95 -- TDEhasnow been enabled ontheManagedinstance116 +**- Set the Key as Default TDE Protector:** 96 96 118 +* Make the key the **default TDE protector** for your instance. 97 97 98 - Conclusion:All the databases havebeenencrypted by an asymmetric key. The key is the sameforeach database ( same encryptionthumbprint).120 +**- Save Configuration:** 99 99 100 - Wearenowable tobackupdatabasesfrom SSMS to Azure storage.122 +* Click **Save** to apply the changes. 101 101 124 +=== **Conclusion** === 102 102 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**. 103 103 104 - ===Backup specificdatabases usingSQLserver agentjobs===128 +This process ensures that your data is protected both at rest and during backup, offering enhanced security for your managed databases in the cloud. 105 105 106 106 107 -we are creating a job to automatically backup only the DBA databases in the instance via the SQL server agent. 108 108 109 - Thebackupwill bedone dailyat3am. Thebackupswill bebacked upintheAzurestorageaccount.132 +=== **1. Backup Specific Databases Using SQL Server Agent Jobs** === 110 110 134 +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. 111 111 112 - 1 Create the script136 +---- 113 113 138 +==== **1. Create the Backup Script** ==== 114 114 115 -=== **1. Declaring Variables** === 116 116 141 +====== **- Declaring Variables** ====== 142 + 117 117 {{code language="sql"}} 118 118 DECLARE @DatabaseName NVARCHAR(128) 119 119 DECLARE @BackupContainerURL NVARCHAR(512) ... ... @@ -126,7 +126,7 @@ 126 126 127 127 ---- 128 128 129 -=== **2. Setting the Azure Blob Storage URL** === 155 +====== **2. Setting the Azure Blob Storage URL** ====== 130 130 131 131 {{code language="sql"}} 132 132 SET @BackupContainerURL = 'https://<your_storage_account>.blob.core.windows.net/sql-backups/' ... ... @@ -135,7 +135,7 @@ 135 135 136 136 ---- 137 137 138 -=== **3. Declaring the Cursor** === 164 +====== **3. Declaring the Cursor** ====== 139 139 140 140 141 141 {{code language="sql"}} ... ... @@ -152,7 +152,7 @@ 152 152 153 153 ---- 154 154 155 -=== **4. Opening the Cursor** === 181 +====== **4. Opening the Cursor** ====== 156 156 157 157 {{code language="sql"}} 158 158 OPEN db_cursor ... ... @@ -166,7 +166,7 @@ 166 166 167 167 ---- 168 168 169 -=== **5. Looping Through Databases** === 195 +====== **5. Looping Through Databases** ====== 170 170 171 171 {{code language="sql"}} 172 172 -- Loop through each database and execute the stored procedure ... ... @@ -204,7 +204,7 @@ 204 204 205 205 ---- 206 206 207 -=== **6. Fetch the Next Database** === 233 +====== **6. Fetch the Next Database** ====== 208 208 209 209 {{code language="sql"}} 210 210 -- Fetch the next database in the cursor ... ... @@ -218,7 +218,7 @@ 218 218 219 219 ---- 220 220 221 -=== **7. Closing and Deallocating the Cursor** === 247 +====== **7. Closing and Deallocating the Cursor** ====== 222 222 223 223 {{code language="sql"}} 224 224 -- Close and deallocate the cursor to clean up resources ... ... @@ -231,8 +231,9 @@ 231 231 * **CLOSE db_cursor**: This closes the cursor once the loop finishes processing all databases. 232 232 * **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. 233 233 260 +====== ====== 234 234 235 -===== 8. Full Script ===== 262 +====== **8. Full Script** ====== 236 236 237 237 238 238 {{code language="sql"}} ... ... @@ -271,54 +271,84 @@ 271 271 {{/code}} 272 272 273 273 274 -=== 2. Set up a new job === 275 275 276 276 277 - -GotoSSMSandclickon SQL Server Agent303 +=== **2. Set Up a New Job in SQL Server Agent** === 278 278 279 - Dropdownmenuandleftclickjobsandselect new job305 +To automate the backup process of the **DBA databases**, follow the steps below to create a new job in SQL Server Agent. 280 280 307 +---- 281 281 282 -====== General:======309 +====== **Step 1: Create a New Job** ====== 283 283 284 -- Enter Job name (DBA databases backup) 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**. 285 285 286 -- Owner (ebssqladmin)315 +---- 287 287 288 - -Category(Databasemaintenance)317 +====== **Step 2: Define Job Properties** ====== 289 289 290 - -Description(Description of the job)319 +In the **New Job** window, configure the job properties: 291 291 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"). 292 292 293 - ====== Steps: Create the steps for the job to follow ======327 +---- 294 294 295 - -Stepname(BackuponlyDBA database)329 +====== **Step 3: Create the Job Steps** ====== 296 296 297 - -Type(Transact-SQLscript)331 +The job will perform the backup through **Transact-SQL** (T-SQL) commands. Set up the following steps: 298 298 299 - - Database (master) 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. 300 300 301 - -Command (paste the script we created)338 +---- 302 302 340 +====== **Step 4: Set the Job Schedule** ====== 303 303 304 - Schedule: Createaschedule for the job to run342 +Now, configure the schedule for the job to run daily at 3:00 AM: 305 305 306 - - Name (DBA database backup) 344 +1. **Schedule Name**: Name the schedule (DBA Database Backup). 345 +1. **Schedule Type**: Choose Recurring for a regular schedule. 346 +1. ((( 347 +**Frequency**: 307 307 308 - - Schedule Type (recurring) 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**: 309 309 310 - - Frequency (Occurs: Daily) 355 +* Set the **time** for the backup to start, such as **3:00 AM**. 356 +))) 311 311 312 - (Recurs every: 1 day(s))358 +---- 313 313 360 +=== **Conclusion** === 314 314 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. 315 315 364 +=== === 316 316 366 +===== Note: We could use the job activity monitor to see if the job executed successfully. ===== 317 317 318 318 319 319 320 320 321 321 372 + 373 + 374 + 375 + 376 + 377 + 378 + 322 322 1 CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'YourStrongPasswordHere!'; 323 323 GO 324 324 ... ... @@ -615,5 +615,3 @@ 615 615 {{/code}} 616 616 617 617 618 - 619 -
- image-20250305152543-1.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.rudim - Size
-
... ... @@ -1,0 +1,1 @@ 1 +19.6 KB - Content