8000 Keycloak does not work on systems with FIPS mode enabled · Issue #9916 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Keycloak does not work on systems with FIPS mode enabled #9916

Closed

Description

@JPercivall

Describe the bug

When system wide crypto policy is set to FIPS there are issues with running Keycloak. This has recently surfaced as RHEL, Fedora, and CentOS has changed the way OpenJDK behaves in this regard. Previously FIPS had to be explicitly enabled for OpenJDK, but is now enabled by default when system-wide policies are configured to conform to FIPS 140-2.

With OpenJDK configured with FIPS conformance there are a number of things not working properly in Keycloak, which is somewhat to be expected as Keycloak has never had official FIPS support.

This issue is limited to ability to run Keycloak on a FIPS enabled system, and not to support FIPS compliance in Keycloak. For FIPS 140-2 support within Keycloak see #9967.

Original JIRA: https://issues.redhat.com/browse/KEYCLOAK-19771

Version

All versions of Keycloak are affected and the issue surfaces rather based on the host system configuration/upgrades.

Container images published to Quay the issue happens in >=15.1.0, but does not happen in <=15.0.2. This is not caused by an issue in Keycloak, but rather the fact that the images <=15.0.2 are not updated with the latest upgrades from RHEL.

Expected behavior

Keycloak is able to run on a FIPS enabled system.

Actual behavior

add-user-keycloak script fails, and Keycloak fails to generate initial certificates. There are probably also further issues, but starting a Keycloak on a FIPS enabled system after the database has been initial at least succeeds.

How to Reproduce?

Enable FIPS mode on a RHEL or Fedora host (fips-mode-setup --enable).

Start Keycloak directly on the host, and you will get the following error:

 Error during startup: org.keycloak.component.ComponentValidationException: Failed to generate keys

Run bin/add-user-keycloak.sh -u admin and you will get the following error:

java.lang.RuntimeException: PBKDF2 algorithm not found

Starting Keycloak as a container with -e KEYCLOAK_USER=user -e KEYCLOAK_PASSWORD=pass results in the PBKDF2 algorithm not found error, while interestingly enough not setting these environment variables the container starts successfully, which is different behaviour to running Keycloak from a ZIP where the failed to generate keys error occurs at startup.

Workaround

Until FIPS is supported by Keycloak, FIPS has to be disabled for Java to make it possible to run Keycloak on systems with FIPS mode enabled.

For bear-metal/ZIP installations use the JAVA_OPTS_APPEND to set -Dcom.redhat.fips=false. For example:

export JAVA_OPTS=-Dcom.redhat.fips=false
bin/kc.sh start-dev

For containers use the JAVA_OPTS_APPEND to set -Dcom.redhat.fips=false. For example:

podman run -p 8080:8080 -e JAVA_OPTS_APPEND="-Dcom.redhat.fips=false" -e KEYCLOAK_ADMIN=<user> -e KEYCLOAK_ADMIN_PASSWORD=<pass> quay.io/keycloak/keycloak

Activity

  1. rush2sk8 commented on Dec 13, 2021

    @rush2sk8

    I too am having this issue. I am running keycloak in a kubernetes environment and it immediately fails and restarts with "java.lang.RuntimeException: PBKDF2 algorithm not found"

  2. transferred this issue fromkeycloak/keycloakon Dec 22, 2021
  3. wjorda commented on Dec 23, 2021

    @wjorda

    This is preventing us from upgrading from 15.0.2 to 16.0.0 running in Kubernetes.
    Given that there is now a CVE (https://access.redhat.com/security/cve/CVE-2021-4133) related to 15.1.1 and below, this issue is of critical importance.

  4. rush2sk8 commented on Dec 30, 2021

    @rush2sk8

    I had a temporary fix by just using 15.0.1 for my base keycloak image.

  5. stianst commented on Jan 3, 2022

    @stianst
    Contributor

    Not sure what's going on here, but I'm not able to reproduce this issue. Can someone provide steps to reproduce this?

  6. Etherchannel01 commented on Jan 3, 2022

    @Etherchannel01

    Would like to add in that I am experiencing the same issue on Openshift when using the operator for version 16.0.0. I will deploy a new keycloak instance with the operator, postgres will come up fine, keycloak pod will attempt to start but instantly crashes with the error "java.lang.RuntimeException: PBKDF2 algorithm not found"

  7. wjorda commented on Jan 3, 2022

    @wjorda

    Not sure what's going on here, but I'm not able to reproduce this issue. Can someone provide steps to reproduce this?

    Using the command from the Docker guide:

    ❯❯❯ docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:16.1.0
    Unable to find image 'quay.io/keycloak/keycloak:16.1.0' locally
    16.1.0: Pulling from keycloak/keycloak
    Digest: sha256:e7b6b1e3ae049a18498763410579b9619cd8c3277b3edc95844701af1cb42fc6
    Status: Downloaded newer image for quay.io/keycloak/keycloak:16.1.0
    java.lang.RuntimeException: PBKDF2 algorithm not found
    

    This appears to affect all container versions newer than 15.0.1. Looks like a problem with the generate users script based on the research done above and my own personal experience. Omitting the environment variables from the command above allowed my cluster to start up.

  8. wjorda commented on Jan 4, 2022

    @wjorda

    Update: I tested on a non-FIPS system and it worked as normal.

    Per Red Hat Support (https://access.redhat.com/solutions/6484731) it looks like the issue is related to FIPS being enabled on the host's kernel. We are running Docker on a hardened CentOS 8 with FIPS enabled.

    Unfortunately disabling FIPS (even temporarily) is not an option for us, so that will make implementing the documented workarounds difficult.

  9. wjorda commented on Jan 5, 2022

    @wjorda

    Running on the affected host with com.redhat.fips=false in JAVA_OPTS (passed in via the containers environment variables) to disable FIPS mode in the JVM also works.

    We have been running with FIPS enabled since v10 without major issues until the 15.0.2 release. We use LDAPS for user storage so the add-keycloak-user.sh script typically only gets called at startup and further user authentication is handled by our directory server. I am not an expert on this but my understanding is that enabling FIPS in the host's kernel causes the JVM in the container to run under FIPS mode by default as well (https://access.redhat.com/articles/5895481).

  10. rx294 commented on Jan 7, 2022

    @rx294
  11. stianst commented on Jan 7, 2022

    @stianst
    Contributor

    @stianst the RHEL UBI8 based images we use inherits host FIPS mode and enforces it within containers.

    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/security_hardening/using-the-system-wide-cryptographic-policies_security-hardening (Section 5.4)

    Thanks, should be possible to easily reproduce this issue then by enabling FIPS in a container. Got no clue why PBKDF2 wouldn't be available though as FIPS doesn't cover password hashing algorithms.

  12. rush2sk8 commented on Jan 10, 2022

    @rush2sk8

    We are also running 15.0.2 in a container in a hardened FIPS enabled Centos 7 machine and can confirm this is the issue.

  13. rwd5213 commented on Jan 12, 2022

    @rwd5213

    There is some related errors when running keytool when setting up TLS such as putting certs in /etc/x509/https. Saw two different keytool errors:
    keytool error: java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY
    keytool error: java.io.IOException: parseAlgParameters failed: PBE AlgorithmParameters not available

    adding that same flag -J-Dcom.redhat.fips=false to the keytool commands in /opt/jboss/tools/x509.sh script mitigates the errors.

    Saw this in 16.1.0 on a Centos 7 FIPS enabled instance.

  14. 29 remaining items

  15. archoversight commented on Jun 10, 2022

    @archoversight

    The work-around of setting JAVA_OPTS_APPEND doesn't work on the 18.0.0-legacy container as the flag is never used when executing the /opt/jboss/keycloak/bin/add-user-keycloak.sh script.

  16. archoversight commented on Jun 10, 2022

    @archoversight

    There is some related errors when running keytool when setting up TLS such as putting certs in /etc/x509/https. Saw two different keytool errors: keytool error: java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY keytool error: java.io.IOException: parseAlgParameters failed: PBE AlgorithmParameters not available

    adding that same flag -J-Dcom.redhat.fips=false to the keytool commands in /opt/jboss/tools/x509.sh script mitigates the errors.

    Saw this in 16.1.0 on a Centos 7 FIPS enabled instance.

    Adding -storetype jks to the key tool command invocation also fixes this issue.

  17. modified the milestones: 19.0.0, 20.0.0 on Jul 26, 2022
  18. trixpan commented on Aug 13, 2022

    @trixpan
    Contributor

    hello there @JPercivall :-)

  19. skyllarr commented on Sep 29, 2022

    @skyllarr

    I was able to fix this error keytool error: java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY by running the keytool command with sudo

    8
  20. assigned and unassigned on Oct 6, 2022
  21. mposolda commented on Oct 18, 2022

    @mposolda
    Contributor

    I am resolving this issue as Keycloak 20 distribution will contain initial support for FIPS . The details are in this README: https://github.com/keycloak/keycloak/blob/main/docs/fips.md .

    There are still some limitations and it is possible that some functionalities won't work as expected (in the testsuite, we see errors related to SAML, X509 authentication and Kerberos/SPNEGO authentication). As the FIPS support is still work in progress.

    For the details around FIPS work, you can take a look at the project: FIPS 140-2 (view)

    The feedback is welcome. Feel free to create new GH issue if you find further issues in the Keycloak 20 release related to FIPS support (not yet released, but will be probably by the end of October). When you create such GH issue, feel free to comment here with the reference to new issue and feel free to tag me directly in this GH comment (or in the new GH issue).

  22. isaacjensen commented on Nov 3, 2022

    @isaacjensen

    Hey @mposolda, the Trellix team would like some credit for contributions made. Are these listed anywhere? Do we plan to have contributors called out for this FIPS effort?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/coreCore server — startup, configuration, providers/SPIs, cross-cutting concernskind/bugCategorizes a PR related to a bug

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0