Repository navigation
Add explicit Entra app-role assignments for managed identities - #21498
Conversation
Co-authored-by: Copilot App <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21498Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21498" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
Privileged Entra directory grants await identity/security review, and redeployment assignment-ID stability and retained-grant behavior remain unverified live, with the new E2E scenario compiled but not executed.
No open issues 🎉
What changed in this PR
Adds explicit, publish-only Entra application-role assignments so services can call an Aspire-modeled API directly using user-assigned managed identities, without separate caller registrations or federation. This implements the bounded managed-identity scope of #21083.
Changes:
- Adds C# overloads and a polyglot export for assigning roles to explicit identities or compute resources.
- Generates deduplicated Graph assignments with deferred principal IDs, stable role IDs, and validation.
- Documents deployment permissions and non-revocation behavior; adds unit, snapshot, and deployment scenario coverage. The new deployment scenario was compiled but not executed.
| File | Description |
|---|---|
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdPolyglotTests.AppRoleAssignments_ExportAcceptsIdentityAndCompute_compute=True.verified.bicep |
Captures compute-target export output. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdPolyglotTests.AppRoleAssignments_ExportAcceptsIdentityAndCompute_compute=False.verified.bicep |
Captures explicit-identity export output. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Symbols_KeepCollidingIdentityAndRoleNamesDistinct.verified.bicep |
Captures collision-safe symbol names. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=True#02.verified.bicep |
Captures explicit identity attachment to compute. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=True#01.verified.bicep |
Captures explicit-identity Graph assignment. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=True#00.verified.bicep |
Captures explicit-identity module dependencies. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=False#02.verified.bicep |
Captures automatically created identity attachment. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=False#01.verified.bicep |
Captures compute-identity Graph assignment. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=False#00.verified.bicep |
Captures automatically created identity dependencies. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.LocalRun_DoesNotRequestAnIdentityOrPublishAssignments.verified.bicep |
Confirms assignments are omitted during local run. |
tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.ExplicitAssignments_UsePrincipalIdsAndStableRoleIds.verified.bicep |
Captures principal bindings and stable role IDs. |
tests/Aspire.Hosting.Azure.EntraId.Tests/EntraIdPolyglotTests.cs |
Tests export dispatch and unsupported targets. |
tests/Aspire.Hosting.Azure.EntraId.Tests/EntraIdAppRoleAssignmentTests.cs |
Tests validation, deduplication, identity resolution, and regeneration. |
tests/Aspire.Deployment.EndToEnd.Tests/AzureEntraIdAppRoleDeploymentTests.cs |
Adds authorization, redeployment, and retained-grant checks. |
src/Aspire.Hosting.Azure.EntraId/README.md |
Documents usage, permissions, and explicit revocation. |
src/Aspire.Hosting.Azure.EntraId/Provisioning/EntraIdSymbolNames.cs |
Allocates identity parameter and assignment symbols. |
src/Aspire.Hosting.Azure.EntraId/Provisioning/EntraIdApiProvisioning.cs |
Emits Graph assignments and removes stale parameter bindings. |
src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs |
Adds assignment overloads, validation, and polyglot export. |
src/Aspire.Hosting.Azure.EntraId/EntraIdAppRoleAssignment.cs |
Records assignment targets and requested roles. |
src/Aspire.Hosting.Azure.EntraId/EntraIdApplicationResource.cs |
Resolves identities, validates roles, and integrates provisioning. |
Review effort: Balanced
Jose Perez Rodriguez (joperezr)
left a comment
There was a problem hiding this comment.
LGTM, just one question.
Mitch Denny (mitchdenny)
left a comment
There was a problem hiding this comment.
Looks good from a surface-level API and security review; no blocking issues identified. Two non-blocking comments:
- Please consider naming the Entra resource
apiRegistrationin examples, with a separately named API workload referencing it. Calling the registrationapimakes the direction ofPublishWithAppRoleAssignment(worker, ...)harder to understand: the worker receives a role on the API registration, not the reverse. - Can you explicitly confirm that create-without-revoke is the intended lifecycle contract? The documentation clearly explains that removing a call, changing its target, or excluding a caller leaves existing grants intact; I want to confirm that this is the deliberate API contract rather than a temporary implementation limitation.
This approval is based on static review and is not formal API/security sign-off or live deployment verification.
Integrate UAMI assignments with the shared existing-registration guard and align new examples with main's .NET project APIs. Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot App <[email protected]>
|
🚀 Deployment tests starting on PR #21498... This will deploy to real Azure infrastructure. Results will be posted here when complete. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
Privileged Entra directory grants await API/security sign-off, and the deployment E2E has only been compiled, leaving assignment-ID stability across forced redeployments and grant retention after removing calls unverified live.
No open issues 🎉
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
|
🚀 Deployment tests starting on PR #21498... This will deploy to real Azure infrastructure. Results will be posted here when complete. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
Privileged Entra directory grants await formal API/security review, and the deployment E2E covering forced-redeployment assignment-ID stability and retained grants was compiled but not executed.
No open issues 🎉
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
|
🚀 Deployment tests starting on PR #21498... This will deploy to real Azure infrastructure. Results will be posted here when complete. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
Privileged Entra directory grants still need API/security review and live redeployment/removal validation, as the compiled-but-unexecuted E2E scenario leaves assignment stability and retained-grant behavior unverified.
No open issues 🎉
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
Thanks - fixed.
It's not temporary - its because this is how child resources work in ARM. The same thing happens with any Azure resource - If you add a Storage Queue in one deployment and then remove the call, we don't delete the Queue. |
Tests selector2 / 100 PR test projects · 2 PR jobs, from 19 changed files. Selected PR test projects (2 / 100)
Selected PR jobs (2)
How these were chosen — grouped by what changed🔧 🔧 🔧 🔧 🔧 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
🔵 Needs a closer look
Privileged Microsoft Graph directory grants still require identity/security review, and the deployment E2E was compiled but not run, leaving assignment-ID stability and retained grants across redeployments unverified.
No open issues 🎉
Review effort: Balanced
|
Pull request created: #2031
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#2031 targeting Added new page Note This draft PR needs human review before merging. |
Description
Enable microservices to call an Entra-protected API directly as their user-assigned managed identities, with explicit application-role assignments. Callers do not need a separate app registration or federated identity credential.
Adds two
PublishWithAppRoleAssignmentoverloads: one accepts an explicit UAMI resource; the other uses a compute resource's attached or automatically provisioned identity. Both are publish/deploy-only and require enabled, Application-compatible roles on an Aspire-created registration. Assignments use deferred principal/object IDs and stable role IDs, with duplicate grants eliminated.Fixes #21083. Part of #21060. This implements the agreed UAMI assignment scope. No new package dependencies. The local-only playground changes used for manual verification are not included.
User-facing usage
C# AppHost:
TypeScript AppHost:
Security considerations
Assignments grant access only when explicitly requested. Declaring a role or referencing a registration does not grant it. Workloads must validate tokens and enforce the required role.
The deploying identity needs
AppRoleAssignment.ReadWrite.AllandApplication.Read.All(or a higher permission covering reads), with administrator consent and the applicable Entra directory role for delegated deployment. These privileges are not granted automatically and are not needed by the caller.Removing an assignment call, changing its target, or excluding a caller does not revoke the previous directory grant. Revocation is an explicit Graph/admin action; existing tokens and managed-identity token caches can delay observed changes. Existing API registrations remain configuration-only.
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'— passed, 498 tests.dotnet build tests\Aspire.Deployment.EndToEnd.Tests\Aspire.Deployment.EndToEnd.Tests.csproj -v:q— passed, zero warnings/errors. The new deployment E2E scenario was compiled, not executed.westus3passed all 35 Aspire deployment steps on the first attempt. The assigned caller returned HTTP 200 with the API's client ID asaud, the UAMI's principal/client IDs asoid/azp, androles: ["Orders.Read"]. An unassigned UAMI returned HTTP 403; wrong-audience and anonymous requests returned HTTP 401. Graph showed one matching role assignment and no federated identity credentials.Checklist
<remarks />and<code />elements on your triple slash comments?