项目简介
Keycloak 提供认证、用户联合、强认证、用户管理和细粒度授权,以最小工作量保护应用和服务安全,支持 OIDC 和 SAML 协议。
README 预览
\n\n\n[](https://bestpractices.coreinfrastructure.org/projects/6818)\n[](https://clomonitor.io/projects/cncf/keycloak)\n[](https://securityscorecards.dev/viewer/?uri=github.com/keycloak/keycloak)\n[](https://artifacthub.io/packages/olm/community-operators/keycloak-operator)\n\n\n[](docs/translation.md)\n\n# Open Source Identity and Access Management\n\nAdd authentication to applications and secure services with minimum effort. No need to deal with storing users or authenticating users.\n\nKeycloak provides user federation, strong authentication, user management, fine-grained authorization, and more.\n\n\n## Help and Documentation\n\n* [Documentation](https://www.keycloak.org/documentation.html)\n* [User Mailing List](https://groups.google.com/d/forum/keycloak-user) - Mailing list for help and general questions about Keycloak\n* Join [#keycloak](https://cloud-native.slack.com/archives/C056HC17KK9) for general questions, or [#keycloak-dev](https://cloud-native.slack.com/archives/C056XU905S6) on Slack for design and development discussions, by creating an account at [https://slack.cncf.io/](https://slack.cncf.io/).\n\n\n## Reporting Security Vulnerabilities\n\nIf you have found a security vulnerability, please look at the [instructions on how to properly report it](https://github.com/keycloak/keycloak/security/policy).\n\n\n## Reporting an issue\n\nIf you believe you have discovered a defect in Keycloak, please open [an issue](https://github.com/keycloak/keycloak/issues).\nPlease remember to provide a good summary, description as well as steps to reproduce the issue.\n\n\n## Getting started\n\nTo run Keycloak, download the distribution from our [website](https://www.keycloak.org/downloads.html). Unzip and run:\n\n bin/kc.[sh|bat] start-dev\n\nAlternatively, you can use the Docker image by running:\n\n docker run quay.io/keycloak/keycloak start-dev\n \nFor more details refer to the [Keycloak Documentation](https://www.keycloak.org/documentation.html).\n\n\n## B
常见问题 (5)
故障排除如何修复间歇性的 Oid4VciNonHaipTestSuite 失败以及 VCIEnsureCredentialTimeClaimsNotLinkable iat 可关联性警告?
这个不稳定的失败是由概率性的 RANDOMIZE 时间声明策略引起的:两个独立的随机偏移量可能重合,使 iat2 - iat1 近似等于真实的签发间隔。重新运行通常可以通过,但确定性的修复方法是使用 ROUND 策略并配合 MINUTE 单位。
在 tests/conformance/src/test/java/org/keycloak/tests/conformance/vci/VciConformanceRealmUtil.java 中,在 applyCommon() 方法内,将 RANDOMIZE/300 秒的配置替换为:
.attribute(OID4VCIConstants.TIME_CLAIMS_STRATEGY, TimeClaimNormalizer.Strategy.ROUND.name())
.attribute(OID4VCIConstants.TIME_ROUND_UNIT, TimeClaimNormalizer.RoundUnit.MINUTE.name())
使用 MINUTE,而不是 HOUR 或 DAY:凭证的有效期为 300 秒,而 300 秒恰好是五个分钟边界。更粗粒度的单位可能会把 exp 舍入回已舍入的 iat,导致凭证立即过期。根据 RFC 9901 §10.1,舍入是一种被允许的不可链接性缓解措施。重新构建并重新运行 Oid4VciNonHaipTestSuite 一致性测试任务。
故障排除如何修复 Keycloak ExternalLinksTest 中 EntityManager API 链接返回 HTTP 404 导致的失败问题?
修正 server-development 用户存储指南中的 EntityManager 链接。将以 /entitymanager 结尾的小写路径替换为区分大小写的 /EntityManager.html。验证更正后的 URL 返回 HTTP 200,然后重新运行:./mvnw install -Dtest=ExternalLinksTest -am -pl docs/documentation/tests -Pdocumentation。
故障排除如何修复 CVE-2026-91777 jackson-databind 反序列化 DoS 漏洞?
将 com.fasterxml.jackson.core:jackson-databind 升级到已修复的版本:**2.22.3**、**2.21.7** 或 **2.18.11**(受影响版本:2.21.5、2.22.1、2.22.2 及更早的版本线)。
**Maven:**
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.22.3</version>
</dependency>
**Gradle:**
implementation 'com.fasterxml.jackson.core:jackson-databind:2.22.3'
**Quarkus 用户:** 该版本由 quarkus-bom 管理(例如 3.40.1 附带的是受影响的版本)。请升级到包含该修复的更新版 quarkus-bom,或者在导入 BOM 之后,在 dependencyManagement 部分中显式固定已修复的 jackson-databind 版本。
该漏洞在将带有 @JsonIdentityInfo 对象 ID 的 JSON 反序列化为 Collection 或 Map 类型时,会导致平方级的 CPU 消耗(N*(N+1)/2 次身份比较)——其中 N 个前向引用以逆序解析——从而使攻击者能够利用浅层、线性大小的载荷发起拒绝服务攻击。该补丁用基于键的查找结构取代了对挂起引用累积器的重复线性扫描。
**无法升级时的缓解措施:** 避免将不可信或攻击者控制的 JSON 反序列化为启用了身份标识(@JsonIdentityInfo)的集合或映射,并在 API 边界强制执行载荷大小限制。
故障排除为什么使用 `!has-role()` 的 Keycloak 工作流条件会作用于相反的用户?
在 Keycloak 26.8.0 中,工作流表达式仅支持 not、and 和 or。! 字符会被静默丢弃,而不会引发验证错误,因此 if: "!has-role(vip)" 会被求值为 if: "has-role(vip)",导致条件反转。请将其替换为受支持的运算符:if: "not has-role(vip)"。同样,使用 and/or 代替 &&/||。在服务器日志中搜索 token recognition error at: '!' 以识别受影响的工作流。修复方案会通过 workflowExpressionInvalid 拒绝无法识别的字符;请在包含 PR "Reject workflow expressions with unrecognized characters" 的版本发布后及时升级。
故障排除如何修复 Keycloak Protection API 创建的资源归属于资源服务器而非指定用户的问题?
此行为在 Keycloak 26.6.x 中是有意设计的。当你使用 PAT 调用 POST /realms/{realm}/authz/protection/resource_set 时,Keycloak 会忽略请求体中的 owner,并将所有权分配给 PAT 的主体,通常是资源服务器。使用 PUT 更新资源不会更改所有者。
若要创建由其他用户拥有的资源,请改用 Keycloak Admin API:
curl -X POST \
"http://localhost:8080/admin/realms/{realm}/clients/{client-uuid}/authz/resource-server/resource" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Alice Resource",
"owner": "{alice-user-id}",
"ownerManagedAccess": true
}'
请使用客户端的 UUID,而不是其 clientId,并使用具有管理授权资源权限的管理员令牌。根据该用户是否应管理此资源来设置 ownerManagedAccess。Protection API 只能为所出示 PAT 所代表的主体创建资源;任意用户所有权现在必须通过 Admin API 来完成。