az 登录从 github 操作任务失败

az login fails from github action task

我正在尝试创建一个 GitHub 操作来将基础设施和我的系统部署到 Azure。要登录,我使用如下 azure 登录操作:

- name: Azure Login
  uses: azure/login@v1.4.0
  with:
    creds: ${{ secrets.AZURE_CREDENTIALS }}

要做到这一点,您必须首先在 Azure 中创建一个服务主体,并将机密作为机密存储在您的 GitHub 存储库中。我使用 az ad sp create-for-rbac 命令巧妙地创建了一个 sp,并定义了足够的权限和所有权限(如 here 所述),但是......我不能再使用 --sdk-auth 标志,因为它已被弃用。我不知道这个标志是否有所不同,但与以前的版本相比,Azure CLI 输出的 JSON 对象有所不同。该命令输出的 (JSON) 对象如下所示:

{
  "appId": "guid",
  "displayName": "Name I gave the app in the az ad sp create for RBAC command",
  "name": "guid",
  "password": "very-secret-string",
  "tenant": "guid"
}

这似乎是某种新对象,因为在以前的版本中,该对象看起来略有不同。以前版本的 AZ CLI 输出一个如下所示的对象:

{
    "clientId": "guid",
    "clientSecret": "super-secret-string",
    "subscriptionId": "guid",
    "tenantId": "guid"
}

现在,我的 GH Actions 工作流程中的登录操作不再有效,我迫切需要它 ;)

我也尝试创建一个联合凭证,但没有结果。现在,说实话,我没有想法,我可以使用一些不同的见解。

工作人员上安装的 Azure CLI 版本似乎有问题。

根据 GH 问题,此问题现已解决,以后不应再发生:https://github.com/Azure/cli/issues/56#issuecomment-965186851

Released a long term fix for any further mismatch issues. Now the default value for azcliversion dynamically points to the version installed on agent. So there will be no mismatch again unless someone explicitly mentions latest. If for some reason there is no version of az cli on the agent then action fall backs to latest.

Most of the hosted agents are also updated to 2.30.0.

Please test your scenarios and let us know if you face any more issues.