Skip to content

Commit d68df2e

Browse files
committed
Network Isolation
Network Isolation
1 parent 3d34260 commit d68df2e

File tree

14 files changed

+2906
-305
lines changed

14 files changed

+2906
-305
lines changed

infra/main.bicep

Lines changed: 216 additions & 78 deletions
Large diffs are not rendered by default.

infra/main.json

Lines changed: 1947 additions & 161 deletions
Large diffs are not rendered by default.

infra/modules/ai-search.bicep renamed to infra/modules/cognitive/ai-search.bicep

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ param managedIdentityPrincipalId string
22

33
param suffix string = uniqueString(resourceGroup().id)
44

5+
@description('The tags to be assigned to the created resources.')
6+
param tags object
7+
58
@description('Service name must only contain lowercase letters, digits or dashes, cannot use dash as the first two or last one characters, cannot contain consecutive dashes, and is limited between 2 and 60 characters in length.')
69
@minLength(2)
710
@maxLength(60)
8-
param name string
11+
param name string = 'km-search-${suffix}'
912

1013
@allowed([
1114
'free'
@@ -45,22 +48,87 @@ param hostingMode string = 'default'
4548
@description('Location for all resources.')
4649
param location string = resourceGroup().location
4750

51+
param vnetId string
52+
param privateEndpointSubnetId string
53+
4854
resource search 'Microsoft.Search/searchServices@2023-11-01' = {
4955
name: name
5056
location: location
57+
tags: tags
5158
sku: {
5259
name: sku
5360
}
5461
properties: {
5562
replicaCount: replicaCount
5663
partitionCount: partitionCount
5764
hostingMode: hostingMode
65+
66+
// bohdan Check `disableLocalAuth: true`
5867
authOptions: {
5968
aadOrApiKey: {}
6069
}
70+
71+
publicNetworkAccess: 'disabled'
72+
}
73+
}
74+
75+
////////////////////////// Private endpoint
76+
77+
// resource privateEndpoint 'Microsoft.Network/privateEndpoints@2024-01-01' = {
78+
// name: 'km-search-pe-${suffix}'
79+
// location: location
80+
// tags: tags
81+
// properties: {
82+
// subnet: {
83+
// id: privateEndpointSubnetId
84+
// }
85+
// privateLinkServiceConnections: [
86+
// {
87+
// name: 'private-endpoint-connection'
88+
// properties: {
89+
// privateLinkServiceId: search.id
90+
// groupIds: ['searchService']
91+
// }
92+
// }
93+
// ]
94+
// }
95+
// }
96+
97+
// resource privateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2024-01-01' = {
98+
// name: 'km-search-pe-zg-${suffix}'
99+
// parent: privateEndpoint
100+
// properties: {
101+
// privateDnsZoneConfigs: [
102+
// {
103+
// name: 'km-search-pe-zg-Config-${suffix}'
104+
// properties: {
105+
// privateDnsZoneId: privateDnsZoneId
106+
// }
107+
// }
108+
// ]
109+
// }
110+
// }
111+
112+
module module_search_pe '../network/private-endpoint.bicep' = {
113+
name: 'module_search_pe_${suffix}'
114+
params: {
115+
suffix: suffix
116+
location: location
117+
tags: tags
118+
119+
serviceName_Used_for_PE: name
120+
121+
DNSZoneName: 'privatelink.search.windows.net' // https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns
122+
vnetId: vnetId
123+
privateEndpointSubnetId: privateEndpointSubnetId
124+
125+
privateLinkServiceId: search.id
126+
privateLinkServiceConnections_GroupIds: ['searchService'] // https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-overview#private-link-resource
61127
}
62128
}
63129

130+
////////////////////////// RBAC
131+
64132
// Search Index Data Contributor
65133
resource roleAssignment1 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
66134
name: guid('Search Index Data Contributor-${suffix}')
@@ -89,4 +157,9 @@ resource roleAssignment2 'Microsoft.Authorization/roleAssignments@2022-04-01' =
89157
}
90158
}
91159

160+
////////////////////////// Output
161+
92162
output searchName string = search.name
163+
164+
// output searchObj object = search
165+
// output searchPrivateEndpointObj object = privateEndpoint

infra/modules/cognitive-services-docIntel.bicep renamed to infra/modules/cognitive/docIntel.bicep

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
param suffix string = uniqueString(resourceGroup().id)
2+
3+
param vnetId string
4+
param privateEndpointSubnetId string
5+
26
param managedIdentityPrincipalId string
37

48
metadata description = 'Creates an Azure Document Intelligence (form recognizer) instance.'
59

610
param name string
711
param location string = resourceGroup().location
812

13+
@description('The tags to be assigned to the created resources.')
14+
param tags object
15+
916
@description('The custom subdomain name used to access the API. Defaults to the value of the name parameter.')
1017
param customSubDomainName string = name
1118
param kind string = 'FormRecognizer'
@@ -30,6 +37,7 @@ resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
3037
name: name
3138
location: location
3239
kind: kind
40+
tags: tags
3341
properties: {
3442
customSubDomainName: customSubDomainName
3543
publicNetworkAccess: publicNetworkAccess
@@ -39,6 +47,28 @@ resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
3947
sku: sku
4048
}
4149

50+
////////////////////////// Private endpoint
51+
52+
module module_DocIntel_pe '../network/private-endpoint.bicep' = {
53+
name: 'module_DocIntel_pe${suffix}'
54+
params: {
55+
suffix: suffix
56+
location: location
57+
tags: tags
58+
59+
serviceName_Used_for_PE: name
60+
61+
DNSZoneName: 'privatelink.cognitiveservices.azure.com' // https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns
62+
vnetId: vnetId
63+
privateEndpointSubnetId: privateEndpointSubnetId
64+
65+
privateLinkServiceId: account.id
66+
privateLinkServiceConnections_GroupIds: ['account'] // https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-overview#private-link-resource
67+
}
68+
}
69+
70+
////////////////////////// RBAC
71+
4272
// Cognitive Services User
4373
resource roleAssignment1 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
4474
name: guid('Cognitive Services User-${suffix}')
@@ -53,4 +83,6 @@ resource roleAssignment1 'Microsoft.Authorization/roleAssignments@2022-04-01' =
5383
}
5484
}
5585

86+
////////////////////////// Output
87+
5688
output endpoint string = account.properties.endpoint

infra/modules/cognitive-services-openAI.bicep renamed to infra/modules/cognitive/openAI.bicep

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
param suffix string = uniqueString(resourceGroup().id)
2-
param managedIdentityPrincipalId string
32

43
metadata description = 'Creates an Azure Cognitive Services instance.'
54
param name string
65
param location string = resourceGroup().location
7-
param tags object = {}
6+
7+
@description('The tags to be assigned to the created resources.')
8+
param tags object
9+
810
@description('The custom subdomain name used to access the API. Defaults to the value of the name parameter.')
911
param customSubDomainName string = name
1012
param deployments array = []
@@ -17,6 +19,12 @@ param sku object = {
1719
}
1820

1921
param allowedIpRules array = []
22+
23+
param vnetId string
24+
param privateEndpointSubnetId string
25+
26+
param managedIdentityPrincipalId string
27+
2028
param networkAcls object = empty(allowedIpRules)
2129
? {
2230
defaultAction: 'Allow'
@@ -47,17 +55,37 @@ resource deployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01
4755
name: deployment.name
4856
properties: {
4957
model: deployment.model
50-
raiPolicyName: contains(deployment, 'raiPolicyName') ? deployment.raiPolicyName : null
58+
raiPolicyName: deployment.?raiPolicyName ?? null
59+
}
60+
sku: deployment.?sku ?? {
61+
name: 'Standard'
62+
capacity: 1
5163
}
52-
sku: contains(deployment, 'sku')
53-
? deployment.sku
54-
: {
55-
name: 'Standard'
56-
capacity: 1
57-
}
5864
}
5965
]
6066

67+
////////////////////////// Private endpoint
68+
69+
module module_openai_pe '../network/private-endpoint.bicep' = {
70+
name: 'module_openai_pe_${suffix}'
71+
params: {
72+
suffix: suffix
73+
location: location
74+
tags: tags
75+
76+
serviceName_Used_for_PE: name
77+
78+
DNSZoneName: 'privatelink.openai.azure.com' // https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns
79+
vnetId: vnetId
80+
privateEndpointSubnetId: privateEndpointSubnetId
81+
82+
privateLinkServiceId: account.id
83+
privateLinkServiceConnections_GroupIds: ['account'] // https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-overview#private-link-resource
84+
}
85+
}
86+
87+
////////////////////////// RBAC
88+
6189
// Cognitive Services OpenAI Contributor
6290
resource roleAssignment1 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
6391
name: guid('Cognitive Services OpenAI Contributor-${suffix}')
@@ -86,6 +114,8 @@ resource roleAssignment2 'Microsoft.Authorization/roleAssignments@2022-04-01' =
86114
}
87115
}
88116

117+
////////////////////////// Output
118+
89119
output endpoint string = account.properties.endpoint
90120
output id string = account.id
91121
output name string = account.name
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
targetScope = 'resourceGroup'
2+
3+
param suffix string = uniqueString(resourceGroup().id)
4+
5+
@description('The location where the resources will be created.')
6+
param location string = resourceGroup().location
7+
8+
@description('The tags to be assigned to the created resources.')
9+
param tags object
10+
11+
@description('The name of the container apps environment. If set, it overrides the name generated by the template.')
12+
param containerAppsEnvironmentName string = 'km-cae-${suffix}'
13+
14+
@description('The name of the log analytics workspace resource create in another module.')
15+
param logAnalyticsWorkspaceName string
16+
17+
@description('The name of the application insights resource create in another module.')
18+
param applicationInsightsName string
19+
20+
@description('The subnet id of the subnet where the container apps environment will be deployed.')
21+
param acaSubnetId string
22+
23+
//////// Previously created resources
24+
25+
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' existing = {
26+
name: logAnalyticsWorkspaceName
27+
}
28+
29+
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
30+
name: applicationInsightsName
31+
}
32+
33+
////////
34+
35+
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-10-01' = {
36+
name: containerAppsEnvironmentName
37+
location: location
38+
tags: tags
39+
// sku: {
40+
// name: 'Consumption'
41+
// }
42+
properties: {
43+
daprAIInstrumentationKey: applicationInsights.properties.InstrumentationKey
44+
appLogsConfiguration: {
45+
destination: 'log-analytics'
46+
logAnalyticsConfiguration: {
47+
customerId: logAnalyticsWorkspace.properties.customerId
48+
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
49+
}
50+
}
51+
52+
// network
53+
zoneRedundant: true
54+
vnetConfiguration: {
55+
infrastructureSubnetId: acaSubnetId
56+
internal: true
57+
}
58+
}
59+
}
60+
61+
output containerAppsEnvironmentName string = containerAppsEnvironment.name
62+
output containerAppsEnvironmentId string = containerAppsEnvironment.id
63+
output containerAppsEnvironmentDomain string = containerAppsEnvironment.properties.defaultDomain
64+
output containerAppsEnvironmentStaticIp string = containerAppsEnvironment.properties.staticIp

infra/modules/container-app.bicep renamed to infra/modules/host/container-app.bicep

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ param suffix string = uniqueString(resourceGroup().id)
44

55
param location string = resourceGroup().location
66

7+
@description('The tags to be assigned to the created resources.')
8+
param tags object
9+
710
param managedIdentityId string
811
param managedIdentityClientId string
12+
param KernelMemoryImageTag string = 'latest'
913

1014
param kmServiceName string = 'km-service-${suffix}'
1115

1216
param containerAppsEnvironmentId string
13-
param appInsightsInstrumentationKey string
14-
param applicationInsightsConnectionString string
17+
@description('The name of the application insights resource create in another module.')
18+
param applicationInsightsName string
1519

1620
param AzureBlobs_Account string
1721
param AzureQueues_Account string
@@ -26,16 +30,25 @@ param AzureAIDocIntel_Endpoint string
2630
param KernelMemory__ServiceAuthorization__AccessKey1 string
2731
param KernelMemory__ServiceAuthorization__AccessKey2 string
2832

33+
//////// Previously created resources
34+
35+
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
36+
name: applicationInsightsName
37+
}
38+
39+
////////
40+
2941
resource kmService 'Microsoft.App/containerApps@2023-05-01' = {
3042
name: kmServiceName
3143
location: location
44+
tags: tags
3245
properties: {
3346
environmentId: containerAppsEnvironmentId
3447
configuration: {
3548
secrets: [
3649
{
3750
name: 'appinsights-key'
38-
value: appInsightsInstrumentationKey
51+
value: applicationInsights.properties.InstrumentationKey
3952
}
4053
]
4154
registries: []
@@ -56,7 +69,7 @@ resource kmService 'Microsoft.App/containerApps@2023-05-01' = {
5669
containers: [
5770
{
5871
name: 'kernelmemory-service'
59-
image: 'docker.io/kernelmemory/service:latest'
72+
image: 'docker.io/kernelmemory/service:${KernelMemoryImageTag}'
6073
command: []
6174
resources: {
6275
cpu: json('0.25')
@@ -69,7 +82,7 @@ resource kmService 'Microsoft.App/containerApps@2023-05-01' = {
6982
}
7083
{
7184
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
72-
value: applicationInsightsConnectionString
85+
value: applicationInsights.properties.ConnectionString
7386
}
7487

7588
{

0 commit comments

Comments
 (0)