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
Add local developer certificate credentials for Entra applications - #21382
Aspire-created Entra registrations can sign users in without a client credential, but authorization-code redemption and downstream token acquisition need one. This adds an opt-in local developer certificate credential, avoiding client secrets and never provisioning a private key into Entra.
RunWithLocalDeveloperCertificateCredential() creates a dedicated 48-hour RSA signing certificate per Entra resource in the AppHost-specific Aspire store. A subsequent run reuses it while more than 24 hours remain; otherwise it atomically overwrites the same owner-protected PFX file. Only public DER certificate material is embedded in the run-mode Bicep template; changing it invalidates the deployment checksum. Referencing workloads receive the matching private PFX through a secret parameter using SourceType = Base64Encoded and Base64EncodedValue.
Aspire declares the selected certificate as the registration's entire keyCredentials collection and lets Graph assign the credential ID. Deployment replaces existing keys, including unexpired predecessors; there is no separate Graph read or merge. A newly persisted certificate is retained after a provisioning failure for retry. Existing registrations remain caller-managed, and publish mode neither generates nor emits local credentials.
The method is exported to polyglot AppHosts (runWithLocalDeveloperCertificateCredential in TypeScript and the equivalent in Python, Go, Java, and Rust). It is covered by the polyglot fixtures and by tests that invoke the exported capability.
Certificate generation is extracted from the CLI into src/Shared/CertificateFactory.cs, source-linked by both the CLI HTTPS certificate manager and the Entra integration. The shared factory retains RSA-2048/SHA-256 signing and the existing subject/authority key identifier handling. HTTPS-specific extensions and Entra-specific validity, storage, and renewal remain with their respective callers.
The Entra playground has an opt-in authorization-code/Graph /me scenario (useLocalCertificate, off by default). An MVC controller using Identity.Web's AuthorizeForScopes restarts interactive sign-in for incremental-consent and conditional-access challenges; the default and Node sign-in flows are unchanged.
// Use distinct registration names or Azure:TenantResourceSuffix values for development and production.varentraWeb=builder.AddEntraIdApplication("entra-web").RunWithLocalDeveloperCertificateCredential().PublishWithFederatedManagedIdentityCredential();builder.AddProject<Projects.Web>("web").WithReference(entraWeb);
For the playground, keep useExistingApplication = false and set useLocalCertificate = true in playground/EntraId/EntraId.AppHost/AppHost.cs. In run mode, the .NET frontend then uses authorization code flow with PKCE and can call Graph /me after user consent.
Security considerations
Development and production must use separate Entra registrations. Different resource groups do not isolate tenant-scoped registrations, and excluding a local credential from publish does not revoke a key previously registered against the same application.
Private PFX files live under IAspireStore.BasePath/dev-certs/Entra/<resource-name>.pfx, with owner-only Windows ACLs or Unix permissions. Renewal retains no private-key generations; stable lock files coordinate access and interrupted temporary writes are cleaned up.
Base64 is not encryption. The PFX is a secret runtime environment value, accessible to the referenced workload and sufficiently privileged host/container tooling. It is not a deployment parameter, image-build input, certificate mount, or published artifact.
Aspire owns the development registration's entire certificate credential collection. Deployments replace unrelated keys and unexpired predecessors; older sessions using a replaced certificate must restart. Use dedicated developer registrations rather than sharing with independently managed certificate credentials.
The provisioning identity needs Graph application creation/update permissions: delegated Application.ReadWrite.All, or application Application.ReadWrite.OwnedBy for owned registrations, subject to tenant policy. Workloads do not need Graph application-management permissions.
Renewal is checked at AppHost startup, not by a background timer. Restart development sessions before certificate expiry. Formal security review remains outstanding.
Passed earlier in this PR (not rerun after the final rebase): Aspire.Hosting.Azure.TestsBicepUtilitiesTests (34 tests), a playground AppHost build into an isolated output directory, and az bicep build of the run-mode template with the pinned Graph extension.
Coverage includes renewal thresholds, isolation, overwrite/recovery, contention/cancellation, Windows ACLs, the single-public-key Bicep shape, renewal-driven checksum changes, secret sensitivity, direct secret resolution without provisioning waits, publish exclusion, polyglot capability export, and loading the private key through Microsoft.Identity.Web and verifying its signature with the published public key.
Certificate rotation/update against Graph was exercised manually by the author. Not yet validated: a generated TypeScript/Python/Go/Java/Rust AppHost run against the new export, the polyglot store location, actual container execution, and non-Windows filesystem behavior. API review and formal security review are pending. Test restore reports existing NU1903 advisories for System.Security.Cryptography.Xml 10.0.10; dependency versions were not changed.
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?
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The suffix lookup can read keys from the wrong Entra registration and overwrite unrelated credentials, while cached provisioning can return certificates Entra no longer trusts.
Adds opt-in local certificate credentials for Aspire-created Entra applications, enabling authorization-code redemption and downstream token acquisition without client secrets.
Handle missing token cache after restart without returning HTTP 500
playground/EntraId/EntraId.Web/Program.cs:84
After a frontend restart, the in-memory token cache is empty while the user's authentication cookie can remain valid. /me then passes authorization, but GetAccessTokenForUserAsync throws MicrosoftIdentityWebChallengeUserException, returning HTTP 500 in the documented restart/reuse workflow. Handle this exception by issuing an OpenID Connect challenge back to /me with the required scopes and any claims challenge, or reject cookies whose accounts are missing from the token cache.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Local-time validity checks can unnecessarily replace certificates across daylight-saving transitions, frontend restarts can cause authenticated requests to return HTTP 500, and certificate provisioning and renewal lack run-mode test-tenant verification.
Recover authentication when token cache is lost after restart
playground/EntraId/EntraId.Web/Program.cs:84
After restarting the .NET frontend, its authentication cookie can remain valid while AddInMemoryTokenCaches() has lost the user's account and tokens. /me then throws MicrosoftIdentityWebChallengeUserException and returns HTTP 500 instead of acquiring a Graph token; RequireAuthorization() only checks the cookie and does not recover the token cache. Handle the interaction-required exception by issuing an OIDC challenge, or reject cookies whose accounts are absent from the cache, so the documented restart scenario can recover without a manual sign-out.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because authentication cookies can outlive the in-memory token cache after a restart, causing authorized /me requests to fail with HTTP 500 instead of reauthenticating.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed for a restart-related authentication edge case where a valid cookie can outlive cached tokens and cause /me to return HTTP 500.
…on conversion
- Compare certificate validity in UTC so a daylight-saving transition cannot make a 48-hour certificate look longer and force replacement.
- Import the stored PFX with the default key set on macOS, which does not support ephemeral PFX imports.
- Reject converting a certificate-configured registration to an existing application before the polyglot adapter assigns any IDs.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The certificate reuse check subtracts local-time endpoints, so a spring daylight-saving transition can trigger unnecessary certificate replacement and invalidate existing sessions.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the local developer certificate lifecycle, provisioning and runtime configuration, publish isolation, and shared certificate factory changes. No blocking correctness findings.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The README incorrectly documents ASPIRE__STORE__PATH as relocating the private PFX even though the builder overwrites it, so it should instead describe setting builder.Configuration["Aspire:Store:Path"] after CreateBuilder and before Build.
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
Aspire-created Entra registrations can sign users in without a client credential, but authorization-code redemption and downstream token acquisition need one. This adds an opt-in local developer certificate credential, avoiding client secrets and never provisioning a private key into Entra.
RunWithLocalDeveloperCertificateCredential()creates a dedicated 48-hour RSA signing certificate per Entra resource in the AppHost-specific Aspire store. A subsequent run reuses it while more than 24 hours remain; otherwise it atomically overwrites the same owner-protected PFX file. Only public DER certificate material is embedded in the run-mode Bicep template; changing it invalidates the deployment checksum. Referencing workloads receive the matching private PFX through a secret parameter usingSourceType = Base64EncodedandBase64EncodedValue.Aspire declares the selected certificate as the registration's entire
keyCredentialscollection and lets Graph assign the credential ID. Deployment replaces existing keys, including unexpired predecessors; there is no separate Graph read or merge. A newly persisted certificate is retained after a provisioning failure for retry. Existing registrations remain caller-managed, and publish mode neither generates nor emits local credentials.The method is exported to polyglot AppHosts (
runWithLocalDeveloperCertificateCredentialin TypeScript and the equivalent in Python, Go, Java, and Rust). It is covered by the polyglot fixtures and by tests that invoke the exported capability.Certificate generation is extracted from the CLI into
src/Shared/CertificateFactory.cs, source-linked by both the CLI HTTPS certificate manager and the Entra integration. The shared factory retains RSA-2048/SHA-256 signing and the existing subject/authority key identifier handling. HTTPS-specific extensions and Entra-specific validity, storage, and renewal remain with their respective callers.The Entra playground has an opt-in authorization-code/Graph
/mescenario (useLocalCertificate, off by default). An MVC controller using Identity.Web'sAuthorizeForScopesrestarts interactive sign-in for incremental-consent and conditional-access challenges; the default and Node sign-in flows are unchanged.Fixes #21071
User-facing usage
For the playground, keep
useExistingApplication = falseand setuseLocalCertificate = trueinplayground/EntraId/EntraId.AppHost/AppHost.cs. In run mode, the .NET frontend then uses authorization code flow with PKCE and can call Graph/meafter user consent.Security considerations
IAspireStore.BasePath/dev-certs/Entra/<resource-name>.pfx, with owner-only Windows ACLs or Unix permissions. Renewal retains no private-key generations; stable lock files coordinate access and interrupted temporary writes are cleaned up.Application.ReadWrite.All, or applicationApplication.ReadWrite.OwnedByfor owned registrations, subject to tenant policy. Workloads do not need Graph application-management permissions.Validation
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".main:dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-namespace "Aspire.Cli.Tests.Certificates" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true". Includes shared-factory signing, supplied key identifiers, and HTTPS extension regression coverage.dotnet build playground\EntraId\EntraId.Web\EntraId.Web.csproj -o artifacts\entra-mvc-web-output -v:q.Aspire.Hosting.Azure.TestsBicepUtilitiesTests(34 tests), a playground AppHost build into an isolated output directory, andaz bicep buildof the run-mode template with the pinned Graph extension.Coverage includes renewal thresholds, isolation, overwrite/recovery, contention/cancellation, Windows ACLs, the single-public-key Bicep shape, renewal-driven checksum changes, secret sensitivity, direct secret resolution without provisioning waits, publish exclusion, polyglot capability export, and loading the private key through Microsoft.Identity.Web and verifying its signature with the published public key.
Certificate rotation/update against Graph was exercised manually by the author. Not yet validated: a generated TypeScript/Python/Go/Java/Rust AppHost run against the new export, the polyglot store location, actual container execution, and non-Windows filesystem behavior. API review and formal security review are pending. Test restore reports existing NU1903 advisories for
System.Security.Cryptography.Xml10.0.10; dependency versions were not changed.Checklist
<remarks />and<code />elements on your triple slash comments?