0

我一直在到处寻找标题中问题的答案,但我发现关于我的问题的相关信息为 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 服务身份验证中被选中。

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

4

1 回答 1

1

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

于 2021-06-30T14:57:59.540 回答