Repository navigation
Stabilize FIPS in CI run - #53309
Draft
ahus1 wants to merge 1 commit into
Draft
Stabilize FIPS in CI run#53309ahus1 wants to merge 1 commit into
ahus1 wants to merge 1 commit into
Conversation
Closes keycloak#53308 Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #53308
Rationale
The FIPS IT job runs on GitHub Actions VMs where the
RDSEEDCPU instruction is unreliable — the hypervisor doesn't guarantee the hardware RNG buffer stays available under load. SinceRDSEEDis a CPU instruction executed directly in userspace by bc-fips native code, there is no way to supplement it from the kernel side (not viarng-tools,haveged, or thefake_fips.cmodule).Approach
bc-fips 2.1.3 supports
-Dorg.bouncycastle.native.cpu_variant=javaas a documented configuration to skip native library loading. When set, bc-fips uses pure-Java FIPS-validated implementations and seeds its DRBG fromSecureRandom.getInstanceStrong()(kernel DRBG //dev/urandom) instead ofRDSEED. This is set viaJAVA_OPTS_APPENDso thatkc.shpasses it to the Keycloak server JVM started by the test framework.Assumptions and decisions
cpu_variant=javais a supported mode, not a workaround. The entropy chain (SecureRandom.getInstanceStrong()→ kernel DRBG →/dev/urandom) is SP 800-90A compliant on FIPS-enabled systems.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. Usingcpu_variant=javain production would sacrifice the performance benefits of native hardware acceleration (AES-NI, native SHA, etc.) for no reason on systems where RDSEED works./proc/sys/crypto/fips_enabled=1on 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.cpu_variant=javaprevents 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 callingsetNativeEnabled(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 inFIPS1402Providerwould 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.run-fips-it.shonly. The FIPS UT script (run-fips-ut.sh) is not changed because unit tests run in the Maven JVM (not viakc.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-Dargument instead.JAVA_OPTS_APPENDpropagates correctly. Both the new test framework (DistributionKeycloakServer→ProcessBuilderinherits environment) and the old Arquillian framework (KeycloakQuarkusServerDeployableContainer→ProcessBuilderinherits environment) pass the parent environment to thekc.shchild process.kc.shappendsJAVA_OPTS_APPENDtoJAVA_OPTSat line 132-134, regardless of whetherJAVA_OPTSwas set explicitly.Dismissed alternative: automatic fallback in
FIPS1402ProviderA code-level fix was considered: in
FIPS1402Provider, after registering the BCFIPS provider, proactively test native entropy by callingSecureRandom.getInstance("DEFAULT", "BCFIPS").nextBytes(new byte[32]). If this throwsIllegalStateException(RDSEED failure), callCryptoServicesRegistrar.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 inBouncyCastleFipsProvider), which means the DRBG reseeds from the entropy source on every call tonextBytes(), 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