Skip to content

Commit d36cf84

Browse files
2 parents 1d0b33d + 7c96b33 commit d36cf84

File tree

15 files changed

+467
-215
lines changed

15 files changed

+467
-215
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: 20 additions & 31 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
@@ -751,7 +736,7 @@ module computerVision 'modules/core/ai/cognitiveservices.bicep' = if (useAdvance
751736
kind: 'ComputerVision'
752737
location: computerVisionLocation != '' ? computerVisionLocation : location
753738
tags: allTags
754-
sku: 'S0'
739+
sku: computerVisionSkuName
755740

756741
enablePrivateNetworking: enablePrivateNetworking
757742
subnetResourceId: enablePrivateNetworking ? network!.outputs.subnetPrivateEndpointsResourceId : null
@@ -931,7 +916,7 @@ module web 'modules/app/web.bicep' = if (hostingModel == 'code' || hostingModel
931916
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
932917
vnetImagePullEnabled: enablePrivateNetworking ? true : false
933918
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
934-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
919+
publicNetworkAccess: 'Enabled' // Always enabling public network access
935920
privateEndpoints: enablePrivateNetworking
936921
? [
937922
{
@@ -984,6 +969,7 @@ module web 'modules/app/web.bicep' = if (hostingModel == 'code' || hostingModel
984969
OPEN_AI_FUNCTIONS_SYSTEM_PROMPT: openAIFunctionsSystemPrompt
985970
SEMANTIC_KERNEL_SYSTEM_PROMPT: semanticKernelSystemPrompt
986971
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
972+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
987973
AZURE_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId // Required so LangChain AzureSearch vector store authenticates with this user-assigned managed identity
988974
APP_ENV: appEnvironment
989975
},
@@ -1020,7 +1006,7 @@ module web 'modules/app/web.bicep' = if (hostingModel == 'code' || hostingModel
10201006
? {
10211007
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
10221008
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
1023-
AZURE_POSTGRESQL_USER: hostingModel == 'container' ? '${websiteName}-docker' : websiteName
1009+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
10241010
}
10251011
: {}
10261012
)
@@ -1034,6 +1020,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code'|| host
10341020
name: hostingModel == 'container' ? '${adminWebsiteName}-docker' : adminWebsiteName
10351021
location: location
10361022
tags: union(tags, { 'azd-service-name': hostingModel == 'container' ? 'adminweb-docker' : 'adminweb' })
1023+
allTags: allTags
10371024
kind: hostingModel == 'container' ? 'app,linux,container' : 'app,linux'
10381025
serverFarmResourceId: webServerFarm.outputs.resourceId
10391026
// runtime settings apply only for code-hosted apps
@@ -1079,6 +1066,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code'|| host
10791066
DATABASE_TYPE: databaseType
10801067
USE_KEY_VAULT: 'true'
10811068
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
1069+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
10821070
APP_ENV: appEnvironment
10831071
},
10841072
databaseType == 'CosmosDB'
@@ -1111,7 +1099,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code'|| host
11111099
? {
11121100
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.?outputs.postgresDbOutput.postgreSQLServerName
11131101
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.?outputs.postgresDbOutput.postgreSQLDatabaseName
1114-
AZURE_POSTGRESQL_USER: hostingModel == 'container' ? '${adminWebsiteName}-docker' : adminWebsiteName
1102+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
11151103
}
11161104
: {}
11171105
)
@@ -1121,7 +1109,7 @@ module adminweb 'modules/app/adminweb.bicep' = if (hostingModel == 'code'|| host
11211109
vnetImagePullEnabled: enablePrivateNetworking ? true : false
11221110
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
11231111
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
1124-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1112+
publicNetworkAccess: 'Enabled' // Always enabling public network access
11251113
privateEndpoints: enablePrivateNetworking
11261114
? [
11271115
{
@@ -1161,7 +1149,7 @@ module function 'modules/app/function.bicep' = if (hostingModel == 'code' || hos
11611149
virtualNetworkSubnetId: enablePrivateNetworking ? network!.outputs.subnetWebResourceId : ''
11621150
vnetRouteAllEnabled: enablePrivateNetworking ? true : false
11631151
vnetImagePullEnabled: enablePrivateNetworking ? true : false
1164-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1152+
publicNetworkAccess: 'Enabled' // Always enabling public network access
11651153
privateEndpoints: enablePrivateNetworking
11661154
? [
11671155
{
@@ -1203,6 +1191,7 @@ module function 'modules/app/function.bicep' = if (hostingModel == 'code' || hos
12031191
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
12041192
DATABASE_TYPE: databaseType
12051193
MANAGED_IDENTITY_CLIENT_ID: managedIdentityModule.outputs.managedIdentityOutput.clientId
1194+
MANAGED_IDENTITY_RESOURCE_ID: managedIdentityModule.outputs.managedIdentityOutput.id
12061195
APP_ENV: appEnvironment
12071196
},
12081197
databaseType == 'CosmosDB'
@@ -1228,7 +1217,7 @@ module function 'modules/app/function.bicep' = if (hostingModel == 'code' || hos
12281217
? {
12291218
AZURE_POSTGRESQL_HOST_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLServerName
12301219
AZURE_POSTGRESQL_DATABASE_NAME: postgresDBModule.outputs.postgresDbOutput.postgreSQLDatabaseName
1231-
AZURE_POSTGRESQL_USER: hostingModel == 'container' ? '${functionName}-docker' : functionName
1220+
AZURE_POSTGRESQL_USER: managedIdentityModule.outputs.managedIdentityOutput.name
12321221
}
12331222
: {}
12341223
)

0 commit comments

Comments
 (0)