Repository navigation
Declare Entra application roles on provisioned registrations - #21357
Conversation
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
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21357Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21357" |
|
Mitch Denny (@mitchdenny), this is ready for your review. It declares Entra app roles on provisioned registrations; assignments and consent are follow-ups. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 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
EntraIdAppRoleandWithAppRole, 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
|
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
Tests selector3 / 100 PR test projects · 1 PR job, from 9 changed files. Selected PR test projects (3 / 100)
Selected PR jobs (1)
How these were chosen — grouped by what changed🔧 🔧 🔧 🔧 🔧 📄 📄 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
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.
|
Damian Edwards (@DamianEdwards) good catch. The EntraId playground now declares |
|
Pull request created: #1964
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1964 targeting Added a new page, Note This draft PR needs human review before merging. |
## 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]>


Description
Adds
EntraIdAppRoleandWithAppRole(EntraIdAppRole)to declare application roles (for exampleUserandAdmin) on Entra registrations created by Aspire. Roles are written to the application'sappRolesin the generated Graph Bicep.id), so they stay stable across deployments. The tenant resource suffix is not part of the ID.AllowedMemberTypesare open-ended strings passed through to Graph (default["User"]).WithAppRolethrows for them.AppRoleson the resource is a read-only list; roles are added only throughWithAppRole.Removal behavior (verified against a real tenant using Bicep generated from this code):
CannotDeleteOrUpdateEnabledEntitlement, and the directory is unchanged.isEnabled: falseand then dropping it succeeds.appRolesis 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 withisEnabled: false. This is documented in the README.Not included (follow-ups): role assignments (
Microsoft.Graph/appRoleAssignedTo), consent, and real-tokenroles/audience verification, which depends on assignments. This will conflict with #21278 inMicrosoftGraphApplicationand the README, so whichever lands second needs a rebase.Part of #21083.
Checklist
<remarks />and<code />elements on your triple slash comments?Fixes: #21083