【问题标题】:ARM Template Web App Authentication Settings not workingARM 模板 Web 应用程序身份验证设置不起作用
【发布时间】:2019-01-28 22:55:19
【问题描述】:

我正在设置我的站点身份验证设置以使用 AAD 提供程序。大多数模板都受到尊重。但是,unauthenticatedClientActionallowedAudiences 未正确分配。我观察到“允许匿名”并且没有分配“允许的观众”。

请注意,我正在使用 ARM 模板 API 2018-02-01。由于文档原因,此问题可能仍然存在,如果您提供答案,请注意它所针对的 ARM 模板版本。

此外,为 ARM 文档团队创建问题以纠正任何问题。

这是我用于这些设置的模板段。它嵌套在我的网站模板中的资源下。

root > Microsoft.Web/Site > 资源

{
    "type": "config",
    "name": "web",
    "apiVersion": "2016-08-01",
    "location": "[parameters('app-location')]",
    "dependsOn": [
        "[resourceId('Microsoft.Web/sites', variables('web-site-name'))]"
    ],
    "properties": {
        "siteAuthEnabled": true,
        "siteAuthSettings": {
            "enabled": true,
            "unauthenticatedClientAction": "RedirectToLoginPage",
            "tokenStoreEnabled": true,
            "defaultProvider": "AzureActiveDirectory",
            "clientId": "[parameters('web-aad-client-id')]",
            "issuer": "[concat('https://sts.windows.net/', parameters('web-aad-tenant'))]",
            "allowedAudiences": [
                "[concat('https://', variables('web-site-name'), '.azurewebsites.net')]"
            ]
        }
    }
}
  • 模板验证
  • 部署不输出任何错误

问题:

  1. unauthenticatedClientAction 分配允许匿名而不是 RedirectToLoginPage
  2. allowedAudiences 未分配任何站点

什么可能导致这些问题?我可能错过了什么?

【问题讨论】:

    标签: azure-active-directory azure-web-app-service azure-resource-manager


    【解决方案1】:

    在与 Azure 支持的优秀人员合作后,我得到了答案。

    请注意,此解决方案针对的是 API 2018-02-01,这是本文发布时的当前版本。

    这个子资源不再是一个有效的解决方案,虽然端点仍然可以识别它的一些字段,但是这个已经被弃用了。

    新的解决方案是将siteAuthSettings 对象添加到主“Microsoft.Web/site”属性中,并且不再需要siteAuthEnabled,因为siteAuthSettings.enable 复制了此功能。

    更新了 ARM 模板(为简洁起见删除了其他设置)

    {
        "name": "[variables('app-service-name')]",
        "type": "Microsoft.Web/sites",
        "location": "[parameters('app-location')]",
        "apiVersion": "2016-08-01",
        "dependsOn": [
            "[variables('app-plan-name')]"
        ],
        "properties": {
            //... other app service settings
            "siteAuthSettings": {
                "enabled": true,
                "unauthenticatedClientAction": "RedirectToLoginPage",
                "tokenStoreEnabled": true,
                "defaultProvider": "AzureActiveDirectory",
                "clientId": "[parameters('web-aad-client-id')]",
                "issuer": "[concat('https://sts.windows.net/', parameters('web-aad-tenant'))]",
                "allowedAudiences": [
                    "[concat('https://', variables('web-site-name'), '.azurewebsites.net')]"
                ]
            }
        }
    }
    

    【讨论】:

    • 我遇到了同样的问题,目前的文档对此还不清楚。我的部分设置不适用其他设置。将它直接放在 wep 应用程序属性中对我有用,但不要忘记将它放在“siteConfig”条目中。
    • "子资源不再是有效的解决方案,已弃用。"这现在在任何地方都有记录吗?最新的 API 文档版本没有弃用 Microsoft.Web/sites/config docs.microsoft.com/en-us/azure/templates/microsoft.web/… 的注释
    • @MartinThøgersen 是的。这是二月份写的。请注意,当时的规格是:docs.microsoft.com/en-us/azure/templates/microsoft.web/… 现在有针对此场景的新规格。
    【解决方案2】:

    正如@Michael 所建议的,siteAuthSettings 对象必须添加到siteConfig 对象中,而不仅仅是在根properties 对象下。

    {
        "apiVersion": "2019-08-01",
        "name": "[variables('webAppName')]",
        "type": "Microsoft.Web/sites",
        "kind": "app",
        "location": "[resourceGroup().location]",
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', variables('appServiceName'))]"
        ],
        "properties": {
            ...
            "siteConfig": {
                "siteAuthSettings": {
                    "enabled": true,
                    "unauthenticatedClientAction": "RedirectToLoginPage",
                    "tokenStoreEnabled": true,
                    "defaultProvider": "AzureActiveDirectory",
                    "clientId": "[parameters('clientId')]",
                    "issuer": "[concat('https://sts.windows.net/', parameters('tenantId'), '/')]"
                }
            }
        }
    }
    

    【讨论】:

    • 由于这个问题是基于我在回答中提到的版本,请您注意这个目标的版本。 apiVersion 字段仅表示节点的type,可以跨 ARM 模板 API 版本共享。谢谢。
    【解决方案3】:

    给出的其他解决方案仅适用于使用经典身份验证体验 (Authentication (Classic))。如果您想使用新的身份验证体验,请使用以下配置:

    {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
        {
          "apiVersion": "2019-08-01",
          "name": "[variables('webAppName')]",
          "type": "Microsoft.Web/sites",
          "kind": "app",
          "location": "[resourceGroup().location]",
          "resources": [
            {
              "type": "config",
              "apiVersion": "2020-12-01",
              "name": "authsettingsV2",
              "location": "[resourceGroup().location]",
              "dependsOn": [
                "[concat('Microsoft.Web/sites/', variables('webAppName'))]"
              ],
              "properties": {
                "platform": {
                  "enabled": true,
                  "runtimeVersion": "~1"
                },
                "identityProviders": {
                  "azureActiveDirectory": {
                    "isAutoProvisioned": false,
                    "registration": {
                      "clientId": "[parameters('clientId')]",
                      "clientSecret": "[variables('clientSecret')]",
                      "openIdIssuer": "[concat('https://sts.windows.net/', parameters('tenantId'), '/v2.0')]"
                    },
                    "validation": {
                      "allowedAudiences": [
                        "https://management.core.windows.net/"
                      ]
                    }
                  }
                },
                "login": {
                  "routes": {},
                  "tokenStore": {
                    "enabled": true,
                    "tokenRefreshExtensionHours": 72,
                    "fileSystem": {},
                    "azureBlobStorage": {}
                  },
                  "preserveUrlFragmentsForLogins": false,
                  "allowedExternalRedirectUrls": [],
                  "cookieExpiration": {
                    "convention": "FixedTime",
                    "timeToExpiration": "08:00:00"
                  },
                  "nonce": {
                    "validateNonce": true,
                    "nonceExpirationInterval": "00:05:00"
                  }
                },
                "globalValidation": {
                  "redirectToProvider": "azureactivedirectory",
                  "unauthenticatedClientAction": "RedirectToLoginPage"
                },
                "httpSettings": {
                  "requireHttps": true,
                  "routes": {
                    "apiPrefix": "/.auth"
                  },
                  "forwardProxy": {
                    "convention": "NoProxy"
                  }
                }
              }
            }
          ]
        }
      ]
    }
    

    【讨论】:

    • 这是在 2019 年 2 月写的。请注意,当时这是规范:docs.microsoft.com/en-us/azure/templates/microsoft.web/... 现在有正如您所指出的,此方案的新细节。
    猜你喜欢
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    相关资源
    最近更新 更多