Skip to content

Commit 742cda3

Browse files
authored
Change Azure OpenAI to use CognitiveServicesOpenAIUser role by default (#10293)
* Change Azure OpenAI to use CognitiveServicesOpenAIUser role by default The CognitiveServicesOpenAIContributor role is too permissive as it allows an app to modify deployments (i.e. models). Instead we should be defaulting to CognitiveServicesOpenAIUser which allows the app to do inference, but not modify the resources. * Fix test to test more than the default.
1 parent 8c1f4d9 commit 742cda3

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/openai-roles.module.bicep

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ resource openai 'Microsoft.CognitiveServices/accounts@2024-10-01' existing = {
1111
name: openai_outputs_name
1212
}
1313

14-
resource openai_CognitiveServicesOpenAIContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
15-
name: guid(openai.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'a001fd3d-188f-4b5d-821b-7da978bf7442'))
14+
resource openai_CognitiveServicesOpenAIUser 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
15+
name: guid(openai.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'))
1616
properties: {
1717
principalId: principalId
18-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'a001fd3d-188f-4b5d-821b-7da978bf7442')
18+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd')
1919
principalType: principalType
2020
}
2121
scope: openai

src/Aspire.Hosting.Azure.CognitiveServices/AzureOpenAIExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static IResourceBuilder<AzureOpenAIResource> AddAzureOpenAI(this IDistrib
9797
var resource = new AzureOpenAIResource(name, configureInfrastructure);
9898
return builder.AddResource(resource)
9999
.WithDefaultRoleAssignments(CognitiveServicesBuiltInRole.GetBuiltInRoleName,
100-
CognitiveServicesBuiltInRole.CognitiveServicesOpenAIContributor);
100+
CognitiveServicesBuiltInRole.CognitiveServicesOpenAIUser);
101101
}
102102

103103
#pragma warning disable CS0618 // Type or member is obsolete

tests/Aspire.Hosting.Azure.Tests/AzureOpenAIExtensionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ param principalId string
9393
name: openai_outputs_name
9494
}
9595
96-
resource openai_CognitiveServicesOpenAIContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
97-
name: guid(openai.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'a001fd3d-188f-4b5d-821b-7da978bf7442'))
96+
resource openai_CognitiveServicesOpenAIUser 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
97+
name: guid(openai.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'))
9898
properties: {
9999
principalId: principalId
100-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'a001fd3d-188f-4b5d-821b-7da978bf7442')
100+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd')
101101
principalType: principalType
102102
}
103103
scope: openai
@@ -106,4 +106,4 @@ param principalId string
106106
output.WriteLine(openaiRolesManifest.BicepText);
107107
Assert.Equal(expectedBicep, openaiRolesManifest.BicepText);
108108
}
109-
}
109+
}

tests/Aspire.Hosting.Azure.Tests/RoleAssignmentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Task OpenAISupport()
5454
var openai = builder.AddAzureOpenAI("openai");
5555

5656
builder.AddProject<Project>("api", launchProfileName: null)
57-
.WithRoleAssignments(openai, CognitiveServicesBuiltInRole.CognitiveServicesOpenAIUser);
57+
.WithRoleAssignments(openai, CognitiveServicesBuiltInRole.CognitiveServicesOpenAIUser, CognitiveServicesBuiltInRole.CognitiveServicesFaceRecognizer);
5858
});
5959
}
6060

tests/Aspire.Hosting.Azure.Tests/Snapshots/RoleAssignmentTests.OpenAISupport.verified.bicep

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@ resource openai_CognitiveServicesOpenAIUser 'Microsoft.Authorization/roleAssignm
1717
principalType: 'ServicePrincipal'
1818
}
1919
scope: openai
20+
}
21+
22+
resource openai_CognitiveServicesFaceRecognizer 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
23+
name: guid(openai.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '9894cab4-e18a-44aa-828b-cb588cd6f2d7'))
24+
properties: {
25+
principalId: principalId
26+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '9894cab4-e18a-44aa-828b-cb588cd6f2d7')
27+
principalType: 'ServicePrincipal'
28+
}
29+
scope: openai
2030
}

0 commit comments

Comments
 (0)