Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated managed Identity - MSI #1387

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions samples/bot-conversation/python/infra/azure.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
@description('Used to generate names for all resources in this file')
param resourceBaseName string

@description('Required when create Azure Bot service')
param botAadAppClientId string

param botAppDomain string

@maxLength(42)
param botDisplayName string

param botServiceName string = resourceBaseName
param identityName string = resourceBaseName
param botServiceSku string = 'F0'

resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
location: location
name: identityName
}

// Register your web service as a bot with the Bot Framework
resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
kind: 'azurebot'
Expand All @@ -22,7 +25,12 @@ resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
properties: {
displayName: botDisplayName
endpoint: 'https://${botAppDomain}/api/messages'
msaAppId: botAadAppClientId

msaAppId: identity.properties.clientId
msaAppMSIResourceId: identity.id
msaAppTenantId:identity.properties.tenantId
msaAppType:'UserAssignedMSI'

msaAppType: 'MultiTenant'
msaAppTenantId: ''
}
Expand Down
3 changes: 0 additions & 3 deletions samples/bot-conversation/python/infra/azure.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"resourceBaseName": {
"value": "bot${{RESOURCE_SUFFIX}}"
},
"botAadAppClientId": {
"value": "${{AAD_APP_CLIENT_ID}}"
},
"botAppDomain": {
"value": "${{BOT_DOMAIN}}"
},
Expand Down
3 changes: 2 additions & 1 deletion samples/bot-conversation/python/teamsapp.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ deploy:
target: ./.env
envs:
MicrosoftAppId: ${{AAD_APP_CLIENT_ID}}
MicrosoftAppPassword: ${{SECRET_AAD_APP_CLIENT_SECRET}}
MicrosoftAppPassword: ${{SECRET_AAD_APP_CLIENT_SECRET}}
BOT_TYPE: 'MultiTenant'
1 change: 1 addition & 0 deletions samples/bot-proactive-messaging-teamsfx/teamsapp.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ deploy:
envs:
BOT_ID: ${{BOT_ID}}
BOT_PASSWORD: ${{SECRET_BOT_PASSWORD}}
BOT_TYPE: 'MultiTenant'

# Generate runtime environment variables
- uses: file/createOrUpdateEnvironmentFile
Expand Down
6 changes: 0 additions & 6 deletions samples/bot-proactive-messaging-teamsfx/teamsapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ provision:
writeToEnvironmentFile:
# Write the information of created resources into environment file for the specified environment variable(s).
teamsAppId: TEAMS_APP_ID
- uses: botAadApp/create # Creates a new AAD app for Bot Registration.
with:
name: ProactiveMessagesTeamsFxbt${{RESOURCE_SUFFIX}}
writeToEnvironmentFile:
botId: BOT_ID
botPassword: SECRET_BOT_PASSWORD
- uses: arm/deploy # Deploy given ARM templates parallelly.
with:
subscriptionId: ${{AZURE_SUBSCRIPTION_ID}} # The AZURE_SUBSCRIPTION_ID is a built-in environment variable. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment varialbe here, but TeamsFx will not ask you to select subscription if it's empty in this case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module botProvision './provision/bot.bicep' = {
params: {
provisionParameters: provisionParameters
userAssignedIdentityId: userAssignedIdentityProvision.outputs.identityResourceId
identityClientId: userAssignedIdentityProvision.outputs.identityClientId
identityResourceId: userAssignedIdentityProvision.outputs.identityResourceId
identityTenantId: userAssignedIdentityProvision.outputs.identityPrincipalId
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@secure()
param provisionParameters object
param userAssignedIdentityId string
param identityName string = provisionParameters.resourceBaseName
param identityResourceId string
param identityClientId string
param identityTenantId string

var resourceBaseName = provisionParameters.resourceBaseName
var botAadAppClientId = provisionParameters['botAadAppClientId'] // Read AAD app client id for Azure Bot Service from parameters
var botServiceName = contains(provisionParameters, 'botServiceName') ? provisionParameters['botServiceName'] : '${resourceBaseName}' // Try to read name for Azure Bot Service from parameters
var botServiceSku = contains(provisionParameters, 'botServiceSku') ? provisionParameters['botServiceSku'] : 'F0' // Try to read SKU for Azure Bot Service from parameters
var botDisplayName = contains(provisionParameters, 'botDisplayName') ? provisionParameters['botDisplayName'] : '${resourceBaseName}' // Try to read display name for Azure Bot Service from parameters
Expand All @@ -19,13 +22,22 @@ resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
properties: {
displayName: botDisplayName
endpoint: uri('https://${webApp.properties.defaultHostName}', '/api/messages')
msaAppId: botAadAppClientId
msaAppId: identityClientId
msaAppMSIResourceId: identityResourceId
msaAppTenantId:identityTenantId
msaAppType:'UserAssignedMSI'
}
sku: {
name: botServiceSku // You can follow https://aka.ms/teamsfx-bicep-add-param-tutorial to add botServiceSku property to provisionParameters to override the default value "F0".
}
}

// Managed Identity resource
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
location: resourceGroup().location
name: identityName
}

// Connect the bot service to Microsoft Teams
resource botServiceMsTeamsChannel 'Microsoft.BotService/botServices/channels@2021-03-01' = {
parent: botService
Expand Down Expand Up @@ -78,6 +90,8 @@ resource webApp 'Microsoft.Web/sites@2021-02-01' = {
output botWebAppSKU string = webAppSKU
output botWebAppName string = webAppName
output botDomain string = webApp.properties.defaultHostName
output BOT_ID string = identity.properties.clientId
output BOT_TENANT_ID string = identity.properties.tenantId
output appServicePlanName string = serverfarmsName
output botServiceName string = botServiceName
output botWebAppResourceId string = webApp.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ param provisionOutputs object
@secure()
param currentAppSettings object

var botWebAppName = split(provisionOutputs.botOutput.value.botWebAppResourceId, '/')[8]
param identityName string = provisionParameters.resourceBaseName

var botAadAppClientSecret = provisionParameters['botAadAppClientSecret']
var botWebAppName = split(provisionOutputs.botOutput.value.botWebAppResourceId, '/')[8]

var botId = provisionParameters['botAadAppClientId']
// Managed Identity resource
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
location: resourceGroup().location
name: identityName
}

resource botWebAppSettings 'Microsoft.Web/sites/config@2021-02-01' = {
name: '${botWebAppName}/appsettings'
properties: union({
INITIATE_LOGIN_ENDPOINT: uri(provisionOutputs.botOutput.value.siteEndpoint, 'auth-start.html') // The page is used to let users consent required OAuth permissions during bot SSO process
BOT_ID: botId // ID of your bot
BOT_PASSWORD: botAadAppClientSecret // Secret of your bot
BOT_ID: identity.properties.clientId // ID of your bot
BOT_TENANT_ID: identity.properties.tenantId // Secret of your bot
IDENTITY_ID: provisionOutputs.identityOutput.value.identityClientId // User assigned identity id, the identity is used to access other Azure resources
PROVISIONOUTPUT__BOTOUTPUT__SITEENDPOINT : provisionOutputs.botOutput.value.siteEndpoint // Site endpoint of AAD application
}, currentAppSettings)
Expand Down
2 changes: 2 additions & 0 deletions samples/msgext-unfurling-ac-loop-components/nodejs/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const config = {
botType: process.env.BOT_TYPE,
botId: process.env.BOT_ID,
botPassword: process.env.BOT_PASSWORD,
botTenantId: process.env.BOT_TENANT_ID
};

module.exports = config;
3 changes: 2 additions & 1 deletion samples/msgext-unfurling-ac-loop-components/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const config = require("./config");
const credentialsFactory = new ConfigurationServiceClientCredentialFactory({
MicrosoftAppId: config.botId,
MicrosoftAppPassword: config.botPassword,
MicrosoftAppType: "MultiTenant",
MicrosoftAppType: config.botType,
MicrosoftAppTenantId: config.botTenantId
});

const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
@description('Used to generate names for all resources in this file')
param resourceBaseName string

@description('Required when create Azure Bot service')
param botAadAppClientId string

@secure()
@description('Required by Bot Framework package in your bot project')
param botAadAppClientSecret string

param webAppSKU string

@maxLength(42)
param botDisplayName string

param serverfarmsName string = resourceBaseName
param webAppName string = resourceBaseName
param identityName string = resourceBaseName
param location string = resourceGroup().location

resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
location: location
name: identityName
}

// Compute resources for your Web App
resource serverfarm 'Microsoft.Web/serverfarms@2021-02-01' = {
kind: 'app'
Expand Down Expand Up @@ -54,11 +53,15 @@ resource webApp 'Microsoft.Web/sites@2021-02-01' = {
}
{
name: 'BOT_ID'
value: botAadAppClientId
value: identity.properties.clientId
}
{
name: 'BOT_TENANT_ID'
value: identity.properties.tenantId
}
{
name: 'BOT_PASSWORD'
value: botAadAppClientSecret
name: 'BOT_TYPE'
value: 'UserAssignedMsi'
}
]
ftpsState: 'FtpsOnly'
Expand All @@ -71,7 +74,9 @@ module azureBotRegistration './botRegistration/azurebot.bicep' = {
name: 'Azure-Bot-registration'
params: {
resourceBaseName: resourceBaseName
botAadAppClientId: botAadAppClientId
identityClientId: identity.properties.clientId
identityResourceId: identity.id
identityTenantId: identity.properties.tenantId
botAppDomain: webApp.properties.defaultHostName
botDisplayName: botDisplayName
}
Expand All @@ -80,3 +85,5 @@ module azureBotRegistration './botRegistration/azurebot.bicep' = {
// The output will be persisted in .env.{envName}. Visit https://aka.ms/teamsfx-actions/arm-deploy for more details.
output BOT_AZURE_APP_SERVICE_RESOURCE_ID string = webApp.id
output BOT_DOMAIN string = webApp.properties.defaultHostName
output BOT_ID string = identity.properties.clientId
output BOT_TENANT_ID string = identity.properties.tenantId
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
"resourceBaseName": {
"value": "ME${{RESOURCE_SUFFIX}}"
},
"botAadAppClientId": {
"value": "${{BOT_ID}}"
},
"botAadAppClientSecret": {
"value": "${{SECRET_BOT_PASSWORD}}"
},
"webAppSKU": {
"value": "B1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ param resourceBaseName string
@maxLength(42)
param botDisplayName string

param botServiceName string = resourceBaseName
param botServiceName string = resourceBaseNameparam identityResourceId string
param identityClientId string
param identityTenantId string
param botServiceSku string = 'F0'
param botAadAppClientId string
param botAppDomain string
Expand All @@ -19,7 +21,10 @@ resource botService 'Microsoft.BotService/botServices@2021-03-01' = {
properties: {
displayName: botDisplayName
endpoint: 'https://${botAppDomain}/api/messages'
msaAppId: botAadAppClientId
msaAppId: identityClientId
msaAppMSIResourceId: identityResourceId
msaAppTenantId:identityTenantId
msaAppType:'UserAssignedMSI'
}
sku: {
name: botServiceSku
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ deploy:
target: ./.localConfigs
envs:
BOT_ID: ${{BOT_ID}}
BOT_PASSWORD: ${{SECRET_BOT_PASSWORD}}
BOT_PASSWORD: ${{SECRET_BOT_PASSWORD}}
BOT_TYPE: 'MultiTenant'