Skip to content

Allow assigning parent account roles to Foundry project identities - #18939

Open
Bhupesh Cholake (RealBhupesh) wants to merge 1 commit into
microsoft:mainfrom
RealBhupesh:codex/foundry-project-role-assignments
Open

Bhupesh Cholake (RealBhupesh) wants to merge 1 commit into
microsoft:mainfrom
RealBhupesh:codex/foundry-project-role-assignments

Conversation

@RealBhupesh

Copy link
Copy Markdown

Description

Add a project-specific WithRoleAssignments overload that grants Cognitive Services roles on the parent Microsoft Foundry account to the Foundry project's own managed identity.

Foundry features such as Memory authenticate through the project's managed identity. The existing generic role-assignment path only grants permissions to resources that reference a target, so calling it on a Foundry project did not emit a role assignment. Using the raw Foundry User GUID in a manual workaround could also produce an invalid Bicep identifier.

This change:

  • records requested parent-account roles on AzureCognitiveServicesProjectResource
  • emits deterministic, normalized Bicep role assignments for the project identity
  • adds the Foundry User role to the ATS-compatible role mapping
  • uses the current Foundry User role name in hosted-agent code
  • documents the Foundry Memory scenario
  • verifies the generated Bicep scope, principal, and role definition

The API is explicit and opt-in. It does not broaden the default permissions assigned to Foundry projects.

Fixes #18938
Addresses #10871

Validation

  • Aspire.Hosting.Foundry.Tests: 119 passed
  • Aspire.Hosting.Foundry.Tests.csproj build: succeeded with 0 warnings and 0 errors
  • dotnet format --verify-no-changes: passed for the changed C# files
  • git diff --check: passed

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
  • 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

The security-sensitive behavior is limited to explicit role requests. The generated assignment uses the requested built-in role, the project's managed identity, and the parent Foundry account scope.

Copilot AI review requested due to automatic review settings July 30, 2026 11:22
@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 -- 18939

Or

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

@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Jul 30, 2026

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.

Pull request overview

Adds opt-in parent-account RBAC assignments for Microsoft Foundry project managed identities.

Changes:

  • Adds C# and ATS role-assignment APIs.
  • Generates scoped Bicep role assignments and tests their output.
  • Updates Foundry User terminology and Memory documentation.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
ProjectResourceTests...verified.bicep Captures generated RBAC infrastructure.
ProjectResourceTests.cs Tests project role assignments.
HostedAgentExtensionTests.cs Updates Foundry User expectations.
README.md Documents the Memory scenario.
ProjectResource.cs Stores requested parent roles.
ProjectBuilderExtension.cs Adds APIs and Bicep generation.
HostedAgentBuilderExtension.cs Updates hosted-agent role terminology.
AzureHostedAgentResource.cs Renames the role constant.
FoundryRole.cs Adds ATS-compatible role mapping.
FoundryExtensions.cs Reuses centralized role conversion.

Name = BicepFunction.CreateGuid(account.Id, project.Id, roleDefinitionId),
Scope = new IdentifierExpression(account.BicepIdentifier),
PrincipalType = RoleManagementPrincipalType.ServicePrincipal,
PrincipalId = projectPrincipalId,
var roleDefinitionId = BicepFunction.GetSubscriptionResourceId("Microsoft.Authorization/roleDefinitions", role.Id);
var roleAssignment = new RoleAssignment(Infrastructure.NormalizeBicepIdentifier($"{prefix}_{role.Name}"))
{
Name = BicepFunction.CreateGuid(account.Id, project.Id, roleDefinitionId),
var subscriptionResourceId = provisioningContext.Subscription.Id.ToString();
var roleDefinitionId = new ResourceIdentifier(
$"{subscriptionResourceId}/providers/Microsoft.Authorization/roleDefinitions/{AzureAIUserRoleDefinitionId}");
$"{subscriptionResourceId}/providers/Microsoft.Authorization/roleDefinitions/{FoundryUserRoleDefinitionId}");
/// <param name="roles">The Microsoft Foundry roles to assign to the project identity.</param>
/// <returns>The resource builder.</returns>
/// <ats-returns>The resource builder.</ats-returns>
[AspireExport("withFoundryProjectRoleAssignments")]
/// .WithRoleAssignments(foundryUserRole);
/// </code>
/// </example>
[AspireExportIgnore(Reason = "CognitiveServicesBuiltInRole is an Azure.Provisioning type not compatible with ATS. Use the FoundryRole-based overload instead.")]

Some Foundry features call other services through the project's managed identity. Assign the required role on the parent Foundry account directly to that identity:

```csharp
@RealBhupesh

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
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.

Can't assign roles like 'Foundry User' to Foundry project resource for Foundry Memory

2 participants