8000 Detect the format of the JRE truststore by trixpan · Pull Request #54171 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Detect the format of the JRE truststore - #54171

Closed
trixpan wants to merge 1 commit into
keycloak:mainfrom
trixpan:fix-jre-truststore-format
Closed

trixpan wants to merge 1 commit into
keycloak:mainfrom
trixpan:fix-jre-truststore-format

Conversation

@trixpan
@trixpan trixpan commented Oct 20, 2026
Copy link
Copy Markdown
Contributor

Closes #28526

Summary

When no javax.net.ssl.trustStore is configured, TruststoreBuilder.includeDefaultTruststore loads the JRE cacerts as PKCS12 with no password. Red Hat OpenJDK ships cacerts as a JKS keystore (a symlink to /etc/pki/ca-trust/extracted/java/cacerts). Providers that don't read JKS content as PKCS12 reject it, BCFIPS among them. As a result, a server started with --features=fips --fips-mode=non-strict and any truststore-paths fails to start:

ERROR: Failed to initialize truststore: /usr/lib/jvm/java-25-openjdk/lib/security/cacerts, type: PKCS12
ERROR: No password supplied for PKCS#12 KeyStore.

--truststore-kubernetes-enabled=false doesn't avoid this, because the merge still runs whenever truststore-paths is set. This differs from the case discussed in #28526: here the JKS file is the JRE's own cacerts, not a truststore the user passed to truststore-paths.

This change:

  • Tries the JRE default keystore type, then JKS, then PKCS12 when loading the JRE fallback truststore, each with no password first and then the well-known default changeit.
  • Loads an explicitly configured javax.net.ssl.trustStore exactly as before.
  • Lists the types tried in the error if none of them load. Passwords are never logged.

Testing

  • TruststoreBuilderTest.testJksDefaultTruststoreIsMerged generates a JKS cacerts at runtime and sets keystore.type.compat=false. That setting makes the JDK reject JKS content loaded as PKCS12, as BCFIPS does. The test fails without the fix and passes with it.

  • ./mvnw test -pl services -Dtest=TruststoreBuilderTest,FileTruststoreProviderFactoryTest: 18 tests pass.

  • ./mvnw spotless:check -pl services

  • End to end: a distribution built from this branch, run in a UBI9 container with Red Hat OpenJDK 25, BCFIPS and a faked /proc/sys/crypto/fips_enabled:

    Mode Options Without this fix With this fix
    non-strict --truststore-paths=<pem> fails at startup starts (HTTP 200)
    strict --truststore-paths=<pem> starts starts
    non-strict no truststore-paths starts starts

Related: #54143 works around this in .github/scripts/run-fips-it.sh. The workaround can be removed once this is merged.

AI assistance

This PR was developed with assistance from Claude Code. I reviewed and understand the submitted changes.

🤖 Generated with Claude Code

When no javax.net.ssl.trustStore is configured, merging the default truststore loaded the JRE cacerts as PKCS12 with no password. On distributions that ship cacerts as JKS, such as Red Hat OpenJDK, providers that do not read JKS content as PKCS12 reject it. With BCFIPS in non-strict mode the server then fails to start whenever truststore-paths is set.

Try the JRE default keystore type, JKS and PKCS12 in turn, with no password and then the well-known default one. An explicitly configured javax.net.ssl.trustStore is loaded as before.

Closes keycloak#28526

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Andre F de Miranda <trixpan@users.noreply.github.com>
@trixpan
trixpan requested a review from a team as a code owner October 20, 2026 12:51
Copilot AI balanced review requested due to automatic review settings October 20, 2026 12:51
@trixpan
trixpan commented Oct 20, 2026
Copy link
Copy Markdown
Contributor Author

@slaskawi you may recall #49139 we discussed two bugs.

One was addressed but the other, #28526 was never addressed. This PR should hopefully solve it.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, preserves explicit truststore configuration, and includes targeted regression coverage with no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes JRE truststore loading across keystore formats, addressing startup failures with Red Hat OpenJDK and non-strict FIPS mode.

Changes:

  • Tries fallback formats and passwords for JRE truststores while preserving explicit configuration behavior.
  • Reports attempted formats when loading fails.
  • Adds a regression test for JKS cacerts with format compatibility disabled.
File Description
services/​src/​test/​java/​org/​keycloak/​truststore/​TruststoreBuilderTest.java Tests merging a JKS JRE truststore.
services/​src/​main/​java/​org/​keycloak/​truststore/​TruststoreBuilder.java Adds format and password fallbacks for JRE truststores.

Review effort: Balanced

@shawkins
Copy link
Copy Markdown
Contributor

Thank you for the pr @trixpan, but I'm closing this in favor of #54394

@shawkins shawkins closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truststore consolidation broke keycloak fips mode

3 participants

0