azure - 服务主体 az cli 登录失败 - 未找到订阅

标签 azure powershell azure-cli azure-cli2

尝试执行az cli使用服务主体登录,并抛出错误,指出 No subscriptions found for <Service_Principal_AppId>. If this is expected, use '--allow-no-subscriptions' 。这段代码以前工作得很好,但现在似乎不再工作了。使用的命令行如下:

$sp_appid = (Get-AzureRmADServicePrincipal -DisplayName $spDisplayName).ApplicationId.Guid
$sp_secret = (Get-AzureKeyVaultSecret -VaultName $kvName -Name $appKeySecretName).SecretValueText
az login --service-principal --username $sp_appid --password $sp_secret --tenant $tenant_Id

我已验证服务主体已分配 Contributor订阅级别的角色。

最佳答案

Azure Active Directory 中创建服务主体后,您需要在订阅中为该新用户提供一些角色:

  • 转到您的订阅
  • 转到访问控制 (IAM)
  • 添加角色分配(例如,让您的服务主体贡献者)

然后 az login 应该可以工作。

关于azure - 服务主体 az cli 登录失败 - 未找到订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55457349/

相关文章:

linux - 大量创建 Azure NSG 规则

Azure KeyVault secret 读取/Azure CLI 限制 (Ansible)

facebook - 如何使用 Windows Azure ACS 从 Facebook 获取更多声明?

xml - 尝试获取XML元素

json - Power shell 脚本在 Windows powershell ISE 中运行良好,但在 Power shell 版本 5 中不起作用

Powershell 不会循环遍历所有对象

azure - 为应用程序创建 Azure 扩展属性

powershell - 新-AzureRmVM : Parameter set cannot be resolved using the specified named parameters

SQL 尝试在存储过程中使用 DATEADD

asp.net - 存储网站的 Azure 缓存访问 key