/
NetworkSecurityGroup_FlowLog_TrafficAnalytics_DINE.json
284 lines (284 loc) · 12 KB
/
NetworkSecurityGroup_FlowLog_TrafficAnalytics_DINE.json
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
{
"properties": {
"displayName": "Configure network security groups to enable traffic analytics",
"description": "Traffic analytics can be enabled for all network security groups hosted in a particular region with the settings provided during policy creation. If it already has Traffic analytics enabled, then policy does not overwrite its settings. Flow Logs are also enabled for the Network security groups that do not have it. Traffic analytics is a cloud-based solution that provides visibility into user and application activity in cloud networks.",
"policyType": "BuiltIn",
"mode": "Indexed",
"metadata": {
"version": "1.2.0",
"category": "Network"
},
"version": "1.2.0",
"parameters": {
"effect": {
"type": "string",
"defaultValue": "DeployIfNotExists",
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
},
"nsgRegion": {
"type": "String",
"metadata": {
"displayName": "Network security group Region",
"description": "Configures for network security groups in the selected region only.",
"strongType": "location"
}
},
"storageId": {
"type": "String",
"metadata": {
"displayName": "Storage Resource ID",
"description": "Resource ID of the storage account where the flow logs are written. Make sure this storage account is located in the selected network security group Region. The format must be: '/subscriptions/{subscription id}/resourceGroups/{resourceGroup name}/providers/Microsoft.Storage/storageAccounts/{storage account name}",
"assignPermissions": true
}
},
"timeInterval": {
"type": "String",
"metadata": {
"displayName": "Traffic analytics processing interval in minutes",
"description": "Traffic analytics processes blobs at the selected frequency."
},
"defaultValue": "60",
"allowedValues": [
"10",
"60"
]
},
"workspaceResourceId": {
"type": "String",
"metadata": {
"displayName": "Workspace resource ID",
"description": "Log Analytics workspace resource id",
"assignPermissions": true
}
},
"workspaceRegion": {
"type": "String",
"metadata": {
"displayName": "Workspace region",
"description": "Log Analytics workspace region",
"strongType": "location"
}
},
"workspaceId": {
"type": "String",
"metadata": {
"displayName": "Workspace ID",
"description": "Log Analytics workspace GUID"
}
},
"networkWatcherRG": {
"type": "String",
"metadata": {
"displayName": "Network Watcher resource group",
"description": "The Network Watcher regional instance is present in this resource group. The network security group flow logs resources are also created. This will be used only if a deployment is required. By default, it is named 'NetworkWatcherRG'.",
"strongType": "existingResourceGroups"
}
},
"networkWatcherName": {
"type": "String",
"metadata": {
"displayName": "Network Watcher name",
"description": "The name of the network watcher under which the flow log resources are created. Make sure it belongs to the same region as the network security group."
}
},
"retentionDays": {
"type": "String",
"metadata": {
"displayName": "Number of days to retain flowlogs",
"description": "The number of days for which flowlog data will be retained in storage account. If you want to retain data forever and do not want to apply any retention policy, set retention (days) to 0."
},
"defaultValue": "30"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
{
"field": "location",
"equals": "[parameters('nsgRegion')]"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Network/networkWatchers/flowlogs",
"resourceGroupName": "[if(empty(coalesce(field('Microsoft.Network/networkSecurityGroups/flowLogs'))), parameters('networkWatcherRG'), split(first(field('Microsoft.Network/networkSecurityGroups/flowLogs[*].id')), '/')[4])]",
"name": "[if(empty(coalesce(field('Microsoft.Network/networkSecurityGroups/flowLogs[*].id'))), 'null/null', concat(split(first(field('Microsoft.Network/networkSecurityGroups/flowLogs[*].id')), '/')[8], '/', split(first(field('Microsoft.Network/networkSecurityGroups/flowLogs[*].id')), '/')[10]))]",
"existenceCondition": {
"anyof": [
{
"field": "Microsoft.Network/networkWatchers/flowLogs/enabled",
"equals": "false"
},
{
"allof": [
{
"field": "Microsoft.Network/networkWatchers/flowLogs/enabled",
"equals": "true"
},
{
"field": "Microsoft.Network/networkWatchers/flowLogs/flowAnalyticsConfiguration.networkWatcherFlowAnalyticsConfiguration.enabled",
"equals": "true"
},
{
"field": "Microsoft.Network/networkWatchers/flowLogs/flowAnalyticsConfiguration.networkWatcherFlowAnalyticsConfiguration.trafficAnalyticsInterval",
"in": [
"10",
"60"
]
}
]
}
]
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageId": {
"type": "String"
},
"timeInterval": {
"type": "String"
},
"workspaceId": {
"type": "String"
},
"workspaceRegion": {
"type": "String"
},
"workspaceResourceId": {
"type": "String"
},
"networkWatcherRG": {
"type": "String"
},
"networkWatcherName": {
"type": "String"
},
"flowlogName": {
"type": "String"
},
"location": {
"type": "String"
},
"targetResource": {
"type": "string"
},
"retentionDays": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"name": "[concat('flowlogDeployment-', uniqueString(parameters('flowlogName')))]",
"apiVersion": "2019-10-01",
"resourceGroup": "[parameters('networkWatcherRG')]",
"properties": {
"mode": "incremental",
"parameters": {},
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"resources": [
{
"type": "Microsoft.Network/networkWatchers/flowLogs",
"name": "[concat(parameters('networkWatcherName'), '/', parameters('flowlogName'))]",
"apiVersion": "2019-11-01",
"location": "[parameters('location')]",
"properties": {
"targetResourceId": "[parameters('targetResource')]",
"storageId": "[parameters('storageId')]",
"enabled": "true",
"flowAnalyticsConfiguration": {
"networkWatcherFlowAnalyticsConfiguration": {
"enabled": true,
"workspaceId": "[parameters('workspaceId')]",
"workspaceRegion": "[parameters('workspaceRegion')]",
"workspaceResourceId": "[parameters('workspaceResourceId')]",
"trafficAnalyticsInterval": "[parameters('timeInterval')]"
}
},
"retentionPolicy": {
"days": "[parameters('retentionDays')]",
"enabled": "true"
},
"format": {
"type": "JSON",
"version": 2
}
}
}
]
}
}
}
]
},
"parameters": {
"storageId": {
"value": "[parameters('storageId')]"
},
"timeInterval": {
"value": "[parameters('timeInterval')]"
},
"workspaceId": {
"value": "[parameters('workspaceId')]"
},
"workspaceRegion": {
"value": "[parameters('workspaceRegion')]"
},
"workspaceResourceId": {
"value": "[parameters('workspaceResourceId')]"
},
"networkWatcherRG": {
"value": "[if(empty(coalesce(field('Microsoft.Network/networkSecurityGroups/flowLogs'))), parameters('networkWatcherRG'), split(first(field('Microsoft.Network/networkSecurityGroups/flowLogs[*].id')), '/')[4])]"
},
"networkWatcherName": {
"value": "[if(empty(coalesce(field('Microsoft.Network/networkSecurityGroups/flowLogs'))), parameters('networkWatcherName'), split(first(field('Microsoft.Network/networkSecurityGroups/flowLogs[*].id')), '/')[8])]"
},
"flowlogName": {
"value": "[if(empty(coalesce(field('Microsoft.Network/networkSecurityGroups/flowLogs'))), concat(take(concat(field('name'), '-', resourceGroup().name), 72), '-', 'flowlog'), split(first(field('Microsoft.Network/networkSecurityGroups/flowLogs[*].id')), '/')[10])]"
},
"location": {
"value": "[field('location')]"
},
"targetResource": {
"value": "[concat(resourceGroup().id, '/providers/Microsoft.Network/networkSecurityGroups/', field('name'))]"
},
"retentionDays": {
"value": "[parameters('retentionDays')]"
}
}
}
}
}
}
},
"versions": [
"1.2.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/e920df7f-9a64-4066-9b58-52684c02a091",
"name": "e920df7f-9a64-4066-9b58-52684c02a091"
}