【问题标题】:Keyvault Authentication (REST API)密钥库身份验证 (REST API)
【发布时间】:2017-05-05 09:14:01
【问题描述】:

我对微软分散的文档有点困惑。

我创建了一个应用程序 (https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal),这意味着我现在拥有:

  • 应用程序 ID
  • 钥匙
  • 目录 ID

我已进入 Azure 门户中的 KeyVault,并已授予该应用程序的权限。

出于测试目的,我正在尝试通过 CURL 运行测试。我为此使用的基础是以下 Microsoft 页面(https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-service-to-service#request-an-access-tokenhttps://docs.microsoft.com/en-us/rest/api/#create-the-request

所以,我要做的第一件事就是通过以下调用获取令牌:

curl -d "grant_type=client_credentials&client_id=<removed_for_security>&client_secret=<removed_for_security>" https://login.microsoftonline.com/<removed_for_security>/oauth2/token

这会返回一个令牌。

然后我(尝试)按如下方式使用该令牌:

curl -H "Authorization: Bearer <removed_for_security>” -vv https://<removed_for_security>.vault.azure.net/secrets/<removed_for_security>/<removed_for_security>

我没有返回任何内容,只是“HTTP/1.1 401 Unauthorized”

【问题讨论】:

  • 我也有同样的问题。在完成以下两个答案后,我仍然收到“401 Unauthorized”错误。是否需要授予特殊的 keyvault 权限(访问策略或其他)才能使用其余 api?我已经授予我的服务主体访问密钥的权限:创建、列出、加密、解密、wrapKey、UnwrapKey、获取。这些是我试图运行的唯一操作。我也已经授予我的服务主体访问 keyvault 资源本身的权限。还是没有运气。

标签: azure azure-keyvault


【解决方案1】:

您需要指定要为其请求令牌的资源。

curl -d "grant_type=client_credentials&client_id=<removed_for_security>&client_secret=<removed_for_security>&resource=https://vault.azure.net" https://login.microsoftonline.com/<removed_for_security>/oauth2/token

并添加 api 版本。

【讨论】:

  • 你拯救了我的夜晚! :)
【解决方案2】:

好的,所以我可以确认您所做的请求是有效的,在大多数情况下,您忘记了 API 版本,但问题不在于 API 版本(它会告诉您)。

https://xxx.vault.azure.net/secrets/xxx/?api-version=2015-06-01

这个网址有效,所以我猜令牌不正确。最简单的检查方法是转到 JWT.io 并将令牌粘贴到那里并查看内容,如果它们与 Key Vault 的预期匹配。可能你有一个不匹配。

【讨论】:

  • 是的。我忘记了 API 版本。
  • 奇怪,当我删除 API 版本时,它特别告诉我我忘记指定 API 版本......很高兴知道它有效@LittleCode
猜你喜欢
  • 1970-01-01
  • 2011-07-25
  • 1970-01-01
  • 2013-06-14
  • 2019-11-23
  • 2013-05-15
  • 2019-09-04
  • 2016-01-29
相关资源
最近更新 更多