Skip to content

Add explicit Entra app-role assignments for managed identities - #21498

Merged
Eric Erhardt (eerhardt) merged 6 commits into
mainfrom
eerhardt-entra-uami-app-role-assignments
Nov 2, 2026
Merged

Eric Erhardt (eerhardt) merged 6 commits into
mainfrom
eerhardt-entra-uami-app-role-assignments

Conversation

@eerhardt

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

Copy link
Copy Markdown
Member

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 PublishWithAppRoleAssignment overloads: 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:

var worker = builder.AddDotnetProject("worker", "../Worker/Worker.csproj");
var apiRegistration = builder.AddEntraIdApplication("entra-api")
    .WithApplicationIdUri()
    .WithAppRole(new EntraIdAppRole("Orders.Read", "Read orders", "Read orders.", ["Application"]))
    .PublishWithAppRoleAssignment(worker, "Orders.Read");

var api = builder.AddDotnetProject("api", "../Api/Api.csproj")
    .WithReference(apiRegistration);

TypeScript AppHost:

const worker = await builder.addContainer("worker", "my-worker-image");
const apiRegistration = await builder.addEntraIdApplication("entra-api")
    .withApplicationIdUri()
    .withAppRole("Orders.Read", "Read orders", "Read orders.", {
        allowedMemberTypes: ["Application"],
    })
    .publishWithAppRoleAssignment(worker, ["Orders.Read"]);

const api = await builder.addContainer("api", "my-api-image")
    .withReference(apiRegistration);

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.All and Application.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.
  • Generated TypeScript SDK signature inspected; both identity and compute targets are accepted, and the exported capability is covered by dispatch tests.
  • Manual Azure Container Apps deployment from this branch in westus3 passed all 35 Aspire deployment steps on the first attempt. The assigned caller returned HTTP 200 with the API's client ID as aud, the UAMI's principal/client IDs as oid/azp, and roles: ["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.
  • Still unverified live: forced-redeployment assignment-ID stability, retained grants after removing assignment calls, and explicit revocation with refreshed-token/cache behavior. The new deployment E2E scenario covers the first two; API and security reviews are also pending.

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

@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 -- 21498

Or

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

@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 21:15
@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

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

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.

LGTM, just one question.

@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. Two non-blocking comments:

  • Please consider naming the Entra resource apiRegistration in examples, with a separately named API workload referencing it. Calling the registration api makes the direction of PublishWithAppRoleAssignment(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]>

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

Privileged directory grants still need API/security review and live redeployment/removal validation, as the new E2E scenario was compiled but not executed.

No open issues 🎉

Review effort: Balanced

@github-actions

This comment has been minimized.

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot November 2, 2026 17:46
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployment tests starting on PR #21498...

This will deploy to real Azure infrastructure. Results will be posted here when complete.

View workflow run

@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

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

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployment tests starting on PR #21498...

This will deploy to real Azure infrastructure. Results will be posted here when complete.

View workflow run

@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

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

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployment tests starting on PR #21498...

This will deploy to real Azure infrastructure. Results will be posted here when complete.

View workflow run

@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

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

@eerhardt

Copy link
Copy Markdown
Member Author

Please consider naming the Entra resource apiRegistration in examples, with a separately named API workload referencing it. Calling the registration api makes the direction of PublishWithAppRoleAssignment(worker, ...) harder to understand: the worker receives a role on the API registration, not the reverse.

Thanks - fixed.

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.

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.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Tests selector

2 / 100 PR test projects · 2 PR jobs, from 19 changed files.

Selected PR test projects (2 / 100)

Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

Selected PR jobs (2)

polyglot, typescript-api-compat


How these were chosen — grouped by what changed

🔧 src/Aspire.Hosting.Azure.EntraId/EntraIdAppRoleAssignment.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🔧 src/Aspire.Hosting.Azure.EntraId/EntraIdApplicationResource.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🔧 src/Aspire.Hosting.Azure.EntraId/EntraIdResourceExtensions.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🔧 src/Aspire.Hosting.Azure.EntraId/Provisioning/EntraIdApiProvisioning.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🔧 src/Aspire.Hosting.Azure.EntraId/Provisioning/EntraIdSymbolNames.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/EntraIdAppRoleAssignmentTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/EntraIdPolyglotTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.ExplicitAssignments_UsePrincipalIdsAndStableRoleIds.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.LocalRun_DoesNotRequestAnIdentityOrPublishAssignments.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=False#00.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=False#01.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=False#02.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=True#00.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=True#01.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Publish_ResolvesIdentityDependenciesAfterPreparation_explicitIdentity=True#02.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdAppRoleAssignmentTests.Symbols_KeepCollidingIdentityAndRoleNamesDistinct.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdPolyglotTests.AppRoleAssignments_ExportAcceptsIdentityAndCompute_compute=False.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

🧪 tests/Aspire.Hosting.Azure.EntraId.Tests/Snapshots/EntraIdPolyglotTests.AppRoleAssignments_ExportAcceptsIdentityAndCompute_compute=True.verified.bicep (changed test)
→ 1 directly: Aspire.Hosting.Azure.EntraId.Tests

Job reasons

Job Triggered by
polyglot affected project Aspire.Hosting.Azure.EntraId
typescript-api-compat affected project Aspire.Hosting.Azure.EntraId

Selection computed for commit 95a6961.

@eerhardt
Eric Erhardt (eerhardt) enabled auto-merge (squash) November 2, 2026 21:39

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

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

@eerhardt
Eric Erhardt (eerhardt) merged commit d2da9d6 into main Nov 2, 2026
61 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: #2031

Generated by PR Documentation Check · copilot · auto · 32.7 AIC · ⌖ 1.16 AIC · ⊞ 7.2K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

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

Added new page integrations/security/microsoft-entra-id-app-roles.mdx (plus sidebar entry) documenting PublishWithAppRoleAssignment, deployment privileges and revocation. Signals: integration_readme_changed (Aspire.Hosting.Azure.EntraId/README.md), pr_body_has_user_facing_section (User-facing usage), pr_body_has_cli_flag_mention (validation commands; likely false positive).

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.

Model and provision Entra application roles and role assignments

4 participants