azure - 登录 Azure cli 以获取服务主体

标签 azure ansible azure-cli azure-service-principal

我正在尝试让我的 ansible 脚本通过 azure cli 登录到 azure。由于某些原因,我不允许使用 ansible azure 包。我必须使用 shell 并直接从那里调用命令。

总的来说,我对 Azure 还很陌生,所以所有这些租户、服务主体等仍然是我没有完全掌握的概念。

我一直在检查official the documentation 。我已经为其创建了一个应用程序注册(名为 ansible_test)。我得到了我需要的一切,包括 secret 。然后我将命令称为:

az login --service-principal -u $AZURE_SERVICE_PRINCIPAL_NAME -p $AZURE_SECRET --tenant $AZURE_TENANT

地点:

$AZURE_SERVICE_PRINCIPAL_NAME = ansible_test
$AZURE_SECRET = ${The one that I've defined via Certificates & secrets section in the app registration}
$AZURE_TENANT = ${The azure tenant that I find in the app registration}

我收到错误:

Get Token request returned http error: 400 and server response: {"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier 'ansible_test' was not found in the directory '${AZURE_TENANT}(Blurred because I'm not sure this is something secret or not)'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.

据我所知,我找错了租客。但我得到的和我从应用程序注册中得到的一模一样。我已经用头撞这堵墙有一段时间了。我尝试了很多其他方法,但似乎不起作用。

在这张图片中,我试图表明我确实已经创建了应用程序注册(据我所知,它是一个服务主体)。我模糊了这些 ID,只是因为我不知道它们是否是私有(private)的。

Overview of the app registration that I've created called ansible_test

我做错了什么?我真的无法理解错误的根源......

最佳答案

服务主体的用户名是其应用程序(客户端)ID,因此您需要使用它而不是应用程序名称。

它在幕后使用客户端凭据流来获取 token ,这需要客户端 ID、租户 ID + 客户端 key /客户端证书进行身份验证。

关于azure - 登录 Azure cli 以获取服务主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66059911/

相关文章:

android - 从 Play 商店下载应用程序时,Azure MSAL 集成不起作用

azure - 在 Azure 服务总线上使用 Rebus 2 进行审核

Ansible 回调插件 : how to get play attribute values with variables expanded?

docker - 为 Ansible Docker 模块设置 "--rm"标志的方法?

Azure 搜索操作组

Azure CLI 2 : how to provide parameters in az group deployment create command?

node.js - Azure DevOps Pipeline - React Js 应用程序构建在构建过程中失败(npm run build)

sql-server - 单个查询中的多个分组信息

azure - Azure Cloud Shell 中 mkdir 所需的 Sudo 权限

azure - 通过 Azure CLI 登录帐户失败