排查 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 与 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 Identity Service 正在尝试使用 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
    
  • 查看日志以详细了解错误。如需详细了解日志记录,请参阅对系统组件使用日志记录和监控