You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`{BLOBURIWITHSAS}`:ThefullURIwherethekeyfileshouldbestoredwiththeSAStokenasaquerystringparameter. TheURIisgeneratedbyAzureStorage when you request a SAS for the uploaded key file.
191
191
192
-
`{KEYIDENTIFIER}`:AzureKeyVaultkeyidentifierusedforkeyencryption. Anaccesspolicyallowstheapplicationtoaccessthekeyvaultwith `Get`, `UnwrapKey`, and `WrapKey` permissions. TheversionofthekeyisobtainedfromthekeyintheEntraorAzureportalafterit'screated.
192
+
`{KEYIDENTIFIER}`:AzureKeyVaultkeyidentifierusedforkeyencryption. Anaccesspolicyallowstheapplicationtoaccessthekeyvaultwith `Get`, `UnwrapKey`, and `WrapKey` permissions. ThekeyidentifierisobtainedfromthekeyintheEntraorAzureportalafterit'screated. Ifyouenableautorotationofthekeyvaultkey, makesurethatyouuseaversionlesskeyidentifierintheapp's key vault configuration, where no key GUID is placed at the end of the identifier (example: `https://contoso.vault.azure.net/keys/data-protection`).
`{BLOB URI WITH SAS}`: The full URI where the key file should be stored with the SAS token as a query string parameter. The URI is generated by Azure Storage when you request a SAS for the uploaded key file.
822
822
823
-
`{KEY IDENTIFIER}`: Azure Key Vault key identifier used for key encryption. An access policy allows the application to access the key vault with `Get`, `Unwrap Key`, and `Wrap Key` permissions. The version of the key is obtained from the key in the Entra or Azure portal after it's created.
823
+
`{KEY IDENTIFIER}`: Azure Key Vault key identifier used for key encryption. An access policy allows the application to access the key vault with `Get`, `Unwrap Key`, and `Wrap Key` permissions. The version of the key is obtained from the key in the Entra or Azure portal after it's created. If you enable autorotation of the key vault key, make sure that you use a versionless key identifier in the app's key vault configuration, where no key GUID is placed at the end of the identifier (example: `https://contoso.vault.azure.net/keys/data-protection`).
824
824
825
825
> [!NOTE]
826
826
> The preceding example uses <xref:Azure.Identity.DefaultAzureCredential> locally (non-Production environment) to simplify authentication while developing apps that deploy to Azure by combining credentials used in Azure hosting environments with credentials used in local development. When moving to production, an alternative is a better choice, such as the <xref:Azure.Identity.ManagedIdentityCredential> shown in the preceding example. For more information, see [Authenticate Azure-hosted .NET apps to Azure resources using a system-assigned managed identity](/dotnet/azure/sdk/authentication/system-assigned-managed-identity).
Copy file name to clipboardExpand all lines: aspnetcore/security/data-protection/configuration/overview.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ The following NuGet packages are required for the Data Protection extensions use
36
36
37
37
## Protect keys with Azure Key Vault (`ProtectKeysWithAzureKeyVault`)
38
38
39
-
To interact with [Azure Key Vault](https://azure.microsoft.com/services/key-vault/) locally using developer credentials, either sign into your storage account in Visual Studio or sign in to Azure using the .NET CLI:
39
+
To interact with [Azure Key Vault](https://azure.microsoft.com/services/key-vault/) locally using developer credentials, either sign into your storage account in Visual Studio or sign in with the [Azure CLI](/cli/azure/). If you haven't already installed the Azure CLI, see [How to install the Azure CLI](/cli/azure/install-azure-cli). You can execute the following command in the Developer PowerShell panel in Visual Studio or from a command shell when not using Visual Studio:
40
40
41
41
```azurecli
42
42
az login
@@ -50,9 +50,12 @@ When establishing the key vault in the Entra or Azure portal:
50
50
51
51
* Create an Azure Managed Identity (or add a role to the existing Managed Identity that you plan to use) with the **Key Vault Crypto User** role. Assign the Managed Identity to the App Service hosting the deployment: **Settings** > **Identity** > **User assigned** > **Add**.
52
52
53
+
> [!NOTE]
54
+
> If you also plan to run an app locally with an authorized user for blob access using the [Azure CLI](/cli/azure/) or Visual Studio's Azure Service Authentication, add your developer Azure user account in **Access Control (IAM)** with the **Key Vault Crypto User** role. If you want to use the Azure CLI through Visual Studio, execute the `az login` command from the Developer PowerShell panel and follow the prompts to authenticate with the tenant.
55
+
53
56
* When key encryption is active, keys in the key file include the comment, ":::no-loc text="This key is encrypted with Azure Key Vault.":::" After starting the app, select the **View/edit** command from the context menu at the end of the key row to confirm that a key is present with key vault security applied.
54
57
55
-
* Optionally, you can enable automatic key vault key rotation without concern about decrypting payloads with data protection keys based on expired/rotated key vault keys. Each generated data protection key includes a reference to the key vault key used to encrypted it. Just make sure that you retain expired key vault keys, don't delete them in the key vault. Use a similar rotation period for both keys with the key vault key rotating more frequently than the data protection key to ensure you are using a new key vault key at the time of data protection key rotation. Also, either manually change the key identifier in the app or write custom code to adopt the latest key identifier for the latest key vault key when automatic key rotation occurs (such code is currently beyond the scope of this coverage).
58
+
* Optionally, you can enable automatic key vault key rotation without concern about decrypting payloads with data protection keys based on expired/rotated key vault keys. Each generated data protection key includes a reference to the key vault key used to encrypted it. Just make sure that you retain expired key vault keys, don't delete them in the key vault. Also, use a versionless key identifier in the app's key vault configuration, where no key GUID is placed at the end of the identifier (example: `https://contoso.vault.azure.net/keys/data-protection`). Use a similar rotation period for both keys with the key vault key rotating more frequently than the data protection key to ensure you are using a new key vault key at the time of data protection key rotation.
56
59
57
60
Protecting keys with Azure Key Vault implements an <xref:Microsoft.AspNetCore.DataProtection.XmlEncryption.IXmlEncryptor> that disables automatic data protection settings, including the key ring storage location. To configure the Azure Blob Storage provider to store the keys in blob storage, follow the guidance in <xref:security/data-protection/implementation/key-storage-providers#azure-storage> and call one of the <xref:Microsoft.AspNetCore.DataProtection.AzureDataProtectionBuilderExtensions.PersistKeysToAzureBlobStorage%2A> overloads in the app. The following example uses the overload that accepts a blob URI and token credential (<xref:Azure.Core.TokenCredential>), relying on an Azure Managed Identity for role-based access control (RBAC). You can also persist the key ring locally with [`PersistKeysToFileSystem`](xref:security/data-protection/implementation/key-storage-providers#file-system).
`{BLOB URI WITH SAS}`: The full URI where the key file should be stored with the SAS token as a query string parameter. The URI is generated by Azure Storage when you request a SAS for the uploaded key file.
90
93
91
-
`{KEY IDENTIFIER}`: Azure Key Vault key identifier used for key encryption. An access policy allows the application to access the key vault with `Get`, `Unwrap Key`, and `Wrap Key` permissions. The version of the key is obtained from the key in the Entra or Azure portal after it's created.
94
+
`{KEY IDENTIFIER}`: Azure Key Vault key identifier used for key encryption. An access policy allows the application to access the key vault with `Get`, `Unwrap Key`, and `Wrap Key` permissions. The version of the key is obtained from the key in the Entra or Azure portal after it's created. If you enable autorotation of the key vault key, make sure that you use a versionless key identifier in the app's key vault configuration, where no key GUID is placed at the end of the identifier (example: `https://contoso.vault.azure.net/keys/data-protection`).
92
95
93
96
For an app to communicate and authorize itself with Azure Key Vault, the [`Azure.Identity` NuGet package](https://www.nuget.org/packages/Azure.Identity/) must be referenced by the app.
94
97
@@ -394,7 +397,7 @@ services.AddDataProtection()
394
397
395
398
`{BLOBURIWITHSAS}`:ThefullURIwherethekeyfileshouldbestoredwiththeSAStokenasaquerystringparameter. TheURIisgeneratedbyAzureStorage when you request a SAS for the uploaded key file.
396
399
397
-
`{KEYIDENTIFIER}`:AzureKeyVaultkeyidentifierusedforkeyencryption. Anaccesspolicyallowstheapplicationtoaccessthekeyvaultwith `Get`, `UnwrapKey`, and `WrapKey` permissions. TheversionofthekeyisobtainedfromthekeyintheEntraorAzureportalafterit'screated.
400
+
`{KEYIDENTIFIER}`:AzureKeyVaultkeyidentifierusedforkeyencryption. Anaccesspolicyallowstheapplicationtoaccessthekeyvaultwith `Get`, `UnwrapKey`, and `WrapKey` permissions. TheversionofthekeyisobtainedfromthekeyintheEntraorAzureportalafterit'screated.Ifyouenableautorotationofthekeyvaultkey, makesurethatyouuseaversionlesskeyidentifierintheapp's key vault configuration, where no key GUID is placed at the end of the identifier (example: `https://contoso.vault.azure.net/keys/data-protection`).
398
401
399
402
ForanapptocommunicateandauthorizeitselfwithAzureKeyVault, the [`Azure.Identity` NuGetpackage](https://www.nuget.org/packages/Azure.Identity/) must be referenced by the app.
Copy file name to clipboardExpand all lines: aspnetcore/security/data-protection/implementation/key-storage-providers.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,14 @@ The [`Azure.Extensions.AspNetCore.DataProtection.Blobs` NuGet package](https://w
34
34
35
35
[!INCLUDE[](~/includes/package-reference.md)]
36
36
37
+
To interact with [Azure Key Vault](https://azure.microsoft.com/services/key-vault/) locally using developer credentials, either sign into your storage account in Visual Studio or sign in with the [Azure CLI](/cli/azure/). If you haven't already installed the Azure CLI, see [How to install the Azure CLI](/cli/azure/install-azure-cli). You can execute the following command in the Developer PowerShell panel in Visual Studio or from a command shell when not using Visual Studio:
38
+
39
+
```azurecli
40
+
az login
41
+
```
42
+
43
+
For more information, see [Sign-in to Azure using developer tooling](/dotnet/azure/sdk/authentication/local-development-dev-accounts#sign-in-to-azure-using-developer-tooling).
44
+
37
45
Configure Azure Blob Storage to maintain data protection keys:
38
46
39
47
* Create an Azure storage account.
@@ -52,14 +60,17 @@ Configure Azure Blob Storage to maintain data protection keys:
52
60
53
61
* Create an Azure Managed Identity (or add a role to the existing Managed Identity that you plan to use) with the **Storage Blob Data Contributor** role. Assign the Managed Identity to the App Service hosting the deployment: **Settings** > **Identity** > **User assigned** > **Add**.
54
62
63
+
> [!NOTE]
64
+
> If you also plan to run an app locally with an authorized user for blob access using the [Azure CLI](/cli/azure/) or Visual Studio's Azure Service Authentication, add your developer Azure user account in **Access Control (IAM)** with the **Storage Blob Data Contributor** role. If you want to use the Azure CLI through Visual Studio, execute the `az login` command from the Developer PowerShell panel and follow the prompts to authenticate with the tenant.
65
+
55
66
To configure the Azure Blob Storage provider, call one of the <xref:Microsoft.AspNetCore.DataProtection.AzureDataProtectionBuilderExtensions.PersistKeysToAzureBlobStorage%2A> overloads in the app. The following example uses the overload that accepts a blob URI and token credential (<xref:Azure.Core.TokenCredential>), relying on an Azure Managed Identity for role-based access control (RBAC).
56
67
57
68
Other overloads are based on:
58
69
59
70
* A blob URI and storage shared key credential (<xref:Azure.Storage.StorageSharedKeyCredential>).
60
71
* A blob URI with a shared access signature (SAS).
61
72
* A connection string, container name, and blob name.
62
-
* A blob client (<xref:Azure.Storage.Blobs.BlobClient>). This approach is demonstrated later in this section.
73
+
* A blob client (<xref:Azure.Storage.Blobs.BlobClient>).
63
74
64
75
For more information on the Azure SDK's API and authentication, see [Authenticate .NET apps to Azure services using the Azure Identity library](/dotnet/azure/sdk/authentication/). For logging guidance, see [Logging with the Azure SDK for .NET: Logging without client registration](/dotnet/azure/sdk/logging#logging-without-client-registration). For apps using dependency injection, an app can call <xref:Microsoft.Extensions.Azure.AzureClientServiceCollectionExtensions.AddAzureClientsCore%2A>, passing `true` for `enableLogForwarding`, to create and wire up the logging infrastructure.
0 commit comments