Skip to content

Support Key Vault resource references for Entra certificate credentials - #21425

Merged
Eric Erhardt (eerhardt) merged 10 commits into
mainfrom
eerhardt-key-vault-certificate-references
Nov 2, 2026
Merged

Eric Erhardt (eerhardt) merged 10 commits into
mainfrom
eerhardt-key-vault-certificate-references

Conversation

@eerhardt

@eerhardt Eric Erhardt (eerhardt) commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

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:

  • 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.

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:

var vault = builder.AddAzureKeyVault("vault");
var entraWeb = builder.AddExistingEntraApplication("entra-web", tenantId, webClientId)
    .WithCertificateFromKeyVault(vault, "MyCert");
builder.AddProject<Projects.Web>("web").WithReference(entraWeb);

TypeScript AppHost:

const vault = await builder.addAzureKeyVault("vault");
const entraWeb = await builder.addExistingEntraApplication("entra-web", tenantId, webClientId)
    .withCertificateFromKeyVault(vault, "MyCert");
await builder.addContainer("web", "my-web-image").withReference(entraWeb);

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.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?
        • Yes
        • No
    • No

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]>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21425

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21425"

@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Oct 30, 2026
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 30, 2026 03:58
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 open issues
What changed in this PR

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.
File Description
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​Snapshots/​AtsTypeScriptCodeGeneratorTests.KeyVaultCertificate_GeneratesSingleTypeScriptMethodWithUrlOrResource.verified.ts Records the URL-or-resource signature.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​AtsTypeScriptCodeGeneratorTests.cs Tests the single exported capability and signature.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests.csproj References Entra for code-generation tests.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdProvisioningTests.KeyVaultCertificate_RunAssignsDeveloperCertificateAccess.verified.bicep Records developer certificate-access assignment.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdProvisioningTests.KeyVaultCertificate_PublishAssignsConsumerIdentityAndCertificateAccess_configureCredentialAfterReference=True.verified.bicep Records workload access with late credential configuration.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdProvisioningTests.KeyVaultCertificate_PublishAssignsConsumerIdentityAndCertificateAccess_configureCredentialAfterReference=False.verified.bicep Records workload access with early credential configuration.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdPolyglotTests.KeyVaultCertificate_ExportAcceptsUrlAndResource.verified.txt Records both polyglot credential forms.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdKeyVaultCertificateTests.ResourceCredential_PreservesVaultReference_operation=Run_configureCredentialAfterReference=True.verified.txt Records resolved run URI with late configuration.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdKeyVaultCertificateTests.ResourceCredential_PreservesVaultReference_operation=Run_configureCredentialAfterReference=False.verified.txt Records resolved run URI with early configuration.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdKeyVaultCertificateTests.ResourceCredential_PreservesVaultReference_operation=Publish_configureCredentialAfterReference=True.verified.txt Records deferred publish URI with late configuration.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdKeyVaultCertificateTests.ResourceCredential_PreservesVaultReference_operation=Publish_configureCredentialAfterReference=False.verified.txt Records deferred publish URI with early configuration.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​EntraIdProvisioningTests.cs Tests developer and workload role generation.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​EntraIdPolyglotTests.cs Tests export dispatch and input validation.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​EntraIdKeyVaultCertificateTests.cs Covers references, binding, emulator URI, roles, and validation.
src/​Aspire.Hosting.Azure.EntraId/​README.md Documents usage, permissions, and latest-version behavior.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdResourceExtensions.cs Adds overload, export adapter, and certificate-access wiring.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdApplicationResource.cs Models resource-backed credentials and deferred vault URIs.
src/​Aspire.Hosting.Azure.EntraId/​Aspire.Hosting.Azure.EntraId.csproj Adds the Key Vault integration dependency.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
1 resolved since last review

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

Extend the vault's default roles in run mode and assign consumer roles when publishing.

Co-authored-by: Copilot App <[email protected]>
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 30, 2026 14:24
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

@github-actions

This comment has been minimized.

@eerhardt
Eric Erhardt (eerhardt) force-pushed the eerhardt-key-vault-certificate-references branch from 96cd788 to 1f1cfa9 Compare October 30, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

High severity Preserve certificate grants for skipped executable consumers

src/​Aspire.Hosting.Azure.EntraId/​EntraIdResourceExtensions.cs:1205

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.

Review effort: Balanced

@mitchdenny Mitch Denny (mitchdenny) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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.

@eerhardt

Copy link
Copy Markdown
Member Author

PR Testing Report

PR Information

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.

@eerhardt

Copy link
Copy Markdown
Member Author

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.

@eerhardt
Eric Erhardt (eerhardt) merged commit b58809d into main Nov 2, 2026
117 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Nov 2, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #2028

Generated by PR Documentation Check · copilot · auto · 30.8 AIC · ⌖ 1.15 AIC · ⊞ 7.1K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#2028 targeting release/17.0.

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.

Note

This draft PR needs human review before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Key Vault resource references for Entra certificate credentials

3 participants