【Azure APIM】解答REST API實現"禁用自簽名證書的證書鏈驗證"中的backends參數值從那里取值的問題?
問題描述
使用APIM服務時候,因為后端的API需要使用自簽名證書進行驗證。如果通過瀏覽器直接訪問后端API返回正常,但是APIM請求的時候返回為500報錯。
在開啟Trace后,發現報錯信息為:error message :The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. (參考文章:http://www.rzrgm.cn/lulight/p/15961708.html)。
微軟的官方給出了解決方案,只需要禁用自簽名證書的證書鏈驗證即可。但是如何關閉這個證書鏈的驗證呢?

除了文章中介紹的Powershell方法外,還可以調用REST API來實現。

只是在REST API的URL中, backendId 這個參數從何而來呢?如何取值?
問題解答
根據實驗,找出了這個請求中的backendId指的就是APIM門戶中所配置的Backends頁面中的 backend name。
如下圖:

而在API配置中,則是通過 set-backend-service policy來使用這個backend。

所以,本文的問題,以上圖的backend為例,在中國區APIM上,如果要禁用對這個API請求時候的自簽名證書的證書鏈驗證。
完整的URL為:
PATCH https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/blackbug-test-backend?api-version=2024-05-01
參數為:
{ "properties": { "description": "your custom description", "tls": { "validateCertificateChain": false, "validateCertificateName": true } } }
參考資料
APIM不能連接到 App Service (APIM cannot connect to APP service) : http://www.rzrgm.cn/lulight/p/15961708.html
Backend - Update : https://learn.microsoft.com/en-us/rest/api/apimanagement/backend/update?view=rest-apimanagement-2024-05-01&tabs=HTTP
Set backend service : https://learn.microsoft.com/en-us/azure/api-management/set-backend-service-policy
當在復雜的環境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 云中,恰是如此!

浙公網安備 33010602011771號