Skip to content

Commit 44f8f28

Browse files
authored
Merge pull request #589 from microsoft/southworks/add/identity-resources
[#548] Create Fn tests for supported authentication types - Adapt Create and Cleanup pipelines
2 parents f70fd32 + 2382310 commit 44f8f28

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

build/yaml/cleanupResources/cleanupResources.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,29 @@ stages:
316316
Write-Host "No pre-existing $(INTERNALSTORAGEACCOUNTNAME) resource found."
317317
}
318318
319+
- stage: "Delete_User_Identities"
320+
displayName: "Delete User Assigned Managed Identities"
321+
dependsOn:
322+
- Delete_App_Service_Plan_DotNet
323+
- Delete_App_Service_Plan_JS
324+
- Delete_App_Service_Plan_Python
325+
jobs:
326+
- job: "Delete"
327+
displayName: "Delete steps"
328+
steps:
329+
- checkout: none
330+
- task: AzureCLI@2
331+
displayName: "Delete User Assigned Managed Identities"
332+
inputs:
333+
azureSubscription: $(AZURESUBSCRIPTION)
334+
scriptType: pscore
335+
scriptLocation: inlineScript
336+
inlineScript: |
337+
az identity delete -n "bffnsimplehostbotdotnetmsi$($env:RESOURCESUFFIX)" -g "$(INTERNALSHAREDRESOURCEGROUPNAME)"
338+
az identity delete -n "bffnsimplehostbotjsmsi$($env:RESOURCESUFFIX)" -g "$(INTERNALSHAREDRESOURCEGROUPNAME)"
339+
az identity delete -n "bffnechoskillbotdotnetmsi$($env:RESOURCESUFFIX)" -g "$(INTERNALSHAREDRESOURCEGROUPNAME)"
340+
az identity delete -n "bffnechoskillbotjsmsi$($env:RESOURCESUFFIX)" -g "$(INTERNALSHAREDRESOURCEGROUPNAME)"
341+
319342
- stage: "Delete_Shared_Resource_Group"
320343
displayName: "Delete Shared Resource Group"
321344
dependsOn:
@@ -326,6 +349,7 @@ stages:
326349
- Delete_CosmosDB
327350
- Delete_Container_Registry
328351
- Delete_Storage_Account
352+
- Delete_User_Identities
329353
jobs:
330354
- job: "Delete"
331355
displayName: "Delete steps"

build/yaml/sharedResources/createAppRegistrations.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ steps:
4848
Invoke-WebRequest -Uri "https://login.microsoftonline.com/${{ parameters.tenantId }}/oauth2/v2.0/token" -Method "POST" -Body $body | ConvertFrom-Json
4949
}
5050
51-
function CreateAppRegistration($token, $appName) {
51+
function CreateAppRegistration($token, $appName, $audience) {
5252
# Create App Registration
5353
5454
$headers = @{
@@ -57,7 +57,7 @@ steps:
5757
5858
$body = @{
5959
displayName = $appName;
60-
signInAudience = "AzureADandPersonalMicrosoftAccount"
60+
signInAudience = $audience;
6161
} | ConvertTo-Json
6262
6363
$app = Invoke-WebRequest -Uri "https://graph.microsoft.com/v1.0/applications" -Method "POST" -Headers $headers -Body $body -ContentType "application/json" | ConvertFrom-Json;
@@ -73,6 +73,16 @@ steps:
7373
$app | Add-Member -MemberType NoteProperty -Name secret -Value $secret.secretText;
7474
7575
$app
76+
77+
if ($audience -eq "AzureADMyOrg") {
78+
# Create Service Principal Object
79+
80+
$body = @{
81+
appId = $app.appId;
82+
} | ConvertTo-Json
83+
84+
$servicePpal = Invoke-WebRequest -Uri "https://graph.microsoft.com/v1.0/servicePrincipals" -Method "POST" -Headers $headers -Body $body -ContentType "application/json" | ConvertFrom-Json;
85+
}
7686
}
7787
7888
function SaveAppRegistrationIntoKeyVault($vaultName, $bot, $app) {
@@ -107,17 +117,22 @@ steps:
107117
@{ appName = "bffnsimplehostbotpython"; variables = @{ appId = "BffnSimpleHostBotPythonAppId"; appSecret = "BffnSimpleHostBotPythonAppSecret"; objectId = "BffnSimpleHostBotPythonAppObjectId" }},
108118
@{ appName = "bffnechoskillbotpython"; variables = @{ appId = "BffnEchoSkillBotPythonAppId"; appSecret = "BffnEchoSkillBotPythonAppSecret"; objectId = "BffnEchoSkillBotPythonAppObjectId" }},
109119
@{ appName = "bffnwaterfallhostbotpython"; variables = @{ appId = "BffnWaterfallHostBotPythonAppId"; appSecret = "BffnWaterfallHostBotPythonAppSecret"; objectId = "BffnWaterfallHostBotPythonAppObjectId" }},
110-
@{ appName = "bffnwaterfallskillbotpython"; variables = @{ appId = "BffnWaterfallSkillBotPythonAppId"; appSecret = "BffnWaterfallSkillBotPythonAppSecret"; objectId = "BffnWaterfallSkillBotPythonAppObjectId" }}
120+
@{ appName = "bffnwaterfallskillbotpython"; variables = @{ appId = "BffnWaterfallSkillBotPythonAppId"; appSecret = "BffnWaterfallSkillBotPythonAppSecret"; objectId = "BffnWaterfallSkillBotPythonAppObjectId" }},
121+
@{ appName = "bffnsimplehostbotdotnetst"; variables = @{ appId = "BffnSimpleHostBotDotNetSTAppId"; appSecret = "BffnSimpleHostBotDotNetSTAppSecret"; objectId = "BffnSimpleHostBotDotNetSTAppObjectId"; signInAudience = "AzureADMyOrg" }},
122+
@{ appName = "bffnsimplehostbotjsst"; variables = @{ appId = "BffnSimpleHostBotJSSTAppId"; appSecret = "BffnSimpleHostBotJSSTAppSecret"; objectId = "BffnSimpleHostBotJSSTAppObjectId"; signInAudience = "AzureADMyOrg" }},
123+
@{ appName = "bffnechoskillbotdotnetst"; variables = @{ appId = "BffnEchoSkillBotDotNetSTAppId"; appSecret = "BffnEchoSkillBotDotNetSTAppSecret"; objectId = "BffnEchoSkillBotDotNetSTObjectId"; signInAudience = "AzureADMyOrg" }},
124+
@{ appName = "bffnechoskillbotjsst"; variables = @{ appId = "BffnEchoSkillBotJSSTAppId"; appSecret = "BffnEchoSkillBotJSSTAppSecret"; objectId = "BffnEchoSkillBotJSSTAppObjectId"; signInAudience = "AzureADMyOrg" }}
111125
)
112126
113127
$token = GetToken
114128
115129
foreach ($bot in $bots) {
116130
$botName = "$($bot.appName)${{ parameters.resourceSuffix }}"
131+
$audience = $($bot.variables.signInAudience) ?? "AzureADMultipleOrgs"
117132
Write-Host "`n[$botName] Starting"
118133
Write-Host "Creating App Registration ..."
119-
120-
$app = CreateAppRegistration $token $botName
134+
135+
$app = CreateAppRegistration $token $botName $audience
121136
Write-Host "
122137
App Registration:
123138
Name: $botName

build/yaml/sharedResources/createSharedResources.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,22 @@ stages:
253253
scriptType: pscore
254254
scriptLocation: inlineScript
255255
inlineScript: "az deployment group create --name $(INTERNALSTORAGEACCOUNTNAME) --resource-group $(INTERNALRESOURCEGROUPNAME) --template-file build/templates/template-storage-account-resources.json --parameters storageAccountName=$(INTERNALSTORAGEACCOUNTNAME)"
256+
257+
- stage: Create_User_Identities
258+
displayName: "Create User Assigned Managed Identities"
259+
dependsOn: Create_Resource_Group
260+
jobs:
261+
- job: Deploy_User_Identities
262+
displayName: "Deploy steps"
263+
steps:
264+
- task: AzureCLI@2
265+
displayName: "Deploy User Assigned Managed Identities"
266+
inputs:
267+
azureSubscription: $(AZURESUBSCRIPTION)
268+
scriptType: pscore
269+
scriptLocation: inlineScript
270+
inlineScript: |
271+
az identity create -g "$(INTERNALRESOURCEGROUPNAME)" -n "bffnsimplehostbotdotnetmsi$($env:RESOURCESUFFIX)"
272+
az identity create -g "$(INTERNALRESOURCEGROUPNAME)" -n "bffnsimplehostbotjsmsi$($env:RESOURCESUFFIX)"
273+
az identity create -g "$(INTERNALRESOURCEGROUPNAME)" -n "bffnechoskillbotdotnetmsi$($env:RESOURCESUFFIX)"
274+
az identity create -g "$(INTERNALRESOURCEGROUPNAME)" -n "bffnechoskillbotjsmsi$($env:RESOURCESUFFIX)"

0 commit comments

Comments
 (0)