Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Cli/AzureCliLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class AzureCliLogin {
loginConfig: LoginConfig;
azPath: string;
loginOptions: ExecOptions;
azVersion: string;

constructor(loginConfig: LoginConfig) {
this.loginConfig = loginConfig;
Expand All @@ -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"];

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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.


await this.registerAzurestackEnvIfNecessary();

Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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.

//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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

else {
args.push("--client-id", this.loginConfig.servicePrincipalId);
}
await this.callCliLogin(args, 'user-assigned managed identity');
}

Expand Down