- Install docker
- Install docker compose
- Add your user to the docker group
sudo usermod -aG docker user_name
- Run the container from the project root directory
docker compose up -d
You can use this website to test your login functionality
-
https://www.keycloak.org/app/#url=http://localhost:8080&realm=cirg&client=app Or directly via
-
http://localhost:8080/realms/cirg/account/#/ (click sign in)
-
Accounts
- Importing and Exporting Realms
- Creating a customized and optimized container image
- Configuring Keycloak for production
- Main doc (log): Google docs log
- Must use standard quay.io/keycloak/keycloak
- No build tools/infrastructure outside the repository - besides docker
- Auto configuration for repository
- Consider Jars for Providers
- POC should use CSS, and migrated to SCSS
- Themes should not have cache off on production
- Keycloak 22
- JDK 17
- Gradle 7
- Scattered repositories
- Methodology that could improve to centralize and standardize development/deployment
- Standard code structure
- Standard build process
- Standard deployment
- Standard env variables, as LOG4J_FORMAT_MSG_NO_LOOKUPS: "true" for CVE-2021-44228
- Docker compose size reduction as a side effect
- Standard start scripts, as docker-entrypoint-override
- Non-standard scripts outside the codebase repositories, living in the infrastructure repository
- Overuse o freemarker - 35:1
- Some templates are version specific and this results in harder to maintain codebases
- Freemarker is a heavy language for servers, and the servers are currently overloaded
- Server parameters that should not go live and can be replaced for development by server start command
-
<theme> <staticMaxAge>-1</staticMaxAge> <cacheThemes>false</cacheThemes> <cacheTemplates>false</cacheTemplates> </theme>
Run default image for development if needed
docker run quay.io/keycloak/keycloak start-dev
Add the docker group to the user if necessary
sudo usermod -aG docker user_name
Use docker-compose to run the server (no build required)
docker compose up -d
Use the following command depending on your setup, if docker-compose is in your path
docker-compose up -d
These commands will import and export realms and users, while providing two main modes of operation.
The recommended mode is offline in which KC will proceed with a direct approach based on kc.sh
, assuming KC is stopped.
Along with KEYCLOAK_BACKUP_ON_SIGTERM set to true, the offline mode will stop KC before proceeding and follow a direct approach with kc.sh
.
This recommendation came from the simplicity of this operation, while increasing safety and consistency. Please note Importing and Exporting Realms.
The import command in the offline mode will not request the server to stop, as it is meant to run before it starts.
The other mode will use the API to import/export data, being more complex in consideration of concerns like cache and data format.
Export users while the container is up and needs to keep running
docker compose exec keycloak /opt/keycloak/sbin/export.sh
Export users while the container is up/down and needs to stop
docker compose exec keycloak /opt/keycloak/sbin/export.sh --offline
Import users while the container is up and needs to keep running
docker compose exec keycloak /opt/keycloak/sbin/import.sh
Import users while the container is up/down and needs to stop
docker compose exec keycloak /opt/keycloak/sbin/import.sh --offline
Three key environment variables control the behavior of the backup and restore processes:
-
KEYCLOAK_BACKUP_ON_SIGTERM:
- This variable, when set to
true
, activates the backup process upon receiving a SIGTERM signal (typically during a container shutdown). - If enabled, the script responsible for handling the SIGTERM signal will trigger an export of Keycloak data, storing it in this backup directory.
- Usage scenario: Primarily used in development environments for preserving data across container restarts or redeployments.
- This variable, when set to
-
KEYCLOAK_BACKUP_RESTORE:
- When set to
true
, this variable enables the restoration of Keycloak data from the backup directory at the startup of the Keycloak container. - If enabled, a script will import data from the backup files located in this directory into Keycloak during the container's initialization process.
- Usage scenario: Useful for initializing Keycloak with pre-existing data, especially after a fresh deployment or in development/testing environments.
- When set to
-
KEYCLOAK_STARTUP_IMPORT:
- When set to
true
, KC will start with "--import-realm". This will ask KC to import the data from/opt/keycloak/data/import
during the initial stages of the boot process. - This process can import data created by the offline mode provided by the export script or by kc.sh.
- When set to
All variables default to false, and they can be used if needed, otherwise, the backup command options should be enough for manual operations.
This repository is structured to facilitate efficient development workflows, with directories designated for specific development purposes. Here's an overview of the key directories:
- Structure: Adheres to the
<module>/src/<main|test>/<language>
format. - Example: A Java module named
example
would have its main source code inexample/src/main/java
.
- Location:
modules/themes
- Purpose: Houses theme development files.
- Structure: Follows
themes/<theme name>/<theme types>
format. - Example:
modules/themes/cirg/login
contains the login part sources for thecirg
theme.
- Location:
lib
- Purpose: Houses additional libraries that might be needed.
- Structure: Follows
lib/<library name>
format. - Example:
lib/groovy
.
- Purpose: Contains initial data for starting development containers.
- Location:
data/import
- Contents: Includes configuration files, database seeds, etc.
- Purpose: Stores backup data created for export/import routines and serves as a mount point for (
/opt/keycloak/backup
). - Location:
data/backup
- Configuration: Refer to the example below for setting up the backup directory in Docker Compose.
# Docker Compose setup example for the backup directory
volumes:
backup:
# Configuration details here
-
- Future - Keycloak dev (keycloak-dev.cirg.washington.edu)
- Future - Keycloak test (keycloak-test.cirg.washington.edu)
- Keycloak alpha (keycloak-alpha.cirg.washington.edu)
-
- Keycloak production (keycloak.cirg.washington.edu)
- Keycloak dev (keycloak-dev.cirg.washington.edu)
- Keycloak test (keycloak-test.cirg.washington.edu)
Gitlab - from 2020 - deprecated Private repo
Github - from 2022 Public repo
- dcw-environments
- helloworld-environments
- The "dcw" and "cosri" systems were intended to extend this.
Github - from 2024 Public repo