-
Notifications
You must be signed in to change notification settings - Fork 881
Add Foundry project role assignments #16736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d348928
c93403a
fd073f8
20e3393
f9e7455
7bf58c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,72 @@ public static IResourceBuilder<AzureCognitiveServicesProjectResource> AddProject | |
|
|
||
| var project = builder.ApplicationBuilder.AddResource(new AzureCognitiveServicesProjectResource(name, ConfigureInfrastructure, builder.Resource)); | ||
| project.Resource.DefaultContainerRegistry = CreateDefaultRegistry(builder.ApplicationBuilder, $"{name}-acr"); | ||
| return project; | ||
| return project.WithAnnotation(new DefaultRoleAssignmentsAnnotation(FoundryProjectRoleHelpers.CreateDefaultRoleDefinitions())); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Assigns the specified roles to the Microsoft Foundry project identity on the parent Microsoft Foundry resource. | ||
| /// This replaces the default project role assignments. | ||
| /// </summary> | ||
| /// <param name="builder">The Microsoft Foundry project resource builder.</param> | ||
| /// <param name="target">The parent Microsoft Foundry resource.</param> | ||
| /// <param name="roles">The built-in Cognitive Services roles to assign to the project identity.</param> | ||
| /// <returns>The updated <see cref="IResourceBuilder{AzureCognitiveServicesProjectResource}"/> with the applied role assignments.</returns> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Microsoft Foundry projects are assigned <see cref="CognitiveServicesBuiltInRole.CognitiveServicesUser"/> on their parent | ||
| /// Microsoft Foundry resource by default. Use this method to replace the default roles, or pass no roles to remove the | ||
| /// default role assignment. | ||
| /// </para> | ||
| /// <example> | ||
| /// The following example assigns the <see cref="CognitiveServicesBuiltInRole.CognitiveServicesOpenAIUser"/> role to a | ||
| /// Microsoft Foundry project identity on its parent Microsoft Foundry resource. | ||
| /// <code lang="csharp"> | ||
| /// var builder = DistributedApplication.CreateBuilder(args); | ||
| /// | ||
| /// var foundry = builder.AddFoundry("foundry"); | ||
| /// var project = foundry.AddProject("project") | ||
| /// .WithRoleAssignments(foundry, CognitiveServicesBuiltInRole.CognitiveServicesOpenAIUser); | ||
| /// </code> | ||
| /// </example> | ||
| /// </remarks> | ||
| [AspireExportIgnore(Reason = "CognitiveServicesBuiltInRole is an Azure.Provisioning type not compatible with ATS. Use the FoundryRole-based overload instead.")] | ||
| public static IResourceBuilder<AzureCognitiveServicesProjectResource> WithRoleAssignments( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this new API. Instead I think we should just add the AI User role assignment from the Project to the Foundry account automatically. See https://aka.ms/FoundryPermissions
|
||
| this IResourceBuilder<AzureCognitiveServicesProjectResource> builder, | ||
| IResourceBuilder<FoundryResource> target, | ||
| params CognitiveServicesBuiltInRole[] roles) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
| ArgumentNullException.ThrowIfNull(target); | ||
|
|
||
| if (!ReferenceEquals(builder.Resource.Parent, target.Resource)) | ||
| { | ||
| throw new ArgumentException($"The target Microsoft Foundry resource must be the parent of project resource '{builder.Resource.Name}'.", nameof(target)); | ||
| } | ||
|
|
||
| builder.Resource.ParentAccountRoleAssignments = roles is null || roles.Length == 0 | ||
| ? [] | ||
| : roles.Distinct().ToArray(); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Assigns the specified roles to the Microsoft Foundry project identity on the parent Microsoft Foundry resource. | ||
| /// This replaces the default project role assignments. | ||
| /// </summary> | ||
| /// <param name="builder">The Microsoft Foundry project resource builder.</param> | ||
| /// <param name="target">The parent Microsoft Foundry resource.</param> | ||
| /// <param name="roles">The Microsoft Foundry roles to assign to the project identity.</param> | ||
| /// <returns>The updated <see cref="IResourceBuilder{AzureCognitiveServicesProjectResource}"/> with the applied role assignments.</returns> | ||
| /// <exception cref="ArgumentException">Thrown when a role value is not a valid <see cref="FoundryRole"/> value.</exception> | ||
| [AspireExport("withFoundryProjectRoleAssignments", MethodName = "withRoleAssignments", Description = "Assigns Microsoft Foundry roles to a project identity.")] | ||
| internal static IResourceBuilder<AzureCognitiveServicesProjectResource> WithRoleAssignments( | ||
| this IResourceBuilder<AzureCognitiveServicesProjectResource> builder, | ||
| IResourceBuilder<FoundryResource> target, | ||
| params FoundryRole[] roles) | ||
| { | ||
| return builder.WithRoleAssignments(target, FoundryRoleHelpers.ToCognitiveServicesBuiltInRoles(roles)); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -402,6 +467,13 @@ internal static void ConfigureInfrastructure(AzureResourceInfrastructure infra) | |
| Value = projectPrincipalId | ||
| }); | ||
|
|
||
| foreach (var role in aspireResource.ParentAccountRoleAssignments) | ||
| { | ||
| var roleAssignment = account.CreateRoleAssignment(role, RoleManagementPrincipalType.ServicePrincipal, projectPrincipalId); | ||
|
sebastienros marked this conversation as resolved.
|
||
| roleAssignment.Name = BicepFunction.CreateGuid(account.Id, project.Id, roleAssignment.RoleDefinitionId); | ||
| infra.Add(roleAssignment); | ||
| } | ||
|
|
||
| /* | ||
| * Container registry for hosted agents | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.