如何排查 API Gateway 生成的 SSL 证书错误?

2 分钟阅读
0

我的后端系统上安装的自签名和过期的 SSL 证书出现问题。如何修复这些错误?

简短描述

当 Amazon API Gateway 与后端执行 SSL 握手时,API Gateway 希望后端提供从可信颁发机构获得的证书。API Gateway 希望证书有效且未过期。API Gateway 还希望信任链完好无损。这意味着 API Gateway 期望证书包含根证书颁发机构(CA)、中间 CA 和父证书详细信息。有了这些信息,API Gateway 可以通过证书链来完成证书验证。

解决方法

测试 HTTP 代理集成

要熟悉 HTTP 代理集成,请从 API Gateway 控制台测试错误的 SSL 证书。有关无效的 SSL 证书和测试的更多信息,请参阅无效的 SSL 网站

1.    使用 GET 方法创建名为“/selfsigned”的资源。然后,使用 URL https://self-signed.badssl.com/ 配置 HTTP 代理集成。

API Gateway 控制台测试 API。您收到以下错误:

Thu Dec 15 16:05:05 UTC 2022 : Sending request to https://self-signed.badssl.com/
Thu Dec 15 16:05:05 UTC 2022 : Execution failed due to configuration error: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

2.    使用 GET 方法创建名为“/expiredcert”的资源。然后,使用 URL https://expired.badssl.com/ 配置 HTTP 代理集成。

API Gateway 控制台测试 API。您收到以下错误:

Thu Dec 15 16:06:02 UTC 2022 : Sending request to https://expired.badssl.com/
Thu Dec 15 16:06:02 UTC 2022 : Execution failed due to configuration error: PKIX path validation failed: java.security.cert.CertPathValidatorException: validity check failed

3.    使用 GET 方法创建名为“/untrustedRootCA”的资源。使用 URL https://untrusted-root.badssl.com/ 配置 HTTP 代理集成。

API Gateway 控制台测试 API。您收到以下错误:

Thu Dec 15 16:06:28 UTC 2022 : Sending request to https://untrusted-root.badssl.com/
Thu Dec 15 16:06:28 UTC 2022 : Execution failed due to configuration error: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

VPC 链接集成

通过 VPC 链接集成,API Gateway 使用执行 TLS 终止操作的下一个跃点执行证书验证。

如果网络负载均衡器具有 TLS 侦听器,则前者将执行 TLS 终止操作并创建与目标的另一个连接。附加到网络负载均衡器的证书必须满足所有要求。在与目标进行 SSL 握手期间,网络负载均衡器不会执行证书验证。网络负载均衡器接受目标实例上安装的过期证书或自签名证书。网络负载均衡器和目标组绑定在一个 VPC 内,并且通信非常安全。如果网络负载均衡器使用 TCP 侦听器,则会进行端到端的 TLS 握手。在这些情况下,后端应用程序必须符合 SSL 要求。

在通过 VPC 链接集成进行 SSL 握手期间,API Gateway 支持服务器名称指示(SNI)。

如果后端网络负载均衡器的自签名证书或私有证书不是由 CA 颁发的,则您会收到以下错误:

Execution failed due to configuration error: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

执行失败错误的解决方法是,在集成的 tlsConfig 对象中将 insecureSkipVerification 设置为 true

**注意:**请将 EXAMPLE-REST-API-IDEXAMPLE-RESOURCE-ID 替换为相应的值。

aws apigateway update-integration --rest-api-id EXAMPLE-REST-API-ID --resource-id EXAMPLE-RESOURCE-ID --http-method GET --patch-operations "op='replace',path='/tlsConfig/insecureSkipVerification',value=true"

相关信息

生成和配置用于后端身份验证的 SSL 证书

API Gateway 支持的 HTTP 和 HTTP 代理集成的证书颁发机构

网络负载均衡器的目标组

AWS 官方
AWS 官方已更新 1 年前