如何對 API Gateway 產生的 SSL 憑證錯誤進行疑難排解?

2 分的閱讀內容
0

我的後端系統上安裝的自我簽署和過期 SSL 憑證發生問題。如何修正這些錯誤?

簡短說明

當 Amazon API Gateway 與後端執行 SSL 交握時,API Gateway 會預期後端提供從受信任之發行者取得的憑證。API Gateway 預期憑證有效且未過期。API Gateway 也預期信任鏈完好無缺。這表示 API Gateway 預期憑證包含根憑證授權單位 (CA)、中繼 CA 和父憑證詳細資訊。有了這些資訊,API Gateway 就可以透過憑證鏈來完成憑證驗證。

解決方案

測試 HTTP Proxy 整合

為了熟悉 HTTP Proxy 整合,請從 API Gateway 主控台測試錯誤的 SSL 憑證。如需有關錯誤的 SSL 憑證和測試的更多資訊,請參閱錯誤的 SSL 網站

1.    使用 GET 方法建立名為 "/selfsigned" 的資源。然後,使用網址 https://self-signed.badssl.com/ 設定 HTTP Proxy 整合。

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" 的資源。然後,使用網址 https://expired.badssl.com/ 設定 HTTP Proxy 整合。

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" 的資源。使用網址 https://untrusted-root.badssl.com/ 設定 HTTP Proxy 整合。

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 終止的下一個躍點執行憑證驗證。

當 Network Load Balancer 具有 TLS 接聽程式時,Network Load Balancer 會執行 TLS 終止並建立與目標的另一個連線。連接至 Network Load Balancer 的憑證必須滿足所有要求。在與目標進行 SSL 交握期間,Network Load Balancer 不會執行憑證驗證。Network Load Balancer 會接受安裝在目標執行個體上的過期或自我簽署憑證。Network Load Balancer 和目標群組必須都在一個 VPC 中,且通訊安全無虞。如果 Network Load Balancer 使用 TCP 接聽程式,則端對端會進行 TLS 交握。在這些情況下,後端應用程式必須符合 SSL 需求。

在透過 VPC 連結整合進行 SSL 交握期間,API Gateway 會支援伺服器名稱指示 (SNI)。

如果後端 Network Load Balancer 使用的自我簽署或私有憑證並非由憑證授權單位 (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 憑證

適用於 HTTP 和 HTTP Proxy 整合、支援 API Gateway 的憑證授權單位

Network Load Balancer 的目標群組

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