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
Provision Entra federation trust from Aspire managed identities - #21227
Adds publish-time APIs that make an Aspire-created Entra ID app registration trust the user-assigned managed identity of the workload that uses it, so a deployed app authenticates with no client secret or certificate.
PublishWithFederatedManagedIdentityCredential() trusts the managed identity of every resource that references the registration.
PublishWithFederatedManagedIdentityCredential(computeResource) trusts one compute resource, which must reference the registration. Only that resource receives the credential.
PublishWithFederatedManagedIdentityCredential(identity) trusts an explicit AzureUserAssignedIdentityResource.
WithFederatedManagedIdentityCredential(clientId) (renamed from WithFicMsi) is configuration-only and is the option for existing registrations. It applies in run mode too, and the registration must already trust the identity.
ManagedIdentityRequiredAnnotation (new, public, experimental ASPIREAZURE003): AzureResourcePreparer gives the annotated compute resource a managed identity even when it has no role assignments. Referencing an Entra app adds it.
For a registration Aspire creates, the generated Bicep adds a Microsoft.Graph/applications/federatedIdentityCredentials resource: issuer is the tenant's v2.0 endpoint, subject is the identity's principal ID, audience is the cloud's token exchange audience (public, US Government, China; other clouds fail with a clear error). The workload receives the identity's client ID as ManagedIdentityClientId.
A validation step runs after azure-prepare-resources and fails with the resource name when a trusted compute resource has no managed identity.
The environment value for ManagedIdentityClientId is resolved lazily, because the preparer evaluates environment callbacks (and a callback's result is cached) before it attaches identities.
The credential is skipped in run mode; use another credential for local development.
Aspire.Hosting.Azure.EntraId.Tests (281 passed) and Aspire.Hosting.Azure.Tests for the preparer change.
Deployed an ACA web + API app to a test tenant with aspire deploy using the PR build. The deployed app acquires an app token as the registration using only the managed identity assertion; a wrong federated subject or audience fails with AADSTS700213 / AADSTS7002121; redeploys are idempotent.
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?
Add PublishWithFederatedManagedIdentityCredential overloads that make an Entra
application registration trust the user-assigned managed identity of each
referencing compute resource, a specific compute resource, or an explicit
identity. Add ManagedIdentityRequiredAnnotation so the Azure resource preparer
gives such resources an identity even without role assignments.
Fixes#21072
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 5fd51945-1cef-4047-aee3-548389684c71
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Identity lifecycle ordering breaks automatic-identity publishing and explicit-identity local provisioning, and generated credential names can exceed Graph limits.
The Azure resource preparer evaluates environment callbacks to discover
dependencies before it attaches each resource's identity, so the managed
identity credential must not require the identity when it is emitted.
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 5fd51945-1cef-4047-aee3-548389684c71
Identity creation depends on call order when using WithCredential. If a workload calls WithReference(entra) before entra.WithCredential(new EntraIdFederatedIdentityCredential()), this check sees no credential, and WithCredential never annotates the recorded consumers. Without other role assignments, the Azure preparer creates no identity and publish-time client ID resolution throws. Apply the identity requirement to existing consumers in the shared credential-registration path, and test both call orders through resource preparation.
Add deployed federation and token exchange integration tests
The new tests verify Bicep and configuration, but not deployed federation. AzureEntraIdDeploymentTests currently echoes tenant/client IDs without enabling federation or exchanging a managed-identity assertion. Extend it to deploy an Azure Container Apps workload with the attached identity, acquire a downstream token through the registration using the emitted configuration, and verify this again after redeployment. Include wrong-subject/audience rejection cases. This covers identity attachment, deployment ordering, and authentication behavior that snapshots cannot establish.
The new consumer-identity mode depends on call order through WithCredential. If a workload calls WithReference(entra) before entra.WithCredential(new EntraIdFederatedIdentityCredential()), this check sees no credential, and WithCredential only appends it. Without another identity requirement, the Azure preparer creates no identity and publishing fails in ResolveIdentity. Have WithCredential call EnsureManagedIdentityRequired for existing consumers when adding a credential with UsesConsumerIdentity, and test both call orders.
/// This setting only affects registrations created by Aspire. Existing registrations are not modified;
/// enable "ID tokens (used for implicit and hybrid flows)" in their Authentication settings instead.
/// </para>
The valid Azure China authority login.chinacloudapi.cn falls through to null. A resource-backed credential configured with this instance is therefore rejected by ValidateProvisioningConfiguration, despite China being supported. Recognize this host alongside login.partner.microsoftonline.cn and add a mapping regression test.
Add deployed federation and token exchange coverage
The new tests verify generated Bicep, annotations, and environment values, but not deployed federation. AzureEntraIdDeploymentTests deploys a registration and echoes IDs; it never exchanges a managed-identity assertion. Add an Azure Container Apps web-to-API scenario that verifies identity attachment, downstream token acquisition without a deployed secret, repeat deployment, and rejection of incorrect subjects/audiences. Snapshots cannot establish that the provider accepts the trust or that token exchange succeeds.
Resource-backed credentials can specify TokenExchangeUrl through WithCredential, but this validation checks only whether the cloud is supported. Environment emission honors the override while generated federation trust always uses the cloud's default audience. For example, a US Government registration with a public-cloud audience override requests assertions that do not match its generated trust, so authentication fails after provisioning. Reject resource-backed overrides that differ from the supported cloud audience and add a mismatch regression test. Leave configuration-only credentials unchanged.
Add regression coverage for compute-resource overload scoping
The compute-resource overload has no focused regression coverage; the federation tests exercise only the parameterless and explicit-identity overloads. Add a test with two referencing workloads and another credential that verifies only the selected identity is trusted, only that workload receives the federated credential, and both credential arrays have contiguous indexes. Also cover before-start rejection of a selected workload that never references the registration. These tests exercise the new scoping and validation branches without requiring a live deployment.
…entity
The public constructor takes the client ID of a managed identity Aspire does not manage. Aspire-managed identities are set through internal constructors, so a raw WithCredential cannot make the registration's Bicep reference an identity that is not provisioned when running.
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 5fd51945-1cef-4047-aee3-548389684c71
The compute-resource overload has no regression coverage: the federation tests call only the parameterless or explicit-identity overloads. Omitting ComputeTarget would broaden trust to every consumer without failing those tests. Add a focused publish-mode test in EntraIdProvisioningTests.cs with two referencing workloads that selects only one. Verify that generated trust includes only its identity and check both workloads' complete credential configuration, including contiguous indexes when another credential follows the scoped one. Also add an unreferenced-target case that exercises the pipeline validation. These tests protect Aspire's workload-scoping contract without requiring a deployed token-exchange test.
The compute-resource overload has no focused regression coverage; the federation tests call only the parameterless and explicit-identity overloads. Its distinct contract is to trust only the selected workload and omit its credential from other consumers. Add tests in Aspire.Hosting.Azure.EntraId.Tests with two consumers using different identities, select one through this overload, and verify the generated trust and both consumers' credential configuration. Include another credential after the scoped entry to check that skipping it leaves no index gaps, and verify that validation rejects a target that never calls WithReference. These are unit-level checks of Aspire's scoping behavior, not deployment or token-exchange tests.
Added a new Microsoft Entra ID integration page documenting PublishWithFederatedManagedIdentityCredential, WithFederatedManagedIdentityCredential (renamed from WithFicMsi) and ManagedIdentityRequiredAnnotation, plus a sidebar entry. Signals: integration_readme_changed (EntraId/README.md), new_public_type (ManagedIdentityRequiredAnnotation), experimental_attribute_added (ASPIREAZURE003), defaults_or_constants_file_changed (EntraIdBicepConstants.cs).
Azure hosting and Entra ID provisioning APIs, managed-identity preparation, generated Bicep, documentation, and tests.
No CLI implementation, Dashboard, VS Code extension, template, or CI infrastructure changes.
Test Scenarios Executed
Scenario 1: Fresh AppHost publish with explicit managed identity federation
Objective: Verify the PR CLI packages compile the documented API and generate deployable Azure Bicep. Coverage Type: Happy path Status: ✅ Passed
Steps:
Created a fresh �spire-empty C# AppHost from the PR hive.
Added Aspire.Hosting.Azure, Aspire.Hosting.Azure.AppContainers, and Aspire.Hosting.Azure.EntraId version 17.0.0-pr.21227.g687bce6a.
Added an Azure Container Apps environment, explicit user-assigned identity, Entra application, federated credential, and container reference.
Ran �spire publish with the installed PR CLI.
Evidence:
�pphost.cs
resh-app-publish.log
main.bicep
�ntra-web.bicep
web.bicep
Observations:
All 12 publish pipeline steps succeeded.
The generated Entra module contains Microsoft.Graph/applications/[email protected].
Issuer is the tenant v2.0 endpoint, subject is the identity principal ID, and audience is �pi://AzureADTokenExchange.
The container receives the Entra client ID and the identity client ID through the generated environment variables and is assigned the user-assigned identity.
The tested PR artifact and exact source commit behave as intended. Live Azure deployment was not repeated because it requires tenant credentials; the PR author documented a successful ACA deployment and token acquisition test in the PR description.
Notes
NuGet emitted existing vulnerability warnings for repository dependency versions during test builds. They did not fail either test project and are not introduced by this PR.
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
Adds publish-time APIs that make an Aspire-created Entra ID app registration trust the user-assigned managed identity of the workload that uses it, so a deployed app authenticates with no client secret or certificate.
PublishWithFederatedManagedIdentityCredential()trusts the managed identity of every resource that references the registration.PublishWithFederatedManagedIdentityCredential(computeResource)trusts one compute resource, which must reference the registration. Only that resource receives the credential.PublishWithFederatedManagedIdentityCredential(identity)trusts an explicitAzureUserAssignedIdentityResource.WithFederatedManagedIdentityCredential(clientId)(renamed fromWithFicMsi) is configuration-only and is the option for existing registrations. It applies in run mode too, and the registration must already trust the identity.ManagedIdentityRequiredAnnotation(new, public, experimentalASPIREAZURE003):AzureResourcePreparergives the annotated compute resource a managed identity even when it has no role assignments. Referencing an Entra app adds it.For a registration Aspire creates, the generated Bicep adds a
Microsoft.Graph/applications/federatedIdentityCredentialsresource: issuer is the tenant's v2.0 endpoint, subject is the identity's principal ID, audience is the cloud's token exchange audience (public, US Government, China; other clouds fail with a clear error). The workload receives the identity's client ID asManagedIdentityClientId.Behavior to be aware of:
PublishWith...overloads throw forAddExistingEntraApplication. (Same inconsistency for other registration-only APIs is tracked in Entra ID: throw when registration-only APIs are used with existing registrations #21256.)azure-prepare-resourcesand fails with the resource name when a trusted compute resource has no managed identity.ManagedIdentityClientIdis resolved lazily, because the preparer evaluates environment callbacks (and a callback's result is cached) before it attaches identities.Fixes #21072
Validation
Aspire.Hosting.Azure.EntraId.Tests(281 passed) andAspire.Hosting.Azure.Testsfor the preparer change.aspire deployusing the PR build. The deployed app acquires an app token as the registration using only the managed identity assertion; a wrong federated subject or audience fails with AADSTS700213 / AADSTS7002121; redeploys are idempotent.Checklist
<remarks />and<code />elements on your triple slash comments?