Skip to content

Commit c94c948

Browse files
committed
Update to private endpoints between app service and keyvault. configure private DNS zones for keyvault.
1 parent 4c1ed8e commit c94c948

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

{{cookiecutter.__src_folder_name}}/infra/aca.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ param keyVaultName string
1515
param dbserverDomainName string
1616
param dbserverDatabaseName string
1717
param dbserverUser string
18+
param virtualNetworkSubnetId string = ''
1819

1920
@secure()
2021
param dbserverPassword string

{{cookiecutter.__src_folder_name}}/infra/appservice.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ param dbserverDomainName string
1111
param dbserverUser string
1212
param dbserverDatabaseName string
1313
{% endif %}
14+
param virtualNetworkSubnetId string = ''
1415

1516
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
1617
name: applicationInsightsName

{{cookiecutter.__src_folder_name}}/infra/core/host/appservice.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ param applicationInsightsName string = ''
88
param appServicePlanId string
99
param keyVaultName string = ''
1010
param managedIdentity bool = !empty(keyVaultName)
11+
param virtualNetworkSubnetId string = ''
1112

1213
// Runtime Properties
1314
@allowed([
@@ -65,6 +66,7 @@ resource appService 'Microsoft.Web/sites@2022-03-01' = {
6566
}
6667
clientAffinityEnabled: clientAffinityEnabled
6768
httpsOnly: true
69+
virtualNetworkSubnetId: virtualNetworkSubnetId
6870
}
6971

7072
identity: { type: managedIdentity ? 'SystemAssigned' : 'None' }

{{cookiecutter.__src_folder_name}}/infra/main.bicep

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,54 @@ resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
5353
tags: tags
5454
}
5555

56+
module virtualNetwork 'br/public:avm/res/network/virtual-network:0.1.8' = {
57+
name: 'virtualNetworkDeployment'
58+
scope: resourceGroup
59+
params: {
60+
// Required parameters
61+
addressPrefixes: [
62+
'10.0.0.0/16'
63+
]
64+
name: '${name}-vnet'
65+
location: location
66+
tags: tags
67+
subnets: [
68+
{
69+
addressPrefix: '10.0.0.0/24'
70+
name: 'keyvault'
71+
tags: tags
72+
}
73+
{
74+
addressPrefix: '10.0.1.0/24'
75+
name: 'web'
76+
tags: tags
77+
delegations: [
78+
{
79+
name: 'msft-web-serverfarm-delegation'
80+
properties: {
81+
serviceName: 'Microsoft.Web/serverFarms'
82+
}
83+
}
84+
]
85+
serviceEndpoints: [
86+
{
87+
service: 'Microsoft.KeyVault'
88+
}
89+
]
90+
}
91+
]
92+
}
93+
}
94+
95+
module privateDnsZone 'br/public:avm/res/network/private-dns-zone:0.3.1' = {
96+
name: 'privateDnsZoneDeployment'
97+
scope: resourceGroup
98+
params: {
99+
name: 'relecloud.net'
100+
tags: tags
101+
}
102+
}
103+
56104
// Store secrets in a keyvault
57105
module keyVault 'br/public:avm/res/key-vault/vault:0.6.2' = {
58106
name: 'keyvault'
@@ -66,10 +114,29 @@ module keyVault 'br/public:avm/res/key-vault/vault:0.6.2' = {
66114
accessPolicies: [
67115
{
68116
objectId: principalId
69-
permissions: { secrets: [ 'get', 'list' ] }
117+
permissions: { secrets: ['get', 'list'] }
70118
tenantId: subscription().tenantId
71119
}
72120
]
121+
networkAcls: {
122+
bypass: 'AzureServices'
123+
defaultAction: 'Deny'
124+
// ipRules: [
125+
// { value: '<your IP>' }
126+
// ]
127+
virtualNetworkRules: [
128+
{
129+
id: virtualNetwork.outputs.subnetResourceIds[1]
130+
}
131+
]
132+
}
133+
privateEndpoints: [
134+
{
135+
name: '${name}-keyvault-pe'
136+
subnetResourceId: virtualNetwork.outputs.subnetResourceIds[0]
137+
privateDnsZoneResourceIds: [privateDnsZone.outputs.resourceId]
138+
}
139+
]
73140
diagnosticSettings: [
74141
{
75142
logCategoriesAndGroups: [
@@ -81,16 +148,17 @@ module keyVault 'br/public:avm/res/key-vault/vault:0.6.2' = {
81148
workspaceResourceId: monitoring.outputs.logAnalyticsWorkspaceId
82149
}
83150
]
84-
secrets: [for secret in secrets: {
151+
secrets: [
152+
for secret in secrets: {
85153
name: secret.name
86154
value: secret.value
87155
tags: tags
88-
attributes : {
156+
attributes: {
89157
exp: 0
90158
nbf: 0
91159
}
92-
}]
93-
160+
}
161+
]
94162
}
95163
}
96164

@@ -191,6 +259,7 @@ module web 'web.bicep' = {
191259
{% if cookiecutter.db_resource == "postgres-addon" %}
192260
postgresServiceId: db.outputs.dbserverID
193261
{% endif %}
262+
virtualNetworkSubnetId: virtualNetwork.outputs.subnetResourceIds[1]
194263
}
195264
}
196265

0 commit comments

Comments
 (0)