Skip to content

Commit ada7676

Browse files
authored
Fix bicep files now that multi-tenant is no longer permitted (#292)
Fixes `Multitenant bot creation is deprecated. Please use SingleTenant or UserAssignedMSI`. MSFT deprecated Multi-Tenant app registrations (see https://docs.azure.cn/en-us/bot-service/provision-and-publish-a-bot?view=azure-bot-service-4.0&tabs=userassigned%2Ccsharp). <img width="800" height="691" alt="image" src="https://github.com/user-attachments/assets/9b989c9e-5e58-4efb-aecb-9b40f0cbcab2" /> This requires certain updates to our bicep files to ensure that users can still use ATK to provision new bots. I tested this change by Creating a fresh new echo bot and using ATK to deploy it without any manual effort. Future versions of the CLI (@preview9 onward) will have this fixed, but for now, you need to manually make the changes demonstrated in this PR. OR If you prefer using Github Copilot, just use this prompt: ``` Please update the Azure Bicep templates to migrate from app registration authentication to managed identity authentication for the Azure Bot Framework. You'll be working with two files that currently use the old app registration pattern. **File: infra/azure.bicep** The current file uses `botAadAppClientId` and `botAadAppClientSecret` parameters. Please make these changes: 1. **Remove these parameters:** ```bicep @description('Required when create Azure Bot service') param botAadAppClientId string @secure() @description('Required by Bot Framework package in your bot project') param botAadAppClientSecret string 2. Add new parameter after the existing parameters: param identityName string = resourceBaseName 3. Add managed identity resource before the serverfarm resource: resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = { location: location name: identityName } 4. Update the webApp resource: - Change comment from "Web App that hosts your bot" to "Web App that hosts your agent" - Update Node.js version from '~16' to '~18' - Replace the BOT_ID and BOT_PASSWORD app settings with: { name: 'BOT_ID' value: identity.properties.clientId } { name: 'BOT_TENANT_ID' value: identity.properties.tenantId } { name: 'BOT_TYPE' value: 'UserAssignedMsi' } - Add identity configuration after the properties section: identity: { type: 'UserAssigned' userAssignedIdentities: { '${identity.id}': {} } } 5. Update the azureBotRegistration module parameters: Replace botAadAppClientId: botAadAppClientId with: identityClientId: identity.properties.clientId identityResourceId: identity.id identityTenantId: identity.properties.tenantId 6. Add new outputs: output BOT_ID string = identity.properties.clientId output BOT_TENANT_ID string = identity.properties.tenantId File: infra/botRegistration/azurebot.bicep 1. Replace the botAadAppClientId parameter with these three: param identityResourceId string param identityClientId string param identityTenantId string 2. Update the botService resource properties: Replace msaAppId: botAadAppClientId with: msaAppId: identityClientId msaAppMSIResourceId: identityResourceId msaAppTenantId:identityTenantId msaAppType:'UserAssignedMSI' These changes eliminate the need for managing bot secrets and use Azure's managed identity for more secure authentication. ```
1 parent 300f6f1 commit ada7676

File tree

9 files changed

+127
-62
lines changed

9 files changed

+127
-62
lines changed

.github/workflows/template-sync.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ jobs:
5757
5858
# Check template directories without matching test changes
5959
for dir in "${!template_dirs[@]}"; do
60-
if [[ -z "${test_dirs[$dir]}" ]]; then
60+
# Only check if the corresponding test directory exists
61+
if [[ -d "tests/$dir" && -z "${test_dirs[$dir]}" ]]; then
6162
echo "::error::Changes detected in template directory but no corresponding test changes found (use skip-test-verification in PR description to skip this check)"
6263
echo "Template directory: packages/cli/templates/typescript/$dir"
6364
echo "Changed files:"
@@ -69,7 +70,8 @@ jobs:
6970
7071
# Check test directories without matching template changes
7172
for dir in "${!test_dirs[@]}"; do
72-
if [[ -z "${template_dirs[$dir]}" ]]; then
73+
# Only check if the corresponding template directory exists
74+
if [[ -d "packages/cli/templates/typescript/$dir" && -z "${template_dirs[$dir]}" ]]; then
7375
echo "::error::Changes detected in test directory but no corresponding template changes found (use skip-test-verification in PR description to skip this check)"
7476
echo "Test directory: tests/$dir"
7577
echo "Changed files:"

packages/cli/configs/atk/basic/csharp/TeamsApp/infra/azure.bicep

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
@description('Used to generate names for all resources in this file')
44
param resourceBaseName string
55

6-
@description('Required when create Azure Bot service')
7-
param botAadAppClientId string
8-
9-
@secure()
10-
@description('Required by Bot Framework package in your bot project')
11-
param botAadAppClientSecret string
12-
136
param webAppSKU string
147

158
@maxLength(42)
169
param botDisplayName string
1710

1811
param serverfarmsName string = resourceBaseName
1912
param webAppName string = resourceBaseName
13+
param identityName string = resourceBaseName
2014
param location string = resourceGroup().location
2115

16+
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
17+
location: location
18+
name: identityName
19+
}
20+
2221
// Compute resources for your Web App
2322
resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
2423
kind: 'app'
@@ -29,7 +28,7 @@ resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
2928
}
3029
}
3130

32-
// Web App that hosts your bot
31+
// Web App that hosts your agent
3332
resource webApp 'Microsoft.Web/sites@2021-02-01' = {
3433
kind: 'app'
3534
location: location
@@ -46,32 +45,44 @@ resource webApp 'Microsoft.Web/sites@2021-02-01' = {
4645
}
4746
{
4847
name: 'WEBSITE_NODE_DEFAULT_VERSION'
49-
value: '~16' // Set NodeJS version to 16.x for your site
48+
value: '~20' // Set NodeJS version to 20.x for your site
5049
}
5150
{
5251
name: 'RUNNING_ON_AZURE'
5352
value: '1'
5453
}
5554
{
5655
name: 'BOT_ID'
57-
value: botAadAppClientId
56+
value: identity.properties.clientId
5857
}
5958
{
60-
name: 'BOT_PASSWORD'
61-
value: botAadAppClientSecret
59+
name: 'BOT_TENANT_ID'
60+
value: identity.properties.tenantId
61+
}
62+
{
63+
name: 'BOT_TYPE'
64+
value: 'UserAssignedMsi'
6265
}
6366
]
6467
ftpsState: 'FtpsOnly'
6568
}
6669
}
70+
identity: {
71+
type: 'UserAssigned'
72+
userAssignedIdentities: {
73+
'${identity.id}': {}
74+
}
75+
}
6776
}
6877

6978
// Register your web service as a bot with the Bot Framework
7079
module azureBotRegistration './botRegistration/azurebot.bicep' = {
7180
name: 'Azure-Bot-registration'
7281
params: {
7382
resourceBaseName: resourceBaseName
74-
botAadAppClientId: botAadAppClientId
83+
identityClientId: identity.properties.clientId
84+
identityResourceId: identity.id
85+
identityTenantId: identity.properties.tenantId
7586
botAppDomain: webApp.properties.defaultHostName
7687
botDisplayName: botDisplayName
7788
}
@@ -80,3 +91,5 @@ module azureBotRegistration './botRegistration/azurebot.bicep' = {
8091
// The output will be persisted in .env.{envName}. Visit https://aka.ms/teamsfx-actions/arm-deploy for more details.
8192
output BOT_AZURE_APP_SERVICE_RESOURCE_ID string = webApp.id
8293
output BOT_DOMAIN string = webApp.properties.defaultHostName
94+
output BOT_ID string = identity.properties.clientId
95+
output BOT_TENANT_ID string = identity.properties.tenantId

packages/cli/configs/atk/basic/csharp/TeamsApp/infra/botRegistration/azurebot.bicep

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ param botDisplayName string
88

99
param botServiceName string = resourceBaseName
1010
param botServiceSku string = 'F0'
11-
param botAadAppClientId string
11+
param identityResourceId string
12+
param identityClientId string
13+
param identityTenantId string
1214
param botAppDomain string
1315

1416
// Register your web service as a bot with the Bot Framework
@@ -19,7 +21,10 @@ resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
1921
properties: {
2022
displayName: botDisplayName
2123
endpoint: 'https://${botAppDomain}/api/messages'
22-
msaAppId: botAadAppClientId
24+
msaAppId: identityClientId
25+
msaAppMSIResourceId: identityResourceId
26+
msaAppTenantId: identityTenantId
27+
msaAppType: 'UserAssignedMSI'
2328
}
2429
sku: {
2530
name: botServiceSku

packages/cli/configs/atk/basic/typescript/infra/azure.bicep

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
@description('Used to generate names for all resources in this file')
44
param resourceBaseName string
55

6-
@description('Required when create Azure Bot service')
7-
param botAadAppClientId string
8-
9-
@secure()
10-
@description('Required by Bot Framework package in your bot project')
11-
param botAadAppClientSecret string
12-
136
param webAppSKU string
147

158
@maxLength(42)
169
param botDisplayName string
1710

1811
param serverfarmsName string = resourceBaseName
1912
param webAppName string = resourceBaseName
13+
param identityName string = resourceBaseName
2014
param location string = resourceGroup().location
2115

16+
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
17+
location: location
18+
name: identityName
19+
}
20+
2221
// Compute resources for your Web App
2322
resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
2423
kind: 'app'
@@ -29,7 +28,7 @@ resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
2928
}
3029
}
3130

32-
// Web App that hosts your bot
31+
// Web App that hosts your agent
3332
resource webApp 'Microsoft.Web/sites@2021-02-01' = {
3433
kind: 'app'
3534
location: location
@@ -42,36 +41,48 @@ resource webApp 'Microsoft.Web/sites@2021-02-01' = {
4241
appSettings: [
4342
{
4443
name: 'WEBSITE_RUN_FROM_PACKAGE'
45-
value: '1' // Run Azure APP Service from a package file
44+
value: '1' // Run Azure App Service from a package file
4645
}
4746
{
4847
name: 'WEBSITE_NODE_DEFAULT_VERSION'
49-
value: '~16' // Set NodeJS version to 16.x for your site
48+
value: '~20' // Set NodeJS version to 20.x for your site
5049
}
5150
{
5251
name: 'RUNNING_ON_AZURE'
5352
value: '1'
5453
}
5554
{
5655
name: 'BOT_ID'
57-
value: botAadAppClientId
56+
value: identity.properties.clientId
5857
}
5958
{
60-
name: 'BOT_PASSWORD'
61-
value: botAadAppClientSecret
59+
name: 'BOT_TENANT_ID'
60+
value: identity.properties.tenantId
61+
}
62+
{
63+
name: 'BOT_TYPE'
64+
value: 'UserAssignedMsi'
6265
}
6366
]
6467
ftpsState: 'FtpsOnly'
6568
}
6669
}
70+
identity: {
71+
type: 'UserAssigned'
72+
userAssignedIdentities: {
73+
'${identity.id}': {}
74+
}
75+
}
6776
}
6877

6978
// Register your web service as a bot with the Bot Framework
7079
module azureBotRegistration './botRegistration/azurebot.bicep' = {
7180
name: 'Azure-Bot-registration'
7281
params: {
7382
resourceBaseName: resourceBaseName
74-
botAadAppClientId: botAadAppClientId
83+
identityClientId: identity.properties.clientId
84+
identityResourceId: identity.id
85+
identityTenantId: identity.properties.tenantId
7586
botAppDomain: webApp.properties.defaultHostName
7687
botDisplayName: botDisplayName
7788
}
@@ -80,3 +91,5 @@ module azureBotRegistration './botRegistration/azurebot.bicep' = {
8091
// The output will be persisted in .env.{envName}. Visit https://aka.ms/teamsfx-actions/arm-deploy for more details.
8192
output BOT_AZURE_APP_SERVICE_RESOURCE_ID string = webApp.id
8293
output BOT_DOMAIN string = webApp.properties.defaultHostName
94+
output BOT_ID string = identity.properties.clientId
95+
output BOT_TENANT_ID string = identity.properties.tenantId

packages/cli/configs/atk/basic/typescript/infra/botRegistration/azurebot.bicep

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ param botDisplayName string
88

99
param botServiceName string = resourceBaseName
1010
param botServiceSku string = 'F0'
11-
param botAadAppClientId string
11+
param identityResourceId string
12+
param identityClientId string
13+
param identityTenantId string
1214
param botAppDomain string
1315

1416
// Register your web service as a bot with the Bot Framework
@@ -19,7 +21,10 @@ resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
1921
properties: {
2022
displayName: botDisplayName
2123
endpoint: 'https://${botAppDomain}/api/messages'
22-
msaAppId: botAadAppClientId
24+
msaAppId: identityClientId
25+
msaAppMSIResourceId: identityResourceId
26+
msaAppTenantId:identityTenantId
27+
msaAppType:'UserAssignedMSI'
2328
}
2429
sku: {
2530
name: botServiceSku

packages/cli/configs/atk/embed/typescript/infra/azure.bicep

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
@description('Used to generate names for all resources in this file')
44
param resourceBaseName string
55

6-
@description('Required when create Azure Bot service')
7-
param botAadAppClientId string
8-
9-
@secure()
10-
@description('Required by Bot Framework package in your bot project')
11-
param botAadAppClientSecret string
12-
136
param webAppSKU string
147

158
@maxLength(42)
169
param botDisplayName string
1710

1811
param serverfarmsName string = resourceBaseName
1912
param webAppName string = resourceBaseName
13+
param identityName string = resourceBaseName
2014
param location string = resourceGroup().location
2115

16+
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
17+
location: location
18+
name: identityName
19+
}
20+
2221
// Compute resources for your Web App
2322
resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
2423
kind: 'app'
@@ -29,7 +28,7 @@ resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
2928
}
3029
}
3130

32-
// Web App that hosts your bot
31+
// Web App that hosts your agent
3332
resource webApp 'Microsoft.Web/sites@2021-02-01' = {
3433
kind: 'app'
3534
location: location
@@ -46,32 +45,44 @@ resource webApp 'Microsoft.Web/sites@2021-02-01' = {
4645
}
4746
{
4847
name: 'WEBSITE_NODE_DEFAULT_VERSION'
49-
value: '~16' // Set NodeJS version to 16.x for your site
48+
value: '~20' // Set NodeJS version to 20.x for your site
5049
}
5150
{
5251
name: 'RUNNING_ON_AZURE'
5352
value: '1'
5453
}
5554
{
5655
name: 'BOT_ID'
57-
value: botAadAppClientId
56+
value: identity.properties.clientId
5857
}
5958
{
60-
name: 'BOT_PASSWORD'
61-
value: botAadAppClientSecret
59+
name: 'BOT_TENANT_ID'
60+
value: identity.properties.tenantId
61+
}
62+
{
63+
name: 'BOT_TYPE'
64+
value: 'UserAssignedMsi'
6265
}
6366
]
6467
ftpsState: 'FtpsOnly'
6568
}
6669
}
70+
identity: {
71+
type: 'UserAssigned'
72+
userAssignedIdentities: {
73+
'${identity.id}': {}
74+
}
75+
}
6776
}
6877

6978
// Register your web service as a bot with the Bot Framework
7079
module azureBotRegistration './botRegistration/azurebot.bicep' = {
7180
name: 'Azure-Bot-registration'
7281
params: {
7382
resourceBaseName: resourceBaseName
74-
botAadAppClientId: botAadAppClientId
83+
identityClientId: identity.properties.clientId
84+
identityResourceId: identity.id
85+
identityTenantId: identity.properties.tenantId
7586
botAppDomain: webApp.properties.defaultHostName
7687
botDisplayName: botDisplayName
7788
}
@@ -80,3 +91,5 @@ module azureBotRegistration './botRegistration/azurebot.bicep' = {
8091
// The output will be persisted in .env.{envName}. Visit https://aka.ms/teamsfx-actions/arm-deploy for more details.
8192
output BOT_AZURE_APP_SERVICE_RESOURCE_ID string = webApp.id
8293
output BOT_DOMAIN string = webApp.properties.defaultHostName
94+
output BOT_ID string = identity.properties.clientId
95+
output BOT_TENANT_ID string = identity.properties.tenantId

packages/cli/configs/atk/embed/typescript/infra/botRegistration/azurebot.bicep

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ param botDisplayName string
88

99
param botServiceName string = resourceBaseName
1010
param botServiceSku string = 'F0'
11-
param botAadAppClientId string
11+
param identityResourceId string
12+
param identityClientId string
13+
param identityTenantId string
1214
param botAppDomain string
1315

1416
// Register your web service as a bot with the Bot Framework
@@ -19,7 +21,10 @@ resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
1921
properties: {
2022
displayName: botDisplayName
2123
endpoint: 'https://${botAppDomain}/api/messages'
22-
msaAppId: botAadAppClientId
24+
msaAppId: identityClientId
25+
msaAppMSIResourceId: identityResourceId
26+
msaAppTenantId: identityTenantId
27+
msaAppType: 'UserAssignedMSI'
2328
}
2429
sku: {
2530
name: botServiceSku

0 commit comments

Comments
 (0)