Skip to content

Conversation

@MoChilia
Copy link
Member

@MoChilia MoChilia commented Feb 20, 2025

Azure CLI introduced 3 new arguments --client-id, --object-id and --resource-id to replace --username for user-assigned managed identity authentication: Azure/azure-cli#30525.

Since azure/login only supports client-id: https://github.com/marketplace/actions/azure-login#login-with-user-assigned-managed-identity, it should map client-id to --client-id instead of --username.

For not introducing breaking changes, --username should be kept in Azure/login for Azure CLI versions before 2.69.0. But it is only valid in Azure/login@v2, once Azure CLI removes the argument --username, Azure/login@v1 will break for user-assigned managed identity login.

The test workflow: https://github.com/Azure/azclitools-actions-test/blob/main/.github/workflows/azure-login-mi-version-test.yml
Workflow result: https://github.com/Azure/azclitools-actions-test/actions/runs/13513290504

Close #506

@MoChilia MoChilia requested a review from YanaXu February 25, 2025 03:55

await this.executeAzCliCommand(["version"], true, execOptions);
core.debug(`Azure CLI version used:\n${output}`);
this.azVersion = JSON.parse(output)["azure-cli"];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked all Azure CLI version to see the output format of this? What if JSON.parse throws an exception?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure CLI hasn't changed its JSON output format for over 5 years.
image
I prefer to use az version to get the Azure CLI version. If JSON.parse throws an exception, it means the user is using an unsupported version of Azure CLI and should be rejected.

@jiasli, do you have any other suggestions for reliably obtaining the Azure CLI version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

az version is stable. It is safe to use it.


async loginWithUserAssignedIdentity(args: string[]) {
args.push("--username", this.loginConfig.servicePrincipalId);
const azcliMinorVersion = parseInt(this.azVersion.split('.')[1], 10);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if parseInt throws an exception? Will it fail the login?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how parseInt could throw an exception on azcliMinorVersion. The Azure CLI version always follows the xx.xx.xx format.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second version section is always an integer.

@MoChilia MoChilia requested a review from jiasli February 27, 2025 06:38
Comment on lines +115 to +117
if (azcliMinorVersion < 69) {
args.push("--username", this.loginConfig.servicePrincipalId);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any schedule on when login action stops supporting Azure CLI < 2.69.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently no plans to change. Telemetry shows that about 30% of users utilize self-hosted runners, which may not always install the latest Azure CLI. Additionally, all managed identity users are using Azure VMs. So I would like to continue supporting login action across different Azure CLI versions, similar to cli action.

@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 3, 2025 06:12 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test March 4, 2025 01:34 — with GitHub Actions Inactive
@MoChilia MoChilia merged commit bbcc074 into master Mar 4, 2025
20 checks passed
@MoChilia MoChilia deleted the sy/mi-clientid branch March 4, 2025 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use --client-id for user-assigned managed identity authentication

5 participants