Skip to content

Commit

Permalink
Fix for certificate issue (#7638)
Browse files Browse the repository at this point in the history
* Fix for certificate issue

* Added localized string in Azure RG task

* Improved error message
  • Loading branch information
Ajay Kumar Yadav authored Jul 6, 2018
1 parent b7244f9 commit b5a292b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Tasks/AzureAppServiceManageV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 0,
"Minor": 2,
"Patch": 35
"Patch": 36
},
"minimumAgentVersion": "1.102.0",
"instanceNameFormat": "$(Action): $(WebAppName)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureAppServiceManageV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 0,
"Minor": 2,
"Patch": 35
"Patch": 36
},
"minimumAgentVersion": "1.102.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@
"loc.messages.CouldNotFetchAccessTokenforAzureStatusCode": "Could not fetch access token for Azure. Status code: %s, status message: %s",
"loc.messages.CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode": "Could not fetch access token for Managed Service Principal. Please configure Managed Service Identity (MSI) for virtual machine 'https://aka.ms/azure-msi-docs'. Status code: %s, status message: %s",
"loc.messages.CouldNotFetchAccessTokenforMSIStatusCode": "Could not fetch access token for Managed Service Principal. Status code: %s, status message: %s",
"loc.messages.UserNameCannotBeNull": "If the 'Run agent service as a user' input is selected, then 'User name' cannot be null."
"loc.messages.UserNameCannotBeNull": "If the 'Run agent service as a user' input is selected, then 'User name' cannot be null.",
"loc.messages.ASE_SSLIssueRecommendation": "To use a certificate, the certificate must be signed by a trusted certificate authority. If getting certificate validation errors, you're probably using a self-signed certificate and to resolve them you need to set a variable named VSTS_ARM_REST_IGNORE_SSL_ERRORS to the value true in the build or release definition."
}
5 changes: 3 additions & 2 deletions Tasks/AzureResourceGroupDeploymentV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 137,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -452,6 +452,7 @@
"CouldNotFetchAccessTokenforAzureStatusCode": "Could not fetch access token for Azure. Status code: %s, status message: %s",
"CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode": "Could not fetch access token for Managed Service Principal. Please configure Managed Service Identity (MSI) for virtual machine 'https://aka.ms/azure-msi-docs'. Status code: %s, status message: %s",
"CouldNotFetchAccessTokenforMSIStatusCode": "Could not fetch access token for Managed Service Principal. Status code: %s, status message: %s",
"UserNameCannotBeNull": "If the 'Run agent service as a user' input is selected, then 'User name' cannot be null."
"UserNameCannotBeNull": "If the 'Run agent service as a user' input is selected, then 'User name' cannot be null.",
"ASE_SSLIssueRecommendation": "To use a certificate, the certificate must be signed by a trusted certificate authority. If getting certificate validation errors, you're probably using a self-signed certificate and to resolve them you need to set a variable named VSTS_ARM_REST_IGNORE_SSL_ERRORS to the value true in the build or release definition."
}
}
5 changes: 3 additions & 2 deletions Tasks/AzureResourceGroupDeploymentV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 137,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down Expand Up @@ -452,6 +452,7 @@
"CouldNotFetchAccessTokenforAzureStatusCode": "ms-resource:loc.messages.CouldNotFetchAccessTokenforAzureStatusCode",
"CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode": "ms-resource:loc.messages.CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode",
"CouldNotFetchAccessTokenforMSIStatusCode": "ms-resource:loc.messages.CouldNotFetchAccessTokenforMSIStatusCode",
"UserNameCannotBeNull": "ms-resource:loc.messages.UserNameCannotBeNull"
"UserNameCannotBeNull": "ms-resource:loc.messages.UserNameCannotBeNull",
"ASE_SSLIssueRecommendation": "ms-resource:loc.messages.ASE_SSLIssueRecommendation"
}
}
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 2,
"Patch": 1
"Patch": 2
},
"releaseNotes": "What's new in version 4.* (preview)<br />Supports Kudu Zip Deploy<br />Supports App Service Environments<br />Improved UI for discovering different App service types supported by the task<br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more Information.",
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 2,
"Patch": 1
"Patch": 2
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down
24 changes: 19 additions & 5 deletions Tasks/Common/azure-arm-rest/AzureServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,26 @@ export class ServiceClient {
}
request.headers['Content-Type'] = 'application/json; charset=utf-8';

var httpResponse = await webClient.sendRequest(request);
if (httpResponse.statusCode === 401 && httpResponse.body && httpResponse.body.error && httpResponse.body.error.code === "ExpiredAuthenticationToken") {
// The access token might have expire. Re-issue the request after refreshing the token.
token = await this.credentials.getToken(true);
request.headers["Authorization"] = "Bearer " + token;
var httpResponse = null;

try
{
httpResponse = await webClient.sendRequest(request);
if (httpResponse.statusCode === 401 && httpResponse.body && httpResponse.body.error && httpResponse.body.error.code === "ExpiredAuthenticationToken") {
// The access token might have expire. Re-issue the request after refreshing the token.
token = await this.credentials.getToken(true);
request.headers["Authorization"] = "Bearer " + token;
httpResponse = await webClient.sendRequest(request);
}
} catch(exception) {
let exceptionString: string = exception.toString();
if(exceptionString.indexOf("Hostname/IP doesn't match certificates's altnames") != -1
|| exceptionString.indexOf("unable to verify the first certificate") != -1
|| exceptionString.indexOf("unable to get local issuer certificate") != -1) {
tl.warning(tl.loc('ASE_SSLIssueRecommendation'));
}

throw exception;
}

return httpResponse;
Expand Down

0 comments on commit b5a292b

Please sign in to comment.