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
{{ message }}
Repository navigation
Support Key Vault resource references for Entra certificate credentials - #21425
Entra certificate credentials can now use a Key Vault resource already modeled in the AppHost instead of requiring a hard-coded vault URL. The URI remains a deferred resource reference during local run and publish, including the Key Vault emulator endpoint in run mode. A literal vault URL is still accepted for vaults managed outside the AppHost. The same exported method accepts either a URL or a Key Vault resource in polyglot AppHosts.
Microsoft.Identity.Web reads the certificate with its private key, which the vault's default Key Vault Secrets User role doesn't allow, so the Key Vault Certificate User role is granted automatically:
Run mode: the role is added to the vault's default roles, so it's granted to the developer identity regardless of consumer type (including plain executables and resources excluded from the manifest). If the vault's defaults were cleared with ClearDefaultRoleAssignments, nothing is added.
Publish mode: the role is attached to every workload referencing the Entra application, whether the credential is added before or after WithReference. A workload with explicit role assignments for that vault (set before referencing the application) keeps them. Publish environments that don't support role assignments fail with the existing "does not support role assignments" error instead of silently falling back to Secrets User.
Adds a dependency from Aspire.Hosting.Azure.EntraId to Aspire.Hosting.Azure.KeyVault, and covers configuration binding, dependency discovery, run/publish RBAC, existing vaults, explicit-role overrides, emulator URI resolution.
Microsoft.Identity.Web's Key Vault credential loader always retrieves the latest certificate version and has no version setting, so there is nothing to configure for version selection. The README documents this.
The certificate must already exist with an exportable private key, and its public key must be registered on the Entra application. The helper does not create certificates or upload public keys.
Existing NU1903 advisories for the test dependency System.Security.Cryptography.Xml were reported during restore/build. No live Azure deployment or certificate retrieval was performed.
Security considerations
This change automatically grants certificate/private-key read access on the selected vault through the Key Vault Certificate User role: to the developer identity when running locally (as part of the vault's default roles, so any resource referencing that vault locally gets it), and to each workload referencing the Entra application when publishing. Explicit role assignments can replace the default, and ClearDefaultRoleAssignments disables the local grant. Certificate material is still fetched by the consuming application's authentication library, not resolved into AppHost-generated environment variables or published artifacts. Security review should confirm the default access scope and identity assumptions.
Checklist
Is this feature complete?
Yes. Ready to ship.
No. Follow-up changes expected.
Are you including unit tests for the changes and scenario tests if relevant?
Yes
No
Did you add public API?
Yes
If yes, did you have an API Review for it?
Yes
No
Did you add <remarks /> and <code /> elements on your triple slash comments?
Yes
No
No
Does the change make any security assumptions or guarantees?
Yes
If yes, have you done a threat model and had a security review?
Preserve vault URI references in consumer configuration and assign certificate access to workloads. Keep literal URLs and a unified polyglot API supported.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Certificate-access grants miss some publishing and local-consumer paths, and deployment E2E coverage does not verify certificate/private-key retrieval using only WithReference(entra).
Adds modeled Azure Key Vault references to Entra certificate credentials, preserving deferred URI resolution across run and publish. This addresses the resource-reference portion of #20833; certificate-version selection remains a follow-up.
Changes:
Adds a resource-based C# overload and a shared URL-or-resource polyglot export while retaining literal URL support.
Introduces default certificate-access role assignments for referencing workloads, with explicit-role overrides.
Adds configuration, provisioning, emulator, and TypeScript signature coverage, plus usage documentation.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Non-targeted publishing skips the callback that registers certificate access, omitting KeyVaultCertificateUser from generated grants and preventing certificate retrieval in deployments relying on those grants.
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical issues remain: all five polyglot fixtures lack the Key Vault package needed for SDK validation, and mixed container/executable consumers can leave developers without the required Certificate User role.
In a local run with a container using WithRoleAssignments(vault, KeyVaultReader).WithReference(vault) and a plain executable referencing this Entra application, the developer receives no Certificate User role. The preparer skips the executable and applies vault defaults only when no global roles exist, so the container's explicit roles suppress this certificate grant. Include skipped consumers' certificate requirements in run-mode role collection while preserving the explicit opt-out, and add a mixed-consumer regression test.
The reason will be displayed to describe this comment to others. Learn more.
Looks good from a surface-level API and security review; no blocking issues identified in that scope. Two non-blocking comments:
Can you explicitly confirm that automatic vault-wide Key Vault Certificate User access, including private-key retrieval for other certificates in the vault, is the intended default? The resource-backed overload has a broader access-management side effect than passing the equivalent URL, which is particularly important for shared vaults. The documented override/opt-out behavior helps.
Please make the new-vault story explicit in the examples/documentation: a vault created by the AppHost is supported, but creating or importing its certificate and registering the public key with Entra remain separate provisioning steps. This helper alone does not provide that end-to-end flow.
This approval is based on static review and is not formal API/security sign-off or live certificate-retrieval verification.
Focus: Reviewer question: is automatic vault-wide Key Vault Certificate User access the intended default?
Artifact Version Verification
Installed CLI:17.0.0-pr.21425.g1f1cfa90 (from the PR dogfood artifacts, local temp install)
Packages: PR hive, suffix pr.21425.g1f1cfa90
Status: Verified: matches head 1f1cfa90ff
Scenarios (local, aspire publish with the PR CLI)
AppHost: Container Apps environment, one shared vault, an existing Entra app using WithCertificateFromKeyVault(vault, ...), and four workloads.
#
Workload
Expected
Result
1
web references only Entra
Key Vault Certificate User on the vault
Passed: web-roles-vault assigns db79e9a7-... (Certificate User) to the workload's identity
2
optout sets WithRoleAssignments(vault, []) before referencing Entra
No role
Passed: optout-roles-vault has the vault reference and no role assignment
3
vault-only references the vault, not Entra
Default Secrets User only
Passed: only 4633458b-... (Secrets User); no Certificate User
4
url-consumer uses the literal URL overload
No automatic role
Passed: no roles module generated
5
Same model without a role-assignment environment
Fails
Passed: The application model does not support role assignments...
6
End-to-end: web app (Microsoft.Identity.Web) using WithCertificateFromKeyVault(vault, "dev-cert") with an existing Entra app, run locally
Certificate is read from the vault and accepted by Entra
Passed (verified manually by Eric Erhardt (@eerhardt)): the app read the certificate from the vault and authenticated with it. The public key was added to the Entra app and the certificate created in the vault manually, as this PR doesn't do either
The first attempt failed with AADSTS700027 (certificate not registered on the application). That was a test-setup error: the AppHost had created a new registration that didn't have the key. It confirmed the certificate was read from Key Vault and used to sign the client assertion. Pointing the AppHost at the existing registration fixed it.
Emitted configuration: web and optout get ENTRA_CLIENT_CREDENTIALS_0_KEY_VAULT_URL = vault_outputs_vaulturi (a Bicep output reference, not a literal); url-consumer gets the literal URL.
Answer to the reviewer question
Verified: the automatic grant is vault-wide, not scoped to the named certificate.
The Bicep role assignment scopes to the whole vault resource.
Key Vault Certificate User reads certificate contents, including the secret (private key) portion for exportable certificates. So an Entra consumer can read every exportable certificate in a shared vault, not only web-certificate.
This is broader than the literal-URL overload, which grants nothing.
Scope in publish: only workloads that reference the Entra app. Scope when running locally: the vault's default roles are extended, so every local reference to that vault gets it.
Opt-outs: WithRoleAssignments(vault, ...) on the workload before referencing Entra (publish), and ClearDefaultRoleAssignments() on the vault (run).
Whether that default is intended is a design decision for the PR author; the behavior above is what the code does today.
Not verified
Run-mode default roles against real Azure beyond the manual run above: unit tests only.
Deployment (aspire deploy) and the managed-identity path in Azure Container Apps.
Interactive sign-in end to end (the existing registration had no redirect URIs configured).
Access-policy (non-RBAC) vaults, where this role has no effect.
Overall result
Behavior matches the PR description, and a real certificate read and authentication worked in a manual run. No defects found.
Can you explicitly confirm that automatic vault-wide Key Vault Certificate User access, including private-key retrieval for other certificates in the vault, is the intended default?
Yes that is the intended default. We don't have the abillity to reference a certificate directly and create a role assignment on it. If this is important, devs can remove our default role assignment and configure the access as necessary.
Added a new Microsoft Entra ID integration page documenting WithCertificateFromKeyVault with a Key Vault resource (C#/TypeScript), automatic Key Vault Certificate User role assignment, and URL fallback. Signals: integration_readme_changed (Aspire.Hosting.Azure.EntraId/README.md), pr_body_has_cli_flag_mention, pr_body_has_user_facing_section ("User-facing usage" section). Files: integrations/security/entra-id.mdx (new), sidebar config.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Entra certificate credentials can now use a Key Vault resource already modeled in the AppHost instead of requiring a hard-coded vault URL. The URI remains a deferred resource reference during local run and publish, including the Key Vault emulator endpoint in run mode. A literal vault URL is still accepted for vaults managed outside the AppHost. The same exported method accepts either a URL or a Key Vault resource in polyglot AppHosts.
Microsoft.Identity.Web reads the certificate with its private key, which the vault's default Key Vault Secrets User role doesn't allow, so the Key Vault Certificate User role is granted automatically:
ClearDefaultRoleAssignments, nothing is added.WithReference. A workload with explicit role assignments for that vault (set before referencing the application) keeps them. Publish environments that don't support role assignments fail with the existing "does not support role assignments" error instead of silently falling back to Secrets User.Adds a dependency from
Aspire.Hosting.Azure.EntraIdtoAspire.Hosting.Azure.KeyVault, and covers configuration binding, dependency discovery, run/publish RBAC, existing vaults, explicit-role overrides, emulator URI resolution.Fixes #20833
Microsoft.Identity.Web's Key Vault credential loader always retrieves the latest certificate version and has no version setting, so there is nothing to configure for version selection. The README documents this.
User-facing usage
C# AppHost:
TypeScript AppHost:
The certificate must already exist with an exportable private key, and its public key must be registered on the Entra application. The helper does not create certificates or upload public keys.
Validation
.\restore.cmd— passed.dotnet test --project tests\Aspire.Hosting.Azure.EntraId.Tests\Aspire.Hosting.Azure.EntraId.Tests.csproj --no-launch-profile -- --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'— passed, 471 tests.git diff --check— passed.Existing NU1903 advisories for the test dependency
System.Security.Cryptography.Xmlwere reported during restore/build. No live Azure deployment or certificate retrieval was performed.Security considerations
This change automatically grants certificate/private-key read access on the selected vault through the Key Vault Certificate User role: to the developer identity when running locally (as part of the vault's default roles, so any resource referencing that vault locally gets it), and to each workload referencing the Entra application when publishing. Explicit role assignments can replace the default, and
ClearDefaultRoleAssignmentsdisables the local grant. Certificate material is still fetched by the consuming application's authentication library, not resolved into AppHost-generated environment variables or published artifacts. Security review should confirm the default access scope and identity assumptions.Checklist
<remarks />and<code />elements on your triple slash comments?