0
votes

I Have been struggling with Azure App Service authentication for a while now. I have CI/CD pipeline running and want to configure app service authentication using an ARM template. See here (part of) my template:

{
  "name": "[parameters('apiAppName')]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "apiVersion": "2015-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', parameters('apiHostingPlanName'))]"
  ],
  "properties": {
    "name": "[parameters('apiAppName')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('apiHostingPlanName'))]",
    "siteConfig": {
      "siteAuthEnabled": true,
      "siteAuthSettings": {
        "unauthenticatedClientAction": 0,
        "defaultProvider": 0,
        "tokenStoreEnabled": true,
        "clientAffinityEnabled": false 
      } 
    }
  }
}

When deploying this, it still shows all authentication providers as not configured.

To configure the AAD provider, I've only come up with two solutions:

  • Configure it useing the portal. Not wat I want, manual clicking doesn't combine with continuous delivery
  • Use Azure Powershell in my release pipeline to create (if not exists) an app registration with client secret and clientid and specify that in the ARM template.

I was wondering, is there any way I can get the needed application identity automatically created? Possibly using / in combination with Managed Service Identity

3

3 Answers

0
votes

maybe something like... add a resources array under the existing Microsoft.Web/sites section.

{
    "name": "authsettings",
    "type": "config",
    "apiVersion": "2015-08-01",
    "dependsOn": [ 
       "[resourceId('Microsoft.Web/sites/', variables('webAppName'))]" 
    ],
    "properties": {
        "enabled": true,
        "httpApiPrefixPath": null,
        "unauthenticatedClientAction": "RedirectToLoginPage",
        "tokenStoreEnabled": true,
        "allowedExternalRedirectUrls": null,
        "defaultProvider": "AzureActiveDirectory",
        "clientId": "[variables('clientId')]",
        "clientSecret": "[variables('clientSecret')]",
        "issuer": "[concat('https://sts.windows.net/', subscription().tenantId, '/')]",
        "allowedAudiences": [
        "[concat('https://', variables('fqdn'), '/.auth/login/aad/callback')]"
        ],
        "additionalLoginParams": null,
        "isAadAutoProvisioned": false
    }
  }
0
votes

I tested different options to make it works using only an Arm Template to deploy the webapp and enable directly the auth but it doesnt seems to work. The way i went to stay with a proper CI/CD manner is by adding an extra task with an Azure CLI command enable the auth and assign the app clientId. My tasks :

- task: RalphJansen.Azure-AD-Application-Management.New-Azure-AD-Application.New-Azure-AD-Application@2
  displayName: 'New Azure AD Application'
  inputs:
   azureSubscription: 'SubscriptionID'
   name: '$(apiName)'
   signOnUrl: 'https://$(apiName).azurewebsites.net'

- task: AzureResourceGroupDeployment@2
    displayName: 'Create WebApp'
    inputs:
     azureSubscription: 'SubscriptionID'
     resourceGroupName: '$(ResourceGroup)'
     location: 'Canada East'
     csmFile: '$(System.DefaultWorkingDirectory)/_build/drop/azuredeploy.json'
     overrideParameters: '-apiName $(apiName) -appServicePlanName $(appServicePlanName)'

- task: AzureCLI@1
  displayName: 'Update WebApp to do Oauth authentification & enable Oauth2ImplicitFlow'
  inputs:
    azureSubscription: 'SubscriptionID'
    scriptLocation: inlineScript
    inlineScript: |
     call az webapp auth update --name $(apiName) --aad-client-id $(out.ApplicationId) --action LoginWithAzureActiveDirectory --enabled true --resource-group "$(ResourceGroup)" --aad-token-issuer-url "https://sts.windows.net/your AAD ID here" --token-store true
     call az ad app update --id $(out.ApplicationId) --oauth2-allow-implicit-flow true
-1
votes

Probably a little late, but if you hadn't found an answer yet...

resources[]

        "apiVersion": "2018-02-01",
        "type": "Microsoft.Web/sites",
        "kind": "app",
        "name": "[variables('webAppName')]",
        "location": "[parameters('location')]",
        "identity": {
            "type": "SystemAssigned"
        },

and include the servicePrincpalId in outputs so that it can be re-used for setting access to the required resources keyvault; blob; sql etc

    "outputs": {
        "appServicePrincipalId": {
            "type": "string",
            "value": "[reference(concat(resourceId('Microsoft.Web/sites/', variables('webAppName')),'/providers/Microsoft.ManagedIdentity/Identities/default'), '2015-08-31-PREVIEW').principalId]"
        },