|
| 1 | +--- |
| 2 | +title: "Breaking change - KeyVault default role assignment changing from KeyVaultAdministrator to KeyVaultSecretsUser" |
| 3 | +description: "Learn about the breaking change in .NET Aspire 9.2 where the default role for Azure KeyVault applications changes to KeyVaultSecretsUser." |
| 4 | +ms.date: 03/27/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs-aspire/issues/2899 |
| 7 | +--- |
| 8 | + |
| 9 | +# KeyVault default role assignment changing from KeyVaultAdministrator to KeyVaultSecretsUser |
| 10 | + |
| 11 | +In .NET Aspire 9.2, the default role assigned to applications referencing Azure KeyVault has changed from <xref:Azure.Provisioning.KeyVault.KeyVaultBuiltInRole.KeyVaultAdministrator> to <xref:Azure.Provisioning.KeyVault.KeyVaultBuiltInRole.KeyVaultSecretsUser>. This change enhances security by limiting default privileges to only reading secrets. Applications requiring higher privileges must explicitly configure them. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET Aspire 9.2 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +Previously, applications referencing Azure KeyVault were automatically granted the `KeyVaultAdministrator` role, which allowed full management of KeyVault settings. |
| 20 | + |
| 21 | +## New behavior |
| 22 | + |
| 23 | +Applications referencing Azure KeyVault are now granted the `KeyVaultSecretsUser` role by default, which restricts access to reading secrets. If higher privileges are required, they can be configured using the `WithRoleAssignments` API. |
| 24 | + |
| 25 | +Example: |
| 26 | + |
| 27 | +```csharp |
| 28 | +using Azure.Provisioning.KeyVault; |
| 29 | + |
| 30 | +var kv = builder.AddAzureKeyVault("kv"); |
| 31 | + |
| 32 | +builder.AddProject<Projects.ApiService>("api") |
| 33 | + .WithRoleAssignments(kv, KeyVaultBuiltInRole.KeyVaultContributor); |
| 34 | +``` |
| 35 | + |
| 36 | +## Type of breaking change |
| 37 | + |
| 38 | +This is a [behavioral change](../categories.md#behavioral-change). |
| 39 | + |
| 40 | +## Reason for change |
| 41 | + |
| 42 | +The `KeyVaultAdministrator` role provides excessive privileges for most applications, as they typically only need to read secrets. Assigning the `KeyVaultSecretsUser` role by default improves security by adhering to the principle of least privilege. |
| 43 | + |
| 44 | +## Recommended action |
| 45 | + |
| 46 | +If your application requires higher privileges than the `KeyVaultSecretsUser` role, explicitly configure the necessary roles using the `WithRoleAssignments` API. For example: |
| 47 | + |
| 48 | +```csharp |
| 49 | +using Azure.Provisioning.KeyVault; |
| 50 | + |
| 51 | +var kv = builder.AddAzureKeyVault("kv"); |
| 52 | + |
| 53 | +builder.AddProject<Projects.ApiService>("api") |
| 54 | + .WithRoleAssignments(kv, KeyVaultBuiltInRole.KeyVaultContributor); |
| 55 | +``` |
| 56 | + |
| 57 | +## Affected APIs |
| 58 | + |
| 59 | +- <xref:Aspire.Hosting.AzureKeyVaultResourceExtensions.AddAzureKeyVault*> |
0 commit comments