适用版本: 7.x-8.9
1. 错误异常的基本描述 #
Failed to get user information from the UserInfo endpoint. 表示 Elasticsearch 在 OIDC 登录流程中已经开始访问 UserInfo Endpoint,但整个获取或处理过程抛出了异常。相比只针对 claims 的异常(Failed to get claims from the Userinfo Endpoint),这个报错范围更宽,既可能是请求发送失败,也可能是响应处理、claims 合并或后续转换阶段出错。
源码显示该异常位于 catch (Exception e) 中,说明只要 UserInfo 调用链中的任何异常没有被更早处理,最终都会包装成这个错误。
常见现象 #
- 用户完成身份提供方登录后,回到 Kibana 或业务系统时认证失败,显示登录错误。
- Elasticsearch 日志出现
ElasticsearchSecurityException,并伴随更底层的网络、TLS、解析或 JSON 处理异常。 - 问题可能稳定复现(如配置错误),也可能只在某些用户或某些身份提供方响应上出现(如特定 claims 格式问题)。
- 在 OIDC 认证流程中,用户可能会被重定向回登录页面,形成登录死循环。
- 如果问题频繁出现,可能导致大量用户无法登录,影响业务正常运行。
典型报错与异常栈 #
常见日志形态通常类似下面这样:
ElasticsearchSecurityException: Failed to get user information from the UserInfo endpoint.
Caused by: java.io.IOException: Connection refused
at org.elasticsearch.xpack.security.authc.oidc.OpenIdConnectRealm...
或者 JSON 解析错误:
ElasticsearchSecurityException: Failed to get user information from the UserInfo endpoint.
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character
at com.fasterxml.jackson.core.JsonParser...
或者 claims 缺失:
ElasticsearchSecurityException: Failed to get user information from the UserInfo endpoint.
Caused by: java.lang.IllegalArgumentException: Missing required claim: sub
at org.elasticsearch.xpack.security.authc.oidc...
2. 为什么会发生这个错误 #
Failed to get user information from the UserInfo endpoint. 的根因是"OIDC UserInfo Endpoint 调用或响应处理失败"。这个异常是一个包装异常,底层可能有多种不同的失败原因:
常见原因通常包括:
- UserInfo Endpoint 不可达:
op.userinfo_endpoint配置错误、DNS 解析失败、网络被防火墙/安全组拦截,导致请求发送失败。 - TLS/SSL 问题:身份提供方的证书不受信任、证书过期、主机名校验失败或 TLS 版本不兼容,导致 HTTPS 连接失败。
- 身份提供方返回异常:IdP 返回的数据结构不符合 Elasticsearch 预期(如非 JSON 格式、缺少必要字段)。
- claims 合并阶段错误:claims 合并时缺少必要字段(如
sub、iss),或某些字段内容格式异常(如期望字符串但收到数组)。 - 节点资源紧张:节点本身 CPU、内存或线程池资源紧张,导致安全认证链路中的请求处理被打断。
- 代理或网关问题:HTTP 代理、反向代理、WAF 等中间设备篡改或截断响应内容。
- 用户信息解析失败:IdP 返回的 UserInfo 内容无法被正确解析(如字符编码问题、非法 JSON)。
- 超时或取消:请求超时被取消(类似
Request was cancelled,但被包装成更通用的异常)。
3. 如何排查和解决这个异常和解决这个异常 #
建议按"先查看 caused by、再定位失败阶段、后检查配置和数据"的顺序处理:
查看完整异常信息:先查看
caused by,确认失败点是请求发送、HTTP 响应还是响应处理。# 查看 Elasticsearch 安全日志 grep -r "Failed to get user information from the UserInfo endpoint" /var/log/elasticsearch/ grep -r "ElasticsearchSecurityException" /var/log/elasticsearch/ | tail -50验证 Realm 配置:检查 Realm 配置里的 UserInfo Endpoint、Claim 映射和 TLS 配置。
# 查看 OIDC Realm 配置 curl -X GET "localhost:9200/_cluster/settings?include_defaults=true&filter_path=*.xpack.security.authc.realms.oidc.*" -u elastic:password重点检查:
op.userinfo_endpoint:UserInfo Endpoint 地址op.issuer:Issuer 地址ssl.*:TLS/SSL 相关配置- Claim 映射配置(如
claims.name、claims.email等)
测试到身份提供方的连通性:从 Elasticsearch 节点直接访问身份提供方,确认网络和证书链正常。
# 测试 HTTP/HTTPS 连通性 curl -v https://your-idp-domain.com/oauth2/userInfo # 检查 TLS 证书 openssl s_client -connect your-idp-domain.com:443 -showcerts抓取 UserInfo 响应内容:核对字段是否满足当前 Realm 映射要求。
# 使用有效的 access_token 手动调用 UserInfo Endpoint curl -H "Authorization: Bearer your_access_token" https://your-idp-domain.com/oauth2/userInfo检查特定用户问题:如果问题只影响个别用户,重点检查其 claims 内容是否缺失或格式异常。
# 查看特定用户的认证日志 grep -r "user.*failed" /var/log/elasticsearch/ | grep "user_id"
排查时需要注意的问题 #
- 这个异常是一个"包装异常",根因藏在
Caused by中,必须找到最根本的异常才能确定问题性质。 - 不同阶段的失败需要不同的处理方式:网络问题看连通性,TLS 问题看证书配置,数据问题看 claims 格式。
- 如果问题只在某些用户上出现,很可能是用户 claims 数据的问题,需要对比正常用户和异常用户的 claims 内容。
4. 如何解决这个错误 #
常用修复思路 #
修正 Realm 配置:修正 UserInfo Endpoint、Claim 映射和证书信任配置。
# elasticsearch.yml 中的 OIDC Realm 配置示例 xpack.security.authc.realms.oidc.oidc1: order: 2 rp.client_id: "your-client-id" rp.response_type: "code" op.issuer: "https://your-idp-domain.com" op.authorization_endpoint: "https://your-idp-domain.com/oauth2/authorize" op.token_endpoint: "https://your-idp-domain.com/oauth2/token" op.userinfo_endpoint: "https://your-idp-domain.com/oauth2/userInfo" op.jwkset_path: "https://your-idp-domain.com/oauth2/jwks" # Claim 映射配置 claims.name: "name" claims.email: "email" claims.roles: "roles" # SSL 配置(如果需要) ssl.truststore.path: "/path/to/truststore.jks" ssl.truststore.password: "truststore_password"修复 TLS 信任链:如果需要,导入 IdP 的 CA 证书到 Elasticsearch 的 truststore。
# 导入 CA 证书 keytool -import -alias idp-ca -file /path/to/idp-ca.crt -keystore /path/to/elasticsearch/config/truststore.jks # 重启 Elasticsearch 使配置生效调整 Claim 映射:如果 IdP 返回的 claims 结构与 Elasticsearch 预期不符,调整映射配置。
# 如果 IdP 返回的 email 字段名为 email_address 而不是 email xpack.security.authc.realms.oidc.oidc1: claims.email: "email_address"修复网络或代理问题:确保 Elasticsearch 节点可以正常访问 IdP,必要时配置 HTTP 代理。
xpack.security.authc.realms.oidc.oidc1: http.proxy.host: "proxy.example.com" http.proxy.port: 3128 http.connect_timeout: "10s" http.socket_timeout: "30s"联系 IdP 管理员:如果 IdP 返回的数据格式有问题,需要联系 IdP 管理员修复。
后续注意事项与推荐建议 #
- 为 OIDC 认证配置合理的重试和降级策略,避免 IdP 短暂不可用导致所有用户无法登录。
- 建立对 IdP 服务可用性、响应时间和错误响应的监控,在 IdP 返回异常时及时预警。
- 定期检查 OIDC 客户端配置和 Claim 映射,确保与 IdP 返回的数据格式保持一致。
- 为认证相关错误配置专门的监控和告警,确保在用户受影响前发现问题。
借助 INFINI 产品提升排障效率 #
- INFINI Console 适合查看集群的安全配置、认证日志和用户访问趋势,帮助快速判断
Failed to get user information是网络问题、TLS 问题还是数据问题,并提供可视化的配置管理和审计功能。 - INFINI Gateway 适合部署在 Elasticsearch 前面做请求观测和流量治理,可以记录所有认证相关请求的详细日志,包括 OIDC 流程中每个步骤的请求和响应内容,帮助定位是 Elasticsearch 配置问题、IdP 返回问题还是网络问题,同时提供请求重试和熔断机制来提升认证稳定性。
- 建议将 OIDC 认证日志、IdP 响应时间和错误率统一接入监控面板,结合 INFINI Console 的告警功能,在认证失败率上升时及时通知管理员。
5. 小结 #
Failed to get user information from the UserInfo endpoint. 是一个范围较宽的 OIDC 异常包装。定位时必须继续向下追 caused by,否则很容易把网络问题、TLS 问题和 claims 格式问题混在一起。大多数情况下,这个问题可以通过找到根本异常、检查 IdP 连通性和修复 Claim 映射来解决。
只要把 OIDC 配置校验、IdP 监控和 Claim 管理固定下来,大多数用户信息获取类异常都可以被快速定位和恢复,也更容易通过 INFINI Console 和 INFINI Gateway 实现持续防护。
相关错误 #
- failed-to-get-claims-from-the-userinfo-endpoint-how-to-solve-this-elasticsearch-exception
- failed-to-get-claims-from-the-userinfo-endpoint-request-was-cancelled-how-to-solve-this-elasticsearch-exception
- failed-to-get-user-information-from-the-userinfo-endpoint-code=-how-to-solve-this-elasticsearch-exception
- failed-to-verify-access-token-how-to-solve-this-elasticsearch-exception
- failed-to-load-ssl-configuration-how-to-solve-this-elasticsearch-exception
参考文档 #
- Elasticsearch OIDC Realm 官方文档
- OpenID Connect UserInfo Endpoint 规范
- Elasticsearch 安全配置官方文档
- INFINI Console 文档
- INFINI Gateway 文档
附:日志上下文 #
下面保留当前页面中的源码或日志片段,便于继续结合异常调用栈定位问题:
}
});
return null;
});
} catch (Exception e) {
claimsListener.onFailure(new ElasticsearchSecurityException("Failed to get user information from the UserInfo endpoint."; e));
}
} /**
* Handle the UserInfo Response from the OpenID Connect Provider. If successful; merge the returned claims with the claims





