| title | Encrypt, Re-Encrypt or Decrypt Columns by Publishing a DAC Package | Microsoft Docs | |||
|---|---|---|---|---|
| ms.custom | ||||
| ms.date | 06/26/2019 | |||
| ms.prod | sql | |||
| ms.reviewer | vanto | |||
| ms.technology | security | |||
| ms.topic | conceptual | |||
| f1_keywords |
|
|||
| helpviewer_keywords |
|
|||
| ms.assetid | 29816a41-f105-4414-8be1-070675d62e84 | |||
| author | jaszymas | |||
| ms.author | jaszymas | |||
| monikerRange | =azuresqldb-current||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDEappliesto-ss-asdb-xxxx-xxx-md]
A data-tier application (DAC) package, also known as a DACPAC, is a portable unit of SQL Server database deployment that defines all of the SQL Server objects, including tables and columns inside the tables. When you publish a DACPAC to a database (when you upgrade a database using a DACPAC), the schema of the target database gets update to match the schema in the DACPAC. You can publish a DACPAC using the Upgrade Data-tier Application Wizard in SQL Server Management Studio, PowerShell, or sqlpackage.
This article addresses special considerations for upgrading a database when the DACPAC or/and the target database contains columns protected with Always Encrypted. If the encryption scheme for a column in the DACPAC differs from the encryption scheme for an existing column in the target database, publishing the DACPAC results in encrypting, decrypting or re-encrypting the data stored in the column. See the below table for details.
| Condition | Action |
|---|---|
| The column is encrypted in the DACPAC and it isn't encrypted in the database. | The data in the column will be encrypted. |
| The column isn't encrypted in the DACPAC and it's encrypted in the database. | The data in the column will be decrypted (the encryption will be removed for the column). |
| The column is encrypted both in the DACPAC and the database, but the column in the DACPAC uses a different encryption type or/and a different column encryption key than the corresponding column in the database. | The data in the column will be decrypted and then re-encrypted to match the encryption configuration in the DACPAC. |
Deploying a DAC package may also result in creating or removing metadata objects for column master keys or column encryption keys for Always Encrypted.
To publish DAC package if Always Encrypted is set up in the DACPAC or/and in the target database, you might need some or all of the below permissions, depending on the differences between the schema in the DACPAC and the target database schema.
ALTER ANY COLUMN MASTER KEY, ALTER ANY COLUMN ENCRYPTION KEY, VIEW ANY COLUMN MASTER KEY DEFINITION, VIEW ANY COLUMN ENCRYPTION KEY DEFINITION
If the upgrade operation triggers a data encryption operation, you also need to be able to access column master keys configured for the impacted columns:
- Certificate Store - Local computer - you must have Read access to the certificate that is used a column master key, or be the administrator on the computer.
- Azure Key Vault - you need the create, get, unwrapKey, wrapKey, sign, and verify permissions on the vault containing the column master key.
- Key Store Provider (CNG) - you might be prompted for the required permission and credentials when using a key store or a key, depending on the store and the KSP configuration.
- Cryptographic Service Provider (CAPI) - you might be prompted for the required permission and credentials when using a key store or a key, depending on the store and the CSP configuration.
For more information, see Create and Store Column Master Keys (Always Encrypted).