The purpose of this document is to guide you through the installation process of the Keycloak. This identity and access management tool is used by Gazelle tools to authenticate users.
Keycloak should be run inside a Docker container.
Keycloak will use a PostgreSQL database. You will need to report the configuration in the environment variables needed at runtime.
su postgresql
psql
postgres=# CREATE USER keycloak;
postgres=# ALTER USER keycloak WITH ENCRYPTED PASSWORD 'keycloak';
postgres=# CREATE DATABASE "keycloak" OWNER keycloak;
postgres=# \q
exit
As SQL :
CREATE USER keycloak;
ALTER USER keycloak WITH ENCRYPTED PASSWORD 'keycloak';
CREATE DATABASE "keycloak" OWNER keycloak;
Database is initialized by Keycloak at runtime.
Clone gazelle-keycloak projet.
Follow instructions given in README.md.
“gazelle” realm is configured as in this guide.
Installation can be performed on a system with Docker.
Keycloak is deployed using docker-compose in this guide, but can run in any orchestrator or plain Docker daemon.
Use the following Dockerfile as a base for your Docker image :
FROM quay.io/keycloak/keycloak:18.0.0
USER root
# install wget
RUN microdnf install -y wget
USER keycloak
# create a certificate for serving HTTPS
RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore
# activate metrics & health endpoints
ENV KC_METRICS_ENABLED=true
ENV KC_HEALTH_ENABLED=true
# Keycloak will use a Postgres database
ENV KC_DB=postgres
ENV GAZELLE_KEYCLOAK_VERSION=1.2.4
# Gazelle specific stuff
# CAS protocol support
RUN wget -O /opt/keycloak/providers/gazelle-keycloak-cas-protocol.jar "https://gazelle.ihe.net/nexus/service/local/repositories/releases/content/net/ihe/gazelle/keycloak/gazelle-keycloak-cas-protocol/${GAZELLE_KEYCLOAK_VERSION}/gazelle-keycloak-cas-protocol-${GAZELLE_KEYCLOAK_VERSION}.jar"
# Gazelle user federation
RUN wget -O /opt/keycloak/providers/gazelle-keycloak-provider.jar "https://gazelle.ihe.net/nexus/service/local/repositories/releases/content/net/ihe/gazelle/keycloak/gazelle-keycloak-provider/${GAZELLE_KEYCLOAK_VERSION}/gazelle-keycloak-provider-${GAZELLE_KEYCLOAK_VERSION}.jar"
# Gazelle theme
RUN wget -O /opt/keycloak/providers/gazelle-keycloak-theme.jar "https://gazelle.ihe.net/nexus/service/local/repositories/releases/content/net/ihe/gazelle/keycloak/gazelle-keycloak-theme/${GAZELLE_KEYCLOAK_VERSION}/gazelle-keycloak-theme-${GAZELLE_KEYCLOAK_VERSION}.jar"
RUN /opt/keycloak/bin/kc.sh build
Configuration is performed using environment variables.
It might be needed to mount some files in container for some cases (TLS certificates, …).
Here is a docker-compose.yml configuring Keycloak in a typical environment :
version: "3.9"
services:
keycloak:
# location of Dockerfile
build: .
restart: on-failure
volumes:
# folder containing certificates
# - "/etc/letsencrypt:/etc/letsencrypt:ro"
environment:
# Keycloak admin user
# Created on first start
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
# Connection to Keycloak DB
KC_DB_URL: jdbc:postgresql://postgres:5432/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: keycloak
# Keycloak is running behind a reverse proxy, reencoding TLS
KC_PROXY: reencrypt
KC_HOSTNAME: keycloak.localhost
# if Keycloak is served in a relative path via reverse proxy
# KC_HTTP_RELATIVE_PATH: /auth
# HTTPS certificate as PEM files
# KC_HTTPS_CERTIFICATE_FILE: /etc/letsencrypt/keycloak.crt
# KC_HTTPS_CERTIFICATE_KEY_FILE: /etc/letsencrypt/keycloak.key
For more specific configurations and edge cases, refer to Keycloak Guides :
Once Keycloak is started, it needs to be configured before being used against Gazelle suite.
First, connect to Keycloak :
/admin/KEYCLOAK_ADMIN/KEYCLOAK_ADMIN_PASSWORDOnce connected, add a realm by clicking “Add realm” from realm selector :

Select a name for your realm, gazelle is a good choice. Then click on “Create”.

First, let’s add a user federation source to check everything is OK. Click on “User Federation” menu item, select “gazelle-user-provider”.

Configure the provider, letting it connect to Test Management database.
userinfo OIDC endpoint to retrieve roles (ex : Rocket.chat)gazelle_role=keycloak_roleDB configuration is checked when user federation configuration is saved.

Now it is possible to list users from Gazelle in “Users” menu entry.

Also, a group has been created for each institution linked to fetched users. The group name is the institution keyword.

Now let’s focus on realm configuration. Click on “Realm settings”.

In login tab, make important changes :

Configuration the SMTP server.

Change Themes settings :

User can access its account with http(s)://<keycloak hostname>/realms/gazelle/account.
In any case, user will not be able to change username, email and name. These are managed by Gazelle user federation.
A user should still be able to activate OTP or change its password.
Account modification is allowed if user has role manage-account in account client.
Click on “Roles” in menu.
Click on “default-roles-gazelle”.

Select “Default Roles” tab and select “account” in “Client Roles”.
Add manage-account to “Client Default Roles” by clicking on “Add selected »”.

For applications being able to use Keycloak to connnect, clients must be created. Clients are configured by clicking on “Clients” in menu.

For using Keycloak with legacy applications using CAS, click on “Create” on upper left.
Click on Save

Now configure the CAS client.

We want roles and institutions in CAS ticket for legacy applications.
Click on “Create” to create a new mapper

Add a mapper for Gazelle roles :

Add a mapper for Gazelle institution :

CAS protocol is now ready to be used with following URLS :
http(s)://<keycloak hostname>/realms/gazelle/protocol/cas/loginhttp(s)://<keycloak hostname>/realms/gazelle/protocol/cas/logoutFor using Keycloak with an application supporting OIDC, click on “Create” on upper left.
Click on Save

Now configure the OIDC client.

We want roles and institutions in tokens and userinfo endpoint.
Click on “Create” to create a new mapper

Add a mapper for Gazelle roles :

Add a mapper for Gazelle institution :

OIDC client is now ready to be used with following configuration :
http(s)://<keycloak hostname>/realms/gazelle/.well-known/openid-configurationhttp(s)://<keycloak hostname>/realms/gazelle/protocol/openid-connect/authhttp(s)://<keycloak hostname>/realms/gazelle/protocol/openid-connect/tokenhttp(s)://<keycloak hostname>/realms/gazelle/protocol/openid-connect/userinfo