0
votes

I am setting up automated deployment pipeline for my website ,as part of it i have to automate Api import using VSTS RM . I have achieved this using custom PS scripts in VSTS tasks. I have used swagger url to import

i.e

Import-AzureRmApiManagementApi –Context $apimContext –SpecificationFormat 'swagger' –SpecificationUrl 'http://mywebapp.com/swagger/docs/v1' –Path 'apis'

To Improve the security we have implemented to redirect the http request https which is secured by client certificate. Here comes the problem.

Now we are not able to use above command to import which is returning 403 forbidden error as API manager don't have option to bypass certificate validation. what can be done to solve this ?

Even i have tried to invoke-webrequest the url with specific cert and to import the API which worked fine in my local machine.

$swaggerurl="https://mywebapp.org/swagger/docs/1" $cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("xyz.cer") $test=Invoke-WebRequest -Uri "$swaggerurl" -Certificate $cert $test.statuscode

Import-AzureRmApiManagementApi –Context $apimContext –SpecificationFormat 'swagger' –SpecificationUrl 'http://mywebapp.com/swagger/docs/v1' –Path 'apis'

But not in VSTS Inline power shell. It is not accepting certificate value and returning 403 forbidden error.

Please let me know how to resolve this ?

Issue :

1.Unable to import to API manager due to https client certificate validation on swagger url.

  1. VSTS inline power shell not accepting certificate parameter details even though i use the right cert. Same case works in local machine. is there any limitation in VSTS inline power shell.

Thanks in advance.

3

3 Answers

0
votes

Using Azure PowerShell step/task instead. (Include in Deploy category)

0
votes

For this to work, API Management service needs to make the WebRequest on your behalf to the url, with a ClientCertificate in the Request. We currently don't provide that option to call Import-AzureRmApiManagementApi with a Client Certificate.

Only available option is to make WebRequest using Powershell (Invoke-RestMethod), download the swagger to a local file and use the -SpecificationPath parameter in the cmdlet

0
votes

This issue has been resolved by changing the private agent to run as admin account. Now Everything works as expected :)

Import of API using VSTS private agent