From 8059dfeb00081b6f89e175e54b06982fb90ff029 Mon Sep 17 00:00:00 2001 From: Jalaj Minda <49639049+jalajmsft@users.noreply.github.com> Date: Tue, 4 Feb 2020 09:56:21 +0530 Subject: [PATCH] Fix issue #12237 - fails when service principal key contains quotes (#12260) * Fix issue #12237 - fails when service principal key contains quotes --- Tasks/AzureCLIV1/azureclitask.ts | 4 +++- Tasks/AzureCLIV1/task.json | 2 +- Tasks/AzureCLIV1/task.loc.json | 2 +- Tasks/AzureCLIV2/azureclitask.ts | 4 +++- Tasks/AzureCLIV2/task.json | 2 +- Tasks/AzureCLIV2/task.loc.json | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Tasks/AzureCLIV1/azureclitask.ts b/Tasks/AzureCLIV1/azureclitask.ts index f693d210349c..488106e9853f 100644 --- a/Tasks/AzureCLIV1/azureclitask.ts +++ b/Tasks/AzureCLIV1/azureclitask.ts @@ -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 diff --git a/Tasks/AzureCLIV1/task.json b/Tasks/AzureCLIV1/task.json index c136d4e0bdc0..efa650b7445f 100644 --- a/Tasks/AzureCLIV1/task.json +++ b/Tasks/AzureCLIV1/task.json @@ -19,7 +19,7 @@ "demands": [], "version": { "Major": 1, - "Minor": 157, + "Minor": 163, "Patch": 0 }, "minimumAgentVersion": "2.0.0", diff --git a/Tasks/AzureCLIV1/task.loc.json b/Tasks/AzureCLIV1/task.loc.json index 6136a25a4a30..362fcf79431a 100644 --- a/Tasks/AzureCLIV1/task.loc.json +++ b/Tasks/AzureCLIV1/task.loc.json @@ -19,7 +19,7 @@ "demands": [], "version": { "Major": 1, - "Minor": 157, + "Minor": 163, "Patch": 0 }, "minimumAgentVersion": "2.0.0", diff --git a/Tasks/AzureCLIV2/azureclitask.ts b/Tasks/AzureCLIV2/azureclitask.ts index 9bedcd51cca6..d84eae16e545 100644 --- a/Tasks/AzureCLIV2/azureclitask.ts +++ b/Tasks/AzureCLIV2/azureclitask.ts @@ -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 diff --git a/Tasks/AzureCLIV2/task.json b/Tasks/AzureCLIV2/task.json index 4ef4ab5fe3f0..213ce699af63 100644 --- a/Tasks/AzureCLIV2/task.json +++ b/Tasks/AzureCLIV2/task.json @@ -21,7 +21,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 5 + "Patch": 6 }, "minimumAgentVersion": "2.0.0", "instanceNameFormat": "Azure CLI $(scriptPath)", diff --git a/Tasks/AzureCLIV2/task.loc.json b/Tasks/AzureCLIV2/task.loc.json index 0fdfe29e685a..5754f48709be 100644 --- a/Tasks/AzureCLIV2/task.loc.json +++ b/Tasks/AzureCLIV2/task.loc.json @@ -21,7 +21,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 5 + "Patch": 6 }, "minimumAgentVersion": "2.0.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat",