Skip to content

Declare Entra application roles on provisioned registrations - #21357

Merged
Eric Erhardt (eerhardt) merged 2 commits into
mainfrom
eerhardt-entra-app-roles
Oct 28, 2026
Merged

Eric Erhardt (eerhardt) merged 2 commits into
mainfrom
eerhardt-entra-app-roles

Conversation

@eerhardt

Copy link
Copy Markdown
Member

Description

Adds EntraIdAppRole and WithAppRole(EntraIdAppRole) to declare application roles (for example User and Admin) on Entra registrations created by Aspire. Roles are written to the application's appRoles in the generated Graph Bicep.

  • Role IDs are derived from the resource name and role value (or supplied with id), so they stay stable across deployments. The tenant resource suffix is not part of the ID.
  • AllowedMemberTypes are open-ended strings passed through to Graph (default ["User"]).
  • Existing registrations are never modified: WithAppRole throws for them.
  • AppRoles on the resource is a read-only list; roles are added only through WithAppRole.

Removal behavior (verified against a real tenant using Bicep generated from this code):

  • Dropping a role that is still enabled fails with CannotDeleteOrUpdateEnabledEntitlement, and the directory is unchanged.
  • Deploying the role with isEnabled: false and then dropping it succeeds.
  • appRoles is sent only when the application declares at least one role, matching the restraint of the scopes work in Provision Entra API identifier URIs, scopes, and caller permissions #21278. To retire the last role, leave it declared with isEnabled: false. This is documented in the README.

Not included (follow-ups): role assignments (Microsoft.Graph/appRoleAssignedTo), consent, and real-token roles/audience verification, which depends on assignments. This will conflict with #21278 in MicrosoftGraphApplication and the README, so whichever lands second needs a rebase.

Part of #21083.

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

Fixes: #21083

Add EntraIdAppRole and WithAppRole to declare app roles (for example User and Admin) on registrations created by Aspire. Role IDs are derived from the resource name and role value, or supplied explicitly, so they stay stable across deployments. Existing registrations are never modified. Role assignments are not provisioned yet.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cfaafd3e-55f3-48d0-a51e-8da68dcbeb54
@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 -- 21357

Or

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

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 27, 2026 23:09
@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Oct 27, 2026
@eerhardt
Eric Erhardt (eerhardt) marked this pull request as ready for review October 27, 2026 23:09
@eerhardt

Copy link
Copy Markdown
Member Author

Mitch Denny (@mitchdenny), this is ready for your review. It declares Entra app roles on provisioned registrations; assignments and consent are follow-ups.

@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

Collection encapsulation, role-value validation, and misleading role-retirement and preservation guidance need correction.

4 open issues
What changed in this PR

Adds application-role declarations to Aspire’s Entra ID hosting integration, covering the role-definition portion of #21083. Role assignments, consent, and token verification remain follow-up work.

Changes:

  • Introduces EntraIdAppRole and WithAppRole, with stable derived or explicit role IDs.
  • Emits declared roles in Graph Bicep while rejecting declarations on existing registrations.
  • Adds provisioning snapshots, validation tests, and role-retirement documentation.
File Description
tests/​Aspire.Hosting.Azure.EntraId.Tests/​Snapshots/​EntraIdProvisioningTests.WithAppRole_GeneratesAppRolesWithStableIds.verified.bicep Captures generated role definitions and stable IDs.
tests/​Aspire.Hosting.Azure.EntraId.Tests/​EntraIdProvisioningTests.cs Tests generation, validation, duplicate IDs, and existing-registration rejection.
src/​Aspire.Hosting.Azure.EntraId/​README.md Documents role declarations, retirement, and limitations.
src/​Aspire.Hosting.Azure.EntraId/​Provisioning/​MicrosoftGraphAppRole.cs Models Graph app-role properties for Bicep generation.
src/​Aspire.Hosting.Azure.EntraId/​Provisioning/​MicrosoftGraphApplication.cs Adds the Graph application’s role collection.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdResourceExtensions.cs Adds the validated WithAppRole builder method.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdAppRole.cs Defines role metadata, validation, and deterministic IDs.
src/​Aspire.Hosting.Azure.EntraId/​EntraIdApplicationResource.cs Stores role declarations and converts them into provisioning constructs.

Review effort: Balanced

@DamianEdwards

Copy link
Copy Markdown
Member

Eric Erhardt (@eerhardt) no playground app that uses these features?

Validate role values against Microsoft Graph's rules, return AppRoles as a read-only collection, document that disabling a role does not revoke existing assignments and that Aspire replaces the full appRoles collection, and declare roles in the EntraId playground.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cfaafd3e-55f3-48d0-a51e-8da68dcbeb54
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

3 / 100 PR test projects · 1 PR job, from 9 changed files.

Selected PR test projects (3 / 100)

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

Selected PR jobs (1)

typescript-api-compat


How these were chosen — grouped by what changed

🔧 src/Aspire.Hosting.Azure.EntraId/EntraIdAppRole.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/MicrosoftGraphAppRole.cs (changed source)
→ 2 directly: Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Tests

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

📄 playground/EntraId/EntraId.AppHost/AppHost.cs (changed)
→ 1 directly: Aspire.Playground.Tests

📄 playground/EntraId/EntraId.Web/Program.cs (changed)
→ 1 directly: Aspire.Playground.Tests

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

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

Job reasons

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

Selection computed for commit 53662ba.

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.

@eerhardt

Copy link
Copy Markdown
Member Author

Damian Edwards (@DamianEdwards) good catch. The EntraId playground now declares User and Admin roles in creation mode (53662ba). The .NET front end lists the roles claim from the ID token after sign-in, and the playground README explains how to assign a role to yourself in the Entra admin center. Aspire only declares roles for now; assignments are a follow-up on #21083. I built the playground but haven't run it against a tenant yet.

@eerhardt
Eric Erhardt (eerhardt) merged commit 4632f1c into main Oct 28, 2026
54 of 55 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 28, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #1964

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

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

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

Added a new page, azure-entra-id-app-roles.mdx, and a sidebar entry. Triggered signals: new_public_type (EntraIdAppRole.cs) and integration_readme_changed (Aspire.Hosting.Azure.EntraId/README.md).

Note

This draft PR needs human review before merging.

Eric Erhardt (eerhardt) added a commit that referenced this pull request Oct 28, 2026
## Description

Enables polyglot AppHosts to use the Entra ID hosting integration,
including new registrations, configuration-only references to existing
registrations, consumer settings, all built-in credential kinds, owners,
deferred redirect URIs, application roles, API scopes and permissions,
admin consent, and managed-identity federation.

Fixes #21076

Supersedes #21292, whose coverage is included here: Rust fixture plus
Rust runner compilation, CI routing for every fixture language, and
generic `withReference` dispatch coverage.

Existing C# signatures and behavior are preserved, as is the package's
preview versioning. Overloaded C# APIs remain available; internal ATS
adapters expose one typed capability per concept. Entra references use
the existing generic `withReference` dispatcher rather than introducing
a competing export.

- Tenant and client IDs independently accept literals or parameter
resources.
- Top-level `addExistingEntraApplication` does not enable Azure
provisioning or query Graph. Fluent `asExistingApplication` retains
previously enabled Azure setup.
- Endpoint redirects remain deferred through run and publish, and
secret/password parameters retain secret tracking.
- Exports `withAppRole(value, displayName, description, {
allowedMemberTypes, id, isEnabled })` over the new `EntraIdAppRole` API;
the generated Bicep matches the C# call.
- Exports `withApplicationIdUri`, `withScope`, `getScopeUri`,
`withPreAuthorizedApplication`, `withApiPermissions` and
`withAdminConsent` for registrations in the AppHost, plus
`withExternalApiPermissions`/`withExternalApiAdminConsent` for Microsoft
Graph and other APIs (well-known API enum or custom API DTO).
`withEntraIdReference` is the only way to set the `DownstreamApis`
prefix, since the generic `withReference` dispatcher has no slot for it.
- Adds behavior and generated TypeScript contract coverage, adds
dedicated Go, Java, Python, Rust and TypeScript
`tests/PolyglotAppHosts/Aspire.Hosting.Azure.EntraId` fixtures that
exercise every export, updates test routing, and documents TypeScript
usage.

### Examples

Existing C# AppHosts continue to work unchanged:

```csharp
var tenantId = builder.AddParameter("entra-tenant");
var clientId = builder.AddParameter("entra-client");
var secret = builder.AddParameter("entra-secret", secret: true);
var entra = builder.AddExistingEntraApplication("entra", tenantId, clientId)
    .WithClientSecret(secret);
builder.AddContainer("worker", "my-worker-image")
    .WithReference(entra, connectionName: "AUTH");
```

Generated TypeScript supports mixed ID inputs and typed credential
arguments:

```typescript
const tenantId = await builder.addParameter("entra-tenant");
const secret = await builder.addParameter("entra-secret", { secret: true });
const entra = await builder.addExistingEntraApplication(
    "entra", tenantId, "00001111-aaaa-2222-bbbb-3333cccc4444")
    .withClientSecret(secret);
await builder.addExecutable("worker", "node", ".", ["worker.mjs"])
    .withReference(entra, { connectionName: "AUTH" });
```

New registrations support deferred endpoint redirects and publish-time
federation:

```typescript
const entra = await builder.addEntraIdApplication("entra");
const web = await builder.addContainer("web", "my-web-image")
    .withHttpEndpoint({ targetPort: 8080 })
    .withReference(entra);
await entra.withRedirectUris(await web.getEndpoint("http"), {
    callbackPaths: ["/signin-oidc"],
});
await entra.publishWithFederatedManagedIdentityCredential({ identity: web });
```

### Security considerations

This exposes existing identity and credential configuration through ATS;
it does not install or configure workload authentication libraries, add
scopes/consent, or change authorization behavior. Client secrets and
certificate passwords require secret parameters. Existing registrations
are never modified. Creating registrations and federation trust still
requires the existing Azure/Graph permissions; owners can manage
registrations. Certificate and assertion paths identify files on the
consumer, not files read by the AppHost.

### Validation

The following commands were run on Windows:

| Command | Result |
| --- | --- |
| `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, 452 tests |
| `dotnet test --project
tests\Aspire.Hosting.CodeGeneration.TypeScript.Tests\Aspire.Hosting.CodeGeneration.TypeScript.Tests.csproj
--no-launch-profile -- --filter-not-trait 'quarantined=true'
--filter-not-trait 'outerloop=true'` | Passed, 153 tests |
| `dotnet test --project
tests\Infrastructure.Tests\Infrastructure.Tests.csproj
--no-launch-profile -- --filter-namespace
'Infrastructure.Tests.TestTriggerMap' --filter-not-trait
'quarantined=true' --filter-not-trait 'outerloop=true'` | 314 passed, 22
failed: Windows bash-path failures in `PrComparisonBaseTests` and
access-denied cleanup of temporary Git objects in `SelectTestsCliTests`
|
| `dotnet test --project
tests\Infrastructure.Tests\Infrastructure.Tests.csproj
--no-launch-profile -- --filter-namespace
'Infrastructure.Tests.TestTriggerMap' --filter-not-class
'*.PrComparisonBaseTests' --filter-not-class '*.SelectTestsCliTests'
--filter-not-trait 'quarantined=true' --filter-not-trait
'outerloop=true'` | Passed, 255 map, acceptance, and graph tests |
| `dotnet run --project tools\SelectTests -- --changed-files
artifacts\entra-polyglot\changed-files.txt --explain` | All changed
files attributed; selected Entra, Azure, TypeScript codegen, and
infrastructure tests plus polyglot/API compatibility jobs |
| `dotnet build src\Aspire.Cli\Aspire.Cli.csproj --nologo -v:q
/p:SkipNativeBuild=true` | Passed |
| `Set-Location` into a copy of each
`tests\PolyglotAppHosts\Aspire.Hosting.Azure.EntraId` fixture (local
project mapping), then `aspire restore` and `npm run build` / `go build
./...` / `pyright` / `javac --enable-preview --source 25` / `cargo
check` | All five passed, mirroring the CI polyglot validation scripts |
| `git diff --check` | Passed |

Manual verification used the locally built CLI (`dotnet
.\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll`) and a temporary
generated TypeScript AppHost:

```powershell
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll restore --apphost artifacts\entra-polyglot\apphost.mts --non-interactive
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll start --non-interactive --isolated --apphost artifacts\entra-polyglot\apphost.mts --format Json
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll describe --apphost artifacts\entra-polyglot\apphost.mts --format Json
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll logs consumer --apphost artifacts\entra-polyglot\apphost.mts --non-interactive
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll stop --apphost artifacts\entra-polyglot\apphost.mts --non-interactive
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll publish --apphost artifacts\entra-polyglot\apphost.mts --output-path artifacts\entra-polyglot\publish-existing --non-interactive --include-exception-details
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll deploy --apphost artifacts\entra-polyglot\apphost.mts --output-path artifacts\entra-polyglot\deploy-existing --non-interactive --include-exception-details
$env:ENTRA_SCENARIO='create'
dotnet .\artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll publish --apphost artifacts\entra-polyglot\apphost.mts --output-path artifacts\entra-polyglot\publish-created --non-interactive --include-exception-details
```

All commands succeeded. Existing registrations reported healthy, and a
Node consumer exited successfully after asserting its injected
configuration, including secret and certificate password values.
Configuration-only publish/deploy completed without Azure provisioning
steps. New-registration publish generated Graph
application/service-principal Bicep, owners, managed-identity
federation, and environment-derived redirect URLs; the templates were
inspected. The validation AppHost was stopped.

After rebasing onto main (including #21357), generated TypeScript
AppHosts calling `withAppRole` and the scope/permission/consent exports
published successfully; the Bicep contained the expected `appRoles`,
identifier URIs, scopes and pre-authorized clients, and the consumer
received the expected `DownstreamApis` configuration. No live
Azure/Graph mutation was performed. Existing NU1903 advisories for
`System.Security.Cryptography.Xml` were not changed.

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [x] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [x] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [x] No
  - [ ] No
- Does the change make any security assumptions or guarantees?
  - [x] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [x] No
  - [ ] No

---------

Co-authored-by: Copilot App <[email protected]>
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