Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

keycloak-config-cli

> 后端框架
Open source

Import YAML/JSON-formatted configuration files into Keycloak - Configuration as Code for Keycloak.

1.2K stars0 likes1 views
WebsiteGitHub

About

Import YAML/JSON-formatted configuration files into Keycloak - Configuration as Code for Keycloak.

Table of Contents

  • Quick start
  • Help and community
  • Config Files
  • Variable Substitution
  • Logging
  • Supported Features
  • Compatibility with Keycloak
  • Build this Project
  • Run Integration Tests
  • Run this Project
  • Docker
  • Helm
  • Configuration
  • Perform Release
  • Commercial Support

keycloak-config-cli

keycloak-config-cli provides declarative, idempotent configuration for Keycloak via the Admin API—version-controlled and CI/CD-ready—covering realms, clients, roles, flows, identity providers, and more.

It is a Keycloak utility to ensure the desired configuration state for a realm based on a JSON/YAML file. The format of the JSON/YAML file is based on the Keycloak realm export format. Store and manage configuration files in Git just like normal code. A Keycloak restart isn't required to apply the configuration.

Help and community

  • Documentation: see DOCUMENTATION.md and docs/FEATURES.md
  • Report an issue: https://github.com/adorsys/keycloak-config-cli/issues
  • Security vulnerability? Please follow SECURITY.md
  • Code of Conduct: CODE_OF_CONDUCT.md
  • Questions and help: Join #keycloak-config-cli on Slack for design discussions and questions. Create an account at https://slack.cncf.io/.

Quick start

Using Docker:

bash
docker run --rm \
  -e KEYCLOAK_URL="http://localhost:8080" \
  -e KEYCLOAK_USER=admin \
  -e KEYCLOAK_PASSWORD=admin123 \
  -e IMPORT_FILES_LOCATIONS='/config/*' \
  -v "$PWD/contrib/example-config":/config \
  adorsys/keycloak-config-cli:latest

Using the JAR (after building or downloading a release):

bash
java -jar ./target/keycloak-config-cli.jar \
  --keycloak.url=http://localhost:8080 \
  --keycloak.user=admin \
  --keycloak.password=admin123 \
  --import.files.locations=./contrib/example-config/moped.json

Config files

The config files are based on the keycloak export files. You can use them to re-import your settings. But keep your files as small as possible. Remove all UUIDs and all stuff which is default set by keycloak.

moped.json is a full working example file you can consider. Other examples are located in the test resources.

Variable Substitution

keycloak-config-cli supports variable substitution of config files. This could be enabled by import.var-substitution.enabled=true (disabled by default).

Variables exposed by spring boot (through configtree or external configuration) can be accessed by $(property.name).

In additional, the string substitution support multiple prefixes for different approaches

…

to replace the values with java system properties or environment variables. Recursive variable replacement like $(file:UTF-8:$(env:KEYCLOAK_PASSWORD_FILE)) is enabled by default if import.var-substitution.enabled is set to true.

JavaScript Evaluation

keycloak-config-cli supports an explicit JavaScript evaluation phase. This is an opt-in feature and can be enabled by import.var-substitution.script-evaluation-enabled=true.

Syntax: $${javascript: ... }

Example:

json
{
  "realm": "$${javascript: 'realm-' + (env.APP_ENV || 'default').toLowerCase()}",
  "enabled": "$${javascript: env.APP_ENV === 'INT'}",
  "sessionTimeout": "$${javascript: 2 * 60 * 60}"
}

The evaluation is sandboxed and only has access to an env object containing all environment variables and system properties. Only JSON-serializable outputs are allowed (string, number, boolean, null, array, object).

The variable substitution is running before the json parser gets executed. This allows json structures or complex values.

See docs/javascript-substitution.md for more information.

See Apache Common StringSubstitutor documentation for more information and advanced usage.

Note: Since variable substitution is a part of the keycloak-config-cli, it's done locally. This means, the environment variables need to be available where keycloak-config-cli is executed.

If import.var-substitution.prefix=${ and import.var-substitution.suffix=} (default in keycloak-config-cli 3.x) is set, then keycloak builtin variables like ${role_uma_authorization} needs to be escaped by $${role_uma_authorization}.

Logging

JSON logging support

keycloak-config-cli supports logging in JSON format. To enable, set SPRING_PROFILES_ACTIVE=json-log.

Log level

CLI Option ENV Variable Description Default
--logging.level.root LOGGING_LEVEL_ROOT define the root log level info
--logging.level.keycloak-config-cli LOGGING_LEVEL_KEYCLOAKCONFIGCLI log level of keycloak-config-cli components value of logging.level.root
--logging.level.http LOGGING_LEVEL_HTTP log level http requests between keycloak-config-cli and Keycloak value of logging.level.root
--logging.level.realm-config LOGGING_LEVEL_REALMCONFIG if set to trace, the realm config including sensitive information will be logged value of logging.level.root

Supported features

See: docs/FEATURES.md

Compatibility with keycloak

Since keycloak-config-cli 4.0 will support the latest 4 releases of keycloak, if possible. There are some exceptions:

  • keycloak-config-cli will try the keep an extended support for RH-SSO
  • keycloak-config-cli will cut the support if keycloak introduces some breaking changes

Build this project

keycloak-config-cli using maven to build and test keycloak-config-cli. In case maven is not installed on your system, the mvnw command will download maven for you.

Further development requirements

  • Java Development Kit (JDK)
  • Docker Desktop or an alternative replacement (e.g Rancher Desktop)

Before running mvn verify, you have to set the JAVA_HOME environment variable to prevent some test failures.

bash
./mvnw verify

# Windows only
mvnw.cmd verify

If your are working with a Docker Desktop replacement, some of the Integrationtests can fail due to internal DNS Lookups (host.docker.internal is not reachable). In this case the host can be replaced by a property.

bash
mvn verify -DJUNIT_LDAP_HOST=an.alternate.host.or.ip

Run integration tests against real keycloak

We are using TestContainers in our integration tests. To run the integration tests a configured docker environment is required.

bash
./mvnw verify

# Windows only
mvnw.cmd verify

Run this project

Start a local keycloak on port 8080:

bash
docker-compose down --remove-orphans && docker-compose up keycloak

before performing following command:

bash
java -jar ./target/keycloak-config-cli.jar \
    --keycloak.url=http://localhost:8080 \
    --keycloak.ssl-verify=true \
    --keycloak.user=admin \
    --keycloak.password=admin123 \
    --import.files.locations=./contrib/example-config/moped.json

Docker

A docker images is available at DockerHub (docker.io/adorsys/keycloak-config-cli) and quay.io (quay.io/adorsys/keycloak-config-cli)

Available docker tags

Tag Description
latest latest available release of keycloak-config-cli which is built against the latest supported Keycloak release.
latest-x.y.z latest available release of keycloak-config-cli which is built against the Keycloak version x.y.z.
edge latest commit on the main branch and which is built against the latest supported Keycloak release.
a.b.c keycloak-config-cli version a.b.c which is built against the latest supported Keycloak release.
a.b.c-x.y.z keycloak-config-cli version a.b.c which is built against the Keycloak version x.y.z.
maven See below

Additionally, the tag maven contains the source code and compile keycloak-config-cli at runtime. This has the advantage to keycloak-config-cli with Keycloak versions, that not official supported., e.g.:

bash
docker run --rm -ti -v $PWD:/config/ -eKEYCLOAK_VERSION=23.0.1 -eMAVEN_CLI_OPTS="-B -ntp -q" adorsys/keycloak-config-cli:edge-build

Docker run

For docker -e you have to replace dots with underscores.

bash
docker run \
    -e KEYCLOAK_URL="http://:8080/" \
    -e KEYCLOAK_USER="" \
    -e KEYCLOAK_PASSWORD="" \
    -e KEYCLOAK_AVAILABILITYCHECK_ENABLED=true \
    -e KEYCLOAK_AVAILABILITYCHECK_TIMEOUT=120s \
    -e IMPORT_FILES_LOCATIONS='/config/*' \
    -v :/config \
    adorsys/keycloak-config-cli:latest

Docker build

You can build an own docker image by running

bash
docker build -t keycloak-config-cli .

Helm

We provide a helm chart here.

Since it makes no sense to deploy keycloak-config-cli as standalone application, you could add it as dependency to your chart deployment.

Checkout helm docs about chart dependencies!

Configuration

CLI option / Environment Variables

Keycloak options

CLI Option ENV Variable Description Default Docs
--keycloak.url KEYCLOAK_URL Keycloak URL including web context. Format: scheme://hostname:port/web-context. -
--keycloak.user KEYCLOAK_USER login user name admin
--keycloak.password `KEYCLOAK_PA

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaautomationconfiguration-as-codeconfiguration-managementcontinuous-integration

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架