8000 Stabilize FIPS in CI run by ahus1 · Pull Request #53309 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Stabilize FIPS in CI run - #53309

Draft
ahus1 wants to merge 1 commit into
keycloak:mainfrom
ahus1:is-53308-fix-fips
Draft

ahus1 wants to merge 1 commit into
keycloak:mainfrom
ahus1:is-53308-fix-fips

Conversation

@ahus1
@ahus1 ahus1 commented Sep 29, 2026 •
Copy link
Copy Markdown
Member

Closes #53308

Rationale

The FIPS IT job runs on GitHub Actions VMs where the RDSEED CPU instruction is unreliable — the hypervisor doesn't guarantee the hardware RNG buffer stays available under load. Since RDSEED is a CPU instruction executed directly in userspace by bc-fips native code, there is no way to supplement it from the kernel side (not via rng-tools, haveged, or the fake_fips.c module).

Approach

bc-fips 2.1.3 supports -Dorg.bouncycastle.native.cpu_variant=java as a documented configuration to skip native library loading. When set, bc-fips uses pure-Java FIPS-validated implementations and seeds its DRBG from SecureRandom.getInstanceStrong() (kernel DRBG / /dev/urandom) instead of RDSEED. This is set via JAVA_OPTS_APPEND so that kc.sh passes it to the Keycloak server JVM started by the test framework.

Assumptions and decisions

  • FIPS compliance is preserved. The bc-fips FIPS 140-3 validation covers both native and pure-Java implementations — cpu_variant=java is a supported mode, not a workaround. The entropy chain (SecureRandom.getInstanceStrong() → kernel DRBG → /dev/urandom) is SP 800-90A compliant on FIPS-enabled systems.
  • Production is unaffected. This property is s 8000 et only in the CI script (run-fips-it.sh). On real FIPS infrastructure (RHEL/OpenShift nodes with actual FIPS kernel mode), RDSEED works reliably and native bc-fips is used as before. Using cpu_variant=java in production would sacrifice the performance benefits of native hardware acceleration (AES-NI, native SHA, etc.) for no reason on systems where RDSEED works.
  • CI is already simulating FIPS. The CI uses a fake kernel module to set /proc/sys/crypto/fips_enabled=1 on Ubuntu — it's testing Keycloak's FIPS code paths, not certifying hardware entropy. Disabling native bc-fips in this environment is consistent with that intent.
  • Native code is not tested in CI with this change. Setting cpu_variant=java prevents the native library from loading entirely, so CI never exercises the native bc-fips code path. This is the same trade-off as the dismissed automatic-fallback alternative below — both end up calling setNativeEnabled(false) and disabling all native crypto (AES-NI, native SHA, etc.), not just the entropy source. The difference is only where the switch is flipped: here in the CI script unconditionally, vs. in Keycloak code only when RDSEED actually fails. An automatic fallback in FIPS1402Provider would be strictly better for CI coverage since it would still attempt native and only degrade when the environment can't support it. However, an automatic fallback would also affect production deployments on VMs where RDSEED intermittently fails — whether that silent degradation is acceptable in production needs a broader discussion. This PR takes the conservative path of scoping the change to CI only.
  • Scoped to run-fips-it.sh only. The FIPS UT script (run-fips-ut.sh) is not changed because unit tests run in the Maven JVM (not via kc.sh/JAVA_OPTS_APPEND) and don't trigger heavy entropy usage. If RDSEED failures appear there too, the property would need to be passed as a Maven -D argument instead.
  • JAVA_OPTS_APPEND propagates correctly. Both the new test framework (DistributionKeycloakServer → ProcessBuilder inherits environment) and the old Arquillian framework (KeycloakQuarkusServerDeployableContainer → ProcessBuilder inherits environment) pass the parent environment to the kc.sh child process. kc.sh appends JAVA_OPTS_APPEND to JAVA_OPTS at line 132-134, regardless of whether JAVA_OPTS was set explicitly.

Dismissed alternative: automatic fallback in FIPS1402Provider

A code-level fix was considered: in FIPS1402Provider, after registering the BCFIPS provider, proactively test native entropy by calling SecureRandom.getInstance("DEFAULT", "BCFIPS").nextBytes(new byte[32]). If this throws IllegalStateException (RDSEED failure), call CryptoServicesRegistrar.setNativeEnabled(false) to fall back to software entropy automatically.

This would make Keycloak resilient to RDSEED failures on VMs without any external configuration, and would provide better CI coverage since native is still attempted before falling back. However, this approach has a deeper reliability problem: bc-fips creates its pooled DRBGs with predictionResistance = true (hardcoded in BouncyCastleFipsProvider), which means the DRBG reseeds from the entropy source on every call to nextBytes(), not just during initial seeding. So even if a one-time startup test passes (RDSEED works under low load), RDSEED could still fail later during any reseed under load. A proactive test cannot reliably guard against an intermittent failure that occurs on every random byte generation. The only reliable approaches are: (1) disable native entirely upfront (cpu_variant=java), or (2) wrap the entropy source to catch and retry/fall back on each call, which would require modifying bc-fips itself.

The loss of native acceleration (AES-NI, SHA) when the fallback triggers is a performance concern, not a correctness or compliance issue — and it only activates in environments that can't support native anyway. The automatic fallback was dismissed for this PR because the silent degradation in production VM deployments needs broader discussion, and the proactive-test variant is unreliable due to DRBG reseeding. This could be revisited as a follow-up if bc-fips adds a more targeted entropy-only fallback.

🤖 Generated with Claude Code

Closes keycloak#53308

Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
@ahus1 ahus1 self-assigned this Sep 29, 2026
@stianst stianst added this to the 27.1 milestone Dec 2, 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.

Flaky FIPS IT: RDSEED entropy failure causes LoginTest.loginWithRememberMeNotSet to fail

2 participants

0