DefaultAzureCredential 可以在 SearchIndexerClient 中工作吗?

问题描述 投票:0回答:1

我正在使用 Azure 搜索索引器客户端。如果我使用 AdminKey 凭据,一切正常。但我想使用我的用户帐户(因为此代码将在 azure 函数中使用,并且我希望 azure 函数的系统身份直接访问搜索索引器)。 所以我尝试使用DefaultAzureCredential。但这给了我 403 错误。在天蓝色门户中,我是该实例的所有者,我还为我授予了索引读者和贡献者角色。那么有没有办法让它发挥作用呢?

var searchClient = new SearchIndexerClient(
    new Uri(searchEndpoint),
    new DefaultAzureCredential()
);
(await searchClient.GetIndexerStatusAsync(indexerName))

这里会抛出403异常。

azure-cognitive-search azure-search-.net-sdk
1个回答
0
投票

在 Azure 认知搜索中为 Azure Function 的系统分配托管标识分配适当的角色。将访问控制设置为两者以启用托管身份访问。检查 Function 应用程序是否设置为使用

DefaultAzureCredential
,它将自动选取托管身份进行身份验证。

enter image description here

  • 转到您的 Azure FunctionSettings 下,选择 Identity系统分配的托管身份已启用。如果未启用,请将其打开并保存更改。

enter image description here

  • 启用后,导航到 Azure 门户中的 Azure 认知搜索 实例。选择 访问控制 (IAM) 单击角色下拉列表中的添加角色分配,选择搜索索引数据贡献者(此角色授予管理搜索索引中的数据的权限)。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.