Skip to content

Commit 12ddec0

Browse files
committed
Updates
1 parent 931e5fd commit 12ddec0

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed

aspnetcore/blazor/call-web-api.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ To configure a production distributed cache provider, see <xref:performance/cach
124124
For more information, see [Token cache serialization: Distributed caches](/entra/msal/dotnet/how-to/token-cache-serialization?tabs=msal#distributed-caches). However, the code examples shown don't apply to ASP.NET Core apps, which configure distributed caches via <xref:Microsoft.Extensions.DependencyInjection.MemoryCacheServiceCollectionExtensions.AddDistributedMemoryCache%2A>, not <xref:Microsoft.Identity.Web.TokenCacheExtensions.AddDistributedTokenCache%2A>.
125125
126126
<!-- DOC AUTHOR NOTE: The next part on using a shared DP key ring is also
127-
covered in the *BWA+Entra* security article. Mirror
127+
covered in the *BWA + Entra* security article. Mirror
128128
changes when updating this portion of content. -->
129129
130130
Use a shared Data Protection key ring in production so that instances of the app across servers in a web farm can decrypt tokens when <xref:Microsoft.Identity.Web.TokenCacheProviders.Distributed.MsalDistributedTokenCacheAdapterOptions.Encrypt%2A?displayProperty=nameWithType> is set to `true`.
@@ -138,7 +138,7 @@ Use a shared Data Protection key ring in production so that instances of the app
138138
>
139139
> Later in the development and testing period, enable token encryption and adopt a shared Data Protection key ring.
140140
141-
The following example shows how to use [Azure Blob Storage and Azure Key Vault (`PersistKeysToAzureBlobStorage`/`ProtectKeysWithAzureKeyVault`)](xref:security/data-protection/configuration/overview#protect-keys-with-azure-key-vault-protectkeyswithazurekeyvault) for the shared key ring. The service configurations are base case scenarios for demonstration purposes. Before deploying production apps, familiarize yourself with the Azure services and adopt best practices using the Azure services' dedicated documentation sets, which are cross-linked at the end of this section.
141+
The following example shows how to use [Azure Blob Storage and Azure Key Vault (`PersistKeysToAzureBlobStorage`/`ProtectKeysWithAzureKeyVault`)](xref:security/data-protection/configuration/overview#protect-keys-with-azure-key-vault-protectkeyswithazurekeyvault) for the shared key ring. The service configurations are base case scenarios for demonstration purposes. Before deploying production apps, familiarize yourself with the Azure services and adopt best practices using the Azure services' dedicated documentation sets, which are linked at the end of this section.
142142
143143
Add the following packages to the server project of the Blazor Web App:
144144
@@ -171,23 +171,16 @@ else
171171
}
172172
173173
builder.Services.AddDataProtection()
174-
.SetApplicationName("BlazorWebAppEntra")
174+
.SetApplicationName("{APPLICATION NAME}")
175175
.PersistKeysToAzureBlobStorage(new Uri("{BLOB URI}"), credential)
176176
.ProtectKeysWithAzureKeyVault(new Uri("{KEY IDENTIFIER}"), credential);
177-
178-
/* Alternative without using an Azure Managed Identity: SAS approach
179-
builder.Services.AddDataProtection()
180-
.SetApplicationName("BlazorWebAppEntra")
181-
.PersistKeysToAzureBlobStorage(new Uri("{BLOB URI WITH SAS}"))
182-
.ProtectKeysWithAzureKeyVault(new Uri("{KEY IDENTIFIER}"), credential);
183-
*/
184177
```
185178
186179
`{MANAGED IDENTITY CLIENT ID}`: The Azure Managed Identity Client ID (GUID).
187180
188-
`{BLOB URI}`: Full URI to the key file. The URI is generated by Azure Storage when you create the key file. Do not use a SAS.
181+
`{APPLICATION NAME}`: <xref:Microsoft.AspNetCore.DataProtection.DataProtectionBuilderExtensions.SetApplicationName%2A> sets the unique name of this app within the data protection system. The value should match across deployments of the app.
189182
190-
`{BLOB URI WITH SAS}`: *This approach only applies if you opt not to use an Azure Managed Identity.* 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.
183+
`{BLOB URI}`: Full URI to the key file. The URI is generated by Azure Storage when you create the key file. Do not use a SAS.
191184
192185
`{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 key identifier 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`).
193186

aspnetcore/blazor/security/blazor-web-app-with-entra.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ Use a shared Data Protection key ring in production so that instances of the app
763763
>
764764
> Later in the development and testing period, enable token encryption and adopt a shared Data Protection key ring.
765765
766-
The following example shows how to use [Azure Blob Storage and Azure Key Vault (`PersistKeysToAzureBlobStorage`/`ProtectKeysWithAzureKeyVault`)](xref:security/data-protection/configuration/overview#protect-keys-with-azure-key-vault-protectkeyswithazurekeyvault) for the shared key ring. The service configurations are base case scenarios for demonstration purposes. Before deploying production apps, familiarize yourself with the Azure services and adopt best practices using the Azure services' dedicated documentation sets, which are cross-linked at the end of this section.
766+
The following example shows how to use [Azure Blob Storage and Azure Key Vault (`PersistKeysToAzureBlobStorage`/`ProtectKeysWithAzureKeyVault`)](xref:security/data-protection/configuration/overview#protect-keys-with-azure-key-vault-protectkeyswithazurekeyvault) for the shared key ring. The service configurations are base case scenarios for demonstration purposes. Before deploying production apps, familiarize yourself with the Azure services and adopt best practices using the Azure services' dedicated documentation sets, which are linked at the end of this section.
767767
768768
Confirm the presence of the following packages in the server project of the Blazor Web App:
769769
@@ -801,21 +801,14 @@ builder.Services.AddDataProtection()
801801
.SetApplicationName("BlazorWebAppEntra")
802802
.PersistKeysToAzureBlobStorage(new Uri("{BLOB URI}"), credential)
803803
.ProtectKeysWithAzureKeyVault(new Uri("{KEY IDENTIFIER}"), credential);
804-
805-
/* Blob URI with SAS approach
806-
builder.Services.AddDataProtection()
807-
.SetApplicationName("BlazorWebAppEntra")
808-
.PersistKeysToAzureBlobStorage(new Uri("{BLOB URI WITH SAS}"))
809-
.ProtectKeysWithAzureKeyVault(new Uri("{KEY IDENTIFIER}"), credential);
810-
*/
811804
```
812805
806+
You can pass any app name to <xref:Microsoft.AspNetCore.DataProtection.DataProtectionBuilderExtensions.SetApplicationName%2A>. Just confirm that all app deployments use the same value.
807+
813808
`{MANAGED IDENTITY CLIENT ID}`: The Azure Managed Identity Client ID (GUID).
814809

815810
`{BLOB URI}`: Full URI to the key file. The URI is generated by Azure Storage when you create the key file. Do not use a SAS.
816811

817-
`{BLOB URI WITH SAS}`: *This approach only applies if you opt not to use an Azure Managed Identity.* 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.
818-
819812
`{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`).
820813

821814
> [!NOTE]

aspnetcore/security/data-protection/configuration/overview.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ When establishing the key vault in the Entra or Azure portal:
5959

6060
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).
6161

62-
To configure the Azure Key Vault provider, call one of the <xref:Microsoft.AspNetCore.DataProtection.AzureDataProtectionKeyVaultKeyBuilderExtensions.ProtectKeysWithAzureKeyVault%2A> overloads. The following example uses the overload that accepts key identifier and token credential (<xref:Azure.Core.TokenCredential>), relying on a Managed Identity for RBAC. Other overloads accept either a key vault client or an app client ID with client secret. For more information, see <xref:security/data-protection/implementation/key-storage-providers#azure-storage>.
62+
To configure the Azure Key Vault provider, call one of the <xref:Microsoft.AspNetCore.DataProtection.AzureDataProtectionKeyVaultKeyBuilderExtensions.ProtectKeysWithAzureKeyVault%2A> overloads. The following example uses the overload that accepts key identifier and token credential (<xref:Azure.Core.TokenCredential>), relying on a Managed Identity for RBAC in production (<xref:Azure.Identity.ManagedIdentityCredential>) or a <xref:Azure.Identity.DefaultAzureCredential> during development and testing. Other overloads accept either a key vault client or an app client ID with client secret. For more information, see <xref:security/data-protection/implementation/key-storage-providers#azure-storage>.
6363

6464
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/) and [Provide access to Key Vault keys, certificates, and secrets with Azure role-based access control](/azure/key-vault/general/rbac-guide?tabs=azure-cli). 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.
6565

@@ -80,23 +80,18 @@ else
8080
}
8181

8282
builder.Services.AddDataProtection()
83+
.SetApplicationName("{APPLICATION NAME}")
8384
.PersistKeysToAzureBlobStorage(new Uri("{BLOB URI}"), credential)
8485
.ProtectKeysWithAzureKeyVault(new Uri("{KEY IDENTIFIER}"), credential);
85-
86-
/* Alternative without using an Azure Managed Identity: SAS approach
87-
builder.Services.AddDataProtection()
88-
.PersistKeysToAzureBlobStorage(new Uri("{BLOB URI WITH SAS}"))
89-
.ProtectKeysWithAzureKeyVault(new Uri("{KEY IDENTIFIER}"), credential);
90-
*/
9186
```
9287

9388
`{MANAGED IDENTITY CLIENT ID}`: The Azure Managed Identity Client ID (GUID).
9489

90+
`{APPLICATION NAME}`: <xref:Microsoft.AspNetCore.DataProtection.DataProtectionBuilderExtensions.SetApplicationName%2A> sets the unique name of this app within the data protection system. The value should match across deployments of the app.
91+
9592
`{BLOB URI}`: Full URI to the key file. The URI is generated by Azure Storage when you create the key file. Do not use a SAS.
9693

97-
`{BLOB URI WITH SAS}`: *This approach only applies if you opt not to use an Azure Managed Identity.* 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.
98-
99-
`{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`).
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 automatic rotation 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`).
10095

10196
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.
10297

@@ -107,6 +102,21 @@ For an app to communicate and authorize itself with Azure Key Vault, the [`Azure
107102
108103
If the app uses the older Azure packages (`Microsoft.AspNetCore.DataProtection.AzureStorage` and `Microsoft.AspNetCore.DataProtection.AzureKeyVault`), we recommend ***removing*** these references and upgrading to the [`Azure.Extensions.AspNetCore.DataProtection.Blobs`](https://www.nuget.org/packages/Azure.Extensions.AspNetCore.DataProtection.Blobs) and [`Azure.Extensions.AspNetCore.DataProtection.Keys`](https://www.nuget.org/packages/Azure.Extensions.AspNetCore.DataProtection.Keys) packages. The newer packages address key security and stability issues.
109104

105+
**Alternative shared-access signature (SAS) approach**: As an alternative to using a Managed Identity for access to the key blob in Azure Blob Storage, you can call the <xref:Microsoft.AspNetCore.DataProtection.AzureDataProtectionBuilderExtensions.PersistKeysToAzureBlobStorage%2A> overload that accepts a blob URI with a SAS token. The following example continues to use either a <xref:Azure.Identity.ManagedIdentityCredential> (production) or <xref:Azure.Identity.DefaultAzureCredential> (development and testing) for its <xref:Azure.Core.TokenCredential>, as seen in the preceding example:
106+
107+
```csharp
108+
builder.Services.AddDataProtection()
109+
.SetApplicationName("{APPLICATION NAME}")
110+
.PersistKeysToAzureBlobStorage(new Uri("{BLOB URI WITH SAS}"))
111+
.ProtectKeysWithAzureKeyVault(new Uri("{KEY IDENTIFIER}"), credential);
112+
```
113+
114+
`{APPLICATION NAME}`: <xref:Microsoft.AspNetCore.DataProtection.DataProtectionBuilderExtensions.SetApplicationName%2A> sets the unique name of this app within the data protection system. The value should match across deployments of the app.
115+
116+
`{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.
117+
118+
`{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 automatic rotation 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`).
119+
110120
## Persist keys to the file system (`PersistKeysToFileSystem`)
111121

112122
To store keys on a UNC share instead of at the *%LOCALAPPDATA%* default location, configure the system with <xref:Microsoft.AspNetCore.DataProtection.DataProtectionBuilderExtensions.PersistKeysToFileSystem%2A>:

0 commit comments

Comments
 (0)