【问题标题】:How do you configure Azure Function authentication by code?如何通过代码配置 Azure Function 身份验证?
【发布时间】:2020-12-04 21:50:58
【问题描述】:

我想通过代码为我的 Azure 功能配置身份验证,无论是 powershell、ARM 模板还是 API?这可能吗?

我的印象是,Azure 函数只不过是一个应用服务,所以我认为它可以在那里解决。

https://docs.microsoft.com/en-us/powershell/module/az.websites/?view=azps-2.0.0#app_service - powershell 中似乎没有任何内容。

https://resources.azure.com/ 似乎没有提供太多信息。

【问题讨论】:

  • 您找到解决方案了吗?所有答案似乎都回答了不同的问题/身份验证方式。如何通过 powershell、MS graph 或 arm 模板更改身份验证设置(添加身份提供者)?

标签: azure azure-functions


【解决方案1】:

以下是有关如何将托管标识用于应用服务和 Azure Functions 的一些文档:https://docs.microsoft.com/en-us/azure/app-service/overview-managed-identity

您可以在消费计划中创建启用 MSI(托管服务标识)的 PowerShell 函数应用。这是一些关于如何做到这一点的文档 (https://azure.microsoft.com/en-us/resources/templates/101-functions-managed-identity/)。

创建函数应用后,您可以授予它对给定资源 https://docs.microsoft.com/en-us/powershell/module/az.resources/new-azroleassignment?view=azps-2.0.0#examples 的访问权限

最后,PowerShell 函数应用附带一个 profile.ps1,其中包含通过 MSI 对 Azure 进行身份验证的代码。

# Authenticate with Azure PowerShell using MSI.
# Remove this if you are not planning on using MSI or Azure PowerShell.
if ($env:MSI_SECRET -and (Get-Module -ListAvailable Az.Accounts)) {
    Connect-AzAccount -Identity
}

请试一试,如果您遇到任何问题,请告诉我们。

【讨论】:

    【解决方案2】:

    Azure Functions 身份验证仍处于挂起状态。目前 AFAIK 没有办法通过代码添加身份验证,除了 Function Host Keys

    您可以在Github 跟踪问题

    【讨论】:

      【解决方案3】:

      使用 terraform 是一种非常好的配置方式,下面是一个很好的示例。 az CLI 'az webapp auth' 现在似乎也得到了很好的支持。 PowerShell 似乎仍然落后。

      https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-28
        • 2021-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多