无需订阅即可进行 github 操作的 Azure 登录 cli

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

我正在阅读本文档https://github.com/azure/login#configure-a-service-principal-with-a-federated-credential-to-use-oidc-based-authentication

我发现我们可以使用 azure 登录 cli

allow-no-subscriptions
参数。

所以我的问题是这个参数的目的是什么?尽管我们已经在存储库的秘密中定义了订阅 id,但当我们可以运行此命令时

az ad sp create-for-rbac --name "myApp" --role contributor \
                            --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
                            --sdk-auth 

因为它输出,订阅ID,租户ID,秘密ID,客户端ID

令人惊讶的是,如果我通过 azure 门户创建应用程序注册,我会收到错误

Error: : No subscriptions found for ***.
Error: Az CLI Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows

尽管订阅 ID 在秘密中明确定义。

如果我只使用该参数

allow-no-subscriptions=false

那么我就没有问题了,它就像魅力一样。

azure github-actions azure-cli
1个回答
0
投票

要从本地计算机创建

rbac
,您需要升级 az 模块,并需要使用
az login

登录 Azure CLi

az upgrade
az login

enter image description here

 az ad sp create-for-rbac --name "myApp" --role contributor \
                            --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
                            --sdk-auth 

enter image description here

*服务原则映射到贡献者角色和订阅范围。 *

请查看以下截图

enter image description here

作为参考,请检查此 Az CLI 登录失败。请检查凭据并确保 az 已安装在运行器上

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