Skip to content

Commit 0e97262

Browse files
Refactor Azure credential retrieval to use AZURE_CLIENT_ID across multiple modules and update dependencies in pyproject.toml
1 parent e2dd7b0 commit 0e97262

File tree

7 files changed

+75
-31
lines changed

7 files changed

+75
-31
lines changed

infra/main.bicep

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,20 @@ param solutionUniqueText string = take(uniqueString(subscription().id, resourceG
3030
'westeurope'
3131
'uksouth'
3232
])
33-
param location string = 'australiaeast'
33+
param location string
3434

3535
// Restricting deployment to only supported Azure OpenAI regions validated with GPT-4o model
3636
@allowed(['australiaeast', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'swedencentral', 'uksouth', 'westus'])
37-
@metadata({ azd: { type: 'location' } })
37+
@metadata({
38+
azd : {
39+
type: 'location'
40+
usageName : [
41+
'OpenAI.GlobalStandard.gpt-4o, 150'
42+
]
43+
}
44+
})
3845
@description('Optional. Location for all AI service resources. This should be one of the supported Azure AI Service locations.')
39-
param azureAiServiceLocation string = 'australiaeast'
46+
param azureAiServiceLocation string
4047

4148
@description('Optional. The tags to apply to all deployed Azure resources.')
4249
param tags resourceInput<'Microsoft.Resources/resourceGroups@2025-04-01'>.tags = {}
@@ -62,13 +69,13 @@ param virtualMachineAdminUsername string = take(newGuid(), 20)
6269
param virtualMachineAdminPassword string = newGuid()
6370

6471
@description('Optional. The Container Registry hostname where the docker images for the backend are located.')
65-
param backendContainerRegistryHostname string = 'biabcontainerreg.azurecr.io'
72+
param backendContainerRegistryHostname string = 'macaer.azurecr.io'
6673

6774
@description('Optional. The Container Image Name to deploy on the backend.')
6875
param backendContainerImageName string = 'macaebackend'
6976

7077
@description('Optional. The Container Image Tag to deploy on the backend.')
71-
param backendContainerImageTag string = 'latest_2025-07-22_895'
78+
param backendContainerImageTag string = 'dev'
7279

7380
@description('Optional. The Container Registry hostname where the docker images for the frontend are located.')
7481
param frontendContainerRegistryHostname string = 'biabcontainerreg.azurecr.io'
@@ -77,7 +84,7 @@ param frontendContainerRegistryHostname string = 'biabcontainerreg.azurecr.io'
7784
param frontendContainerImageName string = 'macaefrontend'
7885

7986
@description('Optional. The Container Image Tag to deploy on the frontend.')
80-
param frontendContainerImageTag string = 'latest_2025-07-22_895'
87+
param frontendContainerImageTag string = 'latest'
8188

8289
@description('Optional. Enable/Disable usage telemetry for module.')
8390
param enableTelemetry bool = true
@@ -1038,6 +1045,10 @@ var cosmosDbResourceName = 'cosmos-${solutionSuffix}'
10381045
var cosmosDbDatabaseName = 'macae'
10391046
var cosmosDbDatabaseMemoryContainerName = 'memory'
10401047

1048+
resource sqlContributorRoleDefinition 'Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions@2024-11-15' existing = {
1049+
name: '${cosmosDbResourceName}/00000000-0000-0000-0000-000000000002'
1050+
}
1051+
10411052
//TODO: update to latest version of AVM module
10421053
module cosmosDb 'br/public:avm/res/document-db/database-account:0.15.0' = {
10431054
name: take('avm.res.document-db.database-account.${cosmosDbResourceName}', 64)
@@ -1062,16 +1073,22 @@ module cosmosDb 'br/public:avm/res/document-db/database-account:0.15.0' = {
10621073
]
10631074
}
10641075
]
1065-
dataPlaneRoleDefinitions: [
1076+
// dataPlaneRoleDefinitions: [
1077+
// {
1078+
// // Cosmos DB Built-in Data Contributor: https://docs.azure.cn/en-us/cosmos-db/nosql/security/reference-data-plane-roles#cosmos-db-built-in-data-contributor
1079+
// roleName: 'Cosmos DB SQL Data Contributor'
1080+
// dataActions: [
1081+
// 'Microsoft.DocumentDB/databaseAccounts/readMetadata'
1082+
// 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*'
1083+
// 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*'
1084+
// ]
1085+
// assignments: [{ principalId: userAssignedIdentity.outputs.principalId }]
1086+
// }
1087+
// ]
1088+
dataPlaneRoleAssignments: [
10661089
{
1067-
// Cosmos DB Built-in Data Contributor: https://docs.azure.cn/en-us/cosmos-db/nosql/security/reference-data-plane-roles#cosmos-db-built-in-data-contributor
1068-
roleName: 'Cosmos DB SQL Data Contributor'
1069-
dataActions: [
1070-
'Microsoft.DocumentDB/databaseAccounts/readMetadata'
1071-
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*'
1072-
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*'
1073-
]
1074-
assignments: [{ principalId: userAssignedIdentity.outputs.principalId }]
1090+
principalId: userAssignedIdentity.outputs.principalId
1091+
roleDefinitionId: sqlContributorRoleDefinition.id
10751092
}
10761093
]
10771094
// WAF aligned configuration for Monitoring
@@ -1331,6 +1348,10 @@ module containerApp 'br/public:avm/res/app/container-app:0.18.1' = {
13311348
name: 'AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME'
13321349
value: aiFoundryAiServicesModelDeployment.name
13331350
}
1351+
{
1352+
name: 'AZURE_CLIENT_ID'
1353+
value: userAssignedIdentity.outputs.clientId // NOTE: This is the client ID of the managed identity, not the Entra application, and is needed for the App Service to access the Cosmos DB account.
1354+
}
13341355
]
13351356
}
13361357
]

src/backend/app_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_cosmos_database_client(self):
115115
try:
116116
if self._cosmos_client is None:
117117
self._cosmos_client = CosmosClient(
118-
self.COSMOSDB_ENDPOINT, credential=get_azure_credential()
118+
self.COSMOSDB_ENDPOINT, credential=get_azure_credential(self.AZURE_CLIENT_ID)
119119
)
120120

121121
if self._cosmos_database is None:
@@ -152,7 +152,7 @@ def get_ai_project_client(self):
152152
return self._ai_project_client
153153

154154
try:
155-
credential = get_azure_credential()
155+
credential = get_azure_credential(self.AZURE_CLIENT_ID)
156156
if credential is None:
157157
raise RuntimeError(
158158
"Unable to acquire Azure credentials; ensure Managed Identity is configured"

src/backend/config_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Config:
3232
@staticmethod
3333
def GetAzureCredentials():
3434
"""Get Azure credentials using the AppConfig implementation."""
35-
return get_azure_credential()
35+
return get_azure_credential(config.AZURE_CLIENT_ID)
3636

3737
@staticmethod
3838
def GetCosmosDatabaseClient():

src/backend/context/cosmos_memory_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def initialize(self):
7373
if not self._database:
7474
# Create Cosmos client
7575
cosmos_client = CosmosClient(
76-
self._cosmos_endpoint, credential=get_azure_credential()
76+
self._cosmos_endpoint, credential=get_azure_credential(config.AZURE_CLIENT_ID)
7777
)
7878
self._database = cosmos_client.get_database_client(
7979
self._cosmos_database

src/backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"azure-ai-evaluation>=1.5.0",
99
"azure-ai-inference>=1.0.0b9",
1010
"azure-ai-projects>=1.0.0b9",
11+
"azure-ai-agents>=1.2.0b1",
1112
"azure-cosmos>=4.9.0",
1213
"azure-identity>=1.21.0",
1314
"azure-monitor-events-extension>=0.1.0",

src/backend/utils_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async def rai_success(description: str, is_task_creation: bool) -> bool:
172172
"""
173173
try:
174174
# Use managed identity for authentication to Azure OpenAI
175-
credential = get_azure_credential()
175+
credential = get_azure_credential(config.AZURE_CLIENT_ID)
176176
access_token = credential.get_token(
177177
"https://cognitiveservices.azure.com/.default"
178178
).token

src/backend/uv.lock

Lines changed: 33 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)