-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazuredeploy.json
458 lines (458 loc) · 26.3 KB
/
azuredeploy.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"title": "AS-Make-GitHub-Repository-Private",
"description": "This playbook is intended to be run from a Microsoft Sentinel Incident. It will look up the GitHub repositories associated with the Incident Account Entities and make them private. A comment noting the affected GitHub repositories will be added to the Incident.",
"prerequisites": "1. Install 'AS-Make-GitHub-Repository-Private' GitHub App for your organization. 2. A private key for the GitHub App Must be generated and encoded. 3. The GitHub App installation ID. 4. An Azure Key Vault Secret. 5. Deploy the 'CreateJWT' Azure Function. Support for the set up and configuration of each of these items can be found here: https://github.com/Accelerynt-Security/AS-Make-GitHub-Repository-Private",
"postDeployment": ["Access to the Azure Key Vault must be granted to the playbook","The Microsoft Sentinel Contributor role must be applied to the playbook"],
"lastUpdateTime": "2023-07-11T04:54:16Z",
"entities": ["Account"],
"tags": ["Microsoft Sentinel", "Incident", "GitHub", "Repository"],
"support": {
"tier": "partner"
},
"author": {
"name": "Accelerynt"
}
},
"parameters": {
"PlaybookName": {
"defaultValue": "AS-Make-GitHub-Repository-Private",
"type": "string",
"metadata": {
"description": "Name of the Logic App resource to be created"
}
},
"GitHubOrganizationName": {
"type": "string",
"metadata" : {
"description" : "Name of the GitHub Organization the repositories are housed in"
}
},
"GitHubAppID": {
"type": "string",
"metadata" : {
"description" : "ID of the 'AS-Update-GitHub-Repository' GitHub App"
}
},
"GitHubAppInstallationID": {
"type": "string",
"metadata" : {
"description" : "Installation ID of the 'AS-Update-GitHub-Repository' GitHub App installed in the GitHub Organization"
}
},
"FunctionAppName": {
"type": "string",
"metadata" : {
"description" : "Name of the Azure Function App housing the 'CreateJWT' Function"
}
},
"KeyVaultName": {
"type": "string",
"metadata" : {
"description" : "Name of the Key Vault that stores the GitHub App's encoded private key"
}
},
"SecretName": {
"type": "string",
"metadata": {
"description": "Name of Key Vault Secret that contains the GitHub App's encoded private key"
}
}
},
"variables": {
"azuresentinel": "[concat('azuresentinel-', parameters('PlaybookName'))]",
"keyvault": "[concat('keyvault-', parameters('PlaybookName'))]"
},
"resources": [
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"name": "[variables('azuresentinel')]",
"location": "[resourceGroup().location]",
"kind": "V1",
"properties": {
"displayName": "[parameters('PlaybookName')]",
"customParameterValues": {},
"parameterValueType": "Alternative",
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/azuresentinel')]"
}
}
},
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"name": "[variables('keyvault')]",
"location": "[resourceGroup().location]",
"kind": "V1",
"properties": {
"displayName": "[parameters('PlaybookName')]",
"parameterValueType": "Alternative",
"alternativeParameterValues": {
"vaultName": "[parameters('KeyVaultName')]"
},
"customParameterValues": {
},
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/keyvault')]"
}
}
},
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[parameters('PlaybookName')]",
"location": "[resourceGroup().location]",
"tags": {
"LogicAppsCategory": "security"
},
"identity": {
"type": "SystemAssigned"
},
"dependsOn": [
"[resourceId('Microsoft.Web/connections', variables('azuresentinel'))]",
"[resourceId('Microsoft.Web/connections', variables('keyvault'))]"
],
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Microsoft_Sentinel_incident": {
"type": "ApiConnectionWebhook",
"inputs": {
"body": {
"callback_url": "@{listCallbackUrl()}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['azuresentinel']['connectionId']"
}
},
"path": "/incident-creation"
}
}
},
"actions": {
"Condition_-_Incident_has_Account_Entities": {
"actions": {
"Add_comment_to_incident_(V3)": {
"runAfter": {
"For_each_-_Account_entity": [
"Succeeded"
]
},
"type": "ApiConnection",
"inputs": {
"body": {
"incidentArmId": "@triggerBody()?['object']?['id']",
"message": "[concat('<p><strong>Made the Following GitHub Repositories Private for ', parameters('GitHubOrganizationName'), ':</strong><br>\n@{variables(''Affected Repositories'')}</p>')]"
},
"host": {
"connection": {
"name": "@parameters('$connections')['azuresentinel']['connectionId']"
}
},
"method": "post",
"path": "/Incidents/Comment"
}
},
"CreateJWT": {
"runAfter": {
"Get_secret": [
"Succeeded"
]
},
"type": "Function",
"inputs": {
"body": {
"app_id": "[parameters('GitHubAppID')]",
"private_key": "@decodeBase64(body('Get_secret')?['value'])"
},
"function": {
"id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name ,'/providers/Microsoft.Web/sites/', parameters('FunctionAppName'), '/functions/CreateJWT')]"
}
}
},
"For_each_-_Account_entity": {
"foreach": "@body('Entities_-_Get_Accounts')?['Accounts']",
"actions": {
"For_each_-_Repository": {
"foreach": "@body('Parse_JSON_-_Repositories')",
"actions": {
"Condition_-_Check_for_Repository_Name_Match": {
"actions": {
"Condition": {
"actions": {
"Append_to_string_variable_-_Affected_Repositories": {
"runAfter": {},
"type": "AppendToStringVariable",
"inputs": {
"name": "Affected Repositories",
"value": "@{items('For_each_-_Account_entity')?['Name']}\n"
}
}
},
"runAfter": {
"HTTP_-_Make_Repository_Private": [
"Succeeded"
]
},
"expression": {
"and": [
{
"equals": [
"@outputs('HTTP_-_Make_Repository_Private')['statusCode']",
200
]
}
]
},
"type": "If"
},
"HTTP_-_Make_Repository_Private": {
"runAfter": {},
"type": "Http",
"inputs": {
"body": {
"private": true
},
"headers": {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer @{body('Parse_JSON_-_Authentication')?['token']}"
},
"method": "PATCH",
"uri": "https://api.github.com/repos/@{items('For_each_-_Repository')['owner']['login']}/@{substring(items('For_each_-_Account_entity')['name'], add(indexOf(items('For_each_-_Account_entity')['name'],'/'), 1), sub(length(items('For_each_-_Account_entity')['name']), add(indexOf(items('For_each_-_Account_entity')['name'],'/'),1)))}"
}
}
},
"runAfter": {},
"expression": {
"and": [
{
"equals": [
"@substring(items('For_each_-_Account_entity')['name'], add(indexOf(items('For_each_-_Account_entity')['name'],'/'), 1), sub(length(items('For_each_-_Account_entity')['name']), add(indexOf(items('For_each_-_Account_entity')['name'],'/'),1)))",
"@items('For_each_-_Repository')?['name']"
]
}
]
},
"type": "If"
}
},
"runAfter": {},
"type": "Foreach"
}
},
"runAfter": {
"Parse_JSON_-_Repositories": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_secret": {
"runAfter": {},
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['keyvault']['connectionId']"
}
},
"method": "get",
"path": "[concat('/secrets/@{encodeURIComponent(''', parameters('SecretName'), ''')}/value')]"
}
},
"HTTP_-_Authenticate_as_a_GitHub_App_installation": {
"runAfter": {
"CreateJWT": [
"Succeeded"
]
},
"type": "Http",
"inputs": {
"headers": {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer @{body('CreateJWT')}"
},
"method": "POST",
"uri": "[concat('https://api.github.com/app/installations/', parameters('GitHubAppInstallationID'), '/access_tokens')]"
}
},
"HTTP_-_Get_Organization_Repositories": {
"runAfter": {
"Parse_JSON_-_Authentication": [
"Succeeded"
]
},
"type": "Http",
"inputs": {
"headers": {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer @{body('Parse_JSON_-_Authentication')?['token']}"
},
"method": "GET",
"uri": "[concat('https://api.github.com/orgs/', parameters('GitHubOrganizationName'), '/repos?per_page=100')]"
},
"description": "To update a repository via GitHub API, the owner of the repo is needed. Because we are only starting with a name, this call is necessary for the remaining required information."
},
"Parse_JSON_-_Authentication": {
"runAfter": {
"HTTP_-_Authenticate_as_a_GitHub_App_installation": [
"Succeeded"
]
},
"type": "ParseJson",
"inputs": {
"content": "@body('HTTP_-_Authenticate_as_a_GitHub_App_installation')",
"schema": {
"properties": {
"expires_at": {
"type": "string"
},
"permissions": {
"properties": {
"organization_user_blocking": {
"type": "string"
}
},
"type": "object"
},
"repository_selection": {
"type": "string"
},
"token": {
"type": "string"
}
},
"type": "object"
}
}
},
"Parse_JSON_-_Repositories": {
"runAfter": {
"HTTP_-_Get_Organization_Repositories": [
"Succeeded"
]
},
"type": "ParseJson",
"inputs": {
"content": "@body('HTTP_-_Get_Organization_Repositories')",
"schema": {
"items": {
"properties": {
"name": {
"type": "string"
},
"owner": {
"properties": {
"id": {
"type": "integer"
},
"login": {
"type": "string"
}
},
"type": "object"
},
"private": {
"type": "boolean"
}
},
"type": "object"
},
"type": "array"
}
}
}
},
"runAfter": {
"Initialize_variable_-_Affected_Repositories": [
"Succeeded"
]
},
"expression": {
"and": [
{
"greater": [
"@length(body('Entities_-_Get_Accounts')?['Accounts'])",
0
]
}
]
},
"type": "If"
},
"Entities_-_Get_Accounts": {
"runAfter": {},
"type": "ApiConnection",
"inputs": {
"body": "@triggerBody()?['object']?['properties']?['relatedEntities']",
"host": {
"connection": {
"name": "@parameters('$connections')['azuresentinel']['connectionId']"
}
},
"method": "post",
"path": "/entities/account"
}
},
"Initialize_variable_-_Affected_Repositories": {
"runAfter": {
"Entities_-_Get_Accounts": [
"Succeeded"
]
},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "Affected Repositories",
"type": "string"
}
]
}
}
},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"azuresentinel": {
"connectionId": "[resourceId('Microsoft.Web/connections', variables('azuresentinel'))]",
"connectionName": "[variables('azuresentinel')]",
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/azuresentinel')]",
"connectionProperties": {
"authentication": {
"type": "ManagedServiceIdentity"
}
}
},
"keyvault": {
"connectionId": "[resourceId('Microsoft.Web/connections', variables('keyvault'))]",
"connectionName": "[variables('keyvault')]",
"id": "[concat('/subscriptions/', subscription().subscriptionId,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/keyvault')]",
"connectionProperties": {
"authentication": {
"type": "ManagedServiceIdentity"
}
}
}
}
}
}
}
}
]
}