Skip to content
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

Fix az cli spn auth #20683

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class azureclitask {
else if (authScheme.toLowerCase() == "serviceprincipal") {
let authType: string = tl.getEndpointAuthorizationParameter(connectedService, 'authenticationType', true);
let cliPassword: string = null;
let authParam: string = null;
var servicePrincipalId: string = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
var tenantId: string = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);

Expand All @@ -231,13 +232,15 @@ export class azureclitask {

if (authType == "spnCertificate") {
tl.debug('certificate based endpoint');
authParam = "--certificate";
let certificateContent: string = tl.getEndpointAuthorizationParameter(connectedService, "servicePrincipalCertificate", false);
cliPassword = path.join(tl.getVariable('Agent.TempDirectory') || tl.getVariable('system.DefaultWorkingDirectory'), 'spnCert.pem');
fs.writeFileSync(cliPassword, certificateContent);
this.cliPasswordPath = cliPassword;
}
else {
tl.debug('key based endpoint');
authParam = "--password";
cliPassword = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalkey", false);
this.servicePrincipalKey = cliPassword;
}
Expand All @@ -246,10 +249,10 @@ export class azureclitask {
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
//login using svn
if (visibleAzLogin) {
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions`), tl.loc("LoginFailed"));
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" ${authParam}="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions`), tl.loc("LoginFailed"));
}
else {
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions --output none`), tl.loc("LoginFailed"));
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" ${authParam}="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions --output none`), tl.loc("LoginFailed"));
}
}
else if(authScheme.toLowerCase() == "managedserviceidentity") {
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"demands": [],
"version": {
"Major": 2,
"Minor": 248,
"Minor": 249,
"Patch": 0
},
"minimumAgentVersion": "2.0.0",
Expand Down Expand Up @@ -225,4 +225,4 @@
"RefreshingAzSession": "Attempting to refresh az-cli session...",
"KeepingAzSessionActiveUnsupportedScheme": "The 'keepAzSessionActive' input might be used only for workload identity federation ARM service connection. The referenced service endpoint auth scheme was unexpected: %s. Change the scheme or remove 'keepAzSessionActive' input."
}
}
}