Skip to content

Commit 7c96b33

Browse files
Pavan-MicrosoftRoopan-MicrosoftAjitPadhi-Microsoftross-p-smithgpickett
authored
fix: Integrate UMI Across Infra, Secure PostgreSQL Connections, and Update Azure Search Identity (#1899)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Roopan-Microsoft <[email protected]> Co-authored-by: Ajit Padhi <[email protected]> Co-authored-by: Roopan P M <[email protected]> Co-authored-by: Ross Smith <[email protected]> Co-authored-by: gpickett <[email protected]> Co-authored-by: Francia Riesco <[email protected]> Co-authored-by: Francia Riesco <[email protected]> Co-authored-by: Prajwal D C <[email protected]> Co-authored-by: Harmanpreet-Microsoft <[email protected]> Co-authored-by: UtkarshMishra-Microsoft <[email protected]> Co-authored-by: Priyanka-Microsoft <[email protected]> Co-authored-by: Prasanjeet-Microsoft <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kiran-Siluveru-Microsoft <[email protected]> Co-authored-by: Prashant-Microsoft <[email protected]> Co-authored-by: Rohini-Microsoft <[email protected]> Co-authored-by: Avijit-Microsoft <[email protected]> Co-authored-by: RaviKiran-Microsoft <[email protected]> Co-authored-by: Somesh Joshi <[email protected]> Co-authored-by: Himanshi Agrawal <[email protected]> Co-authored-by: pradeepjha-microsoft <[email protected]> Co-authored-by: Harmanpreet Kaur <[email protected]> Co-authored-by: Bangarraju-Microsoft <[email protected]> Co-authored-by: Harsh-Microsoft <[email protected]> Co-authored-by: Kanchan-Microsoft <[email protected]> Co-authored-by: Cristopher Coronado <[email protected]> Co-authored-by: Cristopher Coronado Moreira <[email protected]> Co-authored-by: Vamshi-Microsoft <[email protected]> Co-authored-by: Thanusree-Microsoft <[email protected]> Co-authored-by: Niraj Chaudhari (Persistent Systems Inc) <[email protected]> Co-authored-by: Rohini-Microsoft <[email protected]>
1 parent 5d561e9 commit 7c96b33

File tree

15 files changed

+232
-231
lines changed

15 files changed

+232
-231
lines changed

code/backend/batch/utilities/chat_history/postgresdbservice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def connect(self):
3333
database=self.database,
3434
password=token,
3535
port=5432,
36-
ssl="require",
36+
ssl=True,
3737
)
3838
except Exception as e:
3939
logger.error("Failed to connect to PostgreSQL: %s", e)

code/backend/batch/utilities/helpers/azure_postgres_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _create_search_client(self):
3131

3232
# Use the token in the connection string
3333
conn_string = (
34-
f"host={host} user={user} dbname={dbname} password={access_token.token}"
34+
f"host={host} user={user} dbname={dbname} password={access_token.token} sslmode=require"
3535
)
3636
self.conn = psycopg2.connect(conn_string)
3737
logger.info("Connected to Azure PostgreSQL successfully.")

code/backend/batch/utilities/helpers/env_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __load_config(self, **kwargs) -> None:
4040
self.AZURE_SUBSCRIPTION_ID = os.getenv("AZURE_SUBSCRIPTION_ID", "")
4141
self.AZURE_RESOURCE_GROUP = os.getenv("AZURE_RESOURCE_GROUP", "")
4242
self.MANAGED_IDENTITY_CLIENT_ID = os.getenv("MANAGED_IDENTITY_CLIENT_ID", "")
43+
self.MANAGED_IDENTITY_RESOURCE_ID = os.getenv("MANAGED_IDENTITY_RESOURCE_ID", "")
4344

4445
# Azure Search
4546
self.AZURE_SEARCH_SERVICE = os.getenv("AZURE_SEARCH_SERVICE", "")

code/backend/batch/utilities/integrated_vectorization/azure_search_datasource.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from azure.search.documents.indexes.models import (
22
SearchIndexerDataContainer,
33
SearchIndexerDataSourceConnection,
4+
SearchIndexerDataUserAssignedIdentity,
45
)
56
from azure.search.documents.indexes._generated.models import (
67
NativeBlobSoftDeleteDeletionDetectionPolicy,
@@ -35,6 +36,9 @@ def create_or_update_datasource(self):
3536
connection_string=connection_string,
3637
container=container,
3738
data_deletion_detection_policy=NativeBlobSoftDeleteDeletionDetectionPolicy(),
39+
identity=SearchIndexerDataUserAssignedIdentity(
40+
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
41+
),
3842
)
3943
self.indexer_client.create_or_update_data_source_connection(
4044
data_source_connection

code/backend/batch/utilities/integrated_vectorization/azure_search_skillset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SearchIndexerIndexProjectionsParameters,
1212
IndexProjectionMode,
1313
SearchIndexerSkillset,
14+
SearchIndexerDataUserAssignedIdentity,
1415
)
1516
from azure.search.documents.indexes import SearchIndexerClient
1617
from ..helpers.config.config_helper import IntegratedVectorizationConfig
@@ -95,6 +96,9 @@ def create_skillset(self):
9596
if self.env_helper.is_auth_type_keys()
9697
else None
9798
),
99+
auth_identity=SearchIndexerDataUserAssignedIdentity(
100+
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
101+
),
98102
inputs=[
99103
InputFieldMappingEntry(name="text", source="/document/pages/*"),
100104
],

infra/main.bicep

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ var hostingPlanName string = 'asp-${solutionSuffix}'
6363
])
6464
param hostingPlanSku string = 'B3'
6565

66-
@description('The sku tier for the App Service plan')
67-
@allowed([
68-
'Free'
69-
'Shared'
70-
'Basic'
71-
'Standard'
72-
'Premium'
73-
'PremiumV2'
74-
'PremiumV3'
75-
])
76-
param skuTier string = 'Basic'
77-
7866
@description('The type of database to deploy (cosmos or postgres)')
7967
@allowed([
8068
'PostgreSQL'
@@ -361,7 +349,7 @@ param enableRedundancy bool = false
361349
param enablePrivateNetworking bool = false
362350

363351
@description('Optional. Size of the Jumpbox Virtual Machine when created. Set to custom value if enablePrivateNetworking is true.')
364-
param vmSize string?
352+
param vmSize string = 'Standard_DS2_v2'
365353

366354
@secure()
367355
@description('Optional. The user name for the administrator account of the virtual machine. Allows to customize credentials if `enablePrivateNetworking` is set to true.')
@@ -521,11 +509,9 @@ var privateDnsZones = [
521509
'privatelink.openai.azure.com'
522510
'privatelink.blob.${environment().suffixes.storage}'
523511
'privatelink.queue.${environment().suffixes.storage}'
524-
'privatelink.file.${environment().suffixes.storage}'
525512
'privatelink.documents.azure.com'
526513
'privatelink.postgres.cosmos.azure.com'
527514
'privatelink.vaultcore.azure.net'
528-
'privatelink.azurecr.io'
529515
'privatelink.azurewebsites.net'
530516
'privatelink.search.windows.net'
531517
'privatelink.api.azureml.ms'
@@ -537,14 +523,13 @@ var dnsZoneIndex = {
537523
openAI: 1
538524
storageBlob: 2
539525
storageQueue: 3
540-
storageFile: 4
541-
cosmosDB: 5 // 'privatelink.mongo.cosmos.azure.com'
542-
postgresDB: 6 // 'privatelink.postgres.cosmos.azure.com'
543-
keyVault: 7
544-
containerRegistry: 8
545-
appService: 9
546-
searchService: 10
547-
machinelearning: 11
526+
cosmosDB: 4 // 'privatelink.mongo.cosmos.azure.com'
527+
postgresDB: 5 // 'privatelink.postgres.cosmos.azure.com'
528+
keyVault: 6
529+
appService: 7
530+
searchService: 8
531+
machinelearning: 9
532+
// The indexes for 'storageFile' and 'containerRegistry' have been removed as they were unused
548533
}
549534

550535
// ===================================================
@@ -705,7 +690,7 @@ module openai 'modules/core/ai/cognitiveservices.bicep' = {
705690
location: location
706691
tags: allTags
707692
kind: 'OpenAI'
708-
sku: 'S0'
693+
sku: azureOpenAISkuName
709694
deployments: openAiDeployments
710695
userAssignedResourceId: managedIdentityModule.outputs.managedIdentityOutput.id
711696
enablePrivateNetworking: enablePrivateNetworking
@@ -749,7 +734,7 @@ module computerVision 'modules/core/ai/cognitiveservices.bicep' = if (useAdvance
749734
kind: 'ComputerVision'
750735
location: computerVisionLocation != '' ? computerVisionLocation : location
751736
tags: allTags
752-
sku: 'S0'
737+
sku: computerVisionSkuName
753738

754739
enablePrivateNetworking: enablePrivateNetworking
755740
subnetResourceId: enablePrivateNetworking ? network!.outputs.subnetPrivateEndpointsResourceId : null
@@ -919,7 +904,7 @@ module web 'modules/app/web.bicep' = if (hostingModel == 'code') {
919904
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
920905
vnetImagePullEnabled: enablePrivateNetworking ? true : false
921906
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
922-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
907+
publicNetworkAccess: 'Enabled' // Always enabling public network access
923908
privateEndpoints: enablePrivateNetworking
924909
? [
925910
{
@@ -972,6 +957,7 @@ module web 'modules/app/web.bicep' = if (hostingModel == 'code') {
972957
OPEN_AI_FUNCTIONS_SYSTEM_PROMPT: openAIFunctionsSystemPrompt
973958
SEMANTIC_KERNEL_SYSTEM_PROMPT: semanticKernelSystemPrompt
974959
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
960+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
975961
AZURE_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId // Required so LangChain AzureSearch vector store authenticates with this user-assigned managed identity
976962
APP_ENV: appEnvironment
977963
},
@@ -1008,7 +994,7 @@ module web 'modules/app/web.bicep' = if (hostingModel == 'code') {
1008994
? {
1009995
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
1010996
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
1011-
AZURE_POSTGRESQL_USER: websiteName
997+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
1012998
}
1013999
: {}
10141000
)
@@ -1022,6 +1008,7 @@ module web_docker 'modules/app/web.bicep' = if (hostingModel == 'container') {
10221008
name: '${websiteName}-docker'
10231009
location: location
10241010
tags: union(tags, { 'azd-service-name': 'web-docker' })
1011+
allTags: allTags
10251012
kind: 'app,linux,container'
10261013
serverFarmResourceId: webServerFarm.outputs.resourceId
10271014
dockerFullImageName: '${registryName}.azurecr.io/rag-webapp:${appversion}'
@@ -1033,7 +1020,7 @@ module web_docker 'modules/app/web.bicep' = if (hostingModel == 'container') {
10331020
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
10341021
vnetImagePullEnabled: enablePrivateNetworking ? true : false
10351022
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
1036-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1023+
publicNetworkAccess: 'Enabled' // Always enabling public network access
10371024
privateEndpoints: enablePrivateNetworking
10381025
? [
10391026
{
@@ -1087,6 +1074,7 @@ module web_docker 'modules/app/web.bicep' = if (hostingModel == 'container') {
10871074
OPEN_AI_FUNCTIONS_SYSTEM_PROMPT: openAIFunctionsSystemPrompt
10881075
SEMANTIC_KERNEL_SYSTEM_PROMPT: semanticKernelSystemPrompt
10891076
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
1077+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
10901078
AZURE_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId // Required so LangChain AzureSearch vector store authenticates with this user-assigned managed identity
10911079
APP_ENV: appEnvironment
10921080
},
@@ -1123,7 +1111,7 @@ module web_docker 'modules/app/web.bicep' = if (hostingModel == 'container') {
11231111
? {
11241112
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
11251113
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
1126-
AZURE_POSTGRESQL_USER: '${websiteName}-docker'
1114+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
11271115
}
11281116
: {}
11291117
)
@@ -1137,6 +1125,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code') {
11371125
name: adminWebsiteName
11381126
location: location
11391127
tags: union(tags, { 'azd-service-name': 'adminweb' })
1128+
allTags: allTags
11401129
kind: 'app,linux'
11411130
serverFarmResourceId: webServerFarm.outputs.resourceId
11421131
// Python runtime settings
@@ -1179,6 +1168,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code') {
11791168
DATABASE_TYPE: databaseType
11801169
USE_KEY_VAULT: 'true'
11811170
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
1171+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
11821172
APP_ENV: appEnvironment
11831173
},
11841174
databaseType == 'CosmosDB'
@@ -1211,7 +1201,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code') {
12111201
? {
12121202
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.?outputs.postgresDbOutput.postgreSQLServerName
12131203
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.?outputs.postgresDbOutput.postgreSQLDatabaseName
1214-
AZURE_POSTGRESQL_USER: adminWebsiteName
1204+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
12151205
}
12161206
: {}
12171207
)
@@ -1221,7 +1211,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code') {
12211211
vnetImagePullEnabled: enablePrivateNetworking ? true : false
12221212
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
12231213
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
1224-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1214+
publicNetworkAccess: 'Enabled' // Always enabling public network access
12251215
privateEndpoints: enablePrivateNetworking
12261216
? [
12271217
{
@@ -1247,6 +1237,7 @@ module adminweb_docker 'modules/app/adminweb.bicep' = if (hostingModel == 'conta
12471237
name: '${adminWebsiteName}-docker'
12481238
location: location
12491239
tags: union(tags, { 'azd-service-name': 'adminweb-docker' })
1240+
allTags: allTags
12501241
kind: 'app,linux,container'
12511242
serverFarmResourceId: webServerFarm.outputs.resourceId
12521243
// Docker settings
@@ -1289,6 +1280,7 @@ module adminweb_docker 'modules/app/adminweb.bicep' = if (hostingModel == 'conta
12891280
DATABASE_TYPE: databaseType
12901281
USE_KEY_VAULT: 'true'
12911282
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
1283+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
12921284
APP_ENV: appEnvironment
12931285
},
12941286
databaseType == 'CosmosDB'
@@ -1321,7 +1313,7 @@ module adminweb_docker 'modules/app/adminweb.bicep' = if (hostingModel == 'conta
13211313
? {
13221314
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
13231315
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
1324-
AZURE_POSTGRESQL_USER: '${adminWebsiteName}-docker'
1316+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
13251317
}
13261318
: {}
13271319
)
@@ -1331,7 +1323,7 @@ module adminweb_docker 'modules/app/adminweb.bicep' = if (hostingModel == 'conta
13311323
vnetImagePullEnabled: enablePrivateNetworking ? true : false
13321324
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
13331325
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
1334-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1326+
publicNetworkAccess: 'Enabled' // Always enabling public network access
13351327
privateEndpoints: enablePrivateNetworking
13361328
? [
13371329
{
@@ -1371,7 +1363,7 @@ module function 'modules/app/function.bicep' = if (hostingModel == 'code') {
13711363
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
13721364
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
13731365
vnetImagePullEnabled: enablePrivateNetworking ? true : false
1374-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1366+
publicNetworkAccess: 'Enabled' // Always enabling public network access
13751367
privateEndpoints: enablePrivateNetworking
13761368
? [
13771369
{
@@ -1413,6 +1405,7 @@ module function 'modules/app/function.bicep' = if (hostingModel == 'code') {
14131405
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
14141406
DATABASE_TYPE: databaseType
14151407
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
1408+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
14161409
APP_ENV: appEnvironment
14171410
},
14181411
// Conditionally add database-specific settings
@@ -1439,7 +1432,7 @@ module function 'modules/app/function.bicep' = if (hostingModel == 'code') {
14391432
? {
14401433
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
14411434
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
1442-
AZURE_POSTGRESQL_USER: functionName
1435+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
14431436
}
14441437
: {}
14451438
)
@@ -1466,7 +1459,7 @@ module function_docker 'modules/app/function.bicep' = if (hostingModel == 'conta
14661459
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
14671460
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
14681461
vnetImagePullEnabled: enablePrivateNetworking ? true : false
1469-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1462+
publicNetworkAccess: 'Enabled' // Always enabling public network access
14701463
privateEndpoints: enablePrivateNetworking
14711464
? [
14721465
{
@@ -1508,6 +1501,7 @@ module function_docker 'modules/app/function.bicep' = if (hostingModel == 'conta
15081501
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
15091502
DATABASE_TYPE: databaseType
15101503
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
1504+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
15111505
APP_ENV: appEnvironment
15121506
},
15131507
// Conditionally add database-specific settings
@@ -1534,7 +1528,7 @@ module function_docker 'modules/app/function.bicep' = if (hostingModel == 'conta
15341528
? {
15351529
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.?outputs.postgresDbOutput.postgreSQLServerName
15361530
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.?outputs.postgresDbOutput.postgreSQLDatabaseName
1537-
AZURE_POSTGRESQL_USER: '${functionName}-docker'
1531+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
15381532
}
15391533
: {}
15401534
)

0 commit comments

Comments
 (0)