【问题标题】:Azure Function with App Config and managed identity - how to debug locally具有 App Config 和托管标识的 Azure 函数 - 如何在本地调试
【发布时间】:2021-06-30 14:18:01
【问题描述】:

我一直在到处寻找标题中问题的答案,但我找到了 0 个与我的问题相关的信息,是的,有其他服务的示例,但我的情况没有。

我有一个 Azure 应用功能。
我启用了它的托管身份。
我在应用配置访问管理 (IAM) 中为该功能添加了数据读取者角色。
在我添加的代码中

    public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        var appConfigEndpoint = Environment.GetEnvironmentVariable("AppConfigEndpoint");
        builder.ConfigurationBuilder.AddAzureAppConfiguration(options => options.Connect(new Uri(appConfigEndpoint), new ManagedIdentityCredential()));
    }

在我的 Startup.cs 中

当我在本地调试中运行它时,我得到了这个错误:

A host error has occurred during startup operation '<some GUID>'.
Azure.Identity: ManagedIdentityCredential authentication unavailable. No Managed Identity endpoint found.
Value cannot be null. (Parameter 'provider')

还尝试将new ManagedIdentityCredential() 更改为new DefaultAzureCredential(),但后来我得到:

A host error has occurred during startup operation '732e2be5-0729-4279-b15a-833c8313b39a'.
Azure.Data.AppConfiguration: Service request failed.
Status: 403 (Forbidden)

Headers:
Server: openresty/1.17.8.2
Date: Wed, 30 Jun 2021 14:15:22 GMT
Connection: keep-alive
x-ms-request-id: 2f2066ef-9222-42d5-b96b-85a9b338127e
x-ms-client-request-id: 68cd19e1-0166-4567-a3f9-10f9a1cb6f3c
x-ms-correlation-request-id: 2f2066ef-9222-42d5-b96b-85a9b338127e
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Authorization, x-ms-client-request-id, x-ms-useragent, x-ms-content-sha256, x-ms-date, host, Accept, Accept-Datetime, Date, If-Match, If-None-Match, Sync-Token, x-ms-return-client-request-id, ETag, Last-Modified, Link, Memento-Datetime, retry-after-ms, x-ms-request-id, x-ms-client-session-id, x-ms-effective-locale, WWW-Authenticate
Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 0
.
Value cannot be null. (Parameter 'provider')

我的 Azure 帐户已添加到我的 Visual Studio 并在工具 > 选项 > Azure 服务身份验证中被选中。

我快疯了 - 我必须怎么做才能在本地调试?

【问题讨论】:

  • 您是否为您的用户帐户(用于登录 Visual Studio 的帐户)分配了适当的 RBAC 角色?
  • 嗯,我认为因为您收到的是 403(禁止)而不是 401(未经授权),使用 MSI 的身份验证成功,但您可能需要检查授权(RBAC)。因此,请确保您的用户有权访问应用程序配置
  • 您能否编辑您的问题并分享您在运行 Function 应用时收到的确切错误消息?
  • @GauravMantri,一切都自行解决了。看起来 Azure 需要更多时间来同步?

标签: c# azure azure-functions azure-managed-identity azure-app-configuration


【解决方案1】:

ManagedIdentityCredential 仅适用于 Azure。 您可以将其更改为使用DefaultAzureCredential。 它尝试多种方法,包括托管标识和 Visual Studio 身份验证。 所以它也可以在本地工作。 当然,您的用户帐户也需要具有所需的 RBAC 角色。

【讨论】:

    猜你喜欢
    • 2019-06-27
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2018-08-21
    相关资源
    最近更新 更多