-
Notifications
You must be signed in to change notification settings - Fork 422
Use --client-id for user-assigned managed identity authentication in Azure CLI v2.69.0 or later.
#514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use --client-id for user-assigned managed identity authentication in Azure CLI v2.69.0 or later.
#514
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ export class AzureCliLogin { | |
| loginConfig: LoginConfig; | ||
| azPath: string; | ||
| loginOptions: ExecOptions; | ||
| azVersion: string; | ||
|
|
||
| constructor(loginConfig: LoginConfig) { | ||
| this.loginConfig = loginConfig; | ||
|
|
@@ -30,6 +31,7 @@ export class AzureCliLogin { | |
|
|
||
| await this.executeAzCliCommand(["version"], true, execOptions); | ||
| core.debug(`Azure CLI version used:\n${output}`); | ||
| this.azVersion = JSON.parse(output)["azure-cli"]; | ||
|
|
||
| await this.registerAzurestackEnvIfNecessary(); | ||
|
|
||
|
|
@@ -108,7 +110,14 @@ export class AzureCliLogin { | |
| } | ||
|
|
||
| async loginWithUserAssignedIdentity(args: string[]) { | ||
| args.push("--username", this.loginConfig.servicePrincipalId); | ||
| const azcliMinorVersion = parseInt(this.azVersion.split('.')[1], 10); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second version section is always an integer. |
||
| //From Azure-cli v2.69.0, `--username` is replaced with `--client-id`, `--object-id` or `--resource-id`: https://github.com/Azure/azure-cli/pull/30525 | ||
| if (azcliMinorVersion < 69) { | ||
| args.push("--username", this.loginConfig.servicePrincipalId); | ||
| } | ||
|
Comment on lines
+125
to
+127
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| else { | ||
| args.push("--client-id", this.loginConfig.servicePrincipalId); | ||
| } | ||
| await this.callCliLogin(args, 'user-assigned managed identity'); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.parsethrows an exception?There was a problem hiding this comment.
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.

I prefer to use
az versionto get the Azure CLI version. IfJSON.parsethrows 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
az versionis stable. It is safe to use it.