Skip to content

Commit

Permalink
Fix issue #12237 - fails when service principal key contains quotes (#…
Browse files Browse the repository at this point in the history
…12260)

* Fix issue #12237 - fails when service principal key contains quotes
  • Loading branch information
jalajmsft authored Feb 4, 2020
1 parent 1b37e11 commit e414825
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Tasks/AzureCLIV1/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ export class azureclitask {
this.servicePrincipalKey = cliPassword;
}

let escapedCliPassword = cliPassword.replace(/"/g, '\\"');
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
//login using svn
this.throwIfError(tl.execSync("az", "login --service-principal -u \"" + servicePrincipalId + "\" -p \"" + cliPassword + "\" --tenant \"" + tenantId + "\""), tl.loc("LoginFailed"));
this.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" -p "${escapedCliPassword}" --tenant "${tenantId}"`), tl.loc("LoginFailed"));
}
else if(authScheme.toLowerCase() == "managedserviceidentity") {
//login using msi
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"demands": [],
"version": {
"Major": 1,
"Minor": 157,
"Minor": 163,
"Patch": 0
},
"minimumAgentVersion": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"demands": [],
"version": {
"Major": 1,
"Minor": 157,
"Minor": 163,
"Patch": 0
},
"minimumAgentVersion": "2.0.0",
Expand Down
4 changes: 3 additions & 1 deletion Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ export class azureclitask {
this.servicePrincipalKey = cliPassword;
}

let escapedCliPassword = cliPassword.replace(/"/g, '\\"');
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
//login using svn
Utility.throwIfError(tl.execSync("az", "login --service-principal -u \"" + servicePrincipalId + "\" -p \"" + cliPassword + "\" --tenant \"" + tenantId + "\""), tl.loc("LoginFailed"));
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" -p "${escapedCliPassword}" --tenant "${tenantId}"`), tl.loc("LoginFailed"));
}
else if(authScheme.toLowerCase() == "managedserviceidentity") {
//login using msi
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 5
"Patch": 6
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 5
"Patch": 6
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down

0 comments on commit e414825

Please sign in to comment.