forked from microsoft/onefuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazuredeploy.bicep
292 lines (262 loc) · 7.34 KB
/
azuredeploy.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
param name string
param owner string
param clientId string
@secure()
param clientSecret string
param signedExpiry string
param app_func_issuer string
param app_func_audiences array
param cli_app_id string
param authority string
param tenant_domain string
param multi_tenant_domain string
param enable_remote_debugging bool = false
param enable_profiler bool = false
param location string = resourceGroup().location
@description('Azure monitor workbook definitions.')
param workbookData object
@description('The degree of severity for diagnostics logs.')
@allowed([
'Verbose'
'Information'
'Warning'
'Error'
])
param diagnosticsLogLevel string = 'Verbose'
var log_retention = 30
var tenantId = subscription().tenantId
var scaleset_identity = '${name}-scalesetid'
var StorageBlobDataReader = '2a2b9908-6ea1-4ae2-8e65-a410df84e7d1'
var roleAssignmentsParams = [
{
suffix: '-vmss'
role: '9980e02c-c2be-4d73-94e8-173b1dc7cf3c' //VirtualMachineContributor
}
{
suffix: '-storage'
role: '17d1049b-9a84-46fb-8f53-869881c3d3ab' //StorageAccountContributor
}
{
suffix: '-network'
role: '4d97b98b-1d4f-4787-a291-c67834d212e7' //NetworkContributor
}
{
suffix: '-logs'
role: '92aaf0da-9dab-42b6-94a3-d43ce8d16293' //LogAnalyticsContributor
}
{
suffix: '-user_managed_identity'
role: 'f1a07417-d97a-45cb-824c-7a7467783830' //ManagedIdentityOperator
}
{
suffix: '-contributor'
role: 'b24988ac-6180-42a0-ab88-20f7382dd24c' //Contributor
}
{
suffix: '-app_config_reader'
role: '516239f1-63e1-4d78-a4de-a74fb236a071' //App Configuration Data Reader
}
]
resource scalesetIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: scaleset_identity
location: location
}
module operationalInsights 'bicep-templates/operational-insights.bicep' = {
name: 'operational-insights'
params: {
name: name
location: location
log_retention: log_retention
owner: owner
workbookData: workbookData
}
}
module serverFarm 'bicep-templates/server-farms.bicep' = {
name: 'server-farm'
params: {
server_farm_name: name
owner: owner
location: location
use_windows: true
}
}
var keyVaultName = 'of-kv-${uniqueString(resourceGroup().id)}'
resource keyVault 'Microsoft.KeyVault/vaults@2021-10-01' = {
name: keyVaultName
location: location
properties: {
enabledForDiskEncryption: false
enabledForDeployment: true
enabledForTemplateDeployment: true
sku: {
family: 'A'
name: 'standard'
}
networkAcls: {
defaultAction: 'Allow'
bypass: 'AzureServices'
}
accessPolicies: [
{
objectId: function.outputs.principalId
tenantId: tenantId
permissions: {
secrets: [
'get'
'list'
'set'
'delete'
]
certificates: [
'get'
'list'
]
}
}
{
objectId: 'b453993d-81d4-41a7-be3a-549bc2435ffa'
tenantId: tenantId
permissions: {
secrets: [
'get'
'list'
]
certificates: [
'get'
'list'
]
}
}
]
tenantId: tenantId
}
}
module signalR 'bicep-templates/signalR.bicep' = {
name: 'signalR'
params: {
location: location
}
}
module storage 'bicep-templates/storageAccounts.bicep' = {
name: 'storage'
params: {
location: location
owner: owner
}
}
module autoscaleSettings 'bicep-templates/autoscale-settings.bicep' = {
name: 'autoscaleSettings'
params: {
location: location
server_farm_id: serverFarm.outputs.id
owner: owner
workspaceId: operationalInsights.outputs.workspaceId
autoscale_name: 'onefuzz-autoscale-${uniqueString(resourceGroup().id)}'
function_diagnostics_settings_name: 'functionDiagnosticSettings'
}
}
module eventGrid 'bicep-templates/event-grid.bicep' = {
name: 'event-grid'
params: {
location: location
storageFuzzId: storage.outputs.FuzzId
storageFuncId: storage.outputs.FuncId
fileChangesQueueName: storage.outputs.FileChangesQueueName
}
dependsOn: [
storage
]
}
// try to make role assignments to deploy as late as possible in order to have principalId ready
resource roleAssignments 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = [for r in roleAssignmentsParams: {
name: guid('${resourceGroup().id}${r.suffix}-1f')
properties: {
roleDefinitionId: '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/${r.role}'
principalId: function.outputs.principalId
}
dependsOn: [
eventGrid
keyVault
serverFarm
featureFlags
]
}]
// try to make role assignments to deploy as late as possible in order to have principalId ready
resource readBlobUserAssignment 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = {
name: guid('${resourceGroup().id}-user_managed_idenity_read_blob')
properties: {
roleDefinitionId: '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/${StorageBlobDataReader}'
principalId: reference(scalesetIdentity.id, scalesetIdentity.apiVersion, 'Full').properties.principalId
}
dependsOn: [
eventGrid
keyVault
serverFarm
featureFlags
]
}
module featureFlags 'bicep-templates/feature-flags.bicep' = {
name: 'featureFlags'
params: {
location: location
}
}
module function 'bicep-templates/function.bicep' = {
name: 'function'
params: {
name: name
linux_fx_version: 'DOTNET-ISOLATED|7.0'
signedExpiry: signedExpiry
logs_storage: storage.outputs.FuncName
app_func_audiences: app_func_audiences
app_func_issuer: app_func_issuer
client_id: clientId
diagnostics_log_level: diagnosticsLogLevel
location: location
log_retention: log_retention
owner: owner
server_farm_id: serverFarm.outputs.id
use_windows: true
enable_remote_debugging: enable_remote_debugging
}
dependsOn:[
storage
]
}
module functionSettings 'bicep-templates/function-settings.bicep' = {
name: 'functionSettings'
params: {
name: name
owner: owner
functions_worker_runtime: 'dotnet-isolated'
functions_extension_version: '~4'
instance_name: name
app_insights_app_id: operationalInsights.outputs.appInsightsAppId
app_insights_key: operationalInsights.outputs.appInsightsInstrumentationKey
client_secret: clientSecret
signalRName: signalR.outputs.signalRName
funcStorageName: storage.outputs.FuncName
func_storage_resource_id: storage.outputs.FuncId
fuzz_storage_resource_id: storage.outputs.FuzzId
keyvault_name: keyVaultName
monitor_account_name: operationalInsights.outputs.monitorAccountName
cli_app_id: cli_app_id
authority: authority
tenant_domain: tenant_domain
multi_tenant_domain: multi_tenant_domain
enable_profiler: enable_profiler
app_config_endpoint: featureFlags.outputs.AppConfigEndpoint
}
dependsOn: [
function
storage
signalR
]
}
output fuzz_storage string = storage.outputs.FuzzId
output fuzz_name string = storage.outputs.FuzzName
output func_storage string = storage.outputs.FuncId
output func_name string = storage.outputs.FuncName
output scaleset_identity string = scaleset_identity
output tenant_id string = tenantId
output enable_remote_debugging bool = enable_remote_debugging