排解 LDAP 伺服器問題

本文提供 GKE Identity Service 中 LDAP 伺服器問題的疑難排解指南。

連線問題

設定 GKE Identity Service 時,嘗試連線至 LDAP 伺服器可能會發生連線問題。如果用於識別 LDAP 伺服器的憑證與 ClientConfig 中提及的憑證不符,也可能發生連線問題。

錯誤訊息

下列訊息適用於執行 gcloud anthos auth login 指令時發生的錯誤。

  • ERROR: LDAP login failed: could not obtain an STS token: Post "https://127.0.0.1:15001/sts/v1beta/token": failed to obtain an endpoint for deployment anthos-identity-service/ais: Unauthorized
  • ERROR: Configuring Anthos authentication failed

解決方案

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

  • 如果 GKE Identity Service 無法連線至 LDAP 伺服器,請按照下列步驟操作:
    • 如要確認是否有任何網路流量可從叢集連線至 LDAP 伺服器 (身分識別提供者),請使用 telnetnc 或類似指令連線至 LDAP 伺服器。如要連線 LDAP 伺服器,您需要在執行 GKE Identity Service 的節點或 Pod 中執行指令。
    • 如果指令成功,GKE Identity Service Pod 應會連線至 LDAP 伺服器。
    • 如果指令失敗,表示網路連線有問題。請檢查網路設定或聯絡網路管理員,解決連線問題。
  • 確認設定中的公開憑證格式正確,且符合下列情況的 LDAP 伺服器:
    • 您使用 LDAP with TLS。
    • 您可以使用服務帳戶向 LDAP 進行驗證。您可以使用憑證向 LDAP 伺服器驗證服務帳戶。

驗證問題

發生驗證問題的可能情況如下:

  • GKE Identity Service 的 ClientConfig 中,LDAP 供應商設定有誤。
  • 您提供的使用者憑證不存在於 LDAP 伺服器。
  • LDAP 伺服器發生問題。

錯誤訊息

下列訊息適用於執行 gcloud anthos auth login 指令時發生的錯誤。

  • ERROR: LDAP login failed: could not obtain an STS token: Post "https://127.0.0.1:15001/sts/v1beta/token": failed to obtain an endpoint for deployment anthos-identity-service/ais: Unauthorized
  • ERROR: Configuring Anthos authentication failed

解決方案

叢集管理員可以查看 GKE Identity Service 記錄,並透過下列方式解決驗證問題:

  • Can't contact LDAP server:如要進一步瞭解如何解決這個問題,請參閱連線問題
  • Attempting to bind as the LDAP service account:GKE 身分識別服務嘗試使用 ClientConfig 中提供的服務帳戶憑證連線至 LDAP 伺服器。如果沒有這則記錄訊息,表示連線發生問題
  • Successfully completed BIND as LDAP service account:GKE Identity Service 能夠順利連線至 LDAP 伺服器,並使用其服務帳戶進行使用者驗證。如果沒有這則記錄訊息,表示設定有問題。
  • Successfully found an entry for the user in the database:LDAP 伺服器上存在使用者項目。這表示 baseDNfilterloginAttribute 欄位已正確設定,可擷取使用者。只有在記錄詳細程度高於預設層級時,才會顯示這則訊息。如要進一步瞭解如何啟用記錄,請參閱「啟用偵錯記錄」。
  • Attempting to BIND as the user to verify their credentials:GKE Identity Service 正在嘗試驗證使用者憑證。
  • Successfully completed LDAP authentication:使用者驗證成功。如果沒有這則記錄訊息,表示憑證無效。

驗證權杖已過期

即使登入成功,驗證權杖仍可能過期,導致發生問題。

錯誤訊息

ERROR: You must be logged in to the server (Unauthorized)

解決方案

如要解決這個問題,請重新登入伺服器。

RBAC 角色繫結至使用者或群組時發生問題

如果驗證成功,但由於使用者或群組沒有 RBAC 角色繫結,導致授權失敗,就會發生這個問題。舉例來說,當您嘗試發出 kubectl get pods 指令時,這個問題仍會持續發生。

錯誤訊息

Error from server (Forbidden): <SERVICE or PODS> is forbidden: <MORE DETAILS>

解決方案

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

  1. 登入 LDAP 伺服器,查看目標使用者的群組。
  2. 確認 Kubernetes 角色和角色繫結是否定義正確,且與 LDAP 目錄中的值相符。管理員可以透過 Kubernetes 使用者模擬功能,協助驗證角色繫結。
  3. 更新角色繫結,確保目標使用者的群組有權執行必要動作。
  4. 確認群組的 baseDN 值 (以及選用的 filteridentifierAttribute 值) 正確無誤。GKE Identity Service 會使用這些欄位的群組設定,查詢使用者所屬的所有群組。如果 baseDN 為空白,則不會向 Kubernetes API 伺服器提供任何群組。在這種情況下,系統不會記錄任何訊息。如果 baseDN 不為空白,GKE Identity Service 會查詢資料庫,找出使用者的群組。
    • 如果查詢成功,系統會將群組提供給 Kubernetes API 伺服器。
    • 如果查詢失敗,系統不會將群組提供給 Kubernetes API 伺服器。在這種情況下,您需要修正群組的 baseDNfilter 設定值。

使用者同時屬於多個群組

如果使用者屬於多個群組,就會發生這個問題。

錯誤訊息

could not obtain an STS token: STS token exceeds allowed size limit. Possibility of too many groups associated with the credentials provided.

解決方案

叢集管理員必須在 ClientConfig 中設定 filter 欄位,減少查詢傳回 LDAP 伺服器的群組數量。

版本相容性問題

如果 GKE Identity Service 與已安裝的 Google Cloud CLI 版本不相容,就會發生這個問題。

錯誤訊息

  • unable to parse STS Token Response
  • could not obtain an STS token: JSON parse error: The request was malformed.
  • could not obtain an STS token: Grant type must confirm that the request is intended for a token exchange.
  • could not obtain an STS token: Requested token type must correspond to an access token.
  • could not obtain an STS token: Subject token type must be a valid token type supported for token exchange.

解決方案

您需要將 gcloud 公用程式和 GKE Identity Service 升級至最新版本。

401 驗證失敗狀態碼

如果 Kubernetes API 伺服器無法驗證服務,並傳回 401 錯誤代碼,就會發生這個問題。

錯誤訊息

  • ERROR: LDAP login failed: STSToken() failed: could not obtain an STS token: Post "https://127.0.0.1:15001/sts/v1beta/token": DialContext() failed: podEndpoint() failed to obtain an endpoint for deployment anthos-identity-service/ais: Unauthorized

  • ERROR: Configuring Anthos authentication failed

解決方案

您可以透過下列任一方式解決這個問題:

  • 使用下列指令,檢查 GKE Identity Service Pod 是否處於 running 狀態:
    kubectl get pods -l k8s-app=ais -n anthos-identity-service --kubeconfig USER_CLUSTER_KUBECONFIG
  • 使用下列指令檢查 ClientConfig 中的 LDAP 設定:
    kubectl get clientconfig -n kube-public -o jsonpath='{.items[].spec.authentication[].ldap}' --kubeconfig USER_CLUSTER_KUBECONFIG
  • 查看記錄,瞭解錯誤的詳細資訊。如要進一步瞭解記錄功能,請參閱「使用記錄和監控功能查看系統元件」。