【Azure API 管理】在APIM中使用客户端证书验证API的请求,但是一直提示错误"No client certificate received."

简介: 【Azure API 管理】在APIM中使用客户端证书验证API的请求,但是一直提示错误"No client certificate received."

API 管理 (APIM) 是一种为现有后端服务创建一致且现代化的 API 网关的方法。

问题描述

在设置了APIM客户端证书,用户保护后端API,让请求更安全。 但是,最近发现使用客户端证书的API全部出现错误,无法收到客户端证书,通过浏览器中查看,发现证书也是无效的。

在API请求的Trace中,错误消息为:

{
                "source": "client-certificate-handler",
                "timestamp": "2021-07-13T12:23:51.8172847Z",
                "elapsed": "00:00:00.00053",
                "data": "Requesting client certificate because next handler requires access to it."
            }, {
                "source": "client-certificate-handler",
                "timestamp": "2021-07-13T12:23:51.8172847Z",
                "elapsed": "00:00:00.00048",
                "data": "No client certificate received."
            }

在浏览器中查看证书发现无效:

问题验证

根据消息提示,第一反应检查APIM的客户端证书是否有效,是否过期

 

第二步当证书并无异常(没有过期)时,则调查APIM是否有变动,通过配置的Git存储库(APIM Repository), Clone最新的文件后发现版本有变动。发现前后有版本变动 ( IntegrationModuleBitsVersion )

 

第三步:从APIM的证书设置入手,发现有新功能 ”协商客户端证书(Negotiate client certificate)“ 功能,在通过启用它之后,APIM的"No client certificate received" 问题消失

 

 

 

问题原因

因为在设置APIM时候,有一句提示消息为:”若要在开发人员层、基本层、标准层或高级层中通过 HTTP/2 接收和验证客户端证书,必须在“自定义域”边栏选项卡上启用“协商客户端证书”设置“” 。也就是说:如果不使用HTTP/2则不用启用"协商客户端证书"设置。这也是为什么在最初设置时,没有启用该功能的原因。

 

但是现在验证了问题的关键就是APIM升级后,必须启用"协商客户端证书", 通过对APIM的版本改动所发布的Release Notification(新版通知)看,是因为:

 

附录一:使用APIM Repository获取当前APIM中的所有文件,包含根目录的configuration.json文件

第一步:在APIM中启用Repository

第二步:通过 git clone https://username:password@{name}.scm.azure-api.cn/  下载APIM所有文件到本地

 

详细操作步骤:https://docs.azure.cn/zh-cn/api-management/api-management-configuration-repository-git#to-clone-the-repository-to-your-local-machine

 

 

第三步:查看configuration.json文件 IntegrationModuleBitsVersion 信息

{
  "settings": {
    "RegistrationEnabled": "True",
    "UserRegistrationTerms": null,
    "UserRegistrationTermsEnabled": "False",
    "UserRegistrationTermsConsentRequired": "False",
    "DelegationEnabled": "False",
    "DelegationUrl": "",
    "DelegatedSubscriptionEnabled": "False"
  },
  "$ref-policy": "api-management/policies/global.xml",
  "IntegrationModuleVersion": "17",
  "IntegrationModuleBitsVersion": "0.20.1220.0",
  "ExportDate": "2021-06-09T22:08:15.530921Z"
}

 

参考文档

将存储库克隆到本地计算机:https://docs.azure.cn/zh-cn/api-management/api-management-configuration-repository-git#to-clone-the-repository-to-your-local-machine

如何使用 API 管理中的客户端证书身份验证确保 API 安全:https://docs.azure.cn/zh-cn/api-management/api-management-howto-mutual-certificates-for-clients

APIM Release: https://github.com/Azure/API-Management/releases/tag/release-service-2021-05

A regular Azure API Management service update was started on May 5, 2021, and included the following new features, bug fixes, and other improvements. It may take several weeks for your API Management service to receive the update.

Featured

  1. Open-source API Portal is now generally available.
  2. Azure API Management's support for Availability Zones is now generally available.
  3. Request and response validation policies are now generally available.

New

  1. You can now validate the client certificate with the new <validate-client-certificate> policy. Documentation and support in the Azure portal are coming soon.
  2. The Visual Studio Code extension now supports policy debugging for self-hosted gateways running locally.
  3. The Visual Studio Code extension now supports Dapr and validation policies.
  4. The developer portal now supports resource owner password grant flow.
  5. The new Ciphers + Protocols page in the Azure portal lets you manage API gateways' cipher and protocol configuration and displays a warning if a weak cipher or protocol is enabled.
  6. The Locations page in the Azure portal lets you now configure Availability Zones.
  7. You can now apply validation policies with the visual policy editors in the Azure portal, without writing any policy code.
  8. The timeout attribute of the send-request policy now supports policy expressions.

Fixed

  1. Caching issues, which might have resulted in a broken developer portal's administrative interface, are now resolved.

Changed

  1. The client certificate renegotiation feature is now disabled for all new and existing API Management services, except for the services that relied on it in the last 30 days (services with at least one API call that resulted in a client certificate request from a policy, not as part of an initial TLS handshake). The API gateway will request a client certificate only if HostnameConfiguration's property negotiateClientCertificate is set to true. If the property is set to false, the client certificate won't be available in the context.Request.Certificate property.

 

【END】

相关文章
|
20天前
|
安全 API 网络安全
【Azure API 管理】APIM不能连接到 App Service (APIM cannot connect to APP service)
【Azure API 管理】APIM不能连接到 App Service (APIM cannot connect to APP service)
|
20天前
|
API 开发工具 网络架构
【Azure Developer】如何通过Azure Portal快速获取到对应操作的API并转换为Python代码
【Azure Developer】如何通过Azure Portal快速获取到对应操作的API并转换为Python代码
|
20天前
|
API
【API Management】使用 APIM Inbound Policy 来修改Content‐Type Header的值
【API Management】使用 APIM Inbound Policy 来修改Content‐Type Header的值
【API Management】使用 APIM Inbound Policy 来修改Content‐Type Header的值
|
14天前
|
API C# 开发框架
WPF与Web服务集成大揭秘:手把手教你调用RESTful API,客户端与服务器端优劣对比全解析!
【8月更文挑战第31天】在现代软件开发中,WPF 和 Web 服务各具特色。WPF 以其出色的界面展示能力受到欢迎,而 Web 服务则凭借跨平台和易维护性在互联网应用中占有一席之地。本文探讨了 WPF 如何通过 HttpClient 类调用 RESTful API,并展示了基于 ASP.NET Core 的 Web 服务如何实现同样的功能。通过对比分析,揭示了两者各自的优缺点:WPF 客户端直接处理数据,减轻服务器负担,但需处理网络异常;Web 服务则能利用服务器端功能如缓存和权限验证,但可能增加服务器负载。希望本文能帮助开发者根据具体需求选择合适的技术方案。
45 0
|
20天前
|
存储 Kubernetes API
【APIM】Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?
【APIM】Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?
|
20天前
|
API 网络架构 C++
【Azure Key Vault】使用REST API调用Azure Key Vault Secret的示例步骤
【Azure Key Vault】使用REST API调用Azure Key Vault Secret的示例步骤
|
20天前
|
API 网络架构
【Azure Developer】使用 Microsoft Graph API查看用户状态和登录记录
【Azure Developer】使用 Microsoft Graph API查看用户状态和登录记录
|
30天前
|
机器人 API Python
智能对话机器人(通义版)会话接口API使用Quick Start
本文主要演示了如何使用python脚本快速调用智能对话机器人API接口,在参数获取的部分给出了具体的获取位置截图,这部分容易出错,第一次使用务必仔细参考接入参数获取的位置。
|
15天前
|
存储 JSON API
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者
——在成长的路上,我们都是同行者。这篇关于商品详情API接口的文章,希望能帮助到您。期待与您继续分享更多API接口的知识,请记得关注Anzexi58哦! 淘宝API接口(如淘宝开放平台提供的API)允许开发者获取淘宝商品的各种信息,包括商品详情。然而,需要注意的是,直接访问淘宝的商品数据API通常需要商家身份或开发者权限,并且需要遵循淘宝的API使用协议。
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者
|
25天前
|
SQL 存储 数据处理