-
Notifications
You must be signed in to change notification settings - Fork 33
/
azuredeploy.json
315 lines (314 loc) · 17.1 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
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionAppName": {
"type": "string",
"metadata": {
"description": "Name of the Function application and prefix for a few cloud katana resources such as Azure AD applications and managed identity"
}
},
"identityId": {
"type": "string",
"metadata": {
"description": "Id of the managed identity to create Azure AD applications used by cloud katana to expose its API and enable Azure AD authentication and authorization. Format: /subscriptions/SUBSCRIPTIONID/resourcegroups/GROUP/providers/Microsoft.ManagedIdentity/userAssignedIdentities/IDENTITYNAME"
}
},
"assignAppRoleToUser": {
"type": "string",
"metadata": {
"description": "First authorized user to access and use Cloud Katana"
}
},
"utcValue": {
"type": "string",
"defaultValue": "[utcNow()]"
},
"roleGuid": {
"type": "string",
"defaultValue": "[newGuid()]"
},
"artifactsLocation": {
"type": "string",
"metadata": {
"description": "The location of Cloud Katana scripts and configs to deploy the serverless application"
},
"defaultValue": "https://raw.githubusercontent.com/Azure/Cloud-Katana/main"
},
"_artifactsLocationSasToken": {
"type": "securestring",
"metadata": {
"description": "Auto-generated token to access _artifactsLocation (GITHUB_REPO_OR_STORAGE_ACCOUNT). Leave it blank unless you need to provide your own value."
},
"defaultValue": ""
},
"_packageLocation": {
"type": "securestring",
"metadata": {
"description": "The remote location of the Cloud Katana Azure Function app package. By default this points to the Cloud Katana public GitHub repository. You can update this and point to a private location. You can use a Shared Access Signature (SAS)."
},
"defaultValue": "https://github.com/Azure/Cloud-Katana/blob/main/functionapp.zip?raw=true"
},
"enableHybridMode": {
"type": "bool",
"defaultValue": false
},
"automationAccountName": {
"type": "string",
"defaultValue": ""
},
"automationAccountResourceGroupName": {
"type": "string",
"defaultValue": ""
},
"hybridWorkerGroupName": {
"type": "string",
"defaultValue": ""
},
"hybridPowerShellRunbookName": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
"AppName": "[tolower(parameters('functionAppName'))]",
"Identity": "[concat(parameters('functionAppName'), 'Identity')]",
"ServerAppName": "[concat(parameters('functionAppName'), 'Server')]",
"ClientAppName": "[concat(parameters('functionAppName'), 'Client')]",
"roleGuidOne" : "[guid(parameters('roleGuid'), 'guidOne')]",
"roleGuidTwo" : "[guid(parameters('roleGuid'), 'guidTwo')]",
"roleGuidThree" : "[guid(parameters('roleGuid'), 'guidThree')]"
},
"resources": [
{
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2020-10-01",
"name": "createServerApp",
"location": "[resourceGroup().location]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('identityId')]": {}
}
},
"kind": "AzurePowerShell",
"properties": {
"forceUpdateTag": "[parameters('utcValue')]",
"azPowerShellVersion": "6.2",
"timeout": "PT30M",
"scriptContent": "[format('. .\\New-CKAzADApplication.ps1; Connect-AzAccount -Identity; $accessToken = (Get-AzAccessToken -ResourceUrl \"https://graph.microsoft.com/\").Token; $results = New-CKAzADApplication -displayName {0} -identifierUri {1} -webReplyURI {2} -requireAssignedRole -assignAppRoleToUser {3} -accessToken $accessToken; $DeploymentScriptOutputs[\"appId\"] = $results.appId', variables('ServerAppName'), concat('api://',subscription().tenantId,'/cloudkatana'), concat('https://', variables('AppName'), '.azurewebsites.net/.auth/login/aad/callback'), parameters('assignAppRoleToUser'))]",
"supportingScriptUris": [
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/APIs/Invoke-CKMSGraphAPI.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Authentication/Read-CKAccessToken.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/Utils/ConvertFrom-B64ToString.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/New-CKAzADApplication.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/Get-CKAzADApplications.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/New-CKAzADAppServicePrincipal.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/Get-CKAzADServicePrincipals.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Users/Get-CKAzADUsers.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Users/Get-CKAzADUserAppRoleAssignments.ps1', parameters('_artifactsLocationSasToken'))]"
],
"cleanupPreference": "OnSuccess",
"retentionInterval": "PT1H"
}
},
{
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2020-10-01",
"name": "createClientApp",
"location": "[resourceGroup().location]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('identityId')]": {}
}
},
"kind": "AzurePowerShell",
"properties": {
"forceUpdateTag": "[parameters('utcValue')]",
"azPowerShellVersion": "6.2",
"timeout": "PT30M",
"scriptContent": "[format('. .\\New-CKAzADApplication.ps1; Connect-AzAccount -Identity; $accessToken = (Get-AzAccessToken -ResourceUrl \"https://graph.microsoft.com/\").Token; $results = New-CKTAppRegistration -displayName {0} -NativeApp -requireAssignedRole -assignAppRoleToUser {1}; $DeploymentScriptOutputs[\"appId\"] = $results.appId', variables('ClientAppName'), parameters('assignAppRoleToUser'))]",
"supportingScriptUris": [
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/APIs/Invoke-CKMSGraphAPI.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Authentication/Read-CKAccessToken.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/Utils/ConvertFrom-B64ToString.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/New-CKAzADApplication.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/Get-CKAzADApplications.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/New-CKAzADAppServicePrincipal.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/Get-CKAzADServicePrincipals.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Users/Get-CKAzADUsers.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Users/Get-CKAzADUserAppRoleAssignments.ps1', parameters('_artifactsLocationSasToken'))]"
],
"cleanupPreference": "OnSuccess",
"retentionInterval": "PT1H"
}
},
{
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2018-11-30",
"name": "[variables('Identity')]",
"location": "[resourceGroup().location]"
},
{
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2020-10-01",
"name": "sleep",
"dependsOn": [ "[variables('Identity')]" ],
"location": "[resourceGroup().location]",
"kind": "AzurePowerShell",
"properties": {
"forceUpdateTag": "[parameters('utcValue')]",
"azPowerShellVersion": "6.2",
"timeout": "PT30M",
"scriptContent": "Start-Sleep -Seconds 10",
"supportingScriptUris": [],
"cleanupPreference": "OnSuccess",
"retentionInterval": "PT1H"
}
},
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"name": "[variables('roleGuidOne')]",
"dependsOn": ["[concat('Microsoft.Resources/deploymentScripts/', 'sleep')]"],
"properties": {
"roleDefinitionId": "[concat(subscription().id, '/providers/Microsoft.Authorization/roleDefinitions/', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",
"principalId": "[reference(variables('Identity'), '2018-11-30').principalId]",
"principalType": "ServicePrincipal",
"scope": "[resourceGroup().id]"
}
},
{
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2020-10-01",
"name": "grantGraphPermissions",
"dependsOn": ["[concat('Microsoft.Authorization/roleAssignments/', variables('roleGuidOne'))]"],
"location": "[resourceGroup().location]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('identityId')]": {}
}
},
"kind": "AzurePowerShell",
"properties": {
"forceUpdateTag": "[parameters('utcValue')]",
"azPowerShellVersion": "6.2",
"timeout": "PT30M",
"scriptContent": "[format('. .\\Grant-CKAzADAppPermissions.ps1; Connect-AzAccount -Identity; $accessToken = (Get-AzAccessToken -ResourceUrl \"https://graph.microsoft.com/\").Token; Grant-CKAzADAppPermissions -spObjectId {0} -resourceName \"Microsoft Graph\" -Permissions @(\"Application.ReadWrite.All\",\"AppRoleAssignment.ReadWrite.All\",\"Mail.Read\") -permissionType application -accessToken $accessToken', reference(variables('Identity'), '2018-11-30').principalId)]",
"supportingScriptUris": [
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/APIs/Invoke-CKMSGraphAPI.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Authentication/Read-CKAccessToken.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/Utils/ConvertFrom-B64ToString.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/Grant-CKAzADAppPermissions.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/Get-CKOauth2PermissionGrants.ps1', parameters('_artifactsLocationSasToken'))]",
"[concat(parameters('artifactsLocation'), '/CloudKatanaAbilities/AzureAD/Applications/Get-CKAzADServicePrincipals.ps1', parameters('_artifactsLocationSasToken'))]"
],
"cleanupPreference": "OnSuccess",
"retentionInterval": "PT1H"
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "deployFunctionApp",
"dependsOn": [
"createServerApp",
"grantGraphPermissions"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('artifactsLocation'), 'resources/templates/functionApp.json' , parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"serverAppId": {
"value": "[reference('createServerApp').outputs.appId]"
},
"identityName": {
"value": "[variables('Identity')]"
},
"functionAppName": {
"value": "[variables('AppName')]"
},
"_packageLocation": {
"value": "[parameters('_packageLocation')]"
},
"enableHybridMode": {
"value": "[parameters('enableHybridMode')]"
},
"automationAccountName": {
"value": "[parameters('automationAccountName')]"
},
"automationAccountResourceGroupName": {
"value": "[parameters('automationAccountResourceGroupName')]"
},
"hybridWorkerGroupName": {
"value": "[parameters('hybridWorkerGroupName')]"
},
"hybridPowerShellRunbookName": {
"value": "[parameters('hybridPowerShellRunbookName')]"
}
}
}
},
{
"condition": "[parameters('enableHybridMode')]",
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"name": "[variables('roleGuidTwo')]",
"dependsOn": [
"deployFunctionApp"
],
"properties": {
"roleDefinitionId": "[concat(subscription().id, '/providers/Microsoft.Authorization/roleDefinitions/', 'f353d9bd-d4a6-484e-a77a-8050b599b867')]",
"principalId": "[if(parameters('enableHybridMode'), reference(variables('AppName'), '2018-11-30').principalId, '')]",
"principalType": "ServicePrincipal",
"scope": "[resourceGroup().id]"
}
},
{
"condition": "[parameters('enableHybridMode')]",
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"name": "[variables('roleGuidThree')]",
"dependsOn": [
"deployFunctionApp"
],
"properties": {
"roleDefinitionId": "[concat(subscription().id, '/providers/Microsoft.Authorization/roleDefinitions/', '9980e02c-c2be-4d73-94e8-173b1dc7cf3c')]",
"principalId": "[if(parameters('enableHybridMode'), reference(variables('AppName'), '2018-11-30').principalId, '')]",
"principalType": "ServicePrincipal",
"scope": "[resourceGroup().id]"
}
}
],
"outputs": {
"functionAppName": {
"type": "string",
"value": "[variables('AppName')]"
},
"identityName": {
"type": "string",
"value": "[variables('Identity')]"
},
"serverAppName": {
"type": "string",
"value": "[variables('ServerAppName')]"
},
"serverAppId": {
"type": "string",
"value": "[reference('createServerApp').outputs.appId]"
},
"clientAppName": {
"type": "string",
"value": "[variables('ClientAppName')]"
},
"clientAppId": {
"type": "string",
"value": "[reference('createClientApp').outputs.appId]"
}
}
}