使用.pfx证书的Azure APIM证书身份验证错误



大家好。

我在配置带有入站策略的APIm操作时遇到问题,该策略处理对远程端点的调用。我保存了外部服务提供给我的凭证,并在政策中使用指纹。远程端点使用证书验证请求。

<policies>
<inbound>
<base />
<send-request mode="new" response-variable-name="result" timeout="300" ignore-error="false">
<set-url>https://ip:port/path</set-url>
<set-method>POST</set-method>
<set-header name="Accept" exists-action="override">
<value>*/*</value>
</set-header>
<set-header name="Content-Type" exists-action="override">
<value>application/xml</value>
</set-header>
<set-body>@(context.Request.Body.As<string>())</set-body>
<authentication-certificate thumbprint="thubprint" password="password" />
</send-request>
<return-response response-variable-name="result" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>

但是作为响应,我得到500错误

send-request (259.918 ms)
{
"messages": [
"Error occured while calling backend service.",
"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.",
"The remote certificate is invalid according to the validation procedure."
]
}

谢谢先。如有任何帮助,不胜感激。

正如评论中讨论的那样,添加gist作为社区wiki的答案,以帮助可能面临类似问题的社区成员。

但是作为响应,我得到500错误

  • 如果您使用的是自签名证书,则需要禁用证书链验证用于API Management与后端系统通信。否则,它将返回一个500错误码。

尝试从文档中获取以下代码片段:

$context = New-AzApiManagementContext -resourcegroup 'ContosoResourceGroup' -servicename 'ContosoAPIMService'
New-AzApiManagementBackend -Context  $context -Url 'https://contoso.com/myapi' -Protocol http -SkipCertificateChainValidation $true

注意:到目前为止,禁用证书链验证仅适用于后端策略.

你可以参考Azure API管理-验证传入的客户端证书和发送证书到后端,禁用验证证书链安全吗?使用Azure API管理保护你的API

最新更新