跳至內容

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

2 分的閱讀內容
0

我想解決在後端系統上安裝,由 Amazon API Gateway 所產生自我簽屬和過期 SSL 憑證的問題。

解決方法

測試 HTTP Proxy 整合

使用 API 閘道主控台測試錯誤的 SSL 憑證。若要查看錯誤 SSL 憑證的清單,請參閱錯誤 SSL 網站上的 badssl.com

請完成下列步驟:

  1. 建立名為 /selfsigned 的資源。
  2. 在資源上建立 GET 方法。
  3. 設定與網址整合的 HTTP Proxy
  4. 開啟 API Gateway console (API Gateway 主控台)。
  5. 測試 API。
  6. 對另一個名為 /expiredcert 的資源和名為 /untrustedRootCA 的資源重複上述每個步驟。

對於名為 /selfsigned 的資源,您會收到以下錯誤訊息:

"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" (世界標準時間 2022 年 12 月 15 日星期四 16:05:05:傳送請求至 https://self-signed.badssl.com/ 世界標準時間 2022 年 12 月 15 日星期四 16:05:05:由於組態錯誤導致執行失敗:PKIX 路徑建置失敗:sun.security.provider.certpath.SunCertPathBuilderException:找不到請求目標的有效憑證路徑)

對於名為 /expiredcert 的資源,您會收到以下錯誤訊息:

"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" (世界標準時間 2022 年 12 月 15 日星期四 16:06:02:傳送請求至 https://expired.badssl.com/ 世界標準時間 2022 年 12 月 15 日星期四 16:06:02:由於組態錯誤導致執行失敗:PKIX 路徑驗證失敗:java.security.cert.CertPathValidatorException:有效性檢查失敗)

對於名為 /untrustedRootCA 的資源,您會收到以下錯誤訊息:

"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" (世界標準時間 2022 年 12 月 15 日星期四 16:06:28:傳送請求至 https://untrusted-root.badssl.com/ 世界標準時間 2022 年 12 月 15 日星期四 16:06:28:由於組態錯誤導致執行失敗:PKIX 路徑建置失敗:sun.security.provider.certpath.SunCertPathBuilderException:找不到請求目標的有效憑證路徑)

解決組態錯誤

**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本

當 Network Load Balancer 具有 TLS 接聽程式時,Network Load Balancer 會執行 TLS 終止,並與目標建立另一個連線。附加到 Network Load Balancer 的憑證必須滿足所有要求。

Network Load Balancer 在與目標進行 SSL 交握期間不會執行憑證驗證。Network Load Balancer 接受您在目標執行個體上安裝的過期或自我簽署憑證。Network Load Balancer 和目標群組會在虛擬私有雲端 (VPC) 內連結。如果 Network Load Balancer 正在使用 TCP 接聽程式,則 TLS 交握會以將端對端方式進行。在這種情況下,後端應用程式必須滿足 SSL 要求。

API Gateway 在透過 VPC 連結整合進行 SSL 交握期間支援伺服器名稱指示 (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" (由於組態錯誤導致執行失敗:PKIX 路徑建置失敗:sun.security.provider.certpath.SunCertPathBuilderException:找不到請求目標的有效憑證路徑)

若要解決此問題,請執行下列 update-integration AWS CLI 命令,並在整合的 tlsConfig 物件中將 insecureSkipVerification 設定為 true

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"

**注意:**將 EXAMPLE-REST-API-IDEXAMPLE-RESOURCE-ID 替換為您的值。

相關資訊

產生並設定用於 API Gateway 中後端驗證的 SSL 憑證