Skip to content

Commit 4abd024

Browse files
2 parents 17ae566 + ee8edc4 commit 4abd024

File tree

7 files changed

+592
-14
lines changed

7 files changed

+592
-14
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __load_config(self, **kwargs) -> None:
3535
self.secretHelper = SecretHelper()
3636

3737
self.LOGLEVEL = os.environ.get("LOGLEVEL", "INFO").upper()
38+
self.APP_ENV = os.getenv("APP_ENV", "Prod").lower()
3839

3940
# Azure
4041
self.AZURE_SUBSCRIPTION_ID = os.getenv("AZURE_SUBSCRIPTION_ID", "")

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ def create_or_update_datasource(self):
3636
connection_string=connection_string,
3737
container=container,
3838
data_deletion_detection_policy=NativeBlobSoftDeleteDeletionDetectionPolicy(),
39-
identity=SearchIndexerDataUserAssignedIdentity(
40-
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
39+
identity=(
40+
None
41+
if getattr(self.env_helper, "APP_ENV", "").lower() == "dev"
42+
else SearchIndexerDataUserAssignedIdentity(
43+
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
44+
)
4145
),
4246
)
4347
self.indexer_client.create_or_update_data_source_connection(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ def get_vector_search_config(self):
145145
azure_open_ai_parameters = AzureOpenAIParameters(
146146
resource_uri=self.env_helper.AZURE_OPENAI_ENDPOINT,
147147
deployment_id=self.env_helper.AZURE_OPENAI_EMBEDDING_MODEL,
148-
auth_identity=SearchIndexerDataUserAssignedIdentity(
149-
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
148+
auth_identity=(
149+
None
150+
if getattr(self.env_helper, "APP_ENV", "").lower() == "dev"
151+
else SearchIndexerDataUserAssignedIdentity(
152+
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
153+
)
150154
),
151155
)
152156

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ def create_skillset(self):
9696
if self.env_helper.is_auth_type_keys()
9797
else None
9898
),
99-
auth_identity=SearchIndexerDataUserAssignedIdentity(
100-
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
99+
auth_identity=(
100+
None
101+
if getattr(self.env_helper, "APP_ENV", "").lower() == "dev"
102+
else SearchIndexerDataUserAssignedIdentity(
103+
user_assigned_identity=self.env_helper.MANAGED_IDENTITY_RESOURCE_ID
104+
)
101105
),
102106
inputs=[
103107
InputFieldMappingEntry(name="text", source="/document/pages/*"),

infra/main.bicep

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,21 @@ module search 'modules/core/search/search-services.bicep' = if (databaseType ==
857857
principalType: 'User'
858858
}
859859
] : [])
860+
enableSystemAssigned: true
861+
systemAssignedRoleAssignments: [
862+
{
863+
resourceId: storage.outputs.id
864+
roleName: 'Storage Blob Data Contributor'
865+
roleDefinitionId: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
866+
principalType: 'ServicePrincipal'
867+
}
868+
{
869+
resourceId: openai.outputs.resourceId
870+
roleName: 'Cognitive Services User'
871+
roleDefinitionId: 'a97b65f3-24c7-4388-baec-2e87135dc908'
872+
principalType: 'ServicePrincipal'
873+
}
874+
]
860875
}
861876
}
862877

infra/main.json

Lines changed: 537 additions & 6 deletions
Large diffs are not rendered by default.

infra/modules/core/search/search-services.bicep

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ param replicaCount int = 1
3939
param semanticSearch string = 'disabled'
4040
param userAssignedResourceId string = ''
4141
param roleAssignments array = []
42+
@description('Optional. Flag to enable a system-assigned managed identity for the Cognitive Services resource.')
43+
param enableSystemAssigned bool = false
44+
@description('Optional. Array of role assignments to apply to the system-assigned identity at the search service scope. Each item: { roleDefinitionId: "<GUID or built-in role definition id>" }')
45+
param systemAssignedRoleAssignments array = []
4246

4347
// // Define DNS zone group configs as a variable
4448
// var privateDnsZoneGroupConfigs = [for zoneId in privateDnsZoneResourceIds: {
@@ -98,12 +102,27 @@ module avmSearch 'br/public:avm/res/search/search-service:0.11.1' = {
98102
]
99103
: []
100104

101-
// Use only user-assigned identity
102-
managedIdentities: { systemAssigned: false, userAssignedResourceIds: [userAssignedResourceId] }
105+
// Configure managed identity: user-assigned for production, system-assigned allowed for local development with integrated vectorization
106+
managedIdentities: { systemAssigned: enableSystemAssigned, userAssignedResourceIds: [userAssignedResourceId] }
103107
roleAssignments: roleAssignments
104108
}
105109
}
106110

111+
// --- System-assigned identity role assignments for local development with integrated vectorization (optional) --- //
112+
@description('Role assignments applied to the system-assigned identity via AVM module. Objects can include: roleDefinitionId (req), roleName, principalType, resourceId.')
113+
module systemAssignedIdentityRoleAssignments 'br/public:avm/ptn/authorization/resource-role-assignment:0.1.2' = [
114+
for assignment in systemAssignedRoleAssignments: if (enableSystemAssigned && !empty(systemAssignedRoleAssignments)) {
115+
name: take('avm.ptn.authorization.resource-role-assignment.${uniqueString(searchResourceName, assignment.roleDefinitionId, assignment.resourceId)}', 64)
116+
params: {
117+
roleDefinitionId: assignment.roleDefinitionId
118+
principalId: avmSearch.outputs.systemAssignedMIPrincipalId
119+
resourceId: assignment.resourceId
120+
roleName: assignment.roleName
121+
principalType: assignment.principalType
122+
}
123+
}
124+
]
125+
107126
output searchName string = avmSearch.outputs.name
108127
output searchEndpoint string = avmSearch.outputs.endpoint
109128
output searchResourceId string = avmSearch.outputs.resourceId

0 commit comments

Comments
 (0)