mirror of
https://github.com/azure/login.git
synced 2026-03-12 18:07:08 -04:00
Use --client-id for user-assigned managed identity authentication in Azure CLI v2.69.0 or later. (#514)
This commit is contained in:
@@ -8,6 +8,7 @@ export class AzureCliLogin {
|
|||||||
loginConfig: LoginConfig;
|
loginConfig: LoginConfig;
|
||||||
azPath: string;
|
azPath: string;
|
||||||
loginOptions: ExecOptions;
|
loginOptions: ExecOptions;
|
||||||
|
azVersion: string;
|
||||||
|
|
||||||
constructor(loginConfig: LoginConfig) {
|
constructor(loginConfig: LoginConfig) {
|
||||||
this.loginConfig = loginConfig;
|
this.loginConfig = loginConfig;
|
||||||
@@ -30,7 +31,12 @@ export class AzureCliLogin {
|
|||||||
|
|
||||||
await this.executeAzCliCommand(["version"], true, execOptions);
|
await this.executeAzCliCommand(["version"], true, execOptions);
|
||||||
core.debug(`Azure CLI version used:\n${output}`);
|
core.debug(`Azure CLI version used:\n${output}`);
|
||||||
|
try {
|
||||||
|
this.azVersion = JSON.parse(output)["azure-cli"];
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.warning("Failed to parse Azure CLI version.");
|
||||||
|
}
|
||||||
await this.registerAzurestackEnvIfNecessary();
|
await this.registerAzurestackEnvIfNecessary();
|
||||||
|
|
||||||
await this.executeAzCliCommand(["cloud", "set", "-n", this.loginConfig.environment], false);
|
await this.executeAzCliCommand(["cloud", "set", "-n", this.loginConfig.environment], false);
|
||||||
@@ -108,7 +114,20 @@ export class AzureCliLogin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loginWithUserAssignedIdentity(args: string[]) {
|
async loginWithUserAssignedIdentity(args: string[]) {
|
||||||
args.push("--username", this.loginConfig.servicePrincipalId);
|
let azcliMinorVersion = 0;
|
||||||
|
try {
|
||||||
|
azcliMinorVersion = parseInt(this.azVersion.split('.')[1], 10);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.warning("Failed to parse the minor version of Azure CLI. Assuming the version is less than 2.69.0");
|
||||||
|
}
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
args.push("--client-id", this.loginConfig.servicePrincipalId);
|
||||||
|
}
|
||||||
await this.callCliLogin(args, 'user-assigned managed identity');
|
await this.callCliLogin(args, 'user-assigned managed identity');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user