排解 OIDC 供應商問題

本文提供疑難排解指南,協助解決 GKE Identity Service 中的 OIDC 和 AzureAD 身分識別提供者問題。

憑證格式不正確

如果憑證值有格式錯誤,就會發生這個問題。格式設定問題可能與未採用 base64 編碼的憑證值,以及採用 base64 編碼但有誤的值有關。如果憑證不是由根憑證授權單位簽署,或是未提供格式正確的信任鏈,也可能發生這個問題。

錯誤訊息

以下是憑證格式錯誤時顯示的錯誤訊息示例:

  • 未採用 Base64 編碼的憑證: Failed creating HTTP client to fetch the Discovery URI "<Discovery-document URI>" with error: Unable to decode data field, the value should be Base64 encoded

  • 格式不正確或經過 Base64 編碼但內容有誤的憑證: Unable to connect to 'https://example.com', encountered the following error: Problem with the SSL CA cert (path? access rights?). Details: error setting certificate verify locations: CAfile: /tmp/example.pem CApath: none (The certificate could not be read, this is most likely because it's empty or contains a formatting error. Please check your configuration.)

  • 格式不正確或經過 Base64 編碼但內容有誤的憑證: Failed fetching the Discovery URI "<Discovery-document URI>" with error: Unable to load TLS certificates.

解決方案

你可以透過下列任一方式解決問題:

  • 您在 ClientConfig 中提供的憑證值應為 Base64 編碼字串和 PEM 格式字串。詳情請參閱「編碼 CA 憑證」。
  • 如果供應商使用的憑證並非由根憑證授權單位簽署,您必須使用憑證信任鏈結設定 GKE Identity Service。詳情請參閱「中繼憑證」。

憑證值錯誤

如果憑證的值不相符,就會發生這個問題。在這個案例中,憑證格式正確,但與伺服器不符。這也可能表示設定中沒有憑證。

在下列任一情況下,認證值可能會被視為不正確:

  • ClientConfig 中分享的憑證值不正確。如果伺服器憑證的 issuer 與設定的憑證 subject 不符,憑證值就會不正確。
  • ClientConfig 中的憑證不是 Base64 編碼的字串。
  • 使用中繼憑證核發伺服器憑證時,系統不會提供憑證鏈結。

錯誤訊息

以下是憑證值不符時的錯誤訊息範例:

  • 憑證鏈結不完整或與伺服器不符: SSL peer certificate was not OK. Details: SSL certificate problem: unable to get local issuer certificate

  • 憑證鏈結不完整 (對應至無效的部分鏈結,該鏈結並非從根開始或不連續): Failed fetching the Discovery URI "<Discovery-document URI>" with error: The server's TLS certificate did not match expectations.

  • 憑證鏈結有效,但不符合 OIDC 伺服器: AIS was expecting the server to have a different certificate

  • 憑證鏈結有效,但不符合 OIDC 伺服器: Failed fetching the Discovery URI "<Discovery-document URI>" with error: The server's TLS certificate did not match expectations.

解決方案

您在 ClientConfig 中提供的憑證值必須包含格式正確的憑證鏈結,且與身分識別提供者相符。 如要進一步瞭解如何格式化及編碼憑證,請參閱「編碼 CA 憑證」。

使用 gcloud anthos auth login 指令產生的 kubeconfig 檔案時,kubectl 指令會失敗

在 Windows 機器上使用 gcloud anthos auth login 指令搭配 OIDC,為叢集存取權產生 kubeconfig 檔案時,kubectl 指令可能會失敗,並顯示以下錯誤訊息:The command line is too long. 這個問題只會發生在 Windows 系統上,使用相同 kubeconfig 檔案的 Linux 機器則不受影響。根本原因與 Azure Active Directory (Azure AD) 產生驗證權杖的大小有關,當使用者屬於大量群組時 (約 70 到 200 個群組,視群組名稱長度而定),就會發生這個問題。

這個大型權杖會導致 kubectl 指令執行失敗,因為權杖長度超過 Windows 允許的指令列長度上限 (8,191 個字元)。

錯誤訊息

$ kubectl --kubeconfig test-kubeconfig.yml get nodes

The command line is too long.
The command line is too long.
E0102 11:02:29.115256 24320 memcache.go:265] couldn't get current server API group list: Get "https://10.35.0.86:443/api?timeout=32s": getting credentials: exec: executable gcloud failed with exit code 1
The command line is too long.
E0102 11:02:29.350238 24320 memcache.go:265] couldn't get current server API group list: Get "https://10.35.0.86:443/api?timeout=32s": getting credentials: exec: executable gcloud failed with exit code 1
The command line is too long.
E0102 11:02:30.062811 24320 memcache.go:265] couldn't get current server API group list: Get "https://10.35.0.86:443/api?timeout=32s": getting credentials: exec: executable gcloud failed with exit code 1
Unable to connect to the server: getting credentials: exec: executable gcloud failed with exit code 1

解決方案

如要解決這個問題,請按照下列步驟操作:

  • 升級至 GKE 叢集 1.28 以上版本

    如果您執行的 GKE 叢集版本低於 1.28,建議升級至支援的版本。

  • 減少受影響使用者的群組成員資格

    將驗證使用者的群組數量減少至問題門檻以下 (約 70 個群組),即可解決問題。

  • 增加受影響使用者的群組成員資格

    Microsoft Entra ID 功能對權杖中發出的群組數量設有限制。如果群組成員介於 70 到 200 人,可能會導致驗證問題。不過,您可以增加群組成員人數,超過這個限制,即可解決身分識別提供者問題。由於這項限制的行為,當成員人數過多時,Azure AD 會從 id_token 中省略群組,避免命令列過長,進而解決身分識別提供者問題。如要確認限制並瞭解詳情,請參閱 Microsoft Entra ID 說明文件