Keycloak with Quarkus: Better together

Starting with released version 17.0.0, the default Keycloak distribution is now based on Quarkus. As a result, the WildFly based distribution is marked as deprecated. To ensure a smooth migration the legacy distribution will continue to be supported until June 2022.
The main advantages of Keycloak with Quarkus are:
- Immutability of containers
- Faster startup, and smaller footprint
- Significantly simplified configuration
For those who don’t know Keycloak, in short, it provides the following features:
- It acts as an identity provider supporting standards like OAuth, OpenID Connect, and SAML 2.0.
- Keycloak provides local user storage and adapters to integrate other user bases (for instance LDAP).
- It can integrate 3rd party identity providers.
- It provides an administration UI and a REST API for configuration.
In this article, I will describe the new configuration options and ways to install Keycloak. This covers both, productive use and development purposes.
How to install Keycloak with Quarkus
To install Keycloak as Quarkus distribution you have a choice of different options:
- Install on bare metal
- Running using Docker or Podman
- Deploy on Kubernetes
In the further course of this article, I will guide you through the bare metal installation option.
Installation on bare metal
Running and configuring Keycloak with Quarkus
- Run Keycloak in development mode (just for quick local prototyping or general local development)
- Run Keycloak in production mode (as the name suggests: For secure productive purposes)
- Via command-line option as part of kc.sh or kc.bat command (e.g. –db-url-host=myhost)
- By setting an environment variable (i.e. set KC_DB_URL_HOST=myhost)
- By specifying the configuration option in the configuration file conf/keycloak.conf (e.g. db-url-host=myhost)
Run Keycloak in Development Mode
1 |
bin/kc.sh start-dev |


Run Keycloak in Production Mode
1 |
bin/kc.sh start |
1 |
bin\kc.bat start |
- Enabling TLS: As Keycloak exchanges sensitive data (like access tokens), all communication needs to use a secure communication channel. Hence, you must enable HTTP over TLS, or HTTPS.
- Setting the hostname for Keycloak: When running Keycloak in productive environments, you have to set the public-facing internet hostname.
- Configure a production-grade database: The database used by Keycloak is crucial for the overall performance, availability, reliability, and integrity. Therefore, it is needed to use a production-ready database like PostgreSQL or MySQL instead of H2.
Please look into the guide for production configuration for further details.
Enabling TLS
Keycloak by nature uses sensitive data like access tokens. As a result, Keycloak should transmit any data over a secured transport layer only. Therefore using TLS and HTTPS is mandatory for production mode.
Set up a local CA
1 |
mkcert -install |
Generate the certificate
- Change into the Keycloak directory.
- Create a new subdirectory called tls.
- Change into this subdirectory, and then use the following command:
1 |
mkcert localhost keycloak.local |
When looking into the tls subdirectory you will find the following files:
- localhost 1.pem (the certificate)
- localhost 1-key.pem (the private key)
To make it easier later just rename the files to localhost.pem and localhost-key.pem.
- –https-certificate-file=/opt/keycloak-17.0.0/tls/localhost.pem (replace with your path to the certificate file)
- –https-certificate-key-file=/opt/keycloak-17.0.0/tls/localhost-key.pem (replace with your path to the key file)
- –https-protocols=TLSv1.3,TLSv1.2 (the currently recommended TLS protocol versions)
Setting the hostname
- Frontend Endpoints: Frontend endpoints are used to externally access Keycloak. When no hostname is set, the base URL used for the frontend is taken from the incoming request.
- Backend Endpoints: Backend endpoints are used for direct communication between Keycloak and applications like for instance the Token endpoint. Backend endpoints are also taking the base URL from the request by default.
- Administrative Endpoints: To further reduce the attack surface, the administration endpoints for Keycloak and the Admin Console should not be publicly accessible. Therefore, you can secure them by using a reverse proxy. By specifying –hostname-admin=<adminHostname> you can separate the administrative part from the other parts.
- –hostname=keycloak.local:8443 (this sets the hostname with the required port for HTTPS)
- –hostname-strict-backchannel=true (this forces all requests to use the specified hostname and not the URL from the request)
Configure a production-grade database
- MariaDB
- Microsoft SQL Server
- MySQL
- Oracle
- PostgreSQL
1 |
bin/kc.sh build --db postgres |
- –db-url-host=127.0.0.1 (the database hostname or IP address)
- –db-url-database=keycloak (the name of the database to use)
- –db-username=keycloak (the user authorized to connect to the database)
- –db-password=keycloak (the corresponding password for the user)
Startup the productive Keycloak server
In this final section, we are able to start Keycloak in production mode. Let’s see what the corresponding command looks like.
1 |
bin/kc.sh start --https-certificate-file=/opt/keycloak-17.0.0/tls/localhost.pem --https-certificate-key-file=/opt/keycloak-17.0.0/tls/localhost-key.pem --https-protocols=TLSv1.3,TLSv1.2 --db-url-host=127.0.0.1 --db-url-database=keycloak --db-username=keycloak --db-password=keycloak --hostname=keycloak.local:8443 --hostname-strict-backchannel=true |


1 2 |
export KEYCLOAK_ADMIN=admin export KEYCLOAK_ADMIN_PASSWORD=secret |
Final words
- Describing more configuration options like using a reverse proxy or setting up cluster mode
- A walk through the administration interface of Keycloak
- Creating an OAuth / OpenID Connect client.
- And much more
Comment article
Recent posts





Comments
Indiphile
Your article is perfect. Thank you.
Iulian Peca
Hello,
Thanks for the nice article. If I have a cluster of 3 nodes (let’s say node1.local.com,node2.local.com,node3.local.com,) with a loadbalancer in front for internal access (lb-internal.local.com, like communication with application) and another loadbalancer (lb-external.local.com) for external access, what is the hostname that I should use?
Jon Cruz
Thanks for sharing these steps/instructions.
I was looking at upgrading my Keycloak v14 instances when I noticed the switch from WildFly to Quarkus.
This article gives me more than a head start on doing so, and I’m looking forward to you next posts.