Azure Key Vault:用户、组或应用程序没有对 Key Vault 的机密集权限

发布于 2025-01-13 06:07:05 字数 564 浏览 3 评论 0原文

我正在使用 Azure CLI 创建一个脚本,该脚本将自动生成应用程序注册(服务主体),然后使用该应用程序注册创建将存储在 Azure Key Vault 中的机密。

但是,我收到以下错误:

用户、组或应用程序'appid=04b07795-8ddb-461a-bbee-02f9e1bf7b46;oid=0ec2b0e8-daeb-46a8-b627-0d4f61f871 57;numgroups=134;iss=https://sts.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/'没有对密钥保管库“asakeyabcfelaqpgsfnxcy;location=eastus”设置机密权限。如需解决此问题的帮助,请参阅 https://go.microsoft.com/fwlink/? linkid=2125287

任何人都可以提供有关此 ID 是什么以及如何解决此错误的指导吗?这不是我的应用程序注册对象 ID 或应用程序 ID。

I am creating a script using Azure CLI that will automatically generate an App Registration (service principal), and then use that App Registration to create a secret that will be stored in Azure Key Vault.

However, I am getting the following error:

The user, group or application 'appid=04b07795-8ddb-461a-bbee-02f9e1bf7b46;oid=0ec2b0e8-daeb-46a8-b627-0d4f61f87157;numgroups=134;iss=https://sts.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/' does not have secrets set permission on key vault 'asakeyabcfelaqpgsfnxcy;location=eastus'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287

Can anyone provide guidance on what this ID is and how to resolve this error? This is not my App Registration Object ID or App ID.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖正好 2025-01-20 06:07:05

我想你现在关心的有两点,一是你没有添加secret,二是错误消息中的app id不是你注册的。

我想你已经按照文档执行了cli命令,所以我只想解释一下第二点。请允许我向您展示一个代码示例以获得更好的解释。

using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

public async Task<IActionResult> PrivacyAsync()
{
    var kvUri = "https://your_vault_name.vault.azure.net/";
    var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
    _ = await client.SetSecretAsync("test0311", "hello");
    return View();
}

当我们想要将密钥保管库机密添加到 azure 时,我们需要提供凭据以便对我们的操作进行身份验证。这是此处的 DefaultAzureCredential(),它有多个来源来获取身份验证,如下面的屏幕截图所示。

输入图片这里的描述

这意味着如果有人设置了 环境变量 进行身份验证,那么它会覆盖您在执行 cli 命令时输入的信息,这通常可能会导致应用程序与您设置的内容不同的问题。我想你可以按照这个文档检查你的所有配置并重试,或者你可以直接用你在计算机上注册的应用程序添加环境变量。

顺便说一句,请不要忘记 在 Azure 门户中为你注册的 Azure 广告应用添加访问策略

I think there're 2 points you're now concerning, one is you failed to add secret, another is the app id in the error message is not the one you registered.

I think you've followed the document to execute the cli command, so I just want to explain the second point. Pls allow me show you a code sample for a better explanation.

using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

public async Task<IActionResult> PrivacyAsync()
{
    var kvUri = "https://your_vault_name.vault.azure.net/";
    var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
    _ = await client.SetSecretAsync("test0311", "hello");
    return View();
}

When we want to add key vault secret to azure, we need to provide a credential so that our operations are authenticated. This is the DefaultAzureCredential() here, and it has several sources to get the authentication like screenshot below.

enter image description here

That means if someone sets the environment variables for authentication, then it will cover the information you entered when executing cli command, this may usually cause the issue that the app is different from what you set. I think you may follow this document to check all your configurations and try again, or you can directly add environment variables with the app you registered on your computer.

By the way, pls don't forget to add access policy in azure portal for the azure ad app you registered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文