azure - .net 核心密钥库链接失败,本地环境中的访问被禁止
问题描述
我正在运行以下功能作为我的 .net 核心 Web 应用程序的 Main 方法的一部分
private static void LinkKeyVault(IConfigurationBuilder config, string keyVaultEndpoint)
{
if (!string.IsNullOrEmpty(keyVaultEndpoint))
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
config.AddAzureKeyVault(keyVaultEndpoint, keyVaultClient, new DefaultKeyVaultSecretManager());
}
}
当我在本地开发机器上运行此代码时,我收到以下错误“操作返回了无效的状态代码‘禁止’”。当此代码在应用服务用户分配的托管标识下在 Azure 中运行时,一切正常。在我的本地环境中,我使用我的 Azure AD 用户登录,该用户使用密钥保管库访问策略获得访问权限,权限与用户分配的托管标识相同。
dfrds-dev-web-identity 是用户分配的托管标识,DFRDDevelopers 是我的 Azure AD 帐户所属的组。
解决方案
It should work, please make sure the group in which the user account located is a Security
group, not a Microsoft 365
group, just the Security
group is supported in this feature.
To grant data plane access to several users, create an Azure AD security group and add users to that group.
Also, if you want to use Visual Studio to auth, make sure you logged in with the correct account, and try to use RunAs=Developer; DeveloperTool=VisualStudio
in the code to make sure it uses the Visual Studio to auth.
var azureServiceTokenProvider = new AzureServiceTokenProvider(RunAs=Developer; DeveloperTool=VisualStudio);
推荐阅读
- android - 我可以使用相对于 Drag React 尺寸的位图尺寸裁剪位图吗?
- laravel - google API 的社交名流 laravel 身份验证错误
- c# - SMTP RCPT 到测试
- java - 将源附加到 Maven 中的 jar 库
- java - 尝试从 GUI 绘制烟花时出现问题
- c# - 使用 Automapper 更改集合
- python - Python,面向对象
- node.js - Apollo-upload-client 与 Cloudinary
- react-native - 未定义不是对象(评估'region.address_lat')
- jvm - 偶尔使用 G1 扫描 RS 会花费很长时间