Skip to content

Add public AzureRoleAssignmentResource type#16888

Merged
davidfowl merged 2 commits into
mainfrom
eerhardt/role-assignment-targets
May 9, 2026
Merged

Add public AzureRoleAssignmentResource type#16888
davidfowl merged 2 commits into
mainfrom
eerhardt/role-assignment-targets

Conversation

@eerhardt
Copy link
Copy Markdown
Member

@eerhardt eerhardt commented May 8, 2026

Description

Introduces a new public AzureRoleAssignmentResource type so callers can inspect role-assignment resources in the application model (e.g. from a pipeline step) and reason about what role assignments target which Azure resource.

Previously, role-assignment resources added by AzureResourcePreparer were plain AzureProvisioningResource instances, which made it impossible to identify them as role assignments or discover their target/owner without inspecting internal annotations.

The new type exposes:

  • TargetAzureResource — the Azure resource that the roles are assigned on (the scope, e.g. a KeyVault, Storage, etc.).
  • OwnerResource — the Aspire resource that owns this set of role assignments (the resource on which WithRoleAssignments(...) was called). null for global role assignments granted to the deployment principal.
  • IdentityResource — the user-assigned managed identity (AzureUserAssignedIdentityResource) whose principal receives the role assignments. null for global role assignments granted to the deployment principal.

RoleAssignmentResourceAnnotation is also tightened to hold the new typed resource. A regression test is added that uses a pipeline step running after WellKnownPipelineSteps.BeforeStart to enumerate all AzureRoleAssignmentResources targeting a single Azure resource (a Key Vault).

Fixes # (issue)

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

Introduce a public AzureRoleAssignmentResource type so callers can inspect role assignments via pipeline steps. Exposes:

  - TargetAzureResource: the Azure resource roles are assigned on
  - OwnerResource: the Aspire resource that called WithRoleAssignments (null for global)
  - IdentityResource: the user-assigned managed identity bearing the principal (null for global)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 8, 2026 20:10
@eerhardt eerhardt requested a review from mitchdenny as a code owner May 8, 2026 20:10
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

🚀 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 -- 16888

Or

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

@eerhardt eerhardt requested a review from davidfowl May 8, 2026 20:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new public AzureRoleAssignmentResource type in Aspire.Hosting.Azure so role-assignment provisioning resources can be identified and inspected in the distributed application model (including from pipeline steps), instead of appearing as generic AzureProvisioningResource instances.

Changes:

  • Add AzureRoleAssignmentResource (public) to represent role-assignment resources with explicit TargetAzureResource, OwnerResource, and IdentityResource metadata.
  • Update AzureResourcePreparer to create AzureRoleAssignmentResource instances for both targeted and global role-assignment resources.
  • Update/extend Azure hosting tests and snapshots to assert and validate the new typed role-assignment resources (including pipeline-step inspection after WellKnownPipelineSteps.BeforeStart).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureDeployerTests.DeployAsync_WithRedisAccessKeyAuthentication_CreatesCorrectDependencies.verified.txt Snapshot update to reflect role-assignment steps now referencing AzureRoleAssignmentResource.
tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureDeployerTests.DeployAsync_WithPrivateEndpoints_CreatesCorrectDependencies.verified.txt Snapshot update to reflect role-assignment resources being typed as AzureRoleAssignmentResource.
tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureDeployerTests.DeployAsync_WithAzureResourceDependencies_DoesNotHang_step=diagnostics.verified.txt Snapshot update to reflect role-assignment resources being typed as AzureRoleAssignmentResource.
tests/Aspire.Hosting.Azure.Tests/RoleAssignmentTests.cs Update assertions to find AzureRoleAssignmentResource and verify TargetAzureResource/OwnerResource wiring.
tests/Aspire.Hosting.Azure.Tests/AzureUserAssignedIdentityTests.cs Update role-assignment resource assertions to the new type and validate target/owner relationships.
tests/Aspire.Hosting.Azure.Tests/AzureResourcePreparerTests.cs Add a regression test demonstrating pipeline-step inspection of role assignments by target resource; update existing assertions to the new type.
src/Aspire.Hosting.Azure/RoleAssignmentResourceAnnotation.cs Tighten annotation type to point to AzureRoleAssignmentResource instead of AzureProvisioningResource.
src/Aspire.Hosting.Azure/AzureRoleAssignmentResource.cs Add the new public resource type and expose target/owner/identity metadata for inspection.
src/Aspire.Hosting.Azure/AzureResourcePreparer.cs Switch role-assignment resource creation to AzureRoleAssignmentResource for both targeted and global role assignments.

Comment on lines +22 to +27
public sealed class AzureRoleAssignmentResource(
string name,
AzureProvisioningResource targetAzureResource,
IResource? ownerResource,
AzureUserAssignedIdentityResource? identityResource,
Action<AzureResourceInfrastructure> configureInfrastructure)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Added a constructor check that throws ArgumentException when OwnerResource and IdentityResource are not consistently both null (global) or both non-null (targeted), plus a unit test covering both invalid combinations.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Re-running the failed jobs in the CI workflow for this pull request because 2 jobs were identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

Address PR review feedback: enforce that OwnerResource and IdentityResource must both be null (global) or both be non-null (targeted).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

🎬 CLI E2E Test Recordings — 77 recordings uploaded (commit c3c3561)

View all recordings
Status Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireInitSingleFileAppHostRunsViaDotnetRunAppHost ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InteractiveCSharpInitCreatesExpectedFiles ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LatestCliCanStartStableChannelAppHost ▶️ View Recording
LatestCliCanStartStableChannelTypeScriptAppHost ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterAppCore ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #25581232608

@davidfowl davidfowl merged commit 5a757a0 into main May 9, 2026
572 of 575 checks passed
@github-actions github-actions Bot added this to the 13.4 milestone May 9, 2026
aspire-repo-bot Bot added a commit to microsoft/aspire.dev that referenced this pull request May 9, 2026
…gnment inspection

Add a new section to the Azure role assignments guide documenting the
AzureRoleAssignmentResource type introduced in microsoft/aspire#16888.

The new section explains:
- The three properties exposed by AzureRoleAssignmentResource (TargetAzureResource,
  OwnerResource, and IdentityResource)
- How to enumerate role assignment resources from a pipeline step
- The null semantics for global vs. targeted role assignments

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@aspire-repo-bot
Copy link
Copy Markdown
Contributor

Pull request created: #896

Generated by PR Documentation Check

@aspire-repo-bot
Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#896 targeting main.

Added a new "Inspect role assignments programmatically" section to the Manage Azure role assignments guide, documenting the new AzureRoleAssignmentResource type. The section covers the three properties (TargetAzureResource, OwnerResource, IdentityResource), their null semantics, and includes a pipeline step code example showing how to enumerate role assignments targeting a specific Azure resource. Targeting main because release/13.4 does not exist on microsoft/aspire.dev.\n\n- src/frontend/src/content/docs/integrations/cloud/azure/role-assignments.mdx — updated

Note

This draft PR needs human review before merging.

IEvangelist pushed a commit to microsoft/aspire.dev that referenced this pull request May 11, 2026
…gnment inspection

Add a new section to the Azure role assignments guide documenting the
AzureRoleAssignmentResource type introduced in microsoft/aspire#16888.

The new section explains:
- The three properties exposed by AzureRoleAssignmentResource (TargetAzureResource,
  OwnerResource, and IdentityResource)
- How to enumerate role assignment resources from a pipeline step
- The null semantics for global vs. targeted role assignments

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
IEvangelist pushed a commit to microsoft/aspire.dev that referenced this pull request May 11, 2026
…signments guide (#896)

* docs: document AzureRoleAssignmentResource for programmatic role assignment inspection

Add a new section to the Azure role assignments guide documenting the
AzureRoleAssignmentResource type introduced in microsoft/aspire#16888.

The new section explains:
- The three properties exposed by AzureRoleAssignmentResource (TargetAzureResource,
  OwnerResource, and IdentityResource)
- How to enumerate role assignment resources from a pipeline step
- The null semantics for global vs. targeted role assignments

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* PR feedback

---------

Co-authored-by: aspire-repo-bot[bot] <268009190+aspire-repo-bot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants